Add initial project files and configurations for bus_running_record app
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
class BRRMetadata {
|
||||
final String route; // "Metropolitan_Line_Uxbridge"
|
||||
final String date; // "21_09_2025"
|
||||
final String location; // "Uxbridge Station"
|
||||
final String controller; // "Benjamin Watt"
|
||||
final String? sheetNumber;
|
||||
|
||||
BRRMetadata({
|
||||
required this.route,
|
||||
required this.date,
|
||||
required this.location,
|
||||
required this.controller,
|
||||
this.sheetNumber,
|
||||
});
|
||||
|
||||
factory BRRMetadata.fromSchedule(String scheduleText) {
|
||||
// Extract metadata from schedule header
|
||||
final routeMatch = RegExp(r"ROUTE\s+(\w+)").firstMatch(scheduleText);
|
||||
final dateMatch =
|
||||
RegExp(r"(\d{1,2})\s+(\d{1,2})\s+(\d{2})").firstMatch(scheduleText);
|
||||
|
||||
return BRRMetadata(
|
||||
route: routeMatch?.group(1) ?? "Unknown",
|
||||
date: dateMatch != null
|
||||
? "${dateMatch.group(1)}_${dateMatch.group(2)}_20${dateMatch.group(3)}"
|
||||
: DateTime.now().toString().split(" ")[0],
|
||||
location: "Unknown",
|
||||
controller: "Unknown",
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"route": route,
|
||||
"date": date,
|
||||
"location": location,
|
||||
"controller": controller,
|
||||
"sheetNumber": sheetNumber,
|
||||
};
|
||||
}
|
||||
|
||||
factory BRRMetadata.fromJson(Map<String, dynamic> json) {
|
||||
return BRRMetadata(
|
||||
route: json["route"] as String,
|
||||
date: json["date"] as String,
|
||||
location: json["location"] as String,
|
||||
controller: json["controller"] as String,
|
||||
sheetNumber: json["sheetNumber"] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import "trip.dart";
|
||||
|
||||
class BRRState {
|
||||
final List<Trip> trips;
|
||||
final String? scheduleFileName;
|
||||
final DateTime? uploadedAt;
|
||||
final String? routeInfo; // e.g., "Metropolitan Line - Uxbridge"
|
||||
final String? serviceDate; // "21/09/2025"
|
||||
|
||||
BRRState({
|
||||
this.trips = const [],
|
||||
this.scheduleFileName,
|
||||
this.uploadedAt,
|
||||
this.routeInfo,
|
||||
this.serviceDate,
|
||||
});
|
||||
|
||||
BRRState copyWith({
|
||||
List<Trip>? trips,
|
||||
String? scheduleFileName,
|
||||
DateTime? uploadedAt,
|
||||
String? routeInfo,
|
||||
String? serviceDate,
|
||||
}) {
|
||||
return BRRState(
|
||||
trips: trips ?? this.trips,
|
||||
scheduleFileName: scheduleFileName ?? this.scheduleFileName,
|
||||
uploadedAt: uploadedAt ?? this.uploadedAt,
|
||||
routeInfo: routeInfo ?? this.routeInfo,
|
||||
serviceDate: serviceDate ?? this.serviceDate,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"trips": trips.map((trip) => trip.toJson()).toList(),
|
||||
"scheduleFileName": scheduleFileName,
|
||||
"uploadedAt": uploadedAt?.toIso8601String(),
|
||||
"routeInfo": routeInfo,
|
||||
"serviceDate": serviceDate,
|
||||
};
|
||||
}
|
||||
|
||||
factory BRRState.fromJson(Map<String, dynamic> json) {
|
||||
return BRRState(
|
||||
trips: (json["trips"] as List?)
|
||||
?.map((tripJson) => Trip.fromJson(tripJson as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
scheduleFileName: json["scheduleFileName"] as String?,
|
||||
uploadedAt: json["uploadedAt"] != null
|
||||
? DateTime.parse(json["uploadedAt"] as String)
|
||||
: null,
|
||||
routeInfo: json["routeInfo"] as String?,
|
||||
serviceDate: json["serviceDate"] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
class Trip {
|
||||
final String scheduledTime; // "15:31" - default departure time (first non-empty time)
|
||||
final String tripNumber; // "112"
|
||||
final String dutyNumber; // "518"
|
||||
final String runningNumber; // "518"
|
||||
final String tripType; // "", "N", "R", "F"
|
||||
final bool isFinishing;
|
||||
final Map<String, String> stationTimes; // {"UXBG": "15:31", "HILL": "15:42", ...}
|
||||
final List<String> stationOrder; // ["UXBG", "UXBG", "HILL", "ICKE", ...]
|
||||
final String direction; // "outbound" or "inbound"
|
||||
|
||||
String? actualDepartureTime; // "15:33" (nullable - user input)
|
||||
String? actualFleetNumber; // "33523" (nullable - user input)
|
||||
|
||||
Trip({
|
||||
required this.scheduledTime,
|
||||
required this.tripNumber,
|
||||
required this.dutyNumber,
|
||||
required this.runningNumber,
|
||||
this.tripType = "",
|
||||
this.isFinishing = false,
|
||||
this.stationTimes = const {},
|
||||
this.stationOrder = const [],
|
||||
this.direction = "outbound",
|
||||
this.actualDepartureTime,
|
||||
this.actualFleetNumber,
|
||||
});
|
||||
|
||||
bool get isComplete =>
|
||||
actualDepartureTime != null && actualFleetNumber != null;
|
||||
|
||||
Trip copyWith({
|
||||
String? scheduledTime,
|
||||
String? tripNumber,
|
||||
String? dutyNumber,
|
||||
String? runningNumber,
|
||||
String? tripType,
|
||||
bool? isFinishing,
|
||||
Map<String, String>? stationTimes,
|
||||
List<String>? stationOrder,
|
||||
String? direction,
|
||||
String? actualDepartureTime,
|
||||
String? actualFleetNumber,
|
||||
}) {
|
||||
return Trip(
|
||||
scheduledTime: scheduledTime ?? this.scheduledTime,
|
||||
tripNumber: tripNumber ?? this.tripNumber,
|
||||
dutyNumber: dutyNumber ?? this.dutyNumber,
|
||||
runningNumber: runningNumber ?? this.runningNumber,
|
||||
tripType: tripType ?? this.tripType,
|
||||
isFinishing: isFinishing ?? this.isFinishing,
|
||||
stationTimes: stationTimes ?? this.stationTimes,
|
||||
stationOrder: stationOrder ?? this.stationOrder,
|
||||
direction: direction ?? this.direction,
|
||||
actualDepartureTime: actualDepartureTime ?? this.actualDepartureTime,
|
||||
actualFleetNumber: actualFleetNumber ?? this.actualFleetNumber,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"scheduledTime": scheduledTime,
|
||||
"tripNumber": tripNumber,
|
||||
"dutyNumber": dutyNumber,
|
||||
"runningNumber": runningNumber,
|
||||
"tripType": tripType,
|
||||
"isFinishing": isFinishing,
|
||||
"stationTimes": stationTimes,
|
||||
"stationOrder": stationOrder,
|
||||
"direction": direction,
|
||||
"actualDepartureTime": actualDepartureTime,
|
||||
"actualFleetNumber": actualFleetNumber,
|
||||
};
|
||||
}
|
||||
|
||||
factory Trip.fromJson(Map<String, dynamic> json) {
|
||||
return Trip(
|
||||
scheduledTime: json["scheduledTime"] as String,
|
||||
tripNumber: json["tripNumber"] as String,
|
||||
dutyNumber: json["dutyNumber"] as String,
|
||||
runningNumber: json["runningNumber"] as String,
|
||||
tripType: json["tripType"] as String? ?? "",
|
||||
isFinishing: json["isFinishing"] as bool? ?? false,
|
||||
stationTimes: Map<String, String>.from(json["stationTimes"] as Map? ?? {}),
|
||||
stationOrder: List<String>.from(json["stationOrder"] as List? ?? []),
|
||||
direction: json["direction"] as String? ?? "outbound",
|
||||
actualDepartureTime: json["actualDepartureTime"] as String?,
|
||||
actualFleetNumber: json["actualFleetNumber"] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user