-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add TrueSkill leaderboard tabs #2
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
Changes from 4 commits
a158669
118e18a
478f217
a866854
27e1e6a
1aa7eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,6 +305,49 @@ class ApiClient { | |
| } | ||
| } | ||
|
|
||
| Future<List<Team>> getGlobalTrueSkillRankings( | ||
| {String gradeLevel = 'Middle School'}) async { | ||
| // RoboStem API uses a different base URL and key | ||
| final token = _settings.roboStemApiKey ?? AppConstants.roboStemApiKey; | ||
| final dio = Dio(BaseOptions( | ||
| baseUrl: AppConstants.roboStemBaseUrl, // https://api.robostem-api.org | ||
| headers: { | ||
| 'x-api-key': token, | ||
| 'accept': 'application/json', | ||
| }, | ||
| connectTimeout: const Duration(seconds: 30), | ||
| receiveTimeout: const Duration(seconds: 30), | ||
| )); | ||
|
Comment on lines
+311
to
+320
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. This block for creating a |
||
|
|
||
| try { | ||
| final response = await dio.get('/api/rankings/statiq', queryParameters: { | ||
| 'program': 'VIQRC', | ||
| 'limit': 100, // Reduced from 2500 for performance | ||
| 'grade_level': gradeLevel, | ||
| }); | ||
|
|
||
| // RoboStem response structure might differ. Assuming standard list or {data: []} | ||
| List<Map<String, dynamic>> rawList = []; | ||
| if (response.data is List) { | ||
| rawList = (response.data as List).cast<Map<String, dynamic>>(); | ||
| } else if (response.data is Map && response.data['data'] is List) { | ||
| rawList = (response.data['data'] as List).cast<Map<String, dynamic>>(); | ||
| } | ||
|
|
||
| // Client-side filter fallback (just in case API returns mixed results) | ||
| // The sample response shows 'grade_level': 'Middle School' or 'Elementary School' | ||
| final filteredList = rawList.where((item) { | ||
| // Try both 'grade' (standard Team model) and 'grade_level' (API param/possible return) | ||
| final g = item['grade'] ?? item['grade_level']; | ||
| return g == gradeLevel; | ||
| }).toList(); | ||
|
|
||
| return filteredList.map((json) => Team.fromJson(json)).toList(); | ||
| } catch (e) { | ||
| return []; | ||
| } | ||
|
Comment on lines
+338
to
+340
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. The } catch (e) {
if (e is DioException) {
print('RoboStem API Error (TrueSkill): ${e.message} ${e.response?.statusCode}');
} else {
print('Error fetching TrueSkill rankings: $e');
}
return [];
}
Comment on lines
+338
to
+340
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. This } catch (e) {
print('Error fetching global TrueSkill rankings: $e');
rethrow;
} |
||
| } | ||
|
|
||
| Future<List<Team>> searchTeams( | ||
| {String? number, int? program, int? limit}) async { | ||
| // Strategy: Use RobotEvents API for exact team lookup first, | ||
|
|
||
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.
Creating a new
Dioinstance within thegetGlobalTrueSkillRankingsmethod for every call is inefficient. This can lead to performance issues, such as socket exhaustion under heavy use, and prevents connection reuse. It's better to create a dedicatedDioinstance for the RoboStem API at the class level, similar to how_diois handled for RobotEvents, and reuse it across calls.