Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Jan 8, 2025
1 parent 46de15b commit 29095b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function getDepartures(Station $station, Carbon|null $timestamp =
'category' => HafasTravelType::UNKNOWN, //TODO
'number' => preg_replace('/\D/', '', $rawDeparture['verkehrmittel']['name']),
'linename' => $rawDeparture['verkehrmittel']['name'] ?? '',
'journey_number' => preg_replace('/\D/', '', $rawDeparture['verkehrmittel']['name']),
'journey_number' => (int)preg_replace('/\D/', '', $rawDeparture['verkehrmittel']['name']),
'operator_id' => null, //TODO
'origin_id' => $originStation->id,
'destination_id' => $destinationStation->id,
Expand Down
29 changes: 27 additions & 2 deletions app/Http/Resources/DepartureResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public function toArray(Request $request): array {
"provenance" => null,
"line" => [
"type" => "line",
"id" => "ec-9",
"id" => $this->trip->linename,
"fahrtNr" => $this->trip->number,
"name" => $this->trip->linename,
"public" => true,
"adminCode" => "80____",
"productName" => $this->trip->linename, //TODO
"mode" => "train", //TODO
"product" => "national", //TODO
"product" => self::estimateType($this->trip->linename), //not the best, but it works for now
"operator" => null,/*[ //TODO
"type" => "operator",
"id" => "db-fernverkehr-ag",
Expand Down Expand Up @@ -96,4 +96,29 @@ public function toArray(Request $request): array {
"station" => new StationResource($this->station)
];
}

private static function estimateType(string $linename): string {
if(str_contains($linename, 'ICE') || str_contains($linename, 'IC') || str_contains($linename, 'EC')) {
return "nationalExpress";
}
if(str_contains($linename, 'RE') || str_contains($linename, 'RB')) {
return "regional";
}
if(str_contains($linename, 'S')) {
return "suburban";
}
if(str_contains($linename, 'Bus')) {
return "bus";
}
if(str_contains($linename, 'Ferry')) {
return "ferry";
}
if(str_contains($linename, 'U')) {
return "subway";
}
if(str_contains($linename, 'Tram') || str_contains($linename, 'STR')) {
return "tram";
}
return "national";
}
}

0 comments on commit 29095b7

Please sign in to comment.