132 lines
1.9 KiB
Python
132 lines
1.9 KiB
Python
import json
|
|
|
|
from datetime import datetime
|
|
|
|
from pvsim.simulator import (
|
|
PVSimulator,
|
|
SimulationConfig,
|
|
SunModel,
|
|
WeatherModel,
|
|
)
|
|
|
|
from pvsim.faults import (
|
|
FaultConfig,
|
|
FaultManager,
|
|
)
|
|
|
|
from pvsim.plant import PVPlant
|
|
|
|
from pvsim.exporter import (
|
|
SimulationExporter,
|
|
)
|
|
|
|
from pvsim.statistics import (
|
|
SimulationStatistics,
|
|
)
|
|
|
|
CONFIG_PATH = 'pv_simulator/config/plant.json'
|
|
|
|
with open(CONFIG_PATH, 'r') as f:
|
|
raw_config = json.load(f)
|
|
|
|
# ============================================================
|
|
# SIMULAZIONE
|
|
# ============================================================
|
|
|
|
simulation_config = SimulationConfig(
|
|
|
|
start=datetime(
|
|
2026,
|
|
6,
|
|
21,
|
|
0,
|
|
0,
|
|
),
|
|
|
|
end=datetime(
|
|
2026,
|
|
6,
|
|
22,
|
|
0,
|
|
0,
|
|
),
|
|
|
|
timestep_minutes=5,
|
|
|
|
generate_random_faults=True,
|
|
)
|
|
|
|
plant = PVPlant.from_json(CONFIG_PATH)
|
|
|
|
sun_model = SunModel.from_config(raw_config)
|
|
|
|
weather_model = WeatherModel.from_config(raw_config, sun_model)
|
|
|
|
fault_config = FaultConfig.from_config(raw_config)
|
|
fault_manager = FaultManager(config=fault_config)
|
|
|
|
simulator = PVSimulator(
|
|
plant=plant,
|
|
sun=sun_model,
|
|
weather=weather_model,
|
|
fault_manager=fault_manager,
|
|
)
|
|
|
|
result = simulator.run(
|
|
|
|
simulation_config
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# STATISTICS
|
|
# ============================================================
|
|
|
|
statistics = SimulationStatistics(
|
|
|
|
result
|
|
)
|
|
|
|
kpi = statistics.plant_kpi()
|
|
|
|
print(
|
|
|
|
"Energia prodotta:",
|
|
|
|
kpi.energy_kWh,
|
|
|
|
"kWh"
|
|
)
|
|
|
|
print(
|
|
|
|
"Potenza massima:",
|
|
|
|
kpi.peak_power_W,
|
|
|
|
"W"
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# EXPORT
|
|
# ============================================================
|
|
|
|
exporter = SimulationExporter(
|
|
|
|
"output"
|
|
)
|
|
|
|
exporter.export_all(
|
|
|
|
result,
|
|
|
|
csv=True,
|
|
|
|
parquet=True,
|
|
|
|
json=True,
|
|
|
|
statistics=True,
|
|
)
|