send_report added, columns to 80

This commit is contained in:
Mark Kors
2025-10-30 19:48:06 +01:00
parent 6a722f6bf2
commit 288b7cd162
2 changed files with 50 additions and 30 deletions

21
send_report.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Configuratie
TO_EMAIL="mark@markkors.nl"
FROM_EMAIL="laadpaal@raspberry.local"
SUBJECT="Laadrapport $(date +%d-%m-%Y)"
# Genereer rapport
REPORT=$(python3 ~/reports/steve_transaction_report.py --host 192.168.178.201 --port 3307 --user steve --password 'kS9R*xp17ZwCD@CV&E^N' --price-user alfen_user --price-password '5uVgr%f%s2P5GR@3q!' --limit 1)
# Verstuur email met headers
cat <<EOF | msmtp "$TO_EMAIL"
Subject: $SUBJECT
From: $FROM_EMAIL
To: $TO_EMAIL
$REPORT
EOF
echo "✓ Rapport verzonden naar $TO_EMAIL"

View File

@@ -258,12 +258,12 @@ class SteVeReporter:
stop_value = float(transaction['stop_value']) if transaction['stop_value'] else 0
total_consumption = stop_value - start_value
print(f"\nStart meterstand: {start_value:.3f} kWh")
print(f"Eind meterstand: {stop_value:.3f} kWh")
print(f"\nStart: {start_value:.3f} kWh")
print(f"Einde: {stop_value:.3f} kWh")
print(f"Totaal geladen: {total_consumption:.2f} kWh")
if transaction['stop_reason']:
print(f"Stop reden: {transaction['stop_reason']}")
print(f"Stop: {transaction['stop_reason']}")
print("=" * 80)
@@ -276,9 +276,9 @@ class SteVeReporter:
if hourly_data:
print("\nVERBRUIK EN KOSTEN PER UUR:")
print("-" * 100)
print(f"{'Uur':<20} {'Start (kWh)':<15} {'Eind (kWh)':<15} {'Geladen (kWh)':<15} {'Prijs (€/kWh)':<15} {'Kosten (€)':<15}")
print("-" * 100)
print("-" * 80)
print(f"{'Uur':<12} {'Start':<10} {'Eind':<10} {'kWh':<8} {'€/kWh':<11} {'Kosten':<10}")
print("-" * 80)
total_detailed = 0
total_cost = 0
@@ -297,22 +297,22 @@ class SteVeReporter:
total_cost += cost
hours_with_price += 1
price_str = f"{price:.5f}"
cost_str = f"{cost:.2f}"
cost_str = f"{cost:.2f}"
else:
hours_without_price += 1
price_str = "n.v.t."
cost_str = "n.v.t."
print(f"{hour_display:<20} {hour['start_value']:<15.3f} "
f"{hour['end_value']:<15.3f} {hour['consumption']:<15.3f} "
f"{price_str:<15} {cost_str:<15}")
print(f"{hour_display:<12} {hour['start_value']:<10.3f} "
f"{hour['end_value']:<10.3f} {hour['consumption']:<8.3f} "
f"{price_str:<11} {cost_str:<10}")
total_detailed += hour['consumption']
print("-" * 100)
print("-" * 80)
cost_total_str = f"{total_cost:.2f}" if hours_without_price == 0 else f"{total_cost:.2f}*"
print(f"{'TOTAAL':<20} {hourly_data[0]['start_value']:<15.3f} "
f"{hourly_data[-1]['end_value']:<15.3f} {total_detailed:<15.3f} "
f"{'':15} {cost_total_str:<15}")
print(f"{'TOTAAL':<12} {hourly_data[0]['start_value']:<10.3f} "
f"{hourly_data[-1]['end_value']:<10.3f} {total_detailed:<8.3f} "
f"{'':11} {cost_total_str:<10}")
# Statistieken
active_hours = [h for h in hourly_data if h['consumption'] > 0.01]
@@ -320,16 +320,15 @@ class SteVeReporter:
print("\n" + "=" * 80)
print("STATISTIEKEN:")
print("-" * 80)
print(f"Actieve laaduren: {len(active_hours)}")
print(f"Actieve uren: {len(active_hours)}")
print(f"Provider: {provider}")
avg_per_hour = sum(h['consumption'] for h in active_hours) / len(active_hours)
print(f"Gemiddeld per actief uur: {avg_per_hour:.2f} kWh")
print(f"Gemiddeld/uur: {avg_per_hour:.2f} kWh")
max_hour = max(hourly_data, key=lambda x: x['consumption'])
if max_hour['consumption'] > 0:
max_time = datetime.strptime(max_hour['hour'], '%Y-%m-%d %H:00')
print(f"Piekuur verbruik: {max_time.strftime('%d-%m %H:00')} "
f"({max_hour['consumption']:.2f} kWh)")
print(f"Piekuur: {max_time.strftime('%d-%m %H:00')} ({max_hour['consumption']:.2f} kWh)")
# Vind duurste en goedkoopste uur
hours_with_costs = []
@@ -349,14 +348,14 @@ class SteVeReporter:
f"(€{cheapest[1]:.5f}/kWh)")
# Totale kosten
print(f"\n{'TOTALE KOSTEN:':<30} {cost_total_str}")
print(f"\nTOTAALE KOSTEN: {cost_total_str}")
if hours_without_price > 0:
print(f"* Let op: Voor {hours_without_price} uur ontbreken prijsgegevens")
print(f"* {hours_without_price} uur zonder prijsdata")
# Gemiddelde prijs
if hours_with_price > 0:
avg_price = total_cost / total_detailed if total_detailed > 0 else 0
print(f"{'Gemiddelde prijs:':<30}{avg_price:.5f}/kWh")
print(f"Gemiddelde prijs: €{avg_price:.5f}/kWh")
print("=" * 80)
@@ -368,11 +367,11 @@ class SteVeReporter:
print("Geen transacties gevonden.")
return
print("\n" + "=" * 100)
print("\n" + "=" * 80)
print(f"OVERZICHT VAN LAATSTE {len(transactions)} TRANSACTIES")
print("=" * 100)
print(f"{'ID':<6} {'Start':<20} {'Duur':<12} {'kWh':<10} {'Laadpaal':<20} {'RFID':<15}")
print("-" * 100)
print("=" * 80)
print(f"{'ID':<4} {'Start':<17} {'Duur':<10} {'kWh':<8} {'Laadpaal':<16} {'RFID':<12}")
print("-" * 80)
for t in transactions:
trans_id = t['transaction_pk']
@@ -389,13 +388,13 @@ class SteVeReporter:
stop_val = float(t['stop_value']) if t['stop_value'] else 0
kwh = stop_val - start_val
charge_box = t['charge_box_id'][:18] if t['charge_box_id'] else "?"
rfid = t['id_tag'][:13] if t['id_tag'] else "?"
charge_box = t['charge_box_id'][:14] if t['charge_box_id'] else "?"
rfid = t['id_tag'][:10] if t['id_tag'] else "?"
print(f"{trans_id:<6} {start:<20} {duration_str:<12} {kwh:<10.2f} {charge_box:<20} {rfid:<15}")
print(f"{trans_id:<4} {start:<17} {duration_str:<10} {kwh:<8.2f} {charge_box:<16} {rfid:<12}")
print("=" * 100)
print(f"\nGebruik: python3 {sys.argv[0]} --transaction <ID> voor details\n")
print("=" * 80)
print(f"\nGebruik --transaction <ID> voor details\n")
def main():