charagu-eric commited on
Commit
832ca25
·
1 Parent(s): af4540c

returned appliances

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import numpy as np
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
@@ -5,7 +6,6 @@ import seaborn as sns
5
  import streamlit as st
6
  from typing import Dict
7
 
8
- # Constants
9
  ONE_BR_UNITS = 23
10
  TWO_BR_UNITS = 45
11
  SOLAR_PANEL_RATING = 625 # W
@@ -19,6 +19,9 @@ LIGHTS_1BR = 5
19
  LIGHTS_2BR = 12
20
  LIGHT_POWER = 6 # Watts per light
21
 
 
 
 
22
 
23
  def initialize_session_state():
24
  """Initialize session state variables"""
@@ -26,8 +29,7 @@ def initialize_session_state():
26
  "solar_panels": 100,
27
  "batteries": 50,
28
  "panel_price": 13000,
29
- "battery_price": 135000,
30
- # "battery_price": 39000, 200Ah price
31
  "grid_price": 28.44,
32
  }
33
  for key, value in defaults.items():
@@ -43,19 +45,30 @@ def calculate_lighting_consumption(occupancy_1br: float, occupancy_2br: float) -
43
  ) * 6 # 6 hours per day
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
46
  def total_consumption(
47
  occupancy_1br: float, occupancy_2br: float, common_area: float
48
  ) -> float:
49
  """Calculate total monthly consumption"""
50
  lighting = calculate_lighting_consumption(occupancy_1br, occupancy_2br)
51
-
52
- return (lighting + common_area) * 30 # Monthly kWh
53
 
54
 
55
  def solar_production(panels: int) -> float:
56
  """Monthly solar production with losses"""
57
  daily_production = (
58
- panels * SOLAR_PANEL_RATING * 6 * (1 - SYSTEM_LOSSES) / 1000
59
  ) # 5 sun hours
60
  return daily_production * 30 # Monthly kWh
61
 
@@ -65,13 +78,11 @@ def battery_storage(batteries: int) -> float:
65
  return batteries * BATTERY_CAPACITY * BATTERY_VOLTAGE * 0.8 / 1000 # kWh
66
 
67
 
68
- def financial_analysis(
69
- consumption: float, common_area: float, production: float, storage: float
70
- ) -> Dict:
71
  """Detailed financial calculations"""
72
  solar_used = min(production, consumption)
73
  surplus = max(0, production - consumption)
74
- # feed_in_revenue = surplus * FEED_IN_TARIFF / 100 # Convert to Ksh from cents/kWh
75
 
76
  # Account for battery storage
77
  grid_purchased = max(0, consumption - solar_used)
