feat(api): add stop names tables for bb, by and ni

This commit is contained in:
dancingCycle 2023-08-29 12:14:10 +02:00
parent 1ab73e0783
commit 37d332c29a
9 changed files with 288 additions and 2 deletions

View File

@ -5,6 +5,9 @@ import Header from './components/header';
import Home from './pages/home';
import StopsNonConforming from './pages/stops-non-conforming';
import StopsRefined from './pages/stops-refined';
import StopNamesBb from './pages/stop-names-bb';
import StopNamesBy from './pages/stop-names-by';
import StopNamesNi from './pages/stop-names-ni';
import {
getGtfsStopsLastVacuum
@ -63,6 +66,9 @@ export default function App(){
<Route exact path='/' element={<Home/>}/>
<Route exact path='/stops-non-compliant' element={<StopsNonConforming/>}/>
<Route exact path='/stops-refined' element={<StopsRefined/>}/>
<Route exact path='/stop-names-bb' element={<StopNamesBb/>}/>
<Route exact path='/stop-names-ni' element={<StopNamesNi/>}/>
<Route exact path='/stop-names-by' element={<StopNamesBy/>}/>
</Routes>
</Router>
</div>

View File

@ -37,11 +37,14 @@ export default function State ({state}) {
}, []);
if (state !== undefined || state !== null || state === '') {
const linkStopNames = '/stop-names-' + state.toLowerCase();
//console.log('State: linkStopNames: ' + linkStopNames);
/*return a React element*/
return (
<>
<p>
DE-{state.toUpperCase()}: Stops not compliant with the Global ID:&nbsp;
DE-
<Link to={linkStopNames}>{state.toUpperCase()}</ Link>: Stops not compliant with the Global ID:&nbsp;
{countStopsNotDhid} ({countStops !== 0 ? (countStopsNotDhid / countStops * 100).toFixed(3) : 'loading...'} %)
(Stops overall:&nbsp;
{countStops})

View File

@ -0,0 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
function TableStopNamesEntries ({array}) {
if (array !== undefined || array !== null || array.length > 0) {
//iterate over array
return array.map((item, index) => {
return (
<tr
key={item.stop_name}
>
<td>{item.count_id}</td>
<td>{item.count_no_dhid}</td>
<td>{item.count_dhid}</td>
<td>{item.stop_name}</td>
</tr>
);
});
}else{
//data is empty
return null;
}
}
TableStopNamesEntries.propTypes = {
array: PropTypes.array
};
export default TableStopNamesEntries;

View File

@ -0,0 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import TableEntries from './table-stop-names-entries';
/*destructure props object*/
export default function TableStopNames ({array}){
if (array == undefined || array == null || array.length < 1) {
return (
<>
<p>Loading...</p>
</>
);
}else{
return (
<>
<table>
<thead>
<tr>
<th>count_id</th>
<th>count_no_dhid</th>
<th>count_dhid</th>
<th>stop_name</th>
</tr>
</thead>
<tbody>
<TableEntries array={array} />
</tbody>
</table>
</>
);
}
};
TableStopNames.propTypes = {
array: PropTypes.array
};

View File

@ -81,8 +81,8 @@ export default function Home(){
</p>
<State state='bb' />
<State state='be' />
<State state='by' />
<State state='bw' />
<State state='by' />
<State state='hb' />
<State state='he' />
<State state='hh' />

View File

@ -0,0 +1,66 @@
import React, { useEffect, useState } from 'react';
import Table from '../components/table-stop-names';
import {get} from '../utils/request';
export default function StopNamesBb() {
const [countNoGi, setCountNoGi] = useState('loading...');
const [countPartGi, setCountPartGi] = useState('loading...');
const [namesNoGi, setNamesNoGi] = useState([]);
const [namesPartGi, setNamesPartGi] = useState([]);
useEffect(() => {
let address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-no-gi?state=bb';
//console.log('StopNamesBb:useEffect() address: ' + address);
//get count no gi
get(address)
.then(data => {
setCountNoGi((countPartGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-part-gi?state=bb';
//console.log('StopNamesBb:useEffect() address: ' + address);
//get count part gi
get(address)
.then(data => {
setCountPartGi((countNoGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-no-gi?state=bb'
//console.log('StopNamesBb:useEffect() address: ' + address);
//get names no gi
get(address)
.then(data => {
setNamesNoGi((namesNoGi) => data);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-part-gi?state=bb'
//console.log('StopNamesBb:useEffect() address: ' + address);
//get names part gi
get(address)
.then(data => {
setNamesPartGi((namesPartGi) => data);
});
}, []);
return (
<>
<p>
{countNoGi} stops do not use a Global ID as stop_name for any platform/ quay.
</p>
<Table array={namesNoGi} />
<p>
{countPartGi} stops use a Global ID as stop_name for some platforms/ quays.
</p>
<Table array={namesPartGi} />
</>
);
}

View File

@ -0,0 +1,66 @@
import React, { useEffect, useState } from 'react';
import Table from '../components/table-stop-names';
import {get} from '../utils/request';
export default function StopNamesBy() {
const [countNoGi, setCountNoGi] = useState('loading...');
const [countPartGi, setCountPartGi] = useState('loading...');
const [namesNoGi, setNamesNoGi] = useState([]);
const [namesPartGi, setNamesPartGi] = useState([]);
useEffect(() => {
let address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-no-gi?state=by';
//console.log('StopNamesBy:useEffect() address: ' + address);
//get count no gi
get(address)
.then(data => {
setCountNoGi((countPartGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-part-gi?state=by';
//console.log('StopNamesBy:useEffect() address: ' + address);
//get count part gi
get(address)
.then(data => {
setCountPartGi((countNoGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-no-gi?state=by'
//console.log('StopNamesBy:useEffect() address: ' + address);
//get names no gi
get(address)
.then(data => {
setNamesNoGi((namesNoGi) => data);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-part-gi?state=by'
//console.log('StopNamesBy:useEffect() address: ' + address);
//get names part gi
get(address)
.then(data => {
setNamesPartGi((namesPartGi) => data);
});
}, []);
return (
<>
<p>
{countNoGi} stops do not use a Global ID as stop_name for any platform/ quay.
</p>
<Table array={namesNoGi} />
<p>
{countPartGi} stops use a Global ID as stop_name for some platforms/ quays.
</p>
<Table array={namesPartGi} />
</>
);
}

View File

@ -0,0 +1,66 @@
import React, { useEffect, useState } from 'react';
import Table from '../components/table-stop-names';
import {get} from '../utils/request';
export default function StopNamesNi() {
const [countNoGi, setCountNoGi] = useState('loading...');
const [countPartGi, setCountPartGi] = useState('loading...');
const [namesNoGi, setNamesNoGi] = useState([]);
const [namesPartGi, setNamesPartGi] = useState([]);
useEffect(() => {
let address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-no-gi?state=ni';
//console.log('StopNamesNi:useEffect() address: ' + address);
//get count no gi
get(address)
.then(data => {
setCountNoGi((countPartGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-count-part-gi?state=ni';
//console.log('StopNamesNi:useEffect() address: ' + address);
//get count part gi
get(address)
.then(data => {
setCountPartGi((countNoGi) => data[0].count);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-no-gi?state=ni'
//console.log('StopNamesNi:useEffect() address: ' + address);
//get names no gi
get(address)
.then(data => {
setNamesNoGi((namesNoGi) => data);
});
address = 'https://www.v1delfi.api.swingbe.de/stop-names-part-gi?state=ni'
//console.log('StopNamesNi:useEffect() address: ' + address);
//get names part gi
get(address)
.then(data => {
setNamesPartGi((namesPartGi) => data);
});
}, []);
return (
<>
<p>
{countNoGi} stops do not use a Global ID as stop_name for any platform/ quay.
</p>
<Table array={namesNoGi} />
<p>
{countPartGi} stops use a Global ID as stop_name for some platforms/ quays.
</p>
<Table array={namesPartGi} />
</>
);
}

16
ui/app/utils/request.js Normal file
View File

@ -0,0 +1,16 @@
/**
* http get request
*
* @param pth path
*/
export async function get(pth) {
const data = await fetch(pth, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
const jsonData = await data.json();
return jsonData;
}