Created
June 17, 2022 11:01
-
-
Save eisterman/df563e6265326f9901446351f3f92c88 to your computer and use it in GitHub Desktop.
Statistics for Tony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Npgsql.FSharp | |
let connectionString : string = | |
Sql.host "xxx.com" | |
|> Sql.database "xxx" | |
|> Sql.username "xxx" | |
|> Sql.password "xxx" | |
|> Sql.port 12345 | |
|> Sql.requireSslMode | |
|> Sql.trustServerCertificate true | |
|> Sql.formatConnectionString | |
let total_energy_consumed cs_id = | |
connectionString | |
|> Sql.connect | |
|> Sql.query $"SELECT timestamp, power FROM pienosole_api_power WHERE \ | |
chargingstation_id = {cs_id} ORDER BY timestamp DESC" | |
|> Sql.execute (fun read -> read.dateTime "timestamp", read.int "power") | |
|> List.pairwise | |
|> List.map (fun ((t1, _p1), (t0, p0)) -> (t1 - t0).TotalSeconds, p0) | |
|> List.filter (fun (dt, _p0) -> dt <= 360) | |
|> List.foldBack (fun (dt, p0) acc -> acc + float(p0) * dt / 3600. ) <| 0.0 // WattHour | |
(* | |
User: ETYO | |
User-ID: 4056 | |
Managed-parks: 220,226,245,270 | |
BNUM-parkid: bnum - name | |
BNUM-220: 624 - BOUTIN | |
BNUM-226: 637 - Sterlin | |
BNUM-245: 677 - Dubar | |
BNUM-270: 738 - Quesne | |
*) | |
624 |> total_energy_consumed |> (fun x -> printfn $"BOUTIN: %.3f{x/1000.} KWh") | |
637 |> total_energy_consumed |> (fun x -> printfn $"Sterlin: %.3f{x/1000.} KWh") | |
677 |> total_energy_consumed |> (fun x -> printfn $"Dubar: %.3f{x/1000.} KWh") | |
738 |> total_energy_consumed |> (fun x -> printfn $"Quesne: %.3f{x/1000.} KWh") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment