Skip to content

Commit

Permalink
Merge pull request #4 from lucianavlop/lucias-second-branch
Browse files Browse the repository at this point in the history
improve formatting
  • Loading branch information
daithihearn authored Apr 24, 2023
2 parents 1b670fb + 2161f09 commit 61a3d27
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
42 changes: 27 additions & 15 deletions Electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
st.markdown(hide_streamlit_style, unsafe_allow_html=True)

today=datetime.today()
logging.info('Access to dashboard ' + datetime.now().strftime("%H:%M"))

tomorrow_date= today + timedelta(days=1)
start_date_average = today - timedelta(days=30)
hours_day = 24 -1
Expand All @@ -23,11 +25,8 @@
cheapest_period = get_cheapest_period(get_today(), 3)
cheapest_period_today_avg = calculate_average(cheapest_period)

cheapest_period_tom= get_cheapest_period(get_tomorrow(), 3)
cheapest_period_tom_avg = calculate_average(cheapest_period_tom)

todays_health=calculate_day_rating(cheapest_period_today_avg)
tomorrow_health=calculate_day_rating(cheapest_period_tom_avg)


# title
Expand All @@ -43,19 +42,20 @@
currentPrice = round(get_current_price(today_prices).value, 2)
difElec = round(currentPrice - elecAverage, 2)
col1, col2, col3, col4 = st.columns(4)
col1.metric("Precio Promedio (30 días)", elecAverage, delta_color="inverse")
col2.metric("Precio actual - " + datetime.now().strftime("%H:%M"), currentPrice, difElec, delta_color="inverse")
col1.metric("Precio Promedio (30 días)", format_euro(elecAverage), delta_color="inverse")
col2.metric("Precio actual - " + datetime.now().strftime("%H:%M"), format_euro(currentPrice), format_euro(difElec), delta_color="inverse")

labelminhour = "Precio min - " + get_min_price(get_today()).hour + ":00"
labelmaxhour = "Precio max - " + get_max_price(get_today()).hour + ":00"

minToday = round(get_min_price(today_prices).value, 2)
difElecMin = round(minToday - elecAverage, 2)
minToday = get_min_price(today_prices).value
difElecMin = minToday - elecAverage

maxToday = round(get_max_price(today_prices).value, 2)
difElecMax = round(maxToday - elecAverage, 2)
maxToday = get_max_price(today_prices).value
difElecMax = maxToday - elecAverage

col3.metric(labelminhour, minToday, difElecMin, delta_color="inverse")
col4.metric(labelmaxhour, maxToday, difElecMax, delta_color="inverse")
col3.metric(labelminhour, format_euro(minToday), format_euro(difElecMin), delta_color="inverse")
col4.metric(labelmaxhour, format_euro(maxToday), format_euro(difElecMax), delta_color="inverse")


# Plot timeline today
Expand Down Expand Up @@ -85,18 +85,30 @@

#Tomorrow's prices
if get_tomorrow():
#get day rating
cheapest_period_tom= get_cheapest_period(get_tomorrow(), 3)
cheapest_period_tom_avg = calculate_average(cheapest_period_tom)
tomorrow_health=calculate_day_rating(cheapest_period_tom_avg)


st.subheader('Mañana ' + tomorrow_date.strftime('%d/%m') + ' es un día ' + tomorrow_health
)
labelminhourT = "Precio min - " + \
get_min_price(get_tomorrow()).hour + ":00"
labelmaxhourT = "Precio max - " + \
get_max_price(get_tomorrow()).hour + ":00"

minTomorrow = get_min_price(
get_tomorrow()).value
difElecMinT = minTomorrow - elecAverage

maxTomorrow= get_max_price(today_prices).value
difElecMaxT = maxTomorrow - elecAverage


col1, col2, col3, col4 = st.columns(4)
col3.metric(labelminhourT, round(get_min_price(
get_tomorrow()).value, 2), delta_color="inverse")
col4.metric(labelmaxhourT, round(get_max_price(
get_tomorrow()).value, 2), delta_color="inverse")
col3.metric(labelminhourT, format_euro(minTomorrow) , format_euro(difElecMinT), delta_color="inverse")
col4.metric(labelmaxhourT, format_euro(maxTomorrow), format_euro(difElecMaxT), delta_color="inverse")


# Plot timeline tomorrow
Expand Down
11 changes: 4 additions & 7 deletions services/PriceService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import requests
import json
from babel.numbers import format_decimal
from babel.numbers import format_currency
from datetime import date, datetime, timedelta
from dateutil.parser import parse
from dotenv import load_dotenv
Expand Down Expand Up @@ -110,14 +110,13 @@ def calculate_average(prices: list[Price]) -> float:


def format_euro(amount) -> str:
return f'{format_decimal(amount, locale="en_GB", format="#,##0.000")}'
return f'{format_currency(amount, "EUR", locale="es_ES")}'

# lucia´s approach at classifiying the days
def get_date_health (date: date, globalAverage: float) -> str:
range = 0.02
average_date=calculate_average(get_prices(date, date))
lowLine= globalAverage-range
highLine= globalAverage + range
lowLine= globalAverage-VARIANCE
highLine= globalAverage + VARIANCE

if (average_date<lowLine):
return 'BUENO'
Expand All @@ -129,8 +128,6 @@ def get_date_health (date: date, globalAverage: float) -> str:
#Daithi´s approach
def calculate_day_rating(cheapest_period_avg: float) -> str:
recent_average = get_cheap_period_recent_average(30)
logging.info(
f'Recent average: {recent_average} - Tomorrow: {cheapest_period_avg}')

if (recent_average - cheapest_period_avg) > VARIANCE:
return "BUENO"
Expand Down

0 comments on commit 61a3d27

Please sign in to comment.