RICHARDMENSAH commited on
Commit
70c0ca8
1 Parent(s): cc1eb2a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +224 -0
app.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+
4
+ #set page/use all #df is your dataframe
5
+ st.set_page_config(layout="wide", page_title="Ecotiva Carbon Calculator", initial_sidebar_state="expanded")
6
+
7
+ st.subheader("Leading Tomorrow's Climate Action Today")
8
+
9
+ EMISSION_FACTORS = {
10
+ "India": {
11
+ "Transport": 0.14, # kgCO2/km
12
+ "Electricity": 0.02, # kgCO2/kWh
13
+ "Diet": 1.25, # kgCO2/meal, 2.5 kgCO2/kg
14
+ "Waste": 0.1 # kgCO2/meal
15
+ },
16
+ "UK": {
17
+ "Transport": 0.12, # kgCO2/km
18
+ "Electricity": 0.03, # kgCO2/kWh
19
+ "Diet": 1.15, # kgCO2/meal, 2.3 kgCO2/kg
20
+ "Waste": 0.09 # kgCO2/meal
21
+ },
22
+ "Germany": {
23
+ "Transport": 0.13, # kgCO2/km
24
+ "Electricity": 0.02, # kgCO2/kWh
25
+ "Diet": 1.20, # kgCO2/meal, 2.4 kgCO2/kg
26
+ "Waste": 0.1 # kgCO2/meal
27
+ },
28
+ "USA": {
29
+ "Transport": 0.15, # kgCO2/km
30
+ "Electricity": 0.025, # kgCO2/kWh
31
+ "Diet": 1.35, # kgCO2/meal, 2.7 kgCO2/kg
32
+ "Waste": 0.12 # kgCO2/meal
33
+ },
34
+ "West_Africa": {
35
+ "Transport": 0.18, # kgCO2/km
36
+ "Electricity": 0.04, # kgCO2/kWh
37
+ "Diet": 1.40, # kgCO2/meal, 2.8 kgCO2/kg
38
+ "Waste": 0.15 # kgCO2/meal
39
+ },
40
+ "East_Africa": {
41
+ "Transport": 0.17, # kgCO2/km
42
+ "Electricity": 0.035, # kgCO2/kWh
43
+ "Diet": 1.38, # kgCO2/meal, 2.76 kgCO2/kg
44
+ "Waste": 0.14 # kgCO2/meal
45
+ },
46
+ "Central_Africa": {
47
+ "Transport": 0.19, # kgCO2/km
48
+ "Electricity": 0.038, # kgCO2/kWh
49
+ "Diet": 1.45, # kgCO2/meal, 2.9 kgCO2/kg
50
+ "Waste": 0.16 # kgCO2/meal
51
+ },
52
+ "South_Africa": {
53
+ "Transport": 0.16, # kgCO2/km
54
+ "Electricity": 0.03, # kgCO2/kWh
55
+ "Diet": 1.30, # kgCO2/meal, 2.6 kgCO2/kg
56
+ "Waste": 0.11 # kgCO2/meal
57
+ },
58
+ "North_Africa": {
59
+ "Transport": 0.2, # kgCO2/km
60
+ "Electricity": 0.036, # kgCO2/kWh
61
+ "Diet": 1.48, # kgCO2/meal, 2.96 kgCO2/kg
62
+ "Waste": 0.17 # kgCO2/meal
63
+ }
64
+ }
65
+
66
+ st.sidebar.header("Your Carbbon Footprint")
67
+
68
+
69
+ #Adding option menu in sidebar
70
+ with st.sidebar:
71
+ selected = option_menu(
72
+ menu_title=None, #main menu
73
+ options=["Home", "About US", "Products", "Solutions", "Company", "Emissions", "Scope 1-3" ],
74
+ icons=["house", "book", "envelope"],
75
+ menu_icon="cast",
76
+ default_index=0,
77
+ styles={
78
+ "container": {"pardding": "0!important", "background-color": ""},
79
+ "icon": {"color": "orange", "font-size": "25px"},
80
+ "nav-link":{
81
+ "font-size": "25px",
82
+ "text-align": "left",
83
+ "margin": "0px",
84
+ "--hover-color": "#eee",
85
+ },
86
+ "nav-link-selected": {"background-color": "green"},
87
+ }
88
+
89
+
90
+ )
91
+ ## change menu to home page horizontal
92
+ # selected = option_menu(
93
+ # menu_title=None, #"main menu"
94
+ # options=["Home", "Projects", "Contact"],
95
+ # icons=["house", "book", "envelope"],
96
+ # menu_icon="cast",
97
+ # default_index=0,
98
+ # orientation="horizontal",
99
+ # styles={
100
+ # "container": {"pardding": "0!important", "background-color": "white"},
101
+ # "icon": {"color": "orange", "font-size": "25px"},
102
+ # "nav-link":{
103
+ # "font-size": "25px",
104
+ # "text-align": "left",
105
+ # "margin": "0px",
106
+ # "--hover-color": "#eee",
107
+ # },
108
+ # "nav-link-selected": {"background-color": "green"},
109
+ # }
110
+
111
+ # )
112
+
113
+
114
+
115
+ #if option select menu
116
+ if selected == "Home":
117
+ st.title(f"You have selected {selected}")
118
+ if selected == "Projects":
119
+ st.title(f"You have selected {selected}")
120
+ if selected == "Contact":
121
+ st.title(f"You have selected {selected}")
122
+
123
+
124
+ st.title ("Ecotiva Carbon Accounting Software")
125
+
126
+ #user input
127
+ st.subheader("Your Country")
128
+ country = st.selectbox("Select", ['India','UK', 'USA', 'West_Africa', 'East_Africa', 'Central_Africa', 'South_Africa', 'North_Africa' ])
129
+ #country = st.selectbox("Select", ['India', 'Ghana', 'Nigeria'])
130
+
131
+ #devide into columns
132
+ #col1, col2, col3 = st.columns(3)
133
+
134
+ col1, col2 = st.columns(2)
135
+
136
+ with col1:
137
+ st.header('Scope 1')
138
+ st.subheader('Daily commute distance(in km)')
139
+ distance = st.number_input("Distance", 0, key="distance_input")
140
+ #distance = st.slider("Distance", 0, key="distance_input")
141
+
142
+ st.subheader("Monthly Electricity Consumption")
143
+ electricity = st.number_input("Electricity", 0, key='electricity_input')
144
+
145
+
146
+ with col2:
147
+ st.header('Scope 2')
148
+ st.subheader("Waste Generated per Week (per Ton)")
149
+ waste = st.slider("Waste", 0, key="waste_input")
150
+ #distance = st.number_input("Waste", 0.0, 100.0, key="waste_input")
151
+
152
+ st.subheader("Number of Meals per day")
153
+ meals = st.number_input("Meals", 0, key="meals_input")
154
+
155
+
156
+ if distance > 0:
157
+ distance = distance * 365
158
+
159
+ #12months=1year
160
+ if electricity > 0:
161
+ electricity = electricity * 12
162
+
163
+ if meals > 0:
164
+ meal = meals * 365
165
+
166
+ #52week=1year
167
+ if waste > 0:
168
+ waste = waste * 52
169
+
170
+ #Calculate Carbon Emission
171
+ #Defind the variables
172
+ transportation_emissions = EMISSION_FACTORS[country]['Transport'] * distance
173
+ electricity_emissions = EMISSION_FACTORS[country]['Electricity'] * electricity
174
+ diet_emissions = EMISSION_FACTORS[country]['Diet'] * meals
175
+ waste_emissions = EMISSION_FACTORS[country]['Waste'] * waste
176
+
177
+ #Round off here
178
+ transportation_emissions = round(transportation_emissions / 1000, 2)
179
+ electricity_emissions = round(electricity_emissions / 1000, 2)
180
+ diet_emissions = round(diet_emissions / 1000, 2)
181
+ waste_emissions = round(waste_emissions / 1000, 2)
182
+
183
+
184
+ #Convert to tonnes and round off to 2 decimal places
185
+ total_emissions = round(
186
+ transportation_emissions + electricity_emissions + diet_emissions + waste_emissions, 2
187
+ )
188
+
189
+ if st.button("Calculate Emissions"):
190
+
191
+ #Display Result
192
+ st.header("Results")
193
+
194
+ col3, col4 = st.columns(2)
195
+
196
+
197
+ with col3:
198
+ st.subheader('Carbon Emission by Categories')
199
+ st.info(f" Transportation: {transportation_emissions} tonnes C02 per year")
200
+ st.info(f" Electricity: {electricity_emissions} tonnes C02 per year")
201
+ st.info(f" Diet: {diet_emissions} tonnes C02 per year")
202
+ st.info(f" Waste: {waste_emissions} tonnes C02 per year")
203
+
204
+ with col4:
205
+ st.subheader("Total Carbon Footprint")
206
+ st.info(f" Your total carbon footprint is: {total_emissions} tonnes C02 per year")
207
+ st.warning("In 2021, C02 emissions per capita for Ghana was 1.9 tonnes. Between 2000 and 2021, total emission per capita of Ghana grew substantially from 0.08 to 1.9 rising at an increasing annual rate that reached a maximum of 9.41% in 2021")
208
+
209
+
210
+
211
+ # with col3:
212
+ # st.subheader('Carbon Emission by Categories')
213
+ # st.info(f" Transportation: (transportation_emission) tonnes C02 per year")
214
+ # st.info(f" Electricity: (electricity_emissions) tonnes C02 per year")
215
+ # st.info(f" Diet: (diet_emissions) tonnes C02 per year")
216
+ # st.info(f" Waste: (waste_emissions) tonnes C02 per year")
217
+
218
+ # with col4:
219
+ # st.subheader("Total Carbon Footprint")
220
+ # st.info(f" Your total carbon footprint is: (total_emissions) tonnes C02 per year")
221
+ # st.warning("In 2021, C02 emissions per capital for Ghana was 1.9 tones. Between 2000 and 2021, total emission per capital of Ghana grew substantially from 0.08 to 1.9 rising at an increasing annual rate that reached a maximum of 9.41% in 2021")
222
+
223
+
224
+