-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
140 lines (111 loc) · 4.49 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import pandas as pd
import plotly.express as px
import streamlit as st
st.set_page_config(page_title="Fuel and CO2 Dashboard",
page_icon=":bar_chart:",
layout="wide")
@st.cache_data
def get_data():
df = pd.read_csv('ship_fuel_efficiency.csv')
return df
df = get_data()
# --- sidebar ---
st.sidebar.header("Filter Here:")
ship_type = st.sidebar.multiselect(
"Select the Ship Type:",
options=df["ship_type"].unique(),
default=df["ship_type"].unique()
)
fuel_type = st.sidebar.multiselect(
"Select the Fuel Type:",
options=df["fuel_type"].unique(),
default=df["fuel_type"].unique()
)
weather_conditions = st.sidebar.multiselect(
"Select the Weather Conditions:",
options=df["weather_conditions"].unique(),
default=df["weather_conditions"].unique()
)
# query to store selected options
df_selection = df.query(
"ship_type == @ship_type & fuel_type == @fuel_type & weather_conditions == @weather_conditions"
)
# st.dataframe(df_selection)
# --- main page ---
st.title("Fuel Consumption and CO₂ Emissions Dashboard", anchor=False)
st.markdown("This dashboard provides an overview of fuel consumption and CO₂ emissions of various ship types operating in Nigerian waterways over one year. By exploring the efficiency and environmental impact of these vessels, we can provide actionable insights for optimizing maritime operations and reducing emissions.")
st.markdown("##")
# Top Figures
total_fuel = int(df_selection["fuel_consumption"].sum())
total_co2 = int(df_selection["CO2_emissions"].sum())
average_ee = round(df_selection["engine_efficiency"].mean(), 2)
left_column, middle_column, right_column = st.columns(3)
with left_column:
st.subheader("Total Fuel Consumption:", anchor=False)
st.subheader(f"{total_fuel:,}L", anchor=False)
with middle_column:
st.subheader("Total Carbon Emissions:", anchor=False)
st.subheader(f"{total_co2:,}kg", anchor=False)
with right_column:
st.subheader("Average Ship Engine Efficiency:", anchor=False)
st.subheader(f"{average_ee}%", anchor=False)
st.markdown("---")
# --- charts and tables ---
# average fuel consumption per month bar
fuel_per_month = df_selection.groupby(by=["month"], sort=False)[["fuel_consumption"]].mean()
fuel_per_month_bar = px.bar(
fuel_per_month,
x=fuel_per_month.index,
y="fuel_consumption",
orientation="v",
title="<b>Average Fuel Consumption (L) over each Month</b>",
color_discrete_sequence=["#0083B8"] * len(fuel_per_month),
template="plotly_white"
)
# average co2 emission per month bar
co2_per_month = df_selection.groupby(by=["month"], sort=False)[["CO2_emissions"]].mean()
co2_per_month_bar = px.bar(
co2_per_month,
x="CO2_emissions",
y=co2_per_month.index,
orientation="h",
title="<b>Average CO2 Emissions (kg) over each Month</b>",
color_discrete_sequence=["#0083B8"] * len(co2_per_month),
template="plotly_white"
)
# table
import plotly.graph_objects as go
ee_per_month = df_selection.groupby(by=["month"], sort=False)[["engine_efficiency"]].mean()
all_per_month_table = go.Figure(
data=[go.Table(
header=dict(values=['Month', 'Average Fuel Consumption (L)', 'Average CO2 Emissions (kg)', 'Average Engine Efficiency (%)']),
cells=dict(values=[df_selection["month"].unique(),
round(fuel_per_month),
round(co2_per_month),
round(ee_per_month)])
)
])
# co2 over fuel scatter
co2_per_fuel_scatter = px.scatter(
df_selection,
x="fuel_consumption",
y="CO2_emissions",
title="<b>CO2 Emissions (kg) over Fuel Consumption (L)</b>",
color_discrete_sequence=["#0083B8"] * len(co2_per_month),
template="plotly_white"
)
left_column, right_column = st.columns(2)
left_column.plotly_chart(fuel_per_month_bar, use_container_width=True)
right_column.plotly_chart(all_per_month_table, use_container_width=True)
left_column, right_column = st.columns(2)
left_column.plotly_chart(co2_per_month_bar, use_container_width=True)
right_column.plotly_chart(co2_per_fuel_scatter, use_container_width=True)
# --- hide st style ---
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)