Skip to content

Instantly share code, notes, and snippets.

@dhardy92
Created April 14, 2023 14:37
Show Gist options
  • Save dhardy92/c940be9030b8b553b059a8a25960f112 to your computer and use it in GitHub Desktop.
Save dhardy92/c940be9030b8b553b059a8a25960f112 to your computer and use it in GitHub Desktop.
Script Awk pour évaluer sa facture avec l'offre tempo d'EDF en fonction de sont usage réèl passé. en tenant compte des jour blanc et rouge de l'hiver 2022/2023
function tempo_price(date,hour) {
datespec = date " " hour
gsub(/[:-]/," ", datespec)
ts = mktime(datespec)-(6*3600)
tempo_date = strftime("%Y-%m-%d", ts)
tempo_hour = strftime("%H",ts)
tempo["2022-11-29"]="blanc"
tempo["2022-11-30"]="blanc"
tempo["2022-12-01"]="blanc"
tempo["2022-12-02"]="blanc"
tempo["2022-12-05"]="blanc"
tempo["2022-12-06"]="blanc"
tempo["2022-12-07"]="blanc"
tempo["2022-12-08"]="rouge"
tempo["2022-12-09"]="blanc"
tempo["2022-12-10"]="blanc"
tempo["2022-12-12"]="rouge"
tempo["2022-12-13"]="rouge"
tempo["2022-12-14"]="rouge"
tempo["2022-12-15"]="blanc"
tempo["2022-12-16"]="blanc"
tempo["2022-12-17"]="blanc"
tempo["2023-01-16"]="blanc"
tempo["2023-01-17"]="rouge"
tempo["2023-01-18"]="rouge"
tempo["2023-01-19"]="rouge"
tempo["2023-01-20"]="rouge"
tempo["2023-01-21"]="blanc"
tempo["2023-01-23"]="rouge"
tempo["2023-01-24"]="rouge"
tempo["2023-01-25"]="rouge"
tempo["2023-01-26"]="rouge"
tempo["2023-01-27"]="rouge"
tempo["2023-01-28"]="blanc"
tempo["2023-01-30"]="rouge"
tempo["2023-01-31"]="rouge"
tempo["2023-02-01"]="blanc"
tempo["2023-02-02"]="blanc"
tempo["2023-02-03"]="blanc"
tempo["2023-02-04"]="blanc"
tempo["2023-02-06"]="rouge"
tempo["2023-02-07"]="rouge"
tempo["2023-02-08"]="rouge"
tempo["2023-02-09"]="rouge"
tempo["2023-02-10"]="rouge"
tempo["2023-02-11"]="blanc"
tempo["2023-02-13"]="blanc"
tempo["2023-02-14"]="blanc"
tempo["2023-02-15"]="blanc"
tempo["2023-02-16"]="blanc"
tempo["2023-02-22"]="blanc"
tempo["2023-02-23"]="blanc"
tempo["2023-02-24"]="blanc"
tempo["2023-02-27"]="blanc"
tempo["2023-02-28"]="blanc"
tempo["2023-03-01"]="rouge"
tempo["2023-03-02"]="rouge"
tempo["2023-03-03"]="blanc"
tempo["2023-03-06"]="blanc"
tempo["2023-03-07"]="blanc"
tempo["2023-04-04"]="blanc"
tempo["2023-04-05"]="blanc"
tempo["2023-04-06"]="blanc"
tempo["2023-04-07"]="blanc"
tempo["2023-04-13"]="blanc"
price["hp"]["blanc"] = 15.08
price["hc"]["blanc"] = 11.4
price["hp"]["rouge"] = 67.12
price["hc"]["rouge"] = 12.16
price["hc"]["bleu"] = 9.7
price["hp"]["bleu"] = 12.49
tempo_hour >= 16 ? pr = "hc" : pr = "hp"
tempo_date in tempo ? p = price[pr][tempo[tempo_date]] : p = price[pr]["bleu"]
return p
}
/^20/{
date=substr($1,0,10);
hour=substr($1,12,8);
t=tempo_price(date,hour)
total+=$2 * t / 1000
print date,hour,$2, t, $2 * t / 1000
}
END {
print total/100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment