GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sharedmobility_monitoring/sharedmobility_monitoring.py at main · SFOE/sharedmobility_monitoring

Expand file tree

/

sharedmobility_monitoring.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
97 lines (76 loc) · 3.15 KB
/

sharedmobility_monitoring.py

Copy path

File metadata and controls

97 lines (76 loc) · 3.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
"""sharedmobility_monitoring.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/github/nrohrbach/sharedmobility_monitoring/blob/main/sharedmobility_monitoring.ipynb
# Monitoring GBFS-Feeds on sharedmobility.ch
Beschreibung...
"""
#pip install datetime
import requests
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
# GBFS Feeds abfragen
url = 'https://sharedmobility.ch/v2/gbfs'
header = {"Authorization":"[email protected]"}
feeds = requests.get(url,headers=header).json()
# Alle GBFS Feeds als Dataframe laden
id = [s['id'] for s in feeds['systems']]
url = [s['url'] for s in feeds['systems']]
gbfsfeeds = pd.DataFrame(list(zip(id, url)),columns =['provider', 'gbfsurl'])
providers = list(gbfsfeeds['provider'])
"""## Auswertung pro Provider"""
# Auswertung station_status.json
providerList = []
VehiclesInStationList = []
NumberOfStationsList = []
for provider in providers:
try:
stationstatus = requests.get('https://sharedmobility.ch/v2/gbfs/' + provider +'/station_status',headers=header).json()
stationstatus = [s['num_bikes_available'] for s in stationstatus['data']['stations']]
VehiclesInStationList.append(sum(stationstatus))
NumberOfStationsList.append(len(stationstatus))
providerList.append(provider)
except:
VehiclesInStationList.append('nan')
NumberOfStationsList.append('nan')
providerList.append(provider)
# Dataframe erstellen
dict = {'Provider': providerList, 'NumberOfStations': NumberOfStationsList, 'VehiclesInStation': VehiclesInStationList}
dfStationStatus = pd.DataFrame(dict)
# Auswertung free_bike_status.json
providerList = []
FreeBikeList = []
for provider in providers:
try:
freebikesstatus = requests.get('https://sharedmobility.ch/v2/gbfs/' + provider +'/free_bike_status',headers=header).json()
freebikesstatus = [s['bike_id'] for s in freebikesstatus['data']['bikes']]
FreeBikeList.append(len(freebikesstatus))
providerList.append(provider)
except:
FreeBikeList.append('nan')
providerList.append(provider)
# Dataframe erstellen
dict = {'Provider': providerList, 'NumberOfFreeBikes': FreeBikeList}
dfFreeBikes = pd.DataFrame(dict)
# Dataframe zusammenführen und speichern
dfMonitoring = pd.merge(dfStationStatus, dfFreeBikes, how="left", on=["Provider"])
dfMonitoring['Date'] = datetime.today().strftime("%Y-%m-%d")
#Speichern
dfMonitoring.to_csv("data/Sharedmobility_Providers.csv", header=False, index=False, mode='a')
#Visualisierung
df = pd.read_csv("data/Sharedmobility_Providers.csv", parse_dates=['Date'])
df = df.fillna(0)
# LineChart mit Anzahl Fahrzeugen und Anzahl Stationen
for provider in providers:
try:
df_provider = df[df['Provider']==provider]
df_provider = df_provider.pivot(index="Date", columns=["Provider"], values=['NumberOfStations','VehiclesInStation','NumberOfFreeBikes'])
df_provider.plot(figsize=(15,10))
plt.legend(loc='best')
plt.title("Anzahl Fahrzeuge und Stationen: "+ provider)
plt.savefig('plots/' + provider + '.png')
plt.close()
except:
plt.savefig('plots/' + provider + '.png')
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.