Skip to content

Commit

Permalink
WIP : add elo_chart
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Mar 3, 2024
1 parent da7549b commit c8b38e7
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 218 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(
values[0],
values[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),
);
}
Loading

0 comments on commit c8b38e7

Please sign in to comment.