fix locos for trips, hopefully improve build times
Some checks failed
Some checks failed
This commit is contained in:
@@ -52,14 +52,6 @@ jobs:
|
|||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: ${{ env.JAVA_VERSION }}
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
|
||||||
- name: Cache Android SDK
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: ${{ env.ANDROID_SDK_ROOT }}
|
|
||||||
key: android-sdk-${{ runner.os }}-java${{ env.JAVA_VERSION }}-platform33-buildtools33.0.2
|
|
||||||
restore-keys: |
|
|
||||||
android-sdk-${{ runner.os }}-java${{ env.JAVA_VERSION }}-
|
|
||||||
|
|
||||||
- name: Install Android SDK
|
- name: Install Android SDK
|
||||||
run: |
|
run: |
|
||||||
mkdir -p "$ANDROID_SDK_ROOT"/cmdline-tools
|
mkdir -p "$ANDROID_SDK_ROOT"/cmdline-tools
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ class TripDetail {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory TripDetail.fromJson(Map<String, dynamic> json) => TripDetail(
|
factory TripDetail.fromJson(Map<String, dynamic> json) => TripDetail(
|
||||||
id: json['trip_id'] ?? 0,
|
id: json['trip_id'] ?? json['id'] ?? 0,
|
||||||
name: json['trip_name'] ?? '',
|
name: json['trip_name'] ?? '',
|
||||||
mileage: (json['trip_mileage'] as num?)?.toDouble() ?? 0,
|
mileage: (json['trip_mileage'] as num?)?.toDouble() ?? 0,
|
||||||
legCount: json['leg_count'] ?? ((json['trip_legs'] as List?)?.length ?? 0),
|
legCount: json['leg_count'] ?? ((json['trip_legs'] as List?)?.length ?? 0),
|
||||||
@@ -411,16 +411,42 @@ class TripLocoStat {
|
|||||||
this.name,
|
this.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory TripLocoStat.fromJson(Map<String, dynamic> json) => TripLocoStat(
|
factory TripLocoStat.fromJson(Map<String, dynamic> json) {
|
||||||
locoClass: json['loco_class'] ?? json['class'] ?? '',
|
final locoJson = json['loco'] is Map<String, dynamic>
|
||||||
number: json['loco_number'] ?? json['number'] ?? '',
|
? Map<String, dynamic>.from(json['loco'] as Map)
|
||||||
name: json['loco_name'] ?? json['name'],
|
: null;
|
||||||
won: json['won'] == 1 ||
|
final locoClass = json['loco_class'] ??
|
||||||
json['won'] == true ||
|
json['class'] ??
|
||||||
(json['won'] is String && json['won'].toString() == '1'),
|
locoJson?['class'] ??
|
||||||
|
locoJson?['loco_class'] ??
|
||||||
|
'';
|
||||||
|
final locoNumber = json['loco_number'] ??
|
||||||
|
json['number'] ??
|
||||||
|
locoJson?['number'] ??
|
||||||
|
locoJson?['loco_number'] ??
|
||||||
|
'';
|
||||||
|
final locoName =
|
||||||
|
json['loco_name'] ?? json['name'] ?? locoJson?['name'] ?? locoJson?['loco_name'];
|
||||||
|
final wonValue = json['won'] ?? json['result'] ?? json['winner'];
|
||||||
|
final won = _parseWonFlag(wonValue);
|
||||||
|
|
||||||
|
return TripLocoStat(
|
||||||
|
locoClass: locoClass,
|
||||||
|
number: locoNumber,
|
||||||
|
name: locoName,
|
||||||
|
won: won,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _parseWonFlag(dynamic value) {
|
||||||
|
if (value == null) return false;
|
||||||
|
if (value is bool) return value;
|
||||||
|
if (value is num) return value != 0;
|
||||||
|
final normalized = value.toString().toLowerCase();
|
||||||
|
return ['1', 'true', 'win', 'won', 'yes', 'w'].contains(normalized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class EventField {
|
class EventField {
|
||||||
final String name;
|
final String name;
|
||||||
final String display;
|
final String display;
|
||||||
|
|||||||
@@ -277,26 +277,34 @@ class DataService extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<List<TripLocoStat>> fetchTripLocoStats(int tripId) async {
|
Future<List<TripLocoStat>> fetchTripLocoStats(int tripId) async {
|
||||||
try {
|
try {
|
||||||
final json = await api.get('/trips/stats?trip_id=$tripId');
|
final json = await api.get('/trips/stats/$tripId');
|
||||||
if (json is List) {
|
return _parseTripLocoStats(json);
|
||||||
return json
|
|
||||||
.whereType<Map<String, dynamic>>()
|
|
||||||
.map((e) => TripLocoStat.fromJson(e))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
if (json is Map && json['locos'] is List) {
|
|
||||||
return (json['locos'] as List)
|
|
||||||
.whereType<Map<String, dynamic>>()
|
|
||||||
.map((e) => TripLocoStat.fromJson(e))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Failed to fetch trip loco stats: $e');
|
debugPrint('Failed to fetch trip loco stats: $e');
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<TripLocoStat> _parseTripLocoStats(dynamic json) {
|
||||||
|
List<dynamic>? list;
|
||||||
|
if (json is List) {
|
||||||
|
list = json.expand((e) => e is List ? e : [e]).toList();
|
||||||
|
} else if (json is Map) {
|
||||||
|
for (final key in ['locos', 'stats', 'data', 'trip_locos']) {
|
||||||
|
final candidate = json[key];
|
||||||
|
if (candidate is List) {
|
||||||
|
list = candidate.expand((e) => e is List ? e : [e]).toList();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (list == null) return [];
|
||||||
|
return list
|
||||||
|
.whereType<Map<String, dynamic>>()
|
||||||
|
.map((e) => TripLocoStat.fromJson(e))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> fetchEventFields({bool force = false}) async {
|
Future<void> fetchEventFields({bool force = false}) async {
|
||||||
if (_eventFields.isNotEmpty && !force) return;
|
if (_eventFields.isNotEmpty && !force) return;
|
||||||
_isEventFieldsLoading = true;
|
_isEventFieldsLoading = true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: mileograph_flutter
|
name: mileograph_flutter
|
||||||
description: "A new Flutter project."
|
description: "Native app for the Mileograph website"
|
||||||
# The following line prevents the package from being accidentally published to
|
# The following line prevents the package from being accidentally published to
|
||||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
|
|||||||
Reference in New Issue
Block a user