Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Energy balance #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,733 changes: 6,733 additions & 0 deletions datasets/balance_of_fuels/data/balance_of_fuels.csv

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions datasets/balance_of_fuels/datapackage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
profile: data-package
name: balance_of_fuels
title: Balance of solid, liquid and gas fuels, Slovenia, annually
description: Balance of solid, liquid and gas fuels, Slovenia, annually, from 2000 to most recent year available
keywords: [energy, energy balance, fuels]
geography: Slovenia
schedule: annual
licenses:
- name: ODbL-1.0
title: Open Data Commons Open Database License 1.0
path: http://www.opendefinition.org/licenses/odc-odbl
sources:
- title: Statistični urad Republike Slovenije / Statistical Office of the Republic of Slovenia
path: https://www.stat.si/
resources:
- encoding: utf-8
format: csv
hashing: md5
name: energy_balance
path: data/balance_of_fuels.csv
profile: tabular-data-resource
schema:
fields:
- name: fuel
type: string
- name: measured
type: string
- name: year
type: integer
- name: data
type: number
unit: varies
scheme: file
413 changes: 413 additions & 0 deletions datasets/balance_of_fuels/sources/2021/1818002S.px

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions datasets/balance_of_fuels/sources/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy>=1.24.2
pyaxis>=0.3.4
59 changes: 59 additions & 0 deletions datasets/balance_of_fuels/sources/sources2csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python

from pyaxis import pyaxis
import pandas as pd
import os

ENCODING = 'cp1250'


def next_to_this_file(fn):
return os.path.abspath(os.path.join(os.path.dirname(__file__), fn))



def convert_px(px_filename, csv_filename):
print("loading .px: %s" % (px_filename,))
d = pyaxis.parse(px_filename, encoding=ENCODING)

f1 = d["DATA"].copy()

# lowercase columns
print("lowercasing columns")
f1 = f1.rename(columns={col: col.lower().replace(' ', '_') for col in f1.columns })

# clean up values
print("cleaning values")
f2 = f1.copy()
f2["data"] = f2["data"].replace('"-"', None)
f2["data"] = f2["data"].replace('"..."', None)

# check
f2[f2["data"] == '"-"']

# save into csv
print("saving to csv: %s" % (csv_filename,))

# ensure stable sort for clean diffs
f3 = f2.sort_values(by=["leto", "gorivo", "meritve"])

f4 = f3.rename(columns={
"gorivo": "fuel",
"leto": "year",
"meritve": "measured",
})

f4.to_csv(csv_filename, index=False)

units = ", ".join(d["METADATA"].get("UNITS", []))


print("done.")
return d


if __name__ == "__main__":
convert_px(
next_to_this_file("2021/1818002S.px"),
next_to_this_file("../data/balance_of_fuels.csv")
)
7,261 changes: 7,261 additions & 0 deletions datasets/energy_balance/data/energy_balance.csv

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions datasets/energy_balance/datapackage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
profile: data-package
name: energy_balance
title: Annual energy balances in terajoules
description: Annual energy balances in terajoules from 2000 to most recent year available
keywords: [energy, energy balance]
geography: Slovenia
schedule: annual
licenses:
- name: ODbL-1.0
title: Open Data Commons Open Database License 1.0
path: http://www.opendefinition.org/licenses/odc-odbl
sources:
- title: Statistični urad Republike Slovenije / Statistical Office of the Republic of Slovenia
path: https://www.stat.si/
resources:
- encoding: utf-8
format: csv
hashing: md5
name: energy_balance
path: data/energy_balance.csv
profile: tabular-data-resource
schema:
fields:
- name: supply_and_consumption
type: string
- name: year
type: integer
- name: energy_source
type: string
- name: data
type: number
unit: terajoule
scheme: file
139 changes: 139 additions & 0 deletions datasets/energy_balance/sources/2019/1817901S.px

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions datasets/energy_balance/sources/2019/1817903S.px

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions datasets/energy_balance/sources/2021/1817903S.px

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions datasets/energy_balance/sources/poc/d3-sankey.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions datasets/energy_balance/sources/poc/d3.v4.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions datasets/energy_balance/sources/poc/d3.v6.min.js

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions datasets/energy_balance/sources/poc/d3_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D3 ex 1</title>
<script src="/d3.v4.min.js"></script>
</head>
<body>

<div id="chart"></div>

<script>
function chart_data(input_data, max_km) {
var data = [];
for (i in input_data) {
v = input_data[i];
// console.log("i", i, v);
data.push([
[0, v[0]/1000., v[2], v[3]],
[max_km, (v[1] * max_km / 1000. + v[0]) / 1000., v[2], v[3]],
]);
}
return data;
}

var color = d3.scaleOrdinal()
.domain(["ev", "ice"])
.range(["steelblue", "orange"]);

var max_km = 200000;
var chart_width = 600;
var chart_height = 300;

var padding = {
top: 20,
bottom: 50,
left: 70,
right: 30
};

/*
var input_data = [
[4526, 58.2, "Volkwagen ID.3 Pro", "ev"],
[0, 96, "Renault Clio E-Tech 2020", "ice"],
];
*/

var input_data = [
[2920, 57.5, "Nissan Leaf", "ev"],
[0, 157, "Ford Fusion 1.6 2007", "ice"],
];

var data1 = chart_data(input_data, max_km);
console.log("data", data1);

// chart area
var chart = d3.select("#chart")
.append("svg")
.attr("width", chart_width)
.attr("height", chart_height)
.style("border", "1px solid black");

// x axis
var x_axis = d3.scaleLinear()
.domain([0, max_km])
.range([padding.left, chart_width-padding.right]);

var x_axis_g = chart.append("g")
.attr("transform", "translate(0, " + (chart_height - padding.bottom) + ")");

// x axis title
chart.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 5)
.attr("x", 0 - (chart_height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Emisije [ton CO₂]");

// y axis
var y_axis = d3.scaleLinear()
.domain([0, d3.max(data1, function (d) { return d[1]})[1]])
.range([chart_height - padding.bottom, padding.top]);

var y_axis_g = chart.append("g")
.attr("transform", "translate(" + padding.left + ",0)");

// x axis title
chart.append("text")
.attr("y", (chart_height) - padding.top - 10)
.attr("x", (chart_width / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Prevoženih kilometrov");

var lines = chart.selectAll(".line")
.data(data1)
.enter()
.append("path")
.attr("class", "line");

// lines
function update_chart(data) {
x_axis_g.call(d3.axisBottom(x_axis));
y_axis.domain([0, d3.max(data, function (d) { return d[1]})[1]]);
y_axis_g.transition().call(d3.axisLeft(y_axis));

lines.data(data)
.attr("fill", "none")
.attr("class", "line")
.attr("stroke", function(d) {
return color(d[0][3]);
})
.attr("stroke-width", 1.5)
.attr("d", function (d) {
return d3.line()
.x(function (d) {
return x_axis(d[0]);
})
.y(function (d) {
return y_axis(d[1]);
})
(d)
}
);


}

update_chart(data1);

var input_data2 = [
[4526, 58.2, "Volkwagen ID.3 Pro", "ev"],
[0, 96, "Renault Clio E-Tech 2020", "ice"],
];

var data2 = chart_data(input_data2, max_km);
console.log("data2", data2);

setTimeout(function () {
update_chart(data2);
}, 3000);

</script>
</body>
</html>
Loading