-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only show lit quests during night-time #2872
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for displaying this option at all and not always only show those quests that should be only visible by night at night? Would make implementation a little easier, less code and less clutter in the settings menu.
It would be ideal if the app could register a callback whenever the sunset or sunrise event occurs. Maybe one of the libraries mentioned can do that. Then, the VisibleQuestsSource
could listen for that and invalidate the quests so that they are refreshed.
app/src/main/java/de/westnordost/streetcomplete/data/quest/DayNightCycle.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/de/westnordost/streetcomplete/data/osm/osmquests/OsmQuestController.kt
Outdated
Show resolved
Hide resolved
Some roads are lit day and night, so I mainly added it because of that |
Thank you for the review, I will take a closer look tomorrow and see what I can do to fix it up! |
For reference, other conversations related to displaying quests are collected here: #2789 (comment). |
d74f847
to
e5c6135
Compare
app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/DayNightQuestFilter.kt
Show resolved
Hide resolved
app/src/main/java/de/westnordost/streetcomplete/util/CheckIfNight.kt
Outdated
Show resolved
Hide resolved
return calendar | ||
} | ||
|
||
fun isNight(pos: LatLon): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I now recognize that here is a potential for a performance issue. Let's say you have 1000 quests that shall not be visible during day and they shall now be displayed on the map.
Then, the calculation in CheckIfNight
is executed 1000 times. I am not sure how expensive the calculation is, but to circumvent that, I suggest the following:
isNight
calculates the sunset/dawn with the given latitude and longitude truncated to two decimals (precision of ~1km). That should be enough precision- the calculation is cached in a dayTime: Map<LatLon, Pair<LocalTime,LocalTime>>. Only if there is no entry in the map, the calculation is done. LatLon is always the truncated latlon.
- If
isNight
is going to have a state, it would make sense to make this into a class, or maybe just put the code here inDayNightQuestFilter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst I fully agree with you, I'm not sure how to go about implementing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm… … how should this feature actually work?
- When it is detected to be after sunset at the user's current position, all lit quests appear.
- How I imagined it would work before reading the code.
- Should be synchronized with using the dark theme, if the "Auto" theme is selected.
- Simple to implement, cheap to compute.
- What if we don't have the user's current location?
- What if the user is looking (say, to see what quests are available) at a position different than their current location? Use gps or screen/scroll position?
- Lit quests appear if it is past sunset at their current location.
- How it's currently implemented, I think.
- Potential performance issues, or more complicated implemented to mitigate them.
- Might be confusing (hard to figure out when a given lit quest will appear), particularly along with the "available in 3 hours" feature suggested below.
- Might also be cool — seeing lit quests gradually appear as the sun crawls across the map. But would definitely work better if the map visualized the current sun line instead of switching all at once.
Although solution 2 is more robust, personally I'm more inclined toward solution 1 and not worrying about making the app work in those edge cases, since they are not the primary use case of StreetComplete (in-person surveying).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smichel17, if you are going to comment on the code, you should read it first before making assumptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the diff, I came across this code:
Lines 13 to 19 in e5c6135
fun isVisible(quest: Quest): Boolean { | |
return when (quest.type.dayNightCycle) { | |
DAY_AND_NIGHT -> true | |
ONLY_DAY -> !isNight(quest.position) | |
ONLY_NIGHT -> isNight(quest.position) | |
} | |
} |
Which seems to be applied per-quest. I admit I have not traced the call stack more than one step, to here:
StreetComplete/app/src/main/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSource.kt
Lines 86 to 87 in e5c6135
private fun isVisible(quest: Quest): Boolean = | |
visibleQuestTypeSource.isVisible(quest.type) && teamModeQuestFilter.isVisible(quest) && dayNightQuestFilter.isVisible(quest) |
to see if it is called differently, but I don't think my assumption — made after reading the code — was unreasonable.
It seems like I have missed something that you find obvious, but I'm honestly not sure what it is. Also happy to figure it out myself (no need for you to spend time explaining if it really is that obvious) if you want to point me in the right direction (to the code you expected I'd seen).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, maybe a misunderstanding. The way you wrote the other comment sounded like you would comment on the functionality in general as if no code had been written yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, I'd also prefer 1, but I am not going to reject this PR just because 2 and not 1 has been implemented.
If @TurnrDev or you would like to move to behavior 1 instead, I can give advice how to do that on the technical side.
app/src/main/java/de/westnordost/streetcomplete/util/CheckIfNight.kt
Outdated
Show resolved
Hide resolved
Would it be possible to tag (like |
Well, this is the wrong place to propose a tag like this. |
@TurnrDev What would be quite cool would be that if you go into the quest selection settings, it will actually show the quest as disabled and say something like "available in 3 hours" or something |
Could you not infer that from when the changeset was made? (I suppose that might not work with delayed uploads, whether due to connection issues or deliberate choice on the part of the user). |
I got in my head with imposter syndrome, I doubt this will be ready in time for v33 Gonna have to break all my to-do up into smaller tasks and focus on one at a time lol |
To Do
|
Note: If this is merged, the quest priority of lit-quests should go up, as during night, those should have higher priority (because they are easier to solve) |
I was having a thought about this PR recently. What would the plan be for lit on sports pitches? I treat the current lit quest for them as 'can this sporting pitch be lit', rather than is it lit every night like I would treat a similar quest on roads and paths. So (if I'm treating the sporting lit quest appropriately) the sporting lit quest is actually generally easier to answer in the day time as you can see the lighting poles, which might be harder to see at night if they aren't on that particular night. |
Good point, and I agree with you there. I will make changes |
@westnordost As much as I'd like to cache the result, I'm not entirely sure on how to do that! I have changed the function to isDay to resolve a bug with regards to after midnight. I'm testing it soon :) I removed AddPitchLit from the PR, @dbdean raised a good point regarding pitches I also movet the remaining lit quests to the top. Building now :) |
Squashed Commit for streetcomplete#2872
37fa7c0
to
a9f9cdf
Compare
Just tested in Alert, Nunavut, Canada which currently doesn't experience sundown. Worked fine. |
// the sake of mapping it in case it makes sense later | ||
AddPitchSurface(), | ||
AddPitchLit(), | ||
AddPitchLit(), // Not affected by new DayNight cycle because the lights are usually only on during games |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this has been requested by someone before, but I don't completely follow that logic.
The lights are usually only on during games, but only if it is dark outside, right? So, that should not change the fact that whether it is lit or not will only be possible to see when it is dark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but given how infrequent games are- It would be possible to pass by on the street when there isn't a game, see no light on and assume there aren't any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And during the daytime, it will be easier to see if there are lights at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm okay, if you agree with each other there..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the same argument apply to all the lit quests though, well in the positive direction at least, I can see street lights during the day so I should be able to tag them during the daytime. Although I appreciate marking no during the day is vaguer.
I'll also probably add a cache after merge, so the |
I was thinking it might be better to calculate for user position, but I don't know what the course of action to work that out is. |
I have a couple dev tasks I've volunteered to do, so I don't know about my bandwidth here, but besides that I'd be up to help with performance work here (caching and/or using the current map position instead of calculating for each quest individually). |
No, I am right now doing it myself but thank you for the offer |
@westnordost Thank you for your improvements. I'm really not sure I would have ever figured most of that out |
Squashed Commit for streetcomplete#2872
Fixes #1285 by working out the time of civil sunset and sunrise
It currently works via mayCreateQuest the same way blocking quests out of the country works, but that's causing that sync issue when toggling the setting. I need to move the logic to displaying the quest instead of creating the quest, I'm not so sure where that would be in the code base so any help would be appreciated.