Skip to content

Commit

Permalink
Merge branch 'julien4215-elo-chart'
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Apr 11, 2024
2 parents 8c2a567 + 3f34c14 commit 839620b
Show file tree
Hide file tree
Showing 8 changed files with 574 additions and 84 deletions.
22 changes: 22 additions & 0 deletions lib/src/model/user/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,25 @@ class UserPerfGame with _$UserPerfGame {
)
: null;
}

@immutable
class UserRatingHistoryPerf {
final String perf;
final IList<UserRatingHistoryPoint> points;

const UserRatingHistoryPerf({
required this.perf,
required this.points,
});
}

@immutable
class UserRatingHistoryPoint {
final DateTime date;
final int elo;

const UserRatingHistoryPoint({
required this.date,
required this.elo,
});
}
31 changes: 31 additions & 0 deletions lib/src/model/user/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,37 @@ class UserRepository {
mapper: _autocompleteFromJson,
);
}

Future<IList<UserRatingHistoryPerf>> getRatingHistory(UserId id) {
return client.readJsonList(
Uri.parse('$kLichessHost/api/user/$id/rating-history'),
mapper: _ratingHistoryFromJson,
);
}
}

UserRatingHistoryPerf _ratingHistoryFromJson(
Map<String, dynamic> json,
) =>
_ratingHistoryFromPick(pick(json).required());

UserRatingHistoryPerf _ratingHistoryFromPick(
RequiredPick perf,
) {
return UserRatingHistoryPerf(
perf: perf('name').asStringOrThrow(),
points: perf('points').asListOrThrow((point) {
final values = point.asListOrThrow((point) => point.asIntOrThrow());
return UserRatingHistoryPoint(
date: DateTime.utc(
values[0],
values[1] + 1,
values[2],
),
elo: values[3],
);
}).toIList(),
);
}

// --
Expand Down
10 changes: 10 additions & 0 deletions lib/src/model/user/user_repository_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,13 @@ Future<IList<LightUser>> autoCompleteUser(
(client) => UserRepository(client).autocompleteUser(term),
);
}

@riverpod
Future<IList<UserRatingHistoryPerf>> userRatingHistory(
UserRatingHistoryRef ref, {
required UserId id,
}) async {
return ref.withClient(
(client) => UserRepository(client).getRatingHistory(id),
);
}
6 changes: 4 additions & 2 deletions lib/src/view/puzzle/storm_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class _Body extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: Styles.sectionTopPadding,
padding:
Styles.sectionTopPadding.add(Styles.horizontalBodyPadding),
child: StatCardRow(
[
StatCard(
Expand All @@ -82,7 +83,8 @@ class _Body extends ConsumerWidget {
),
),
Padding(
padding: Styles.sectionTopPadding,
padding:
Styles.sectionTopPadding.add(Styles.horizontalBodyPadding),
child: StatCardRow(
[
StatCard(
Expand Down
Loading

0 comments on commit 839620b

Please sign in to comment.