Skip to content

Commit

Permalink
feat: better oebb coach sequence (#522)
Browse files Browse the repository at this point in the history
* WIP

* feat: new OEBB info backend, better conversion to DB coachSequence format
  • Loading branch information
marudor authored Oct 10, 2021
1 parent 461582a commit ca45d1c
Show file tree
Hide file tree
Showing 33 changed files with 2,512 additions and 1,949 deletions.
219 changes: 73 additions & 146 deletions cypress/fixtures/abfahrtenFrankfurtHbf.json

Large diffs are not rendered by default.

823 changes: 274 additions & 549 deletions cypress/fixtures/abfahrtenHamburgHbf.json

Large diffs are not rendered by default.

810 changes: 270 additions & 540 deletions cypress/fixtures/abfahrtenHannoverHbf.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cypress/fixtures/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@
"scheduledPlatform": "12",
"auslastung": false,
"reihung": false,
"hiddenReihung": true,
"cancelled": true
}
4 changes: 2 additions & 2 deletions cypress/integration/abfahrtenSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('Abfahrten Settings', () => {
it('Show fahrzeuggruppe', () => {
cy.intercept(
{
url: '/api/reihung/v2/wagen/371/2019-08-07T12:50:00.000Z?*',
url: '/api/reihung/v3/wagen/371?*',
query: {
trainType: 'ICE',
evaNumber: '8000105',
departure: '2019-08-07T12:50:00.000Z',
},
},
{
Expand Down
12 changes: 6 additions & 6 deletions cypress/integration/reihung.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ describe('Reihung', () => {
cy.visit('/');
cy.intercept(
{
url: '/api/reihung/v2/wagen/371/2019-08-07T12:50:00.000Z?*',
url: '/api/reihung/v3/wagen/371?*',
query: {
trainType: 'ICE',
evaNumber: '8000105',
departure: '2019-08-07T12:50:00.000Z',
},
},
{
Expand Down Expand Up @@ -51,10 +51,10 @@ describe('Reihung', () => {
cy.navigateToStation('Hannover Hbf');
cy.intercept(
{
url: '/api/reihung/v2/wagen/537/2020-02-22T11:26:00.000Z?*',
url: '/api/reihung/v3/wagen/537?*',
query: {
trainType: 'ICE',
evaNumber: '8000152',
departure: '2020-02-22T11:26:00.000Z',
},
},
{
Expand All @@ -63,10 +63,10 @@ describe('Reihung', () => {
).as('537');
cy.intercept(
{
url: '/api/reihung/v2/wagen/587/2020-02-22T11:26:00.000Z?*',
url: '/api/reihung/v3/wagen/587?*',
query: {
trainType: 'ICE',
evaNumber: '8000152',
departure: '2020-02-22T11:26:00.000Z',
},
},
{
Expand Down
22 changes: 10 additions & 12 deletions packages/client/Abfahrten/Components/Abfahrt/BaseAbfahrt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,16 @@ export const BaseAbfahrt = memo(function BaseAbfahrt({
<Mid />
<End />
</div>
{detail &&
abfahrt.departure &&
(abfahrt.reihung || abfahrt.hiddenReihung) && (
<LazyReihung
loadHidden={!abfahrt.reihung && abfahrt.hiddenReihung}
trainNumber={abfahrt.train.number}
currentEvaNumber={abfahrt.currentStopPlace.evaNumber}
trainType={abfahrt.train.type}
scheduledDeparture={abfahrt.departure.scheduledTime}
fallbackTrainNumbers={wingNumbersWithoutSelf}
/>
)}
{detail && abfahrt.departure && (
<LazyReihung
loadHidden={!abfahrt.reihung}
trainNumber={abfahrt.train.number}
currentEvaNumber={abfahrt.currentStopPlace.evaNumber}
initialDeparture={abfahrt.initialDeparture}
scheduledDeparture={abfahrt.departure.scheduledTime}
fallbackTrainNumbers={wingNumbersWithoutSelf}
/>
)}
{detail && (
<div
className={classes.scrollMarker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@
"platform": "18",
"scheduledPlatform": "18",
"auslastung": true,
"reihung": true,
"hiddenReihung": false
"reihung": true
}
1 change: 0 additions & 1 deletion packages/client/Common/Components/Details/Stop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export const Stop: FC<Props> = ({ stop, showWR, train, isPast }) => {
trainNumber={showWR.number}
currentEvaNumber={stop.station.id}
scheduledDeparture={depOrArrival.scheduledTime}
trainType={showWR.type}
loadHidden={!depOrArrival?.reihung}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions packages/client/Common/Components/Reihung/Explain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const iconExplanation: { [K in keyof typeof icons]: string } = {
family: 'Familienbereich',
disabled: 'Schwerbehindertenplätze',
info: 'Dienstabteil',
wifi: 'WLAN',
};

export const Explain: FC = () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/client/Common/Components/Reihung/Fahrzeug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LocalDining,
Motorcycle,
NotificationsOff,
WifiOutlined,
} from '@material-ui/icons';
import { makeStyles } from '@material-ui/core';
import { SitzplatzInfo } from './SitzplatzInfo';
Expand All @@ -31,6 +32,7 @@ export const icons: {
family: ChildCare,
disabled: Accessibility,
info: InfoOutlined,
wifi: WifiOutlined,
};

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -171,8 +173,8 @@ export const Fahrzeug: FC<Props> = ({
}) => {
const classes = useStyles();
const { startprozent, endeprozent } = fahrzeug.positionamhalt;
const start = Number.parseInt(startprozent, 10);
const end = Number.parseInt(endeprozent, 10);
const start = Number.parseFloat(startprozent);
const end = Number.parseFloat(endeprozent);

const position = {
left: `${(start - correctLeft) * scale}%`,
Expand All @@ -183,7 +185,9 @@ export const Fahrzeug: FC<Props> = ({
<div
className={clsx(classes.wrap, {
[classes.wrongWing]: wrongWing,
[classes.closed]: fahrzeug.status === 'GESCHLOSSEN',
[classes.closed]:
fahrzeug.status === 'GESCHLOSSEN' ||
fahrzeug.additionalInfo.klasse === 4,
})}
data-testid={`reihungFahrzeug${fahrzeug.wagenordnungsnummer}`}
style={position}
Expand Down
7 changes: 5 additions & 2 deletions packages/client/Common/Components/Reihung/Gruppe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export const Gruppe: FC<Props> = ({
const fahrzeuge = useMemo(() => {
const wrongWing =
originalTrainNumber !== gruppe.verkehrlichezugnummer &&
originalTrainNumber.length <= 4 &&
gruppe.verkehrlichezugnummer.length <= 4;
// originalTrainNumber.length <= 4 &&
// gruppe.verkehrlichezugnummer.length <= 4 &&
gruppe.allFahrzeug.some(
(f) => f.status !== 'GESCHLOSSEN' && f.additionalInfo.klasse !== 4,
);
return gruppe.allFahrzeug.map((f) => {
return (
<Fahrzeug
Expand Down
4 changes: 2 additions & 2 deletions packages/client/Common/Components/Reihung/Sektor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const Sektor: FC<Props> = ({ sektor, correctLeft, scale }) => {
const classes = useStyles();
const position = useMemo(() => {
const { startprozent, endeprozent } = sektor.positionamgleis;
const start = Number.parseInt(startprozent, 10);
const end = Number.parseInt(endeprozent, 10);
const start = Number.parseFloat(startprozent);
const end = Number.parseFloat(endeprozent);

return {
left: `${(start - correctLeft) * scale}%`,
Expand Down
12 changes: 6 additions & 6 deletions packages/client/Common/Components/Reihung/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const useStyles = makeStyles((theme) => ({
interface Props {
className?: string;
trainNumber: string;
trainType?: string;
fallbackTrainNumbers?: string[];
currentEvaNumber: string;
scheduledDeparture: Date;
initialDeparture?: Date;
loadHidden?: boolean;
withLegend?: boolean;
}
Expand All @@ -77,7 +77,7 @@ export const Reihung: FC<Props> = ({
currentEvaNumber,
scheduledDeparture,
trainNumber,
trainType,
initialDeparture,
loadHidden,
fallbackTrainNumbers,
}) => {
Expand All @@ -94,20 +94,20 @@ export const Reihung: FC<Props> = ({
if (reihung === undefined) {
void getReihung(
trainNumber,
trainType,
currentEvaNumber,
scheduledDeparture,
initialDeparture,
fallbackTrainNumbers,
);
}
}, [
currentEvaNumber,
fallbackTrainNumbers,
getReihung,
initialDeparture,
reihung,
scheduledDeparture,
trainNumber,
trainType,
]);

const mainStyle = useMemo(() => {
Expand Down Expand Up @@ -146,7 +146,7 @@ export const Reihung: FC<Props> = ({
))}
</div>
<div className={classes.reihungWrap}>
{reihung.allFahrzeuggruppe.map((g) => (
{reihung.allFahrzeuggruppe.map((g, i) => (
<Gruppe
showGruppenZugnummer={reihung.differentZugnummer}
showUIC={showUIC}
Expand All @@ -158,8 +158,8 @@ export const Reihung: FC<Props> = ({
showDestination={
reihung.differentDestination && g.allFahrzeug.length > 1
}
key={g.fahrzeuggruppebezeichnung}
gruppe={g}
key={i}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,5 @@
"platform": "Fern 7",
"scheduledPlatform": "Fern 7",
"auslastung": true,
"reihung": true,
"hiddenReihung": false
"reihung": true
}
13 changes: 7 additions & 6 deletions packages/client/Common/provider/ReihungenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ async function fetchSequence(
trainNumber: string,
scheduledDeparture: Date,
evaNumber: string,
trainType?: string,
initialDeparture?: Date,
): Promise<Formation | undefined> {
try {
const r = await Axios.get<Formation>(
`/api/reihung/v2/wagen/${trainNumber}/${scheduledDeparture.toISOString()}`,
`/api/reihung/v3/wagen/${trainNumber}`,
{
params: {
evaNumber,
trainType,
departure: scheduledDeparture.toISOString(),
initialDeparture: initialDeparture?.toISOString(),
},
},
);
Expand All @@ -32,9 +33,9 @@ function useReihungInner() {
const getReihung = useCallback(
async (
trainNumber: string,
trainType: string | undefined,
currentEvaNumber: string,
scheduledDeparture: Date,
initialDeparture?: Date,
fallbackTrainNumbers: string[] = [],
) => {
let reihung: Formation | undefined | null;
Expand All @@ -44,14 +45,14 @@ function useReihungInner() {
trainNumber,
scheduledDeparture,
currentEvaNumber,
trainType,
initialDeparture,
),
...fallbackTrainNumbers.map((fallback) =>
fetchSequence(
fallback,
scheduledDeparture,
currentEvaNumber,
trainType,
initialDeparture,
),
),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const JnySegmentTrain: FC<Props> = ({
className={classes.reihung}
trainNumber={segment.train.number}
currentEvaNumber={segment.segmentStart.id}
trainType={segment.train.type}
scheduledDeparture={segment.departure.scheduledTime}
/>
)}
Expand Down
27 changes: 15 additions & 12 deletions packages/oebb/coachSequence.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { format } from 'date-fns';
import Axios from 'axios';
import type { OEBBCoachSequence } from 'oebb/types/coachSequence';
import type { OEBBInfo } from 'oebb/types/coachSequence';

const client = Axios.create({
baseURL: 'https://live.oebb.at/backend/api/train',
baseURL: 'https://live.oebb.at/backend',
});

export async function coachSequence(
trainName: string,
export async function info(
trainNumber: number,
evaNumber: string,
departureDate: Date,
): Promise<OEBBCoachSequence> {
return await (
await client.get(
`/${trainName}/stationEva/${evaNumber}/departure/${format(
departureDate,
'dd.MM.yyyy',
)}`,
)
): Promise<OEBBInfo | undefined> {
const info = (
await client.get<OEBBInfo>('/info', {
params: {
trainNr: trainNumber,
station: evaNumber,
date: format(departureDate, 'yyyy-MM-dd'),
},
})
).data;
if (info.timeTableInfo.trainNr !== trainNumber) return undefined;
return info;
}
Loading

0 comments on commit ca45d1c

Please sign in to comment.