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

feat: Add private-leaderboard command #12

Merged
merged 1 commit into from
Dec 14, 2022

Conversation

byarr
Copy link
Contributor

@byarr byarr commented Dec 11, 2022

Adds a private leaderboard command to print the results of a given private leaderboard.

Example output is similar to that on the website - but without colors or headers.

1       142     ★★★★★★★★★★★                     byarr
2       129     ★★★★★★★★★★★                     Someone else
3       125     ★★★★★★★★★★★                     anonymous user #122345
4       108     ★★★★★★★★★★★                     Bob Jones
5       87      ★★★★★★★★★★★                     Jane Doe
6       83      ★★★★★★★★★★★                     abcdef
7       78      ★★★.★★★★★★★                     anonymous user #12344
8       28      ★★★★★★.....                     Some one

@scarvalhojr
Copy link
Owner

That looks great, thank you!

@@ -317,3 +320,103 @@ pub fn read(
println!("\n{}", from_read(desc.as_bytes(), col_width));
Ok(())
}

fn get_private_leaderboard_results(
args: &Args,
Copy link
Owner

Choose a reason for hiding this comment

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

We don't need args here

}

#[derive(Deserialize)]
struct Member {
Copy link
Owner

Choose a reason for hiding this comment

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

We could simplify this by implementing TryFrom<&Value> for Member so we only load the fields we need. We could even count the number of stars for each day then rather than when we're writing to the terminal. This would avoid all the fields xxx are never read clippy warnings.

session: &str,
leaderboard: &str,
) -> AocResult<()> {
let (year, day) = puzzle_year_day(args.year, args.day)?;
Copy link
Owner

Choose a reason for hiding this comment

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

I think instead of calling puzzle_year_day we need a new function. Something that: 1) unwraps the year if given or returns the latest event year, e.g. let year = args.year.unwrap_or_else(latest_event_year); and 2) returns the last unlocked day for the selected year.

@scarvalhojr
Copy link
Owner

I'll merge this as it is and will do some minor changes to make Clippy happy

@scarvalhojr scarvalhojr merged commit 1823498 into scarvalhojr:main Dec 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.

2 participants