Skip to content

Commit

Permalink
Aggiunto calcolo tariffa monooraria e F23
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualdj committed Dec 2, 2023
1 parent 1fdda5f commit ecc993b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Mostra i costi del PUN di un anno, diviso per mesi e fasce orarie (F1, F2 e F3).
I valori vengono scaricati dal sito [MercatoElettrico.org](https://www.mercatoelettrico.org/It/Default.aspx).

È stato aggiunto anche il calcolo della fascia mono-oraria e F23, basata su calcoli documentati non in modo perfetto ma che sembrano portare a risultati identici (o perlomeno simili) alle tariffe ufficiali.

## Installazione dei prerequisiti

`python3 -m pip install -r ./requirements.txt`
Expand All @@ -11,13 +13,13 @@ I valori vengono scaricati dal sito [MercatoElettrico.org](https://www.mercatoel

`python3 ./pun-fasce.py <anno>`

L'`anno` può non essere specificato (in quel caso si intende l'anno corrente).
L'`anno` è opzionale e in quel caso si intende l'anno corrente.
Il risultato è simile a questo:

```text
Mese F1 (€/kWh) F2 (€/kWh) F3 (€/kWh)
1/2022 0.257190 0.242350 0.196390
2/2022 0.224880 0.225680 0.193650
3/2022 0.320080 0.329120 0.286190
4/2022 0.256230 0.266580 0.228860
Mese MO (€/kWh) F1 (€/kWh) F2 (€/kWh) F3 (€/kWh) F23 (€/kWh)
1/2023 0.174490 0.196240 0.184240 0.155100 0.168504
2/2023 0.161070 0.174330 0.172890 0.144220 0.157408
3/2023 0.136380 0.139780 0.151950 0.124660 0.137213
4/2023 0.134970 0.135550 0.152050 0.126400 0.138199
```
16 changes: 13 additions & 3 deletions pun-fasce.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def get_fascia(data, festivo, ora):
def fmt_mean(list):
return format(round(mean(list), 5), '.6f')

# Calcola la fascia F23 sulla base delle fasce F2 e F3, formattando il risultato
def calc_f23(f2, f3):
# La motivazione del calcolo è oscura, ma sembra corretta, vedere:
# https://github.com/virtualdj/pun_sensor/issues/24#issuecomment-1829846806

return format(round(mean(f2), 5) * .46 + round(mean(f3), 5) * .54, '.6f')

# Recupera l'anno dall'argomento (o usa quello corrente)
parser = argparse.ArgumentParser(description='Mostra i costi del PUN di un anno, diviso per mesi e fasce orarie.')
parser.add_argument('year', type=int, nargs='?',
Expand Down Expand Up @@ -88,9 +95,10 @@ def fmt_mean(list):
f1 = []
f2 = []
f3 = []
monoorario = []

# Header output
print('Mese','F1 (€/kWh)','F2 (€/kWh)','F3 (€/kWh)', sep='\t')
print('Mese','MO (€/kWh)','F1 (€/kWh)','F2 (€/kWh)','F3 (€/kWh)','F23 (€/kWh)', sep='\t')

# Esamina le righe non vuote a partire dalla seconda
for row in range(2, sheet.max_row):
Expand Down Expand Up @@ -118,7 +126,7 @@ def fmt_mean(list):
# Nuovo mese
# Stampa i totali precedenti
if (prev_month > 0):
print(f'{prev_month}/{anno}', fmt_mean(f1), fmt_mean(f2), fmt_mean(f3), sep='\t')
print(f'{prev_month}/{anno}', fmt_mean(monoorario), fmt_mean(f1), fmt_mean(f2), fmt_mean(f3), calc_f23(f2, f3), sep='\t')

# Memorizza il nuovo mese
prev_month = dat2.month
Expand All @@ -127,6 +135,7 @@ def fmt_mean(list):
f1.clear()
f2.clear()
f3.clear()
monoorario.clear()

# Estrae la fascia oraria
#print("Len", len(f1), len(f2), len(f3))
Expand All @@ -137,12 +146,13 @@ def fmt_mean(list):
f2.append(prezzo)
elif fascia == 1:
f1.append(prezzo)
monoorario.append(prezzo)

# Verifica se l'ultimo mese è completo
next_day = dat2 + timedelta(days=1)
if (next_day.month != prev_month):
# Mese completo, mostra statistiche
print(f'{prev_month}/{anno}', fmt_mean(f1), fmt_mean(f2), fmt_mean(f3), sep='\t')
print(f'{prev_month}/{anno}', fmt_mean(monoorario), fmt_mean(f1), fmt_mean(f2), fmt_mean(f3), calc_f23(f2, f3), sep='\t')

# Controlla se il file è stato trovato
if (not xlsFound):
Expand Down

0 comments on commit ecc993b

Please sign in to comment.