rehanafzal commited on
Commit
cd8e15c
·
verified ·
1 Parent(s): fcb4f92

Update app_backend.py

Browse files
Files changed (1) hide show
  1. app_backend.py +10 -50
app_backend.py CHANGED
@@ -1,46 +1,3 @@
1
- # import pandas as pd
2
- # import numpy as np
3
- # import plotly.express as px
4
- # from datetime import datetime, timedelta
5
- # import requests
6
-
7
- # # Function to fetch real-time weather data
8
- # def fetch_weather(api_key, location):
9
- # url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
10
- # response = requests.get(url).json()
11
- # if response["cod"] == 200:
12
- # return {
13
- # "temperature": response["main"]["temp"],
14
- # "wind_speed": response["wind"]["speed"],
15
- # "weather": response["weather"][0]["description"]
16
- # }
17
- # return None
18
-
19
- # # Generate synthetic grid data
20
- # def generate_synthetic_data():
21
- # time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
22
- # return pd.DataFrame({
23
- # "timestamp": time_index,
24
- # "total_consumption_kwh": np.random.randint(200, 500, len(time_index)),
25
- # "grid_generation_kwh": np.random.randint(150, 400, len(time_index)),
26
- # "storage_usage_kwh": np.random.randint(50, 150, len(time_index)),
27
- # "solar_output_kw": np.random.randint(50, 150, len(time_index)),
28
- # "wind_output_kw": np.random.randint(30, 120, len(time_index)),
29
- # "grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
30
- # })
31
-
32
- # # Load optimization recommendation
33
- # def optimize_load(demand, solar, wind):
34
- # renewable_supply = solar + wind
35
- # if renewable_supply >= demand:
36
- # return "Grid Stable"
37
- # return "Use Backup or Adjust Load"
38
-
39
- # # Export functions for use in Streamlit
40
- # if __name__ == "__main__":
41
- # print("Backend ready!")
42
-
43
-
44
  import pandas as pd
45
  import numpy as np
46
  import plotly.express as px
@@ -59,19 +16,20 @@ def fetch_weather(api_key, location):
59
  }
60
  return None
61
 
62
- # Generate synthetic grid data in MW (for generation) and kWh (for load)
63
  def generate_synthetic_data():
64
  time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
65
  return pd.DataFrame({
66
  "timestamp": time_index,
67
- "load_demand_mw": np.random.uniform(0.2, 0.5, len(time_index)), # Load demand in MW
68
- "solar_output_mw": np.random.uniform(0.05, 0.15, len(time_index)), # Solar output in MW
69
- "wind_output_mw": np.random.uniform(0.03, 0.12, len(time_index)), # Wind output in MW
70
- "battery_storage_kwh": np.random.randint(100, 500, len(time_index)), # Battery storage in kWh
 
71
  "grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
72
  })
73
 
74
- # Load optimization recommendation in MW
75
  def optimize_load(demand, solar, wind):
76
  renewable_supply = solar + wind
77
  if renewable_supply >= demand:
@@ -80,4 +38,6 @@ def optimize_load(demand, solar, wind):
80
 
81
  # Export functions for use in Streamlit
82
  if __name__ == "__main__":
83
- print("Backend ready!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import numpy as np
3
  import plotly.express as px
 
16
  }
17
  return None
18
 
19
+ # Generate synthetic grid data
20
  def generate_synthetic_data():
21
  time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
22
  return pd.DataFrame({
23
  "timestamp": time_index,
24
+ "total_consumption_kwh": np.random.randint(200, 500, len(time_index)),
25
+ "grid_generation_kwh": np.random.randint(150, 400, len(time_index)),
26
+ "storage_usage_kwh": np.random.randint(50, 150, len(time_index)),
27
+ "solar_output_kw": np.random.randint(50, 150, len(time_index)),
28
+ "wind_output_kw": np.random.randint(30, 120, len(time_index)),
29
  "grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
30
  })
31
 
32
+ # Load optimization recommendation
33
  def optimize_load(demand, solar, wind):
34
  renewable_supply = solar + wind
35
  if renewable_supply >= demand:
 
38
 
39
  # Export functions for use in Streamlit
40
  if __name__ == "__main__":
41
+ print("Backend ready!")
42
+
43
+