forked from evan-harley/CamAPIDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
81 lines (59 loc) · 2.42 KB
/
app.py
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
import numpy as np
import pandas as pd
import plotly.express as px
import requests
import streamlit as st
from stqdm import stqdm
TEST = False
def parse_data(data: dict) -> pd.DataFrame:
data = {'camID': data['id'],
'latitude': data['location']['latitude'],
'longitude': data['location']['longitude'],
'lastAttemptTime': data['imageStats']['lastAttempt']['time'],
'lastAttemptResponseTime': data['imageStats']['lastAttempt']['seconds'],
'updatePeriodMean': data['imageStats']['updatePeriodMean'],
'updatePeriodStdDev': data['imageStats']['updatePeriodStdDev'],
'markedStale': data['imageStats']['markedStale'],
'markedDelayed': data['imageStats']['markedDelayed']}
return pd.DataFrame([data])
@st.cache(suppress_st_warning=True)
def load_data() -> pd.DataFrame:
df = pd.DataFrame()
for i in stqdm(range(2, 1018)):
api_url = f"http://dev-images.drivebc.ca/webcam/api/v1/webcams/{i}"
response = requests.get(api_url)
if response.status_code != 200:
continue
else:
row = parse_data(response.json())
df = pd.concat([df, row])
df.reset_index(drop=True, inplace=True)
df['status'] = 'Active'
df.loc[df['markedStale'], 'status'] = 'Stale'
df.loc[df['markedDelayed'], 'status'] = 'Delayed'
df['responseTimeZScore'] = np.abs((df['lastAttemptResponseTime'] - df['updatePeriodMean'])/(df['updatePeriodStdDev'] + 1))
return df
st.title("Camera API Dashboard")
st.markdown("""
## Introduction
This is a small proof of concept web app which shows some basic stats related to the BC Highway Cam Data
in order to assist the team with parts of their job.
## Pages
There are two pages so far not counting this introductory page
1) The Map View
This view plots the data on a map which should allow the team to see where trouble cameras are at a glance
2) Overview Statistics
This view shows 4 major details:
1) How many Cameras are currently Stale
2) How many Cameras are currently Delayed
3) Which Cameras are currently Stale or Delayed
4) Which Cameras are near their Stale or Delayed Threshold
""")
def main():
if 'data' not in st.session_state:
if not TEST:
st.session_state['data'] = load_data()
else:
st.session_state['data'] = pd.read_pickle('data.pkl')
if __name__ == "__main__":
main()