@@ -80,7 +91,9 @@ def financial_analysis(
80
  grid_offset = min(grid_purchased, storage)
81
  grid_purchased -= grid_offset
82
 
83
- monthly_savings = (consumption - common_area) * st.session_state.grid_price / 100
 
 
84
  total_investment = (
85
  st.session_state.solar_panels * st.session_state.panel_price
86
  + st.session_state.batteries * st.session_state.battery_price
@@ -109,6 +122,8 @@ def create_consumption_breakdown(
109
  """Create detailed consumption breakdown"""
110
  breakdown = {
111
  "Lighting": calculate_lighting_consumption(occupancy_1br, occupancy_2br) * 30,
 
 
112
  "Common Areas": common_area * 30,
113
  }
114
  return pd.DataFrame.from_dict(breakdown, orient="index", columns=["kWh"])
@@ -195,7 +210,7 @@ def main():
195
  st.number_input(
196
  "Battery Price (Ksh)",
197
  5000,
198
- 300000,
199
  step=1000,
200
  key="battery_price",
201
  help="Cost per battery unit",
@@ -229,7 +244,7 @@ def main():
229
  scenarios = {}
230
 
231
  # Common area consumption remains constant
232
- common_area_consumption = (1782 + 180 + 12) / 1000 # kWh per day
233
 
234
  # Generate scenarios with different occupancy combinations
235
  occupancy_levels = [0.0, 0.25, 0.50, 0.75, 1.0]
@@ -256,9 +271,7 @@ def main():
256
  consumption = total_consumption(params["1br"], params["2br"], params["common"])
257
  production = solar_production(st.session_state.solar_panels)
258
  storage = battery_storage(st.session_state.batteries)
259
- financials = financial_analysis(
260
- consumption, common_area_consumption * 30, production, storage
261
- )
262
  analysis_data.append({"Scenario": name, **financials})
263
 
264
  df = pd.DataFrame(analysis_data)
@@ -483,7 +496,7 @@ def main():
483
 
484
  **Savings Calculation:**
485
  - Grid Price: {st.session_state.grid_price} Ksh/kWh
486
- - Monthly Savings = (Total Consumption - Common Areas)× Grid Price)
487
  - Payback Period = Total Investment / Annual Savings
488
 
489
  **Filtered Scenario Data:**
@@ -531,8 +544,8 @@ def main():
531
  fig3 = plt.figure(figsize=(8, 8))
532
  ax3 = fig3.add_subplot(111)
533
 
534
- colors = ["#FF9800", "#4CAF50"]
535
- explode = (0.1, 0)
536
 
537
  wedges, texts, autotexts = ax3.pie(
538
  breakdown_df["kWh"],
 
1
+ # Constants
2
  import numpy as np
3
  import pandas as pd
4
  import matplotlib.pyplot as plt
 
6
  import streamlit as st
7
  from typing import Dict
8
 
 
9
  ONE_BR_UNITS = 23
10
  TWO_BR_UNITS = 45
11
  SOLAR_PANEL_RATING = 625 # W
 
19
  LIGHTS_2BR = 12
20
  LIGHT_POWER = 6 # Watts per light
21
 
22
+ # Non-kitchen appliance consumption
23
+ APPLIANCES = (300 * 24 * 30) + (300 * 6 * 30) # kWh/month
24
+
25
 
26
  def initialize_session_state():
27
  """Initialize session state variables"""
 
29
  "solar_panels": 100,
30
  "batteries": 50,
31
  "panel_price": 13000,
32
+ "battery_price": 39000,
 
33
  "grid_price": 28.44,
34
  }
35
  for key, value in defaults.items():
 
45
  ) * 6 # 6 hours per day
46
 
47
 
48
+ def calculate_appliance_consumption(
49
+ occupancy_1br: float, occupancy_2br: float
50
+ ) -> float:
51
+ """Calculate daily appliance consumption"""
52
+ return (
53
+ occupancy_1br * ONE_BR_UNITS * (250 - (LIGHTS_1BR * LIGHT_POWER * 6 / 1000))
54
+ ) + (
55
+ occupancy_2br * TWO_BR_UNITS * (400 - (LIGHTS_2BR * LIGHT_POWER * 6 / 1000))
56
+ ) # Daily kWh
57
+
58
+
59
  def total_consumption(
60
  occupancy_1br: float, occupancy_2br: float, common_area: float
61
  ) -> float:
62
  """Calculate total monthly consumption"""
63
  lighting = calculate_lighting_consumption(occupancy_1br, occupancy_2br)
64
+ appliances = calculate_appliance_consumption(occupancy_1br, occupancy_2br)
65
+ return (lighting + appliances + common_area) * 30 # Monthly kWh
66
 
67
 
68
  def solar_production(panels: int) -> float:
69
  """Monthly solar production with losses"""
70
  daily_production = (
71
+ panels * SOLAR_PANEL_RATING * 5 * (1 - SYSTEM_LOSSES) / 1000
72
  ) # 5 sun hours
73
  return daily_production * 30 # Monthly kWh
74
 
 
78
  return batteries * BATTERY_CAPACITY * BATTERY_VOLTAGE * 0.8 / 1000 # kWh
79
 
80
 
81
+ def financial_analysis(consumption: float, production: float, storage: float) -> Dict:
 
 
82
  """Detailed financial calculations"""
83
  solar_used = min(production, consumption)
84
  surplus = max(0, production - consumption)
85
+ feed_in_revenue = surplus * FEED_IN_TARIFF / 100 # Convert to Ksh from cents/kWh
86
 
87
  # Account for battery storage
88
  grid_purchased = max(0, consumption - solar_used)
 
91
  grid_offset = min(grid_purchased, storage)
92
  grid_purchased -= grid_offset
93
 
94
+ monthly_savings = (
95
+ (consumption * st.session_state.grid_price / 100)
96
+
97
  total_investment = (
98
  st.session_state.solar_panels * st.session_state.panel_price
99
  + st.session_state.batteries * st.session_state.battery_price
 
122
  """Create detailed consumption breakdown"""
123
  breakdown = {
124
  "Lighting": calculate_lighting_consumption(occupancy_1br, occupancy_2br) * 30,
125
+ "Appliances": calculate_appliance_consumption(occupancy_1br, occupancy_2br)
126
+ * 30,
127
  "Common Areas": common_area * 30,
128
  }
129
  return pd.DataFrame.from_dict(breakdown, orient="index", columns=["kWh"])
 
210
  st.number_input(
211
  "Battery Price (Ksh)",
212
  5000,
213
+ 100000,
214
  step=1000,
215
  key="battery_price",
216
  help="Cost per battery unit",
 
244
  scenarios = {}
245
 
246
  # Common area consumption remains constant
247
+ common_area_consumption = 5.904 # kWh per day
248
 
249
  # Generate scenarios with different occupancy combinations
250
  occupancy_levels = [0.0, 0.25, 0.50, 0.75, 1.0]
 
271
  consumption = total_consumption(params["1br"], params["2br"], params["common"])
272
  production = solar_production(st.session_state.solar_panels)
273
  storage = battery_storage(st.session_state.batteries)
274
+ financials = financial_analysis(consumption, production, storage)
 
 
275
  analysis_data.append({"Scenario": name, **financials})
276
 
277
  df = pd.DataFrame(analysis_data)
 
496
 
497
  **Savings Calculation:**
498
  - Grid Price: {st.session_state.grid_price} Ksh/kWh
499
+ - Monthly Savings = (Total Consumption × Grid Price) - (Grid Purchased × Grid Price)
500
  - Payback Period = Total Investment / Annual Savings
501
 
502
  **Filtered Scenario Data:**
 
544
  fig3 = plt.figure(figsize=(8, 8))
545
  ax3 = fig3.add_subplot(111)
546
 
547
+ colors = ["#FF9800", "#2196F3", "#4CAF50"]
548
+ explode = (0.1, 0, 0)
549
 
550
  wedges, texts, autotexts = ax3.pie(
551
  breakdown_df["kWh"],