Skip to content

Commit

Permalink
Merge pull request #5 from jtimko16/improve-streamlit-app
Browse files Browse the repository at this point in the history
Improve streamlit app
  • Loading branch information
jtimko16 authored Jan 10, 2025
2 parents 9a6be05 + 570fbfa commit f9def66
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 1,678 deletions.
Binary file modified requirements.txt
Binary file not shown.
39 changes: 22 additions & 17 deletions src/fun/api_f.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import pandas as pd
import requests

def fetch_nordpool_data(area: str = "EE")->pd.DataFrame:

def fetch_nordpool_data(area: str = "EE") -> pd.DataFrame:
"""Fetch one day ahead electricity prices for a specific aread/country
Args:
area (str): Two letter country code"""
area (str): Usually two letter country code"""
# Create an instance of the elspot API
prices_spot = elspot.Prices()

# Fetch hourly prices for today
data = prices_spot.hourly(areas=[area])

Expand All @@ -19,9 +20,9 @@ def fetch_nordpool_data(area: str = "EE")->pd.DataFrame:

## Change timezone to CET (UTC+1)
area_df["start"] = pd.to_datetime(area_df["start"]).dt.tz_convert("CET")

## Rename start column to hour and remove end
area_df = area_df.rename(columns={"start": "hour"})
area_df = area_df.rename(columns={"start": "datetime"})
area_df = area_df.drop(columns=["end"])

## Rename value to electricity_price
Expand All @@ -30,9 +31,11 @@ def fetch_nordpool_data(area: str = "EE")->pd.DataFrame:
return area_df


def get_weather_forecast(latitude: float = 59.437, longitude: float = 24.7535)->pd.DataFrame:
def get_weather_forecast(
latitude: float = 59.437, longitude: float = 24.7535
) -> pd.DataFrame:
"""Fetch weather forecast for a specific location
Args:
latitude (float): Latitude of the location
longitude (float): Longitude of the location"""
Expand All @@ -41,7 +44,7 @@ def get_weather_forecast(latitude: float = 59.437, longitude: float = 24.7535)->
"latitude": latitude,
"longitude": longitude,
"hourly": "temperature_2m,wind_speed_10m,direct_radiation,diffuse_radiation",
"timezone": "CET" # Directly request data in CET
"timezone": "CET", # Directly request data in CET
}

# Fetch weather data
Expand All @@ -59,14 +62,16 @@ def get_weather_forecast(latitude: float = 59.437, longitude: float = 24.7535)->
diffuse_radiation = hourly_data.get("diffuse_radiation", [])

# Create a DataFrame
df = pd.DataFrame({
"hour": pd.to_datetime(times), # Convert times to datetime
"temperature_2m": temperature_2m,
"wind_speed_10m": wind_speed_10m,
"direct_radiation": direct_radiation,
"diffuse_radiation": diffuse_radiation,
})
df = pd.DataFrame(
{
"datetime": pd.to_datetime(times), # Convert times to datetime
"temperature_2m": temperature_2m,
"wind_speed_10m": wind_speed_10m,
"direct_radiation": direct_radiation,
"diffuse_radiation": diffuse_radiation,
}
)

# Ensure timezone is CET
df["hour"] = df["hour"].dt.tz_localize("CET")
df["datetime"] = df["datetime"].dt.tz_localize("CET")
return df
Empty file removed src/fun/data_prep_f.py
Empty file.
Loading

0 comments on commit f9def66

Please sign in to comment.