Spaces:
Sleeping
Sleeping
File size: 8,271 Bytes
2724a3c b24634c e849fe2 fbf2a5a e849fe2 fbf2a5a e849fe2 fbf2a5a e849fe2 fbf2a5a e849fe2 fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c fbf2a5a b24634c e849fe2 8f2dde4 5ed16f3 8f2dde4 e849fe2 |
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# import pandas as pd
# import numpy as np
# import plotly.express as px
# from datetime import datetime, timedelta
# import requests
# # Function to fetch real-time weather data
# def fetch_weather(api_key, location):
# url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
# response = requests.get(url).json()
# if response["cod"] == 200:
# return {
# "temperature": response["main"]["temp"],
# "wind_speed": response["wind"]["speed"],
# "weather": response["weather"][0]["description"]
# }
# return None
# # Generate synthetic grid data
# def generate_synthetic_data():
# time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
# return pd.DataFrame({
# "timestamp": time_index,
# "total_consumption_kwh": np.random.randint(200, 500, len(time_index)),
# "grid_generation_kwh": np.random.randint(150, 400, len(time_index)),
# "storage_usage_kwh": np.random.randint(50, 150, len(time_index)),
# "solar_output_kw": np.random.randint(50, 150, len(time_index)),
# "wind_output_kw": np.random.randint(30, 120, len(time_index)),
# "grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
# })
# # Load optimization recommendation
# def optimize_load(demand, solar, wind):
# renewable_supply = solar + wind
# if renewable_supply >= demand:
# return "Grid Stable"
# return "Use Backup or Adjust Load"
# # Export functions for use in Streamlit
# if __name__ == "__main__":
# print("Backend ready!")
# code2
# import pandas as pd
# import numpy as np
# from datetime import datetime, timedelta
# import requests
# # Function to fetch real-time weather data
# def fetch_weather(api_key, location):
# url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
# response = requests.get(url).json()
# if response["cod"] == 200:
# return {
# "temperature": response["main"]["temp"],
# "wind_speed": response["wind"]["speed"],
# "weather": response["weather"][0]["description"]
# }
# return None
# # Generate synthetic data
# def generate_synthetic_data():
# time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
# return pd.DataFrame({
# "timestamp": time_index,
# "total_power_consumption_mw": np.random.randint(200, 500, len(time_index)),
# "grid_generation_mw": np.random.randint(100, 300, len(time_index)),
# "storage_utilization_mw": np.random.randint(50, 150, len(time_index)),
# })
# # Generate storage data
# def generate_storage_data():
# return {
# "wind": 5,
# "solar": 7,
# "turbine": 10,
# "total_stored_kwh": 2000
# }
# # Export functions for use in Streamlit
# if __name__ == "__main__":
# print("Backend ready!")
# code 3
# import pandas as pd
# import numpy as np
# from datetime import datetime, timedelta
# # Function to fetch weather data remains unchanged
# # Generate synthetic grid data
# def generate_synthetic_data():
# time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
# return pd.DataFrame({
# "timestamp": time_index,
# "power_consumption_mw": np.random.randint(50, 200, len(time_index)),
# "grid_generation_mw": np.random.randint(30, 150, len(time_index)),
# "storage_utilization_mw": np.random.randint(10, 50, len(time_index)),
# "grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
# })
# # Generate synthetic storage data
# def generate_storage_data():
# wind_storage = np.random.randint(5, 15)
# solar_storage = np.random.randint(7, 20)
# turbine_storage = np.random.randint(10, 25)
# total_storage = wind_storage + solar_storage + turbine_storage
# return {
# "wind_storage_mw": wind_storage,
# "solar_storage_mw": solar_storage,
# "turbine_storage_mw": turbine_storage,
# "total_storage_mw": total_storage
# }
# # Generate synthetic trade data
# def generate_trade_data():
# countries = ["Country A", "Country B", "Country C"]
# exports = np.random.randint(10, 50, len(countries))
# imports = np.random.randint(5, 30, len(countries))
# return pd.DataFrame({
# "country": countries,
# "exports_mw": exports,
# "imports_mw": imports
# })
# # Updated optimization recommendation
# def optimize_load(demand, generation, storage):
# if generation + storage >= demand:
# return "Grid is Stable with Current Supply"
# elif demand - (generation + storage) < 20:
# return "Activate Backup or Optimize Load"
# else:
# return "Immediate Action Required: Adjust Load or Increase Generation"
# # Export functions
# if __name__ == "__main__":
# print("Backend ready for enhanced dashboard!")
# code 4
import pandas as pd
import numpy as np
import requests
from datetime import datetime
# Function to fetch real-time weather data
def fetch_weather(api_key, location):
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
response = requests.get(url).json()
if response["cod"] == 200:
return {
"temperature": response["main"]["temp"],
"wind_speed": response["wind"]["speed"],
"weather": response["weather"][0]["description"]
}
return None
# Generate synthetic grid data
def generate_synthetic_data():
time_index = pd.date_range(start=datetime.now(), periods=24, freq="H")
return pd.DataFrame({
"timestamp": time_index,
"load_demand_kwh": np.random.randint(200, 500, len(time_index)),
"solar_output_kw": np.random.randint(50, 150, len(time_index)),
"wind_output_kw": np.random.randint(30, 120, len(time_index)),
"grid_health": np.random.choice(["Good", "Moderate", "Critical"], len(time_index))
})
# Load optimization recommendation
def optimize_load(demand, solar, wind):
renewable_supply = solar + wind
if renewable_supply >= demand:
return "Grid Stable"
return "Use Backup or Adjust Load"
if __name__ == "__main__":
print("Backend ready!")
# code 5
# import random
# import pandas as pd
# def fetch_data():
# # Simulating fetching data from a database or API
# data = {
# 'temperature': random.uniform(-10, 30),
# 'wind_speed': random.uniform(0, 20),
# 'weather_condition': random.choice(['Clear', 'Overcast Clouds', 'Thunderstorm', 'Rain']),
# 'timestamps': pd.date_range("2025-01-01", periods=10, freq='H'),
# 'total_consumption': [random.uniform(50, 100) for _ in range(10)],
# 'grid_generation': [random.uniform(30, 80) for _ in range(10)],
# 'storage_usage': [random.uniform(10, 30) for _ in range(10)],
# 'solar_storage': random.uniform(10, 30),
# 'wind_storage': random.uniform(10, 30),
# 'hydro_storage': random.uniform(10, 30),
# 'total_storage': random.uniform(50, 100),
# }
# return data
# def generate_recommendations(data):
# recommendations = []
# if data['total_consumption'][-1] > data['grid_generation'][-1]:
# recommendations.append("Consider integrating additional renewable sources to meet the current demand.")
# if data['storage_usage'][-1] > data['total_storage'] * 0.8:
# recommendations.append("Energy storage is running low. Consider optimizing the grid or adding more storage.")
# return recommendations
# def grid_health_status(data):
# status = "Grid is operating normally."
# if data['total_consumption'][-1] > 90:
# status = "Warning: High consumption detected!"
# if data['wind_speed'] > 15:
# status = "Warning: High wind speeds, may affect wind turbine output."
# return status
# def generate_trading_options(data):
# if data['total_storage'] > 60:
# return "Energy is available for export to neighboring countries."
# else:
# return "Energy reserves are low. Trading is not recommended at this moment."
|