Skip to content

✨ Add "Compare with past me" feature - #36

Open
kidager wants to merge 2 commits into
techinpark:mainfrom
kidager:feature/compare-with-past-self
Open

✨ Add "Compare with past me" feature#36
kidager wants to merge 2 commits into
techinpark:mainfrom
kidager:feature/compare-with-past-self

Conversation

@kidager

@kidager kidager commented May 8, 2026

Copy link
Copy Markdown

What does this PR do?

Adds a self-comparison option that mirrors the existing "compare with friend" feature, but the "friend" is yourself N days ago. Lets solo users see at a glance whether today is better or worse than yesterday (or 2 days ago, a week ago, etc.).

Note: this contribution was developed with AI assistance (Claude). All code was reviewed and tested by the author before submission.

How it works

  • New menu items mirroring the friend flow:
    • Compare with past me (⌘P), prompts for an integer offset N (default 1, yesterday).
    • Change past me offset, replaces the entry once active.
    • Stop comparing with past me, hidden when off.
  • The offset is persisted under a new UserDefaults key self_compare_offset (0 = disabled, the default).
  • Reuses the same GitHub HTML response, no extra network request.
  • The welcome line updates to "vs me N day(s) ago".
  • Friend and past-me modes are mutually exclusive in the UI: enabling one clears the other to avoid ambiguity over what the day-pair column means.

Localization

en and ko Localizable.strings updated with matching keys.

Backward compatibility

Off by default. Users who don't enable it see no behavior change.

Screenshots

Compare with past me, offset = 1 (yesterday):

Screenshot 2026-05-08 at 16 45 37

Compare with past me, offset = 2:

Screenshot 2026-05-08 at 16 45 48

Default state, no friend, no self-compare:

Screenshot 2026-05-08 at 16 46 07

Testing

Manually tested on macOS by the author across the four state combinations (off, self-compare on, friend on, switching between them). The repo has no test target today, so no unit tests are included to keep the diff focused. The new parsing helper is a small addition (a daysBack parameter on parseHtmltoData) and is straightforward to cover later if a test target is added.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a 'Compare with past self' feature, allowing users to compare their current GitHub contributions with their own data from a specified number of days ago. The implementation includes new menu items, localized strings, and logic to manage the mutual exclusivity of friend and past self comparisons. Feedback focuses on maintaining Swift style consistency regarding spacing and optimizing performance by avoiding redundant HTML parsing during data fetching.

Comment thread Sources/AppDelegate.swift Outdated
Comment thread Sources/AppDelegate.swift Outdated
Comment thread Sources/AppDelegate.swift Outdated
self.myContributes = contributeDataList
self.mystreaks = self.parseHtmltoDataForCount(html: html)
if self.friendUsername.isEmpty && self.selfCompareOffset > 0 {
self.friendContributes = self.parseHtmltoData(html: html, daysBack: self.selfCompareOffset)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This call triggers a redundant full parse of the HTML string using SwiftSoup. Note that the HTML is already parsed at line 569 (for contributeDataList) and again at line 574 (for mystreaks). Adding a third parse here significantly impacts performance, especially on slower connections or larger contribution graphs.

Consider refactoring parseHtmltoData to accept a pre-parsed Document or to return the full list of contribution data so that the caller can slice it as needed without re-parsing the entire document.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. Addressed in 2a9f338 by extracting parseSortedDays(html:), which performs the SwiftSoup parse, sort, and tooltip injection once. parseHtmltoData and parseHtmltoDataForCount now take the pre-parsed [Element] and only slice/walk it. The HTML is parsed exactly once per fetch, regardless of whether self-compare is on. As a side effect, this also fixes the pre-existing 2-parse pattern (one for myContributes, one for mystreaks).

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.

1 participant