Spaces:
Sleeping
Sleeping
Update app_backend.py
Browse files- app_backend.py +54 -16
app_backend.py
CHANGED
@@ -1,6 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
@@ -16,28 +57,25 @@ def fetch_weather(api_key, location):
|
|
16 |
}
|
17 |
return None
|
18 |
|
19 |
-
# Generate synthetic
|
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 |
-
"
|
25 |
-
"
|
26 |
-
"
|
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 |
-
#
|
33 |
-
def
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
|
39 |
# Export functions for use in Streamlit
|
40 |
if __name__ == "__main__":
|
41 |
print("Backend ready!")
|
42 |
-
|
43 |
-
|
|
|
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 |
import pandas as pd
|
44 |
import numpy as np
|
|
|
45 |
from datetime import datetime, timedelta
|
46 |
import requests
|
47 |
|
|
|
57 |
}
|
58 |
return None
|
59 |
|
60 |
+
# Generate synthetic data
|
61 |
def generate_synthetic_data():
|
62 |
time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
|
63 |
return pd.DataFrame({
|
64 |
"timestamp": time_index,
|
65 |
+
"total_power_consumption_mw": np.random.randint(200, 500, len(time_index)),
|
66 |
+
"grid_generation_mw": np.random.randint(100, 300, len(time_index)),
|
67 |
+
"storage_utilization_mw": np.random.randint(50, 150, len(time_index)),
|
|
|
|
|
|
|
68 |
})
|
69 |
|
70 |
+
# Generate storage data
|
71 |
+
def generate_storage_data():
|
72 |
+
return {
|
73 |
+
"wind": 5,
|
74 |
+
"solar": 7,
|
75 |
+
"turbine": 10,
|
76 |
+
"total_stored_kwh": 2000
|
77 |
+
}
|
78 |
|
79 |
# Export functions for use in Streamlit
|
80 |
if __name__ == "__main__":
|
81 |
print("Backend ready!")
|
|
|
|