feat(api): starting here, only consider location type 0

This commit is contained in:
dancingCycle 2023-08-28 11:35:25 +02:00
parent e8405bab5a
commit de726a85e0
4 changed files with 177 additions and 77 deletions

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react'
import { Link, BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Header from './components/header';
@ -6,23 +6,48 @@ import Home from './pages/home';
import StopsNonConforming from './pages/stops-non-conforming';
import StopsRefined from './pages/stops-refined';
import {
getGtfsStopsLastVacuum
} from './utils/api';
import packageInfo from '../package.json'
const VERSION = packageInfo.version;
export default function App(){
const [gtfsStopsLastVacuum, setGtfsStopsLastVacuum] = useState('loading...');
const fetch = async () => {
let rsps=await getGtfsStopsLastVacuum();
setGtfsStopsLastVacuum((gtfsStopsLastVacuum) => rsps);
};
useEffect(() => {
/*effect goes here*/
fetch();
/*use an empty dependency countStopsGtfs to ensure the hook is running only once*/
/*TODO study dependency countStopsGtfs: https://reactjs.org/docs/hooks-effect.html*/
}, []);
return (
<div className='App'>
<Router>
<Header />
<h1>DELFI-Display</h1>
<p>
Display analysis results made on public transport data provided by &nbsp;
This website (Version:&nbsp;{VERSION}) dislays analysis results made on public transport data provided by &nbsp;
<a href="https://www.delfi.de/"
target="_blank" rel="noopener noreferrer"
>
DELFI
</a>.
</a>&nbsp;
last updated on &nbsp;{gtfsStopsLastVacuum}.
</p>
<h2>GTFS Static Feed</h2>
<p>
The so called "DELFI-Datensatz GTFS" is a GTFS Static Feed provided by DELFI accessible either via the &nbsp;
The so called "DELFI-Datensatz GTFS" is a "GTFS Schedule" feed provided by DELFI accessible either via the &nbsp;
<a href="https://www.opendata-oepnv.de"
target="_blank" rel="noopener noreferrer"
>

View File

@ -13,19 +13,35 @@ export default function Header(){
</button>
</Link>
<Link
to='https://www.swingbe.de/imprint/'
title="imprint"
target="_blank"
rel="noopener noreferrer nofollow"
to='https://www.swingbe.de/imprint/'
>
<button>
Imprint
</button>
</Link>
<Link
to='https://www.swingbe.de/privacy-policy/'
title="privacy policy"
target="_blank"
rel="noopener noreferrer nofollow"
to='https://www.swingbe.de/privacy-policy/'
>
<button>
Privacy Policy
</button>
</Link>
<Link
title="source"
target="_blank"
rel="noopener noreferrer nofollow"
to='https://git.wtf-eg.de/dancesWithCycles/delfi'
>
<button>
Source
</button>
</Link>
</>
);
};

View File

@ -20,6 +20,7 @@ import {
getStopsCountGtfsDeByNotDhid,
getStopsCountGtfsDeBwNotDhid,
getStopsCountGtfs,
getStopsCountGtfsLt0,
getStopsCountGtfsDe,
getStopsCountGtfsDeHb,
getStopsCountGtfsDeHh,
@ -43,6 +44,7 @@ export default function Home(){
const [countStopsGtfs, setCountStopsGtfs] = useState('loading...');
const [countStopsGtfsDe, setCountStopsGtfsDe] = useState('loading...');
const [countStopsGtfsLt0, setCountStopsGtfsLt0] = useState('loading...');
const [countStopsGtfsDeHb, setCountStopsGtfsDeHb] = useState('loading...');
const [countStopsGtfsDeHh, setCountStopsGtfsDeHh] = useState('loading...');
const [countStopsGtfsDeNi, setCountStopsGtfsDeNi] = useState('loading...');
@ -99,6 +101,13 @@ export default function Home(){
}
};
const fetchGtfsLt0 = async () => {
let count=await getStopsCountGtfsLt0();
if(count > -1){
setCountStopsGtfsLt0((countStopsGtfsLt0) => count);
}
};
const fetchGtfsDeHh = async () => {
let count=await getStopsCountGtfsDeHh();
if(count > -1){
@ -328,6 +337,7 @@ export default function Home(){
fetchGtfs();
fetchGtfsDe();
fetchGtfsLt0();
fetchGtfsDeHb();
fetchGtfsDeHh();
fetchGtfsDeNi();
@ -369,9 +379,22 @@ export default function Home(){
return (
<>
<p>
Number of stops:&nbsp;
Number of entries in the stops.txt file no matter the&nbsp;
<Link
title="gtfs stops location type"
target="_blank"
rel="noopener noreferrer nofollow"
to='https://gtfs.org/schedule/reference/#stopstxt'
>
location type
</Link>
:&nbsp;
{countStopsGtfs}
</p>
<p>
Starting here, only stops with location_type="0" are considered for further data analysis:&nbsp;
{countStopsGtfsLt0}
</p>
<p>
Number of stops inside DE:&nbsp;
{countStopsGtfsDe}

View File

@ -3,7 +3,7 @@ import axios from 'axios';
import config from './config';
export async function getStopsCountGtfs(){
//console.log('stops:getStopsCountGtfs() Start...');
//console.log('api:getStopsCountGtfs() Start...');
let count=null;
try {
@ -15,12 +15,12 @@ export async function getStopsCountGtfs(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfs() Done.');
//console.log('api:getStopsCountGtfs() Done.');
return count;
};
export async function getStopsCountGtfsDe(){
//console.log('stops:getStopsCountGtfsDe() Start...');
//console.log('api:getStopsCountGtfsDe() Start...');
let count=null;
try {
@ -32,12 +32,12 @@ export async function getStopsCountGtfsDe(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDe() Done.');
//console.log('api:getStopsCountGtfsDe() Done.');
return count;
};
export async function getStopsCountGtfsDeNotDhid(){
//console.log('stops:getStopsCountGtfsDeNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeNotDhid() Start...');
let count=null;
try {
@ -49,12 +49,12 @@ export async function getStopsCountGtfsDeNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeHb(){
//console.log('stops:getStopsCountGtfsDeHb() Start...');
//console.log('api:getStopsCountGtfsDeHb() Start...');
let count=null;
try {
@ -66,12 +66,12 @@ export async function getStopsCountGtfsDeHb(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHb() Done.');
//console.log('api:getStopsCountGtfsDeHb() Done.');
return count;
};
export async function getStopsCountGtfsDeHbNotDhid(){
//console.log('stops:getStopsCountGtfsDeHbNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeHbNotDhid() Start...');
let count=null;
try {
@ -83,12 +83,12 @@ export async function getStopsCountGtfsDeHbNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHbNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeHbNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeHhNotDhid(){
//console.log('stops:getStopsCountGtfsDeHhNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeHhNotDhid() Start...');
let count=null;
try {
@ -100,12 +100,12 @@ export async function getStopsCountGtfsDeHhNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHhNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeHhNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeNiNotDhid(){
//console.log('stops:getStopsCountGtfsDeNiNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeNiNotDhid() Start...');
let count=null;
try {
@ -117,12 +117,12 @@ export async function getStopsCountGtfsDeNiNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeNiNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeNiNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeHh(){
//console.log('stops:getStopsCountGtfsDeHh() Start...');
//console.log('api:getStopsCountGtfsDeHh() Start...');
let count=null;
try {
@ -134,12 +134,12 @@ export async function getStopsCountGtfsDeHh(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHh() Done.');
//console.log('api:getStopsCountGtfsDeHh() Done.');
return count;
};
export async function getStopsCountGtfsDeNi(){
//console.log('stops:getStopsCountGtfsDeNi() Start...');
//console.log('api:getStopsCountGtfsDeNi() Start...');
let count=null;
try {
@ -151,12 +151,12 @@ export async function getStopsCountGtfsDeNi(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeNi() Done.');
//console.log('api:getStopsCountGtfsDeNi() Done.');
return count;
};
export async function getStopsCountGtfsDeSh(){
//console.log('stops:getStopsCountGtfsDeSh() Start...');
//console.log('api:getStopsCountGtfsDeSh() Start...');
let count=null;
try {
@ -168,12 +168,12 @@ export async function getStopsCountGtfsDeSh(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSh() Done.');
//console.log('api:getStopsCountGtfsDeSh() Done.');
return count;
};
export async function getStopsCountGtfsDeMv(){
//console.log('stops:getStopsCountGtfsDeMv() Start...');
//console.log('api:getStopsCountGtfsDeMv() Start...');
let count=null;
try {
@ -185,12 +185,12 @@ export async function getStopsCountGtfsDeMv(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeMv() Done.');
//console.log('api:getStopsCountGtfsDeMv() Done.');
return count;
};
export async function getStopsCountGtfsDeBb(){
//console.log('stops:getStopsCountGtfsDeBb() Start...');
//console.log('api:getStopsCountGtfsDeBb() Start...');
let count=null;
try {
@ -202,12 +202,12 @@ export async function getStopsCountGtfsDeBb(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBb() Done.');
//console.log('api:getStopsCountGtfsDeBb() Done.');
return count;
};
export async function getStopsCountGtfsDeBe(){
//console.log('stops:getStopsCountGtfsDeBe() Start...');
//console.log('api:getStopsCountGtfsDeBe() Start...');
let count=null;
try {
@ -219,12 +219,12 @@ export async function getStopsCountGtfsDeBe(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBe() Done.');
//console.log('api:getStopsCountGtfsDeBe() Done.');
return count;
};
export async function getStopsCountGtfsDeSt(){
//console.log('stops:getStopsCountGtfsDeSt() Start...');
//console.log('api:getStopsCountGtfsDeSt() Start...');
let count=null;
try {
@ -236,12 +236,12 @@ export async function getStopsCountGtfsDeSt(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSt() Done.');
//console.log('api:getStopsCountGtfsDeSt() Done.');
return count;
};
export async function getStopsCountGtfsDeNw(){
//console.log('stops:getStopsCountGtfsDeNw() Start...');
//console.log('api:getStopsCountGtfsDeNw() Start...');
let count=null;
try {
@ -253,12 +253,12 @@ export async function getStopsCountGtfsDeNw(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeNw() Done.');
//console.log('api:getStopsCountGtfsDeNw() Done.');
return count;
};
export async function getStopsCountGtfsDeHe(){
//console.log('stops:getStopsCountGtfsDeHe() Start...');
//console.log('api:getStopsCountGtfsDeHe() Start...');
let count=null;
try {
@ -270,12 +270,12 @@ export async function getStopsCountGtfsDeHe(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHe() Done.');
//console.log('api:getStopsCountGtfsDeHe() Done.');
return count;
};
export async function getStopsCountGtfsDeSn(){
//console.log('stops:getStopsCountGtfsDeSn() Start...');
//console.log('api:getStopsCountGtfsDeSn() Start...');
let count=null;
try {
@ -287,12 +287,12 @@ export async function getStopsCountGtfsDeSn(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSn() Done.');
//console.log('api:getStopsCountGtfsDeSn() Done.');
return count;
};
export async function getStopsCountGtfsDeTh(){
//console.log('stops:getStopsCountGtfsDeTh() Start...');
//console.log('api:getStopsCountGtfsDeTh() Start...');
let count=null;
try {
@ -304,12 +304,12 @@ export async function getStopsCountGtfsDeTh(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeTh() Done.');
//console.log('api:getStopsCountGtfsDeTh() Done.');
return count;
};
export async function getStopsCountGtfsDeRp(){
//console.log('stops:getStopsCountGtfsDeRp() Start...');
//console.log('api:getStopsCountGtfsDeRp() Start...');
let count=null;
try {
@ -321,12 +321,12 @@ export async function getStopsCountGtfsDeRp(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeRp() Done.');
//console.log('api:getStopsCountGtfsDeRp() Done.');
return count;
};
export async function getStopsCountGtfsDeSl(){
//console.log('stops:getStopsCountGtfsDeSl() Start...');
//console.log('api:getStopsCountGtfsDeSl() Start...');
let count=null;
try {
@ -338,12 +338,12 @@ export async function getStopsCountGtfsDeSl(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSl() Done.');
//console.log('api:getStopsCountGtfsDeSl() Done.');
return count;
};
export async function getStopsCountGtfsDeBy(){
//console.log('stops:getStopsCountGtfsDeBy() Start...');
//console.log('api:getStopsCountGtfsDeBy() Start...');
let count=null;
try {
@ -355,12 +355,12 @@ export async function getStopsCountGtfsDeBy(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBy() Done.');
//console.log('api:getStopsCountGtfsDeBy() Done.');
return count;
};
export async function getStopsCountGtfsDeBw(){
//console.log('stops:getStopsCountGtfsDeBw() Start...');
//console.log('api:getStopsCountGtfsDeBw() Start...');
let count=null;
try {
@ -372,12 +372,12 @@ export async function getStopsCountGtfsDeBw(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBw() Done.');
//console.log('api:getStopsCountGtfsDeBw() Done.');
return count;
};
export async function getStopsCountGtfsDeShNotDhid(){
//console.log('stops:getStopsCountGtfsDeShNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeShNotDhid() Start...');
let count=null;
try {
@ -389,12 +389,12 @@ export async function getStopsCountGtfsDeShNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeShNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeShNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeMvNotDhid(){
//console.log('stops:getStopsCountGtfsDeMvNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeMvNotDhid() Start...');
let count=null;
try {
@ -406,12 +406,12 @@ export async function getStopsCountGtfsDeMvNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeMvNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeMvNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeBbNotDhid(){
//console.log('stops:getStopsCountGtfsDeBbNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeBbNotDhid() Start...');
let count=null;
try {
@ -423,12 +423,12 @@ export async function getStopsCountGtfsDeBbNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBbNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeBbNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeBeNotDhid(){
//console.log('stops:getStopsCountGtfsDeBeNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeBeNotDhid() Start...');
let count=null;
try {
@ -440,12 +440,12 @@ export async function getStopsCountGtfsDeBeNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBeNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeBeNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeStNotDhid(){
//console.log('stops:getStopsCountGtfsDeStNotDhid() Start...');
//console.log('api:getStopsCountGtfsDeStNotDhid() Start...');
let count=null;
try {
@ -457,12 +457,12 @@ export async function getStopsCountGtfsDeStNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeStNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeStNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeNwNotDhid(){
//console.log('stops:getStopsCountGtfsDeNwNotDhid() Nwart...');
//console.log('api:getStopsCountGtfsDeNwNotDhid() Nwart...');
let count=null;
try {
@ -474,12 +474,12 @@ export async function getStopsCountGtfsDeNwNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeNwNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeNwNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeHeNotDhid(){
//console.log('stops:getStopsCountGtfsDeHeNotDhid() Heart...');
//console.log('api:getStopsCountGtfsDeHeNotDhid() Heart...');
let count=null;
try {
@ -491,12 +491,12 @@ export async function getStopsCountGtfsDeHeNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeHeNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeHeNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeSnNotDhid(){
//console.log('stops:getStopsCountGtfsDeSnNotDhid() Snart...');
//console.log('api:getStopsCountGtfsDeSnNotDhid() Snart...');
let count=null;
try {
@ -508,12 +508,12 @@ export async function getStopsCountGtfsDeSnNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSnNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeSnNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeThNotDhid(){
//console.log('stops:getStopsCountGtfsDeThNotDhid() Thart...');
//console.log('api:getStopsCountGtfsDeThNotDhid() Thart...');
let count=null;
try {
@ -525,12 +525,12 @@ export async function getStopsCountGtfsDeThNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeThNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeThNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeRpNotDhid(){
//console.log('stops:getStopsCountGtfsDeRpNotDhid() Rpart...');
//console.log('api:getStopsCountGtfsDeRpNotDhid() Rpart...');
let count=null;
try {
@ -542,12 +542,12 @@ export async function getStopsCountGtfsDeRpNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeRpNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeRpNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeSlNotDhid(){
//console.log('stops:getStopsCountGtfsDeSlNotDhid() Slart...');
//console.log('api:getStopsCountGtfsDeSlNotDhid() Slart...');
let count=null;
try {
@ -559,12 +559,12 @@ export async function getStopsCountGtfsDeSlNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeSlNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeSlNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeByNotDhid(){
//console.log('stops:getStopsCountGtfsDeByNotDhid() Byart...');
//console.log('api:getStopsCountGtfsDeByNotDhid() Byart...');
let count=null;
try {
@ -576,12 +576,12 @@ export async function getStopsCountGtfsDeByNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeByNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeByNotDhid() Done.');
return count;
};
export async function getStopsCountGtfsDeBwNotDhid(){
//console.log('stops:getStopsCountGtfsDeBwNotDhid() Bwart...');
//console.log('api:getStopsCountGtfsDeBwNotDhid() Bwart...');
let count=null;
try {
@ -593,7 +593,43 @@ export async function getStopsCountGtfsDeBwNotDhid(){
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('stops:getStopsCountGtfsDeBwNotDhid() Done.');
//console.log('api:getStopsCountGtfsDeBwNotDhid() Done.');
return count;
};
export async function getGtfsStopsLastVacuum(){
console.log('api:getGtfsStopsLastVacuum() Start...');
let date=null;
try {
//TODO handle errors: https://www.valentinog.com/blog/await-react/
const address = `${config.API}gtfs-stops-last-vacuum`;
const res = await axios.get(address);
date=res.data[0].last_vacuum;
console.log('api:getGtfsStopsLastVacuum() date: ' + date);
} catch (err) {
console.error('err.message: ' + err.message);
date=-1;
}
console.log('api:getGtfsStopsLastVacuum() Done.');
return date;
};
export async function getStopsCountGtfsLt0(){
//console.log('api:getStopsCountGtfsLt0() Start...');
let count=null;
try {
//TODO handle errors: https://www.valentinog.com/blog/await-react/
const address = `${config.API}stops-count-gtfs-lt-0`;
const res = await axios.get(address);
count=res.data[0].count;
console.log('api:getStopsCountGtfsLt0() count: ' + count);
} catch (err) {
console.error('err.message: ' + err.message);
count=-1;
}
//console.log('api:getStopsCountGtfsLt0() Done.');
return count;
};