-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemand_profile.py
More file actions
86 lines (60 loc) · 2.45 KB
/
Demand_profile.py
File metadata and controls
86 lines (60 loc) · 2.45 KB
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
import streamlit as st
import pandas as pd
import streamlit.components.v1 as components
from utils.components import header
from utils.plotly_charts import animated_unique_ids_area
st.set_page_config(page_title="Mobility Patterns", layout="wide")
@st.cache_data
def cargar_datos():
return pd.read_csv("data/wp_trips.csv")
df = cargar_datos()
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.sort_values(by="timestamp")
header()
st.markdown("<h1 style='text-align: left;'>DEMAND PROFILE</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: left;font-size: 20px;'>This page shows data collected in the last day. The data collected with Indra's MaaS app over the last day is shown. The data has been properly anonymized</p>", unsafe_allow_html=True)
with open("style.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
last_update = df["timestamp"].max().strftime("%Y-%m-%d")
unique_devices = df["ID"].nunique()
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric(label="Last Update", value=last_update)
with col2:
st.metric(label="Unique Devices", value=unique_devices)
with col3:
st.metric(label="Number of Trips", value="432")
with col4:
st.metric(label="Average Trip Length", value="8.45 km")
df['timestamp'] = pd.to_datetime(df['timestamp'])
df.set_index('timestamp', inplace=True)
df_resampled = df.resample('10T').apply(lambda x: x['ID'].nunique())
fig = animated_unique_ids_area(df_resampled)
st.plotly_chart(fig, use_container_width=True)
#""" @st.cache_resource
#def load_html(filename):
# if "html_loaded" not in st.session_state:
# with st.spinner("Loading..."):
# with open(filename, "r", encoding="utf-8") as f:
# st.session_state.html_content = f.read()
# st.session_state.html_loaded = True
# return st.session_state.html_content
#
#html_content=load_html("data/waypoints.html") """
html_fix = """
<script>
setTimeout(() => {
window.dispatchEvent(new Event('resize'));
}, 200);
</script>
"""
@st.cache_resource
def load_html(filename):
with open(filename, "r", encoding="utf-8") as f:
return f.read()
html_content = load_html("data/waypoints.html")
html_inyectado = html_content + html_fix
components.html(html_inyectado, height=800, width=2000, scrolling=False)
st.markdown("<p style='text-align: center;'>Below you can analyze the raw data.</p>", unsafe_allow_html=True)
with st.expander("Show data..."):
st.dataframe(df)