initial codex commit
Some checks failed
Release / build (push) Failing after 48s
Release / release-dev (push) Has been skipped
Release / release-master (push) Has been skipped
Release / windows-build (push) Has been cancelled

This commit is contained in:
2025-12-11 01:08:30 +00:00
parent e6d7e71a36
commit 40ee16d2d5
20 changed files with 2902 additions and 283 deletions

View File

@@ -41,6 +41,7 @@ class HomepageStats {
final List<LocoSummary> topLocos;
final List<LeaderboardEntry> leaderboard;
final List<TripSummary> trips;
final UserData? user;
HomepageStats({
required this.totalMileage,
@@ -48,23 +49,37 @@ class HomepageStats {
required this.topLocos,
required this.leaderboard,
required this.trips,
this.user,
});
factory HomepageStats.fromJson(Map<String, dynamic> json) {
final userData = json['user_data'];
final mileageData = json['milage_data'];
final totalMileage = mileageData is Map && mileageData['mileage'] != null
? (mileageData['mileage'] as num).toDouble()
: 0.0;
return HomepageStats(
totalMileage: (json['milage_data']['mileage'] as num).toDouble(),
yearlyMileage: (json['yearly_mileage'] as List)
totalMileage: totalMileage,
yearlyMileage: (json['yearly_mileage'] as List? ?? [])
.map((e) => YearlyMileage.fromJson(e))
.toList(),
topLocos: (json['top_locos'] as List)
topLocos: (json['top_locos'] as List? ?? [])
.map((e) => LocoSummary.fromJson(e))
.toList(),
leaderboard: (json['leaderboard_data'] as List)
leaderboard: (json['leaderboard_data'] as List? ?? [])
.map((e) => LeaderboardEntry.fromJson(e))
.toList(),
trips: (json['trip_data'] as List)
trips: (json['trip_data'] as List? ?? [])
.map((e) => TripSummary.fromJson(e))
.toList(),
user: userData == null
? null
: UserData(
userData['username'] ?? '',
userData['full_name'] ?? '',
userData['user_id'] ?? '',
userData['email'] ?? '',
),
);
}
}
@@ -112,6 +127,13 @@ class Loco {
class LocoSummary extends Loco {
final double? mileage;
final int? journeys;
final int? trips;
final String? status;
final String? domain;
final String? owner;
final String? livery;
final String? location;
final Map<String, dynamic> extra;
LocoSummary({
required int locoId,
@@ -124,7 +146,15 @@ class LocoSummary extends Loco {
String? locoEvn,
this.mileage,
this.journeys,
}) : super(
this.trips,
this.status,
this.domain,
this.owner,
this.livery,
this.location,
Map<String, dynamic>? extra,
}) : extra = extra ?? const {},
super(
id: locoId,
type: locoType,
number: locoNumber,
@@ -136,17 +166,30 @@ class LocoSummary extends Loco {
);
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
locoId: json['loco_id'],
locoType: json['type'],
locoNumber: json['number'],
locoName: json['name'] ?? "",
locoClass: json['class'],
locoOperator: json['operator'],
locoNotes: json['notes'],
locoEvn: json['evn'],
mileage: (json['loco_mileage'] as num?)?.toDouble() ?? 0,
journeys: json['loco_journeys'] ?? 0,
);
locoId: json['loco_id'] ?? json['id'] ?? 0,
locoType: json['type'] ?? json['loco_type'] ?? '',
locoNumber: json['number'] ?? json['loco_number'] ?? '',
locoName: json['name'] ?? json['loco_name'] ?? "",
locoClass: json['class'] ?? json['loco_class'] ?? '',
locoOperator: json['operator'] ?? json['loco_operator'] ?? '',
locoNotes: json['notes'],
locoEvn: json['evn'] ?? json['loco_evn'],
mileage: ((json['loco_mileage'] ?? json['mileage']) as num?)
?.toDouble() ??
0,
journeys: (json['loco_journeys'] ?? json['journeys'] ?? 0) is num
? (json['loco_journeys'] ?? json['journeys'] ?? 0).toInt()
: 0,
trips: (json['loco_trips'] ?? json['trips']) is num
? (json['loco_trips'] ?? json['trips']).toInt()
: null,
status: json['status'] ?? json['loco_status'],
domain: json['domain'],
owner: json['owner'] ?? json['loco_owner'],
livery: json['livery'],
location: json['location'],
extra: Map<String, dynamic>.from(json),
);
}
class LeaderboardEntry {
@@ -285,3 +328,75 @@ class Station {
country: json['country'],
);
}
class TripLeg {
final int? id;
final String start;
final String end;
final DateTime? beginTime;
final String? network;
final String? route;
final double? mileage;
final String? notes;
final List<Loco> locos;
TripLeg({
required this.id,
required this.start,
required this.end,
required this.beginTime,
required this.network,
required this.route,
required this.mileage,
required this.notes,
required this.locos,
});
factory TripLeg.fromJson(Map<String, dynamic> json) => TripLeg(
id: json['leg_id'],
start: json['leg_start'] ?? '',
end: json['leg_end'] ?? '',
beginTime:
json['leg_begin_time'] != null && json['leg_begin_time'] is String
? DateTime.tryParse(json['leg_begin_time'])
: (json['leg_begin_time'] is DateTime
? json['leg_begin_time']
: null),
network: json['leg_network'],
route: json['leg_route'],
mileage: (json['leg_mileage'] as num?)?.toDouble(),
notes: json['leg_notes'],
locos: (json['locos'] as List?)
?.map((e) => Loco.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
);
}
class TripDetail {
final int id;
final String name;
final double mileage;
final int legCount;
final List<TripLeg> legs;
TripDetail({
required this.id,
required this.name,
required this.mileage,
required this.legCount,
required this.legs,
});
factory TripDetail.fromJson(Map<String, dynamic> json) => TripDetail(
id: json['trip_id'] ?? 0,
name: json['trip_name'] ?? '',
mileage: (json['trip_mileage'] as num?)?.toDouble() ?? 0,
legCount: json['leg_count'] ??
((json['trip_legs'] as List?)?.length ?? 0),
legs: (json['trip_legs'] as List?)
?.map((e) => TripLeg.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
);
}