Skip to content

Commit

Permalink
save results as csv (#142)
Browse files Browse the repository at this point in the history
* save results as csv

* results folder

* typer outputs CLI

* update req

* frontend

* refactor

* rm fe

* rm typer help

* rm streamlit
  • Loading branch information
aryanbhosale authored Jul 11, 2024
1 parent 82d1ff7 commit 562dead
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
29 changes: 23 additions & 6 deletions examples/inverter_example.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
""" Example code to run the forecast"""
import pandas as pd
from datetime import datetime
from datetime import datetime, timezone
from quartz_solar_forecast.forecast import run_forecast
from quartz_solar_forecast.pydantic_models import PVSite
from datetime import datetime, timezone
import os
import typer

# Set plotly backend to be plotly, you might have to install plotly
pd.options.plotting.backend = "plotly"

def main():

def main(save_outputs: bool = False):
timestamp = datetime.now().timestamp()
timestamp_str = datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
ts = pd.to_datetime(timestamp_str)
Expand All @@ -26,6 +25,24 @@ def main():

predictions_with_recent_pv_df["power_kw_no_live_pv"] = predictions_df["power_kw"]

if save_outputs:
# Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(__file__))

# Create a 'results' directory if it doesn't exist
results_dir = os.path.join(script_dir, 'results')
os.makedirs(results_dir, exist_ok=True)

# Save dataframe to CSV file in the 'results' directory
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
csv_filename = f"predictions_with_recent_pv_{current_time}.csv"
csv_path = os.path.join(results_dir, csv_filename)
predictions_with_recent_pv_df.to_csv(csv_path, index=True)

print(f"CSV file saved at: {csv_path}")
else:
print("Outputs not saved to CSV. Use --save-outputs to save.")

# plot
fig = predictions_with_recent_pv_df.plot(
title="PV Forecast",
Expand All @@ -36,4 +53,4 @@ def main():
fig.show(renderer="browser")

if __name__ == "__main__":
main()
typer.run(main)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ openmeteo-requests==1.2.0
requests-cache==1.2.0
retry-requests==2.0.0
gdown==5.1.0
xgboost==2.0.3
xgboost==2.0.3
plotly
typer

0 comments on commit 562dead

Please sign in to comment.