Sponsored by AppSignal
Would you like to see your link here? Contact us
Notesclub

Engie visualisator

engie_visualisator.livemd

Engie visualisator

Mix.install([
  {:vega_lite, "~> 0.1.6"},
  {:kino_vega_lite, "~> 0.1.6"},
  {:jason, "~> 1.4.1"},
  {:kino_explorer, "~> 0.1.4"}
])

Raw Data

Go to https://particuliers.engie.fr/espace-client/consommations.html.

  • Inspect the page
  • Open the Network tab
  • Search the request named “consoMoisAnnee” and click on it
  • Click on the sub tab Response
  • Copy paste the content in a file conso.json
  • Drag the file in the box below
file = Kino.Input.file("Your data file")
file_input = Kino.Input.read(file)
path = Kino.Input.file_path(file_input.file_ref)
raw_data = File.read!(path)
{:ok, json} = Jason.decode(raw_data)

Graph

alias VegaLite, as: Vl

data = json["listeConsoCalendaire"]

Vl.new(title: "Total Consumption in kWh per Month", width: 720, height: 400)
|> Vl.data_from_values(data)
|> Vl.encode_field(:x, "calendrier.mois", title: "Month")
|> Vl.encode_field(:y, "consoGlobal", title: "Total Consumption in kWh", type: :quantitative)
|> Vl.encode_field(:color, "calendrier.annee", title: "Year")
|> Vl.mark(:line)
alias VegaLite, as: Vl

# Vos données
data = json["listeConsoCalendaire"]

# Création du graphique
Vl.new(title: "Total Amount Including Tax per Month", width: 720, height: 400)
|> Vl.data_from_values(data)
|> Vl.encode_field(:x, "calendrier.mois", title: "Month")
|> Vl.encode_field(:y, "montantGlobalTTC",
  title: "Total Amount Including Tax",
  type: :quantitative
)
|> Vl.encode_field(:color, "calendrier.annee", title: "Year")
|> Vl.mark(:line)
alias VegaLite, as: Vl

# Vos données
data = json["listeConsoCalendaire"]

# Création du graphique
Vl.new(title: "Monthly Subscription Cost", width: 720, height: 400)
|> Vl.data_from_values(data)
|> Vl.encode_field(:x, "calendrier.mois", title: "Month")
|> Vl.encode_field(:y, "montantGlobalAboTTC", title: "Subscription cost", type: :quantitative)
|> Vl.encode_field(:color, "calendrier.annee", title: "Year")
|> Vl.mark(:line)
alias VegaLite, as: Vl

# Vos données
data = json["listeConsoCalendaire"]

# Création du graphique
Vl.new(title: "Monthly Usage Cost", width: 720, height: 400)
|> Vl.data_from_values(data)
|> Vl.encode_field(:x, "calendrier.mois", title: "Month")
|> Vl.encode_field(:y, "montantGlobalConsoTTC",
  title: "Monthly Usage Cost (without subscription)",
  type: :quantitative
)
|> Vl.encode_field(:color, "calendrier.annee", title: "Année")
|> Vl.mark(:line)