Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions lib/generate_matches_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
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 =
"<APIKEY>"; // example value, replace to use in your own project
"fHNgYvUmzk3iawp0SC8XCIzePCWIE4kbZWMn6ypsL7VZ5NclTgcy9v0lbgXECA7E"; // example value, replace to use in your own project

File jsonFile = File("matches.json");

if (!jsonFile.existsSync()) {
jsonFile.createSync(recursive: true);
}

var (redAlliance, blueAlliance) = await getEventTeams("2025isde1", tbaAPIKey);
var (redAlliance, blueAlliance) = await getEventTeams("2025isde3", tbaAPIKey);

Map<String, dynamic> blueJson =
blueAlliance.map((key, value) => MapEntry(key.toString(), value));
Expand All @@ -29,3 +29,53 @@ void main() async {

print("Generated matches.json successfuly!");
}

Future<(Map<int, List<String>>, Map<int, List<String>>)> 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<int, List<String>> redAlliance = {};
Map<int, List<String>> blueAlliance = {};

if (jsonResponse is List<dynamic>) {
for (var match in jsonResponse) {
final alliancesObjects = match["alliances"];
List<String> currentGameRed = [];
List<String> 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);
}
2 changes: 1 addition & 1 deletion lib/pages/admin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _AdminPageState extends State<AdminPage>
List<FormPageData> _matchPages = [];
List<FormPageData> _pitPages = [];
int _currentTab = 0;
String eventKey = "2025isde1";
String eventKey = "2025isde3";

@override
void initState() {
Expand Down
154 changes: 94 additions & 60 deletions lib/pages/summation/team_overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -240,83 +239,118 @@ class _TeamOverviewPageState extends State<TeamOverviewPage> {
List<Widget> gauges = [];
List<Widget> currPageGauges = [];
String currPage = "";
int gaugeCount = 0;
List<Widget> 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;
}

Expand Down
56 changes: 0 additions & 56 deletions lib/services/scouting/helper_methods.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -83,56 +77,6 @@ Map<String, dynamic> evaluateSearchQuery(String text) {
return map;
}

Future<(Map<int, List<String>>, Map<int, List<String>>)> 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<int, List<String>> redAlliance = {};
Map<int, List<String>> blueAlliance = {};

if (jsonResponse["error"] != null) {
throw ArgumentError(
"Error while getting data from https://www.thebluealliance.com/api/v3");
}

if (jsonResponse is List<dynamic>) {
for (var match in jsonResponse) {
final alliancesObjects = match["alliances"];
List<String> currentGameRed = [];
List<String> 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();

Expand Down
2 changes: 1 addition & 1 deletion lib/services/scouting/question.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Question {
print("Answer: $answer");
answerValue = answer as String;
} else {
answerValue = answer[0];
answerValue = answer;
}
return {
'type': type.name,
Expand Down
2 changes: 1 addition & 1 deletion lib/services/scouting/scouting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Scouting {

static List<BuildContext> _matchPagesContexts = [];

static String competitionName = "2025isde1";
static String competitionName = "2025isde3";

static int _currentPage = -1;

Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/scout_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

// Project imports:
Expand Down
Loading