Skip to content

Commit

Permalink
update deps. run dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
mootw committed Nov 27, 2023
1 parent 91f6d21 commit 8a07907
Show file tree
Hide file tree
Showing 46 changed files with 544 additions and 526 deletions.
17 changes: 7 additions & 10 deletions app/lib/durationformat.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@



String formatDuration (Duration duration) {
String formatDuration(Duration duration) {
String s = "";

int mins = duration.inMinutes.abs();
if(mins > 0) {
if (mins > 0) {
s = "$mins min${mins != 1 ? "s" : ""}";
}
int hours = duration.inHours.abs();
if(hours > 0) {
if (hours > 0) {
s = "$hours hour${hours != 1 ? "s" : ""}";
}
int days = duration.inDays.abs();
if(days > 0) {
if (days > 0) {
s = "$days day${days != 1 ? "s" : ""}";
}

if(duration.inMinutes == 0) {
if (duration.inMinutes == 0) {
return "now";
}
if(duration.isNegative) {
if (duration.isNegative) {
return "$s ago";
} else {
return "in $s";
Expand All @@ -30,4 +27,4 @@ String formatDuration (Duration duration) {
String offsetDurationInMins(Duration duration) {
//Do not add a negative sign since it is already included in the minutes.
return "${duration.isNegative == true ? "" : "+"}${duration.inMinutes} min${duration.inMinutes == 1 ? "" : "s"}";
}
}
15 changes: 8 additions & 7 deletions app/lib/edit_lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:provider/provider.dart';

//Route should return when editing is complete. This is the signal to clear the edit lock.
//This function will not throw an exception and always fail safe by navigating to the other page.
Future<T?> navigateWithEditLock<T>(
BuildContext context, String key, Function(BuildContext context) navigteFunction) async {
final editLockUri = context.read<DataProvider>().serverURI.resolve("/edit_lock");

Future<T?> navigateWithEditLock<T>(BuildContext context, String key,
Function(BuildContext context) navigteFunction) async {
final editLockUri =
context.read<DataProvider>().serverURI.resolve("/edit_lock");

//Check if this key is being edited
try {
final isLocked = await apiClient.get(editLockUri,
Expand Down Expand Up @@ -56,7 +57,7 @@ Future<T?> navigateWithEditLock<T>(
}
//Navigate
T? result;
if(context.mounted) {
if (context.mounted) {
result = await navigteFunction(context);
}
//Clear lock
Expand All @@ -70,9 +71,9 @@ Future<T?> navigateWithEditLock<T>(
return result;
}
} catch (e) {
Logger.root.warning("edit lock error", e);
Logger.root.warning("edit lock error", e);
//Fail save and navigate anyways
if(context.mounted) {
if (context.mounted) {
return await navigteFunction(context);
}
}
Expand Down
50 changes: 26 additions & 24 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ class _MyHomePageState extends State<MyHomePage> {
body: Row(children: [
if (largeDevice)
NavigationRail(
backgroundColor: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
labelType: NavigationRailLabelType.all,
onDestinationSelected: (int index) {
backgroundColor:
Theme.of(context).bottomNavigationBarTheme.backgroundColor,
labelType: NavigationRailLabelType.all,
onDestinationSelected: (int index) {
setState(() {
_currentPageIndex = index;
});
},
destinations: const [
NavigationRailDestination(
destinations: const [
NavigationRailDestination(
selectedIcon: Icon(Icons.calendar_today),
icon: Icon(Icons.calendar_today_outlined),
label: Text('Schedule'),
Expand All @@ -154,25 +155,26 @@ class _MyHomePageState extends State<MyHomePage> {
icon: Icon(Icons.book_outlined),
label: Text('Docs'),
),
], selectedIndex: _currentPageIndex),
Expanded(
child: [
AllMatchesPage(
// 10/10 hack to make the widget re-scroll to the correct spot on load
// this will force it to scroll whenever the matches length changes
// we could add another value here to make it scroll on other changes too
key: Key(data.event.matches.length.toString()),
scrollPosition: nextMatch == null
? null
: (data.event.matches.values.toList().indexOf(nextMatch) *
matchCardHeight) -
(matchCardHeight * 2),
),
const TeamGridList(showEditButton: true),
const AnalysisPage(),
const DocumentationScreen(),
][_currentPageIndex],
),
],
selectedIndex: _currentPageIndex),
Expanded(
child: [
AllMatchesPage(
// 10/10 hack to make the widget re-scroll to the correct spot on load
// this will force it to scroll whenever the matches length changes
// we could add another value here to make it scroll on other changes too
key: Key(data.event.matches.length.toString()),
scrollPosition: nextMatch == null
? null
: (data.event.matches.values.toList().indexOf(nextMatch) *
matchCardHeight) -
(matchCardHeight * 2),
),
const TeamGridList(showEditButton: true),
const AnalysisPage(),
const DocumentationScreen(),
][_currentPageIndex],
),
]),
drawer: Drawer(
child: ListView(children: [
Expand Down
11 changes: 3 additions & 8 deletions app/lib/providers/identity_provider.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@


import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';


String unknownIdentity = "unknown";

class IdentityProvider extends ChangeNotifier {

String identity = unknownIdentity;

IdentityProvider () {
IdentityProvider() {
() async {
final prefs = await SharedPreferences.getInstance();
identity = prefs.getString("scout_identity") ?? unknownIdentity;
}();
}

Future setIdentity (String newIdentity) async {
Future setIdentity(String newIdentity) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString("scout_identity", newIdentity);
identity = newIdentity;
notifyListeners();
}

}
}
3 changes: 1 addition & 2 deletions app/lib/providers/loading_status_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
LoadingIndicatorService loadingService = LoadingIndicatorService();

class LoadingIndicatorService {

final StreamController<int> _isLoadingStream = StreamController<int>();
late Stream<int> loadingCount;

Expand Down Expand Up @@ -37,4 +36,4 @@ class LoadingIndicatorService {
}
_isLoadingStream.add(_count);
}
}
}
9 changes: 4 additions & 5 deletions app/lib/scouting_tools/scouting_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:snout_db/event/pitscoutresult.dart';
import 'package:snout_db/config/surveyitem.dart';

class ScoutingToolWidget extends StatefulWidget {

final SurveyItem tool;
final PitScoutResult survey;

Expand Down Expand Up @@ -118,9 +117,9 @@ class _ScoutingToolWidgetState extends State<ScoutingToolWidget> {
// label: Text('false'),
icon: Icon(Icons.cancel, color: Colors.redAccent)),
ButtonSegment<bool?>(
value: null,
// label: Text('unknown'),
icon: Icon(Icons.question_mark),
value: null,
// label: Text('unknown'),
icon: Icon(Icons.question_mark),
),
ButtonSegment<bool?>(
value: true,
Expand Down Expand Up @@ -158,7 +157,7 @@ class _ScoutingToolWidgetState extends State<ScoutingToolWidget> {
subtitle: _value == null
? const Text("No Image")
: Image.memory(
fit: BoxFit.contain,
fit: BoxFit.contain,
Uint8List.fromList(base64Decode(_value).cast<int>())),
);
}
Expand Down
16 changes: 4 additions & 12 deletions app/lib/screens/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ class AnalysisPage extends StatefulWidget {
}

class _AnalysisPageState extends State<AnalysisPage> {

@override
Widget build(BuildContext context) {
return ListView(children: [
const Text(
"Scoreboard (shows average value of all metrics for each team, like heatmaps) - Metrics Explorer - Maybe allow for more 'sql' like queries here?? - Scatter plot!!! AND PLOT FOR METRIC OVER TIME"),

ListTile(
title: const Text("Team Averages"),
leading: const Icon(Icons.table_chart),
Expand All @@ -33,7 +31,6 @@ class _AnalysisPageState extends State<AnalysisPage> {
builder: (builder) => const TableTeamAveragesPage()));
},
),

ListTile(
title: const Text("Match Recordings"),
leading: const Icon(Icons.table_chart),
Expand All @@ -44,29 +41,25 @@ class _AnalysisPageState extends State<AnalysisPage> {
builder: (builder) => const TableMatchRecordingsPage()));
},
),

ListTile(
title: const Text("Consistency Analysis"),
leading: const Icon(Icons.candlestick_chart_outlined),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (builder) => const BoxPlotAnalysis()));
Navigator.push(context,
MaterialPageRoute(builder: (builder) => const BoxPlotAnalysis()));
},
),

ListTile(
title: const Text("Match Preview"),
leading: const Icon(Icons.preview),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (builder) => const AnalysisMatchPreview(red: [], blue: [])));
builder: (builder) =>
const AnalysisMatchPreview(red: [], blue: [])));
},
),

ListTile(
title: const Text("Heatmap by Event Type"),
leading: const Icon(Icons.map),
Expand All @@ -77,7 +70,6 @@ class _AnalysisPageState extends State<AnalysisPage> {
builder: (builder) => const AnalysisHeatMapByEventType()));
},
),

ListTile(
title: const Text("Event Heatmap Analysis"),
leading: const Icon(Icons.map),
Expand Down
16 changes: 11 additions & 5 deletions app/lib/screens/analysis/boxplot_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ class BoxPlotAnalysis extends StatefulWidget {
}

class _BoxPlotAnalysisState extends State<BoxPlotAnalysis> {

MatchResultsProcess? _selectedProcess;

@override
void initState() {
super.initState();
//Automatically select the first process by default if it exists (it might be null!)
_selectedProcess = context.read<DataProvider>().event.config.matchscouting.processes.firstOrNull;
_selectedProcess = context
.read<DataProvider>()
.event
.config
.matchscouting
.processes
.firstOrNull;
}

@override
Expand All @@ -36,8 +41,10 @@ class _BoxPlotAnalysisState extends State<BoxPlotAnalysis> {
for (final team in data.event.teams)
MapEntry(team, [
for (final match in data.event.teamRecordedMatches(team))
data.event.runMatchResultsProcess(_selectedProcess!,
match.value.robot[team.toString()], team)?.value ??
data.event
.runMatchResultsProcess(_selectedProcess!,
match.value.robot[team.toString()], team)
?.value ??
0
])
]);
Expand Down Expand Up @@ -68,7 +75,6 @@ class _BoxPlotAnalysisState extends State<BoxPlotAnalysis> {
: element.max) ??
0;


//Sort them by the average
SplayTreeMap<int, List<num>>? valuesSorted;
if (teamValues != null) {
Expand Down
12 changes: 9 additions & 3 deletions app/lib/screens/analysis/heatmap_event_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ class _AnalysisHeatMapByEventTypeState
void initState() {
super.initState();
//select the first event type if it is exists
_selectedEvent = context.read<DataProvider>().event.config.matchscouting.events.firstOrNull;
_selectedEvent = context
.read<DataProvider>()
.event
.config
.matchscouting
.events
.firstOrNull;
}

@override
Expand Down Expand Up @@ -73,8 +79,8 @@ class _AnalysisHeatMapByEventTypeState
(previousValue, element) => [
...previousValue,
...element
.timelineRedNormalized(
data.event.config.fieldStyle)
.timelineRedNormalized(data
.event.config.fieldStyle)
.where((event) =>
event.id ==
_selectedEvent!.id)
Expand Down
Loading

0 comments on commit 8a07907

Please sign in to comment.