-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize Date Parsing in calculateMostActiveDay #513
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
Open
is0692vs
wants to merge
1
commit into
main
Choose a base branch
from
perf-optimize-date-parsing-6923459134969605479
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,14 +89,20 @@ function calculateStreaks(calendar: { count: number }[]): { longestStreak: numbe | |
| } | ||
|
|
||
| function calculateMostActiveDay(calendar: { date: string; count: number }[]): string | null { | ||
| if (calendar.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; | ||
| const weekdayTotals = Array.from({ length: 7 }, () => 0); | ||
| const startDay = new Date(`${calendar[0].date}T00:00:00Z`).getUTCDay(); | ||
|
|
||
| for (const day of calendar) { | ||
| for (let i = 0; i < calendar.length; i++) { | ||
| const day = calendar[i]; | ||
| if (day.count === 0) { | ||
| continue; | ||
| } | ||
| const weekday = new Date(`${day.date}T00:00:00Z`).getUTCDay(); | ||
| const weekday = (startDay + i) % 7; | ||
| weekdayTotals[weekday] += day.count; | ||
|
Comment on lines
+98
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Invalid first date poisons calculateMostActiveDay now computes all weekdays from calendar[0].date; if that first date is invalid, startDay becomes NaN and all contributions are accumulated into a non-numeric array property, causing the function to return null even when later days have valid dates and counts. Agent Prompt
|
||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Hiroki-org/github-user-summary
Length of output: 23085
🏁 Script executed:
Repository: Hiroki-org/github-user-summary
Length of output: 32996
🌐 Web query:
GitHub GraphQL contributionCalendar contributionDays date order💡 Result:
In the GitHub GraphQL API, the contribution calendar data is structured hierarchically, and the order of contribution days is deterministic based on the calendar timeline [1][2]. Within the contributionCalendar object, data is organized as follows: 1. Weeks: The contributionCalendar field contains a weeks list (ContributionCalendarWeek) [1][2]. This list is ordered chronologically by time, with each week representing a distinct seven-day period [1][2]. 2. Days: Each ContributionCalendarWeek object contains a contributionDays list (ContributionCalendarDay) [1][2]. Within each week, the days are ordered chronologically, starting from the first day of that week [1][2]. Each day object includes a date field, which allows you to programmatically verify the chronological sequence [1][2]. You can retrieve this information by querying the user's contributionsCollection [3][4]. Since the API returns these objects in an ordered array structure (weeks followed by the days within those weeks), you do not need to perform manual sorting to maintain the chronological order of the calendar [1][4].
Citations:
曜日を
day.dateから取得してください。calculateMostActiveDay()はstartDay + iで実際に存在しない曜日にカウントを加算します。calendarが昇順でも欠落日を含む場合は曜日より大きなズレになります。週境界を超えて連続していない日付でのmostActiveDay検証を追加してください。🤖 Prompt for AI Agents