[ZTM Gdansk] Merge real departure with scheduled for better destination showcase

This commit is contained in:
Kacper Donat 2020-01-15 20:32:11 +01:00
parent 78263302c8
commit 4b389582ad
2 changed files with 23 additions and 5 deletions

View File

@ -22,7 +22,7 @@ const sessionStoragePersist = new VuexPersistence<State>({
storage: window.sessionStorage
});
export default new Vuex.Store({
const store = new Vuex.Store({
state, mutations, actions,
modules: { messages, departures, favourites },
plugins: [
@ -31,4 +31,6 @@ export default new Vuex.Store({
localStoragePersist.plugin,
sessionStoragePersist.plugin,
]
})
});
export default store;

View File

@ -42,9 +42,9 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
public function getForStop(Stop $stop): Collection
{
$real = $this->getRealDepartures($stop);
$now = Carbon::now();
$now = Carbon::now()->second(0);
$first = $real->map(t\getter('scheduled'))->min() ?? $now;
$scheduled = $this->getScheduledDepartures($stop, $first < $now ? $now : $first);
$scheduled = $this->getScheduledDepartures($stop, $first);
return $this->pair($scheduled, $real);
}
@ -103,10 +103,26 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
})->merge(collect($schedule)->map(function (Departure $scheduled) {
return [ null, $scheduled ];
}))->map(function ($pair) {
return $pair[0] ?? $pair[1];
return $this->merge(...$pair);
})->sortBy(function (Departure $departure) {
$time = $departure->getEstimated() ?? $departure->getScheduled();
return $time->getTimestamp();
});
}
private function merge(?Departure $real, ?Departure $scheduled)
{
if (!$real) {
return $scheduled;
}
if (!$scheduled) {
return $real;
}
$departure = clone $real;
$departure->setDisplay($scheduled->getDisplay());
return $departure;
}
}