Skip to content
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

Merged
merged 1 commit into from
Aug 22, 2021

Conversation

TurnrDev
Copy link
Contributor

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.

@TurnrDev
Copy link
Contributor Author

Screenshot_20210511-203347.jpg

Copy link
Member

@westnordost westnordost left a 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.

@TurnrDev
Copy link
Contributor Author

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.

Some roads are lit day and night, so I mainly added it because of that

@TurnrDev
Copy link
Contributor Author

Thank you for the review, I will take a closer look tomorrow and see what I can do to fix it up!

@smichel17
Copy link
Member

For reference, other conversations related to displaying quests are collected here: #2789 (comment).
It might be worth giving them a skim — or not, some are quite long :P

@TurnrDev TurnrDev force-pushed the feature/sunsetlit branch from d74f847 to e5c6135 Compare May 12, 2021 21:39
@TurnrDev TurnrDev requested a review from westnordost May 13, 2021 21:56
return calendar
}

fun isNight(pos: LatLon): Boolean {
Copy link
Member

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:

  1. isNight calculates the sunset/dawn with the given latitude and longitude truncated to two decimals (precision of ~1km). That should be enough precision
  2. 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.
  3. 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 in DayNightQuestFilter

Copy link
Contributor Author

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

Copy link
Member

@smichel17 smichel17 May 21, 2021

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?

  1. 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?
  2. 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).

Copy link
Member

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.

Copy link
Member

@smichel17 smichel17 May 21, 2021

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:

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:

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).

Copy link
Member

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.

Copy link
Member

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.

@dbdean
Copy link
Contributor

dbdean commented May 21, 2021

Would it be possible to tag (like survey:atnight=yes or something) to indicate that the answer was surveyed during night time?That way we could re-ask this for roads/paths/etc that are already tagged lit but weren't surveyed at night to verify that they are actually lit at night time, and didn't just look like they should be lit.

@westnordost
Copy link
Member

Well, this is the wrong place to propose a tag like this.

@westnordost
Copy link
Member

@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

@10992-osm
Copy link

Would it be possible to tag (like survey:atnight=yes or something) to indicate that the answer was surveyed during night time?That way we could re-ask this for roads/paths/etc that are already tagged lit but weren't surveyed at night to verify that they are actually lit at night time, and didn't just look like they should be lit.

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).

@TurnrDev
Copy link
Contributor Author

TurnrDev commented Jun 7, 2021

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

@TurnrDev
Copy link
Contributor Author

TurnrDev commented Jun 8, 2021

To Do

@westnordost
Copy link
Member

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)

@dbdean
Copy link
Contributor

dbdean commented Jul 18, 2021

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.

@TurnrDev
Copy link
Contributor Author

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

@TurnrDev TurnrDev requested a review from westnordost August 21, 2021 08:11
@TurnrDev
Copy link
Contributor Author

@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 :)

@TurnrDev
Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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..

Copy link
Collaborator

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.

@westnordost
Copy link
Member

I'll also probably add a cache after merge, so the isDay will not be calculated for every single road.

@TurnrDev
Copy link
Contributor Author

I'll also probably add a cache after merge, so the isDay will not be calculated for every single road.

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.

@westnordost westnordost merged commit 03645ed into streetcomplete:master Aug 22, 2021
@smichel17
Copy link
Member

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).
…I'd be more exited about it if someone wanted to do the profiling exploration first (the most boring and most important part :P)

@westnordost
Copy link
Member

No, I am right now doing it myself but thank you for the offer

@TurnrDev TurnrDev deleted the feature/sunsetlit branch August 23, 2021 05:17
@TurnrDev
Copy link
Contributor Author

@westnordost Thank you for your improvements. I'm really not sure I would have ever figured most of that out

@westnordost westnordost mentioned this pull request Feb 13, 2022
Helium314 pushed a commit to Helium314/SCEE that referenced this pull request May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider enabling "Is lit" quest only during night
6 participants