-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added SFERA mapping for graduated station speed (#82)
- Loading branch information
1 parent
f4f9013
commit 62fe845
Showing
20 changed files
with
621 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
das_client/lib/model/journey/graduated_station_speeds.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:das_client/model/journey/speed.dart'; | ||
import 'package:das_client/model/journey/train_series.dart'; | ||
|
||
class GraduatedStationSpeeds { | ||
GraduatedStationSpeeds({ | ||
required this.trainSeries, | ||
this.text, | ||
this.incomingSpeeds = const [], | ||
this.outgoingSpeeds = const [], | ||
}) : assert(trainSeries.isNotEmpty); | ||
|
||
final List<TrainSeries> trainSeries; | ||
final String? text; | ||
final List<Speed> incomingSpeeds; | ||
final List<Speed> outgoingSpeeds; | ||
|
||
factory GraduatedStationSpeeds.from(List<TrainSeries> trainSeries, String speedString, {String? text}) { | ||
final parts = speedString.split('/'); | ||
final incomingSpeeds = parts[0].split('-'); | ||
final outgoingSpeeds = parts.length > 1 ? parts[1].split('-') : []; | ||
|
||
// validate station speed format | ||
final speedRegex = RegExp(Speed.speedRegex); | ||
final formatSatisfied = [...incomingSpeeds, ...outgoingSpeeds].every((speed) => speedRegex.hasMatch(speed)); | ||
if (incomingSpeeds.isNotEmpty && !formatSatisfied) { | ||
throw ArgumentError('Invalid graduated station speed format: $speedString'); | ||
} | ||
|
||
return GraduatedStationSpeeds( | ||
trainSeries: trainSeries, | ||
text: text, | ||
incomingSpeeds: incomingSpeeds.map((speed) => Speed.from(speed)).toList(), | ||
outgoingSpeeds: outgoingSpeeds.map((speed) => Speed.from(speed)).toList(), | ||
); | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'GraduatedStationSpeeds(trainSeries: $trainSeries, incomingSpeeds: $incomingSpeeds, outgoingSpeeds: $outgoingSpeeds)'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Speed { | ||
const Speed({ | ||
required this.speed, | ||
this.isSquared = false, | ||
this.isCircled = false, | ||
}); | ||
|
||
factory Speed.from(String value) { | ||
if (RegExp(speedRegex).hasMatch(value)) { | ||
final digit = RegExp(r'\d+').stringMatch(value); | ||
return Speed( | ||
speed: int.parse(digit!), | ||
isCircled: value.contains('{'), | ||
isSquared: value.contains('['), | ||
); | ||
} | ||
|
||
throw ArgumentError('Invalid speed format: $value'); | ||
} | ||
|
||
static const speedRegex = r'^\d+$|^\[\d+\]$|^\{\d+\}$'; // exp. 50, {60} or [70] | ||
|
||
final int speed; | ||
|
||
/// Normally means that speed is higher than given by signaling. Can have other meanings so this variable is named generically. | ||
final bool isSquared; | ||
|
||
/// Normally means that speed is lower than given by signaling. Can have other meanings so this variable is named generically. | ||
final bool isCircled; | ||
|
||
@override | ||
String toString() { | ||
return 'Speed(speed: $speed, isSquared: $isSquared, isCircled: $isCircled)'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:das_client/model/journey/graduated_station_speeds.dart'; | ||
import 'package:das_client/model/journey/train_series.dart'; | ||
|
||
class StationSpeedData { | ||
StationSpeedData({this.graduatedStationSpeeds = const []}); | ||
|
||
final List<GraduatedStationSpeeds> graduatedStationSpeeds; | ||
|
||
GraduatedStationSpeeds? graduatedSpeedsFor(TrainSeries? trainSeries) { | ||
if (trainSeries == null) return null; | ||
|
||
return graduatedStationSpeeds.firstWhereOrNull((it) => it.trainSeries.contains(trainSeries)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:das_client/sfera/src/model/graduated_speed_info_entity.dart'; | ||
import 'package:das_client/sfera/src/model/sfera_xml_element.dart'; | ||
|
||
class GraduatedSpeedInfo extends SferaXmlElement { | ||
static const String elementType = 'entries'; | ||
|
||
GraduatedSpeedInfo({super.type = elementType, super.attributes, super.children, super.value}); | ||
|
||
Iterable<GraduatedSpeedInfoEntity> get entities => children.whereType<GraduatedSpeedInfoEntity>(); | ||
} |
17 changes: 17 additions & 0 deletions
17
das_client/lib/sfera/src/model/graduated_speed_info_entity.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:das_client/sfera/src/model/sfera_xml_element.dart'; | ||
|
||
class GraduatedSpeedInfoEntity extends SferaXmlElement { | ||
static const String elementType = 'entry'; | ||
|
||
GraduatedSpeedInfoEntity({super.type = elementType, super.attributes, super.children, super.value}); | ||
|
||
String? get nSpeed => attributes['nSpeed']; | ||
|
||
String? get roSpeed => attributes['roSpeed']; | ||
|
||
String? get adSpeed => attributes['adSpeed']; | ||
|
||
String? get sSpeed => attributes['sSpeed']; | ||
|
||
String? get text => attributes['text']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:das_client/sfera/src/model/graduated_speed_info.dart'; | ||
import 'package:das_client/sfera/src/model/network_specific_parameter.dart'; | ||
import 'package:das_client/sfera/src/model/nsp_xml_element.dart'; | ||
|
||
class XmlGraduatedSpeedInfo extends NetworkSpecificParameter with NspXmlElement<GraduatedSpeedInfo> { | ||
static const String elementName = 'xmlGraduatedSpeedInfo'; | ||
|
||
XmlGraduatedSpeedInfo({super.attributes, super.children, super.value}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.