#!/usr/bin/env python3 __author__ = "guiguis" __version__ = "0.1.0" import json import pandas as pd import sys def main(): costs = {'bleu': {'hc': 8.62, 'hp': 12.72}, 'blanc': {'hc': 11.12, 'hp': 16.53}, 'rouge': {'hc': 12.22, 'hp': 54.86}, 'tarif_bleu': {'hc': 14.70, 'hp': 18.41}} with open('daily.json') as f: daily = json.load(f) last_year = daily['listeConsommationLinkyJour'][-365:] sorted_daily = sorted(last_year, key=lambda d: d['consoElecGlobal'], reverse=True) consumptions_with_color = [] for i in range(365): day = {'date': sorted_daily[i]['dateDebutReleve'], 'hp': sorted_daily[i]['consoElecHp'], 'hc': sorted_daily[i]['consoElecHc']} if i < 23: day['color'] = 'rouge' elif i < 67: day['color'] = 'blanc' else: day['color'] = 'bleu' consumptions_with_color.append(day) tarif_bleu_cost = 0 for day in consumptions_with_color: tarif_bleu_cost += day['hp'] * costs['tarif_bleu']['hp'] + day['hc'] * costs['tarif_bleu']['hc'] efforts = [x * 0.01 for x in range(0, 101, 5)] yearly_costs = {} for effort in efforts: yearly_cost = 0 for day in consumptions_with_color: if not day['color'] == 'rouge': cost = day['hp'] * costs[day['color']]['hp'] + day['hc'] * costs[day['color']]['hc'] else: cost = day['hp'] * costs[day['color']]['hp'] * effort + day['hc'] * costs[day['color']]['hc'] yearly_cost += cost yearly_costs[effort] = int(yearly_cost/100) df = pd.DataFrame(yearly_costs.items(), columns=['effort', 'coût']) print(f'Coût en tarif bleu = {int(tarif_bleu_cost / 100)}') print(df) if __name__ == "__main__": main()