diff --git a/lib/generate_matches_json.dart b/lib/generate_matches_json.dart index 136924c..58bcd7b 100644 --- a/lib/generate_matches_json.dart +++ b/lib/generate_matches_json.dart @@ -2,12 +2,12 @@ import 'dart:convert'; import 'dart:io'; -// Project imports: -import 'package:scouting_site/services/scouting/helper_methods.dart'; +// Package imports: +import 'package:http/http.dart' as http; void main() async { const String tbaAPIKey = - ""; // example value, replace to use in your own project + "fHNgYvUmzk3iawp0SC8XCIzePCWIE4kbZWMn6ypsL7VZ5NclTgcy9v0lbgXECA7E"; // example value, replace to use in your own project File jsonFile = File("matches.json"); @@ -15,7 +15,7 @@ void main() async { jsonFile.createSync(recursive: true); } - var (redAlliance, blueAlliance) = await getEventTeams("2025isde1", tbaAPIKey); + var (redAlliance, blueAlliance) = await getEventTeams("2025isde3", tbaAPIKey); Map blueJson = blueAlliance.map((key, value) => MapEntry(key.toString(), value)); @@ -29,3 +29,53 @@ void main() async { print("Generated matches.json successfuly!"); } + +Future<(Map>, Map>)> getEventTeams( + String eventKey, String tbaApiKey) async { + const String apiUrl = 'https://www.thebluealliance.com/api/v3'; + + final response = await http.get( + Uri.parse("$apiUrl/event/$eventKey/matches/simple"), + headers: {'X-TBA-Auth-Key': tbaApiKey}); + + final jsonResponse = jsonDecode(response.body); + + if (jsonResponse.length == 0) { + throw ArgumentError( + "Error while getting data from https://www.thebluealliance.com/api/v3"); + } + + Map> redAlliance = {}; + Map> blueAlliance = {}; + + if (jsonResponse is List) { + for (var match in jsonResponse) { + final alliancesObjects = match["alliances"]; + List currentGameRed = []; + List currentGameBlue = []; + + for (var teamKey in alliancesObjects["red"]["team_keys"]) { + currentGameRed + .add(teamKey.toString().substring(3)); // remove the frc prefix + } + for (var teamKey in alliancesObjects["blue"]["team_keys"]) { + currentGameBlue + .add(teamKey.toString().substring(3)); // remove the frc prefix + } + + redAlliance[match["match_number"] as int] = currentGameRed; + blueAlliance[match["match_number"] as int] = currentGameBlue; + } + } + // print(jsonResponse); + return ( + redAlliance, + blueAlliance, + ); +} + +String prettyJson(dynamic json) { + var spaces = ' ' * 4; + var encoder = JsonEncoder.withIndent(spaces); + return encoder.convert(json); +} diff --git a/lib/pages/admin_page.dart b/lib/pages/admin_page.dart index 0e95a3a..44459e4 100644 --- a/lib/pages/admin_page.dart +++ b/lib/pages/admin_page.dart @@ -23,7 +23,7 @@ class _AdminPageState extends State List _matchPages = []; List _pitPages = []; int _currentTab = 0; - String eventKey = "2025isde1"; + String eventKey = "2025isde3"; @override void initState() { diff --git a/lib/pages/summation/team_overview.dart b/lib/pages/summation/team_overview.dart index eee1fb5..7df5cc8 100644 --- a/lib/pages/summation/team_overview.dart +++ b/lib/pages/summation/team_overview.dart @@ -7,7 +7,6 @@ import 'package:flutter/services.dart'; // Package imports: import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; -import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; // Project imports: import 'package:scouting_site/services/cast.dart'; @@ -240,83 +239,118 @@ class _TeamOverviewPageState extends State { List gauges = []; List currPageGauges = []; String currPage = ""; + int gaugeCount = 0; + List columnGauges = []; + for (var entry in questionAverages.entries) { var split = entry.key.split("_"); String pageName = split[0]; String questionText = split.getRange(1, split.length).join("_"); - if (topValues.containsKey(pageName)) { - if (topValues[pageName]!.containsKey(questionText)) { - if (currPage != pageName) { - currPage = pageName; - currPageGauges = []; - gauges.add(Text( - pageName, - textScaler: const TextScaler.linear(1.8), - style: const TextStyle(fontWeight: FontWeight.bold), - )); - gauges.add(Row( + if (topValues.containsKey(pageName) && + topValues[pageName]!.containsKey(questionText)) { + if (currPage != pageName) { + if (currPageGauges.isNotEmpty) { + columnGauges.add(Row( mainAxisAlignment: MainAxisAlignment.center, children: currPageGauges, )); + currPageGauges = []; } - double start = 0; - double end = topValues[pageName]![questionText]!; - if (start == end) { - end = 10; + if (columnGauges.isNotEmpty) { + gauges.add(Column(children: columnGauges)); + columnGauges = []; } - Color precentileColor = getColorByPrecentile(entry.value, end); - currPageGauges.add( - Column( - mainAxisSize: MainAxisSize.min, - children: [ - Stack( - alignment: Alignment.center, - children: [ - RadialGauge( - track: RadialTrack( - start: start, - end: end, - hideLabels: false, - steps: 1, - color: Colors.black, - thickness: 40, - trackStyle: const TrackStyle( - labelStyle: TextStyle( + + currPage = pageName; + gaugeCount = 0; + gauges.add(Text( + pageName, + textScaler: const TextScaler.linear(1.8), + style: const TextStyle(fontWeight: FontWeight.bold), + )); + } + + double start = 0; + double end = topValues[pageName]![questionText]!; + if (start == end) end = 10; + + Color percentileColor = getColorByPrecentile(entry.value, end); + + currPageGauges.add( + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Stack( + alignment: Alignment.center, + children: [ + RadialGauge( + track: RadialTrack( + start: start, + end: end, + hideLabels: false, + steps: 1, + color: Colors.black, + thickness: 40, + trackStyle: const TrackStyle( + labelStyle: TextStyle( color: GlobalColors.teamColor, fontWeight: FontWeight.bold, - )), - trackLabelFormater: (double value) { - return value.toStringAsFixed(2); - }, + ), ), - valueBar: [ - RadialValueBar( - valueBarThickness: 40, - value: entry.value, - color: precentileColor, - ) - ], + trackLabelFormater: (double value) { + return value.toStringAsFixed(2); + }, ), - Text( - entry.value.toStringAsFixed(2), - style: TextStyle( - color: precentileColor, fontWeight: FontWeight.bold), - textScaler: const TextScaler.linear(2), + valueBar: [ + RadialValueBar( + valueBarThickness: 40, + value: entry.value, + color: percentileColor, + ) + ], + ), + Text( + entry.value.toStringAsFixed(2), + style: TextStyle( + color: percentileColor, + fontWeight: FontWeight.bold, ), - ], - ), - Transform.translate( - offset: const Offset(0, -70), - child: Text(questionText), - ) - ], - ), - ); - currPageGauges.add(const SizedBox(width: 20)); + textScaler: const TextScaler.linear(2), + ), + ], + ), + Transform.translate( + offset: const Offset(0, -70), + child: Text(questionText), + ) + ], + ), + ); + currPageGauges.add(const SizedBox(width: 20)); + gaugeCount++; + + if (gaugeCount >= 5) { + columnGauges.add(Row( + mainAxisAlignment: MainAxisAlignment.center, + children: currPageGauges, + )); + currPageGauges = []; + gaugeCount = 0; } } } + + if (currPageGauges.isNotEmpty) { + columnGauges.add(Row( + mainAxisAlignment: MainAxisAlignment.center, + children: currPageGauges, + )); + } + if (columnGauges.isNotEmpty) { + gauges.add(Column(children: columnGauges)); + } + return gauges; } diff --git a/lib/services/scouting/helper_methods.dart b/lib/services/scouting/helper_methods.dart index 64b364d..dc86f51 100644 --- a/lib/services/scouting/helper_methods.dart +++ b/lib/services/scouting/helper_methods.dart @@ -1,9 +1,3 @@ -// Dart imports: -import 'dart:convert'; - -// Package imports: -import 'package:http/http.dart' as http; - // Project imports: import 'package:scouting_site/services/scouting/form_data.dart'; @@ -83,56 +77,6 @@ Map evaluateSearchQuery(String text) { return map; } -Future<(Map>, Map>)> getEventTeams( - String eventKey, String tbaApiKey) async { - const String apiUrl = 'https://www.thebluealliance.com/api/v3'; - - final response = await http.get( - Uri.parse("$apiUrl/event/$eventKey/matches/simple"), - headers: {'X-TBA-Auth-Key': tbaApiKey}); - - final jsonResponse = jsonDecode(response.body); - - Map> redAlliance = {}; - Map> blueAlliance = {}; - - if (jsonResponse["error"] != null) { - throw ArgumentError( - "Error while getting data from https://www.thebluealliance.com/api/v3"); - } - - if (jsonResponse is List) { - for (var match in jsonResponse) { - final alliancesObjects = match["alliances"]; - List currentGameRed = []; - List currentGameBlue = []; - - for (var teamKey in alliancesObjects["red"]["team_keys"]) { - currentGameRed - .add(teamKey.toString().substring(3)); // remove the frc prefix - } - for (var teamKey in alliancesObjects["blue"]["team_keys"]) { - currentGameBlue - .add(teamKey.toString().substring(3)); // remove the frc prefix - } - - redAlliance[match["match_number"] as int] = currentGameRed; - blueAlliance[match["match_number"] as int] = currentGameBlue; - } - } - // print(jsonResponse); - return ( - redAlliance, - blueAlliance, - ); -} - -String prettyJson(dynamic json) { - var spaces = ' ' * 4; - var encoder = JsonEncoder.withIndent(spaces); - return encoder.convert(json); -} - String getNumAsFixed(num number) { if (number is int) return number.toString(); diff --git a/lib/services/scouting/question.dart b/lib/services/scouting/question.dart index 023be7d..484f1d9 100644 --- a/lib/services/scouting/question.dart +++ b/lib/services/scouting/question.dart @@ -61,7 +61,7 @@ class Question { print("Answer: $answer"); answerValue = answer as String; } else { - answerValue = answer[0]; + answerValue = answer; } return { 'type': type.name, diff --git a/lib/services/scouting/scouting.dart b/lib/services/scouting/scouting.dart index 701e82d..8625697 100644 --- a/lib/services/scouting/scouting.dart +++ b/lib/services/scouting/scouting.dart @@ -24,7 +24,7 @@ class Scouting { static List _matchPagesContexts = []; - static String competitionName = "2025isde1"; + static String competitionName = "2025isde3"; static int _currentPage = -1; diff --git a/lib/widgets/scout_app_bar.dart b/lib/widgets/scout_app_bar.dart index b503142..ea056a2 100644 --- a/lib/widgets/scout_app_bar.dart +++ b/lib/widgets/scout_app_bar.dart @@ -1,5 +1,7 @@ // Flutter imports: import 'package:flutter/material.dart'; + +// Package imports: import 'package:font_awesome_flutter/font_awesome_flutter.dart'; // Project imports: diff --git a/matches.json b/matches.json index 241ee44..4beecdf 100644 --- a/matches.json +++ b/matches.json @@ -1,626 +1 @@ -{ - "blue": { - "1": [ - "6740", - "5654", - "7067" - ], - "2": [ - "3211", - "1576", - "1577" - ], - "3": [ - "1580", - "1942", - "9738" - ], - "10": [ - "3339", - "6740", - "5951" - ], - "11": [ - "1690", - "6230", - "3083" - ], - "12": [ - "9303", - "5135", - "6740" - ], - "13": [ - "9738", - "2630", - "5990" - ], - "14": [ - "7067", - "5715", - "6738" - ], - "15": [ - "1574", - "1577", - "8175" - ], - "16": [ - "3316", - "1580", - "4338" - ], - "17": [ - "5990", - "6738", - "1690" - ], - "18": [ - "3083", - "8175", - "9738" - ], - "19": [ - "9303", - "1576", - "2630" - ], - "20": [ - "7177", - "1580", - "1574" - ], - "21": [ - "3065", - "4338", - "1577" - ], - "22": [ - "1580", - "4320", - "7067" - ], - "23": [ - "5654", - "6738", - "1574" - ], - "24": [ - "6230", - "9740", - "3211" - ], - "25": [ - "2230", - "2679", - "1942" - ], - "26": [ - "2630", - "4319", - "4320" - ], - "27": [ - "1577", - "9303", - "6230" - ], - "28": [ - "1576", - "4338", - "5654" - ], - "29": [ - "3211", - "1574", - "4319" - ], - "30": [ - "3339", - "7067", - "9740" - ], - "31": [ - "2630", - "2679", - "8175" - ], - "32": [ - "5654", - "3316", - "1577" - ], - "33": [ - "1574", - "1576", - "3065" - ], - "34": [ - "9740", - "9738", - "4338" - ], - "35": [ - "5951", - "4320", - "1942" - ], - "36": [ - "6740", - "3211", - "2230" - ], - "37": [ - "1576", - "6230", - "3316" - ], - "38": [ - "4338", - "6740", - "2230" - ], - "39": [ - "5654", - "3211", - "3339" - ], - "4": [ - "3316", - "2230", - "2630" - ], - "40": [ - "9738", - "1690", - "8175" - ], - "41": [ - "1574", - "5990", - "2679" - ], - "42": [ - "6740", - "5135", - "1576" - ], - "43": [ - "2230", - "1580", - "5990" - ], - "44": [ - "5135", - "8175", - "5951" - ], - "45": [ - "7177", - "7067", - "5654" - ], - "46": [ - "1690", - "4338", - "2679" - ], - "47": [ - "5715", - "9303", - "5990" - ], - "48": [ - "1577", - "9738", - "5135" - ], - "49": [ - "7067", - "2230", - "1690" - ], - "5": [ - "3083", - "5654", - "5951" - ], - "50": [ - "1942", - "3065", - "9303" - ], - "51": [ - "3083", - "6738", - "4320" - ], - "52": [ - "7177", - "9740", - "2630" - ], - "53": [ - "5135", - "3339", - "1580" - ], - "54": [ - "5951", - "1576", - "4319" - ], - "55": [ - "9303", - "7177", - "4320" - ], - "56": [ - "5715", - "6230", - "2230" - ], - "57": [ - "9740", - "6738", - "3316" - ], - "58": [ - "8175", - "2230", - "7177" - ], - "59": [ - "6738", - "2679", - "4319" - ], - "6": [ - "6230", - "5990", - "5135" - ], - "60": [ - "3339", - "1574", - "6230" - ], - "61": [ - "6740", - "1942", - "5715" - ], - "62": [ - "5951", - "9740", - "3065" - ], - "7": [ - "1942", - "9740", - "3083" - ], - "8": [ - "4320", - "3065", - "2679" - ], - "9": [ - "1580", - "5715", - "1577" - ] - }, - "red": { - "1": [ - "6738", - "5715", - "9738" - ], - "2": [ - "6230", - "6740", - "7177" - ], - "3": [ - "5135", - "1574", - "9740" - ], - "10": [ - "3211", - "9303", - "1574" - ], - "11": [ - "9740", - "5654", - "4319" - ], - "12": [ - "1576", - "2230", - "3339" - ], - "13": [ - "2679", - "3211", - "3316" - ], - "14": [ - "7177", - "5951", - "1690" - ], - "15": [ - "4320", - "5654", - "3065" - ], - "16": [ - "1942", - "7067", - "6230" - ], - "17": [ - "2679", - "5951", - "9740" - ], - "18": [ - "4320", - "3339", - "1942" - ], - "19": [ - "4319", - "1577", - "6740" - ], - "20": [ - "2230", - "5135", - "5654" - ], - "21": [ - "5715", - "5951", - "3211" - ], - "22": [ - "3316", - "1690", - "5135" - ], - "23": [ - "8175", - "5990", - "6740" - ], - "24": [ - "1576", - "9738", - "5715" - ], - "25": [ - "4338", - "3083", - "9303" - ], - "26": [ - "3339", - "7177", - "3065" - ], - "27": [ - "5135", - "1942", - "6738" - ], - "28": [ - "2230", - "3065", - "9738" - ], - "29": [ - "3083", - "5715", - "3316" - ], - "30": [ - "6740", - "1690", - "1580" - ], - "31": [ - "5990", - "5951", - "7177" - ], - "32": [ - "1690", - "3339", - "5715" - ], - "33": [ - "2679", - "7177", - "3083" - ], - "34": [ - "6738", - "1580", - "9303" - ], - "35": [ - "6230", - "2630", - "5135" - ], - "36": [ - "5990", - "4319", - "7067" - ], - "37": [ - "8175", - "9303", - "5951" - ], - "38": [ - "9740", - "3083", - "1580" - ], - "39": [ - "7067", - "1577", - "6738" - ], - "4": [ - "3065", - "8175", - "6738" - ], - "40": [ - "2630", - "3065", - "5715" - ], - "41": [ - "4319", - "7177", - "1942" - ], - "42": [ - "4320", - "5715", - "9740" - ], - "43": [ - "1577", - "1942", - "2630" - ], - "44": [ - "6738", - "3211", - "6230" - ], - "45": [ - "3316", - "4319", - "3339" - ], - "46": [ - "9738", - "4320", - "1574" - ], - "47": [ - "3065", - "3083", - "5654" - ], - "48": [ - "4338", - "8175", - "3339" - ], - "49": [ - "4319", - "2630", - "3211" - ], - "5": [ - "2679", - "3339", - "7067" - ], - "50": [ - "1574", - "3316", - "6740" - ], - "51": [ - "1580", - "2679", - "1576" - ], - "52": [ - "5951", - "6230", - "4338" - ], - "53": [ - "3065", - "5990", - "3211" - ], - "54": [ - "7067", - "3316", - "8175" - ], - "55": [ - "1942", - "1574", - "1690" - ], - "56": [ - "9738", - "5654", - "2679" - ], - "57": [ - "1577", - "6740", - "3083" - ], - "58": [ - "9303", - "9738", - "7067" - ], - "59": [ - "3211", - "5135", - "4338" - ], - "6": [ - "5715", - "4338", - "7177" - ], - "60": [ - "5990", - "3083", - "1576" - ], - "61": [ - "5654", - "2630", - "1580" - ], - "62": [ - "1690", - "1577", - "4320" - ], - "7": [ - "8175", - "4319", - "2230" - ], - "8": [ - "2630", - "7067", - "1576" - ], - "9": [ - "6738", - "3316", - "9738" - ] - } -} \ No newline at end of file +{"blue":{},"red":{}} \ No newline at end of file