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

Rewrite night day ratio algorithm #313

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Rewrite night day ratio algorithm #313

merged 1 commit into from
Nov 15, 2024

Conversation

Yun-Wu
Copy link
Contributor

@Yun-Wu Yun-Wu commented Nov 14, 2024

Closes #314

@Yun-Wu Yun-Wu requested a review from walljcg November 14, 2024 13:56
Copy link
Contributor

@atmorling atmorling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - also xref @walljcg's offline approval of this chage

Comment on lines +59 to +79
def calculate_day_night_distance(date, segment_start, segment_end, dist_meters, daily_summary):
sunrise = daily_summary.loc[date, "sunrise"]
sunset = daily_summary.loc[date, "sunset"]

if segment_start < sunset and segment_end > sunset: # start in day and end in night
day_percent = (sunset - segment_start) / (segment_end - segment_start)
elif segment_start < sunrise and segment_end > sunrise: # start in night and end in day
day_percent = (segment_end - sunrise) / (segment_end - segment_start)
elif sunrise < sunset:
if segment_end < sunrise or segment_start > sunset: # all night
day_percent = 0
elif segment_start >= sunrise and segment_end <= sunset: # all day
day_percent = 1
else: # sunrise >= sunset
if segment_end < sunset or segment_start > sunrise: # all day
day_percent = 1
elif segment_start >= sunset and segment_end <= sunrise: # all night
day_percent = 0

daily_summary.loc[date, "day_distance"] += day_percent * dist_meters
daily_summary.loc[date, "night_distance"] += (1 - day_percent) * dist_meters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this. So much clearer 🥳

@atmorling atmorling merged commit 201af4c into master Nov 15, 2024
6 of 8 checks passed
@atmorling atmorling deleted the daynight branch November 15, 2024 12:18
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.

Rewrite day_night_ratio
2 participants