-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathranking.html
158 lines (145 loc) · 5.7 KB
/
ranking.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<meta charset="utf-8"><script type="module">
import { css, h1, h2, link, add, create, style, hr } from "https://js.sabae.cc/stdom.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
import { Num } from "https://js.sabae.cc/Num.js";
const makeRanking = (data) => {
makeRankingCO2diff(data);
makeRankingCO2(data);
makeRankingArea(data);
};
const makeRankingCO2diff = (data) => {
const sec = add("section");
const h2 = create("h2");
h2.textContent = "炭素削減率ランキング";
sec.appendChild(h2);
const co2types = [
"電気起算校舎(t-CO2)",
"化石燃料起算校舎(t-CO2)",
"電気起算寄宿舎(t-CO2)",
"化石燃料起算寄宿舎(t-CO2)",
];
const calcCO2 = (k) => co2types.reduce((prev, cur) => prev + parseFloat(k[cur]), 0);
const list = data.co2.data.map(d => {
const co2 = calcCO2(d);
const dp = data.co2Past.data.find(d2 => d.事業所名 == d2.事業所名);
const co2past = calcCO2(dp);
const co2diff = co2past - co2;
const co2ratio = co2diff / co2past;
const co2ratios = (co2diff > 0 ? "" : "+") + (-co2diff / co2past * 100).toFixed(1) + "%";
//console.log(d.事業所名, co2, co2past, co2diff)
return {
事業所名: d.事業所名,
co2, co2past, co2diff, co2ratio, co2ratios
};
//}).sort((a, b) => a.co2diff - b.co2diff);
}).sort((a, b) => b.co2ratio - a.co2ratio);
const tbl = create("table");
sec.appendChild(tbl);
for (let i = 0; i < list.length; i++) {
const d = list[i];
const tr = create("tr");
tbl.appendChild(tr);
addtd(tr, (i + 1) + "位");
addtd(tr, d["事業所名"], getKosenLink(data, d["事業所名"]));
//addtd(tr, Num.addComma(d.ratios + "t-CO2"));
addtd(tr, d.co2ratios + " (" + d.co2past + "→" + d.co2 + " t-CO2)");
}
};
const makeRankingCO2 = (data) => {
const sec = add("section");
const h2 = create("h2");
h2.textContent = "低炭素ランキング (CO2排出量)";
sec.appendChild(h2);
const co2types = [
"電気起算校舎(t-CO2)",
"化石燃料起算校舎(t-CO2)",
"電気起算寄宿舎(t-CO2)",
"化石燃料起算寄宿舎(t-CO2)",
];
const calcCO2 = (k) => co2types.reduce((prev, cur) => prev + parseFloat(k[cur]), 0);
const list = data.co2.data.sort((a, b) => {
return calcCO2(a) - calcCO2(b);
});
const tbl = create("table");
sec.appendChild(tbl);
for (let i = 0; i < list.length; i++) {
const d = list[i];
const tr = create("tr");
tbl.appendChild(tr);
addtd(tr, (i + 1) + "位");
addtd(tr, d["事業所名"], getKosenLink(data, d["事業所名"]));
addtd(tr, Num.addComma(calcCO2(d)) + "t-CO2");
co2types.forEach((t) => {
addtd(tr, t.substring(0, t.length - "(t-CO2)".length).replace("寄宿舎", "寮") + " " + Num.addComma(d[t]));
});
}
};
const makeRankingArea = (data) => {
const sec = add("section");
const h2 = create("h2");
h2.textContent = "広さランキング (学校+寮)";
sec.appendChild(h2);
const calcArea = (k) => parseFloat(k["寄宿舎(㎡)"]) + parseFloat(k["校舎(㎡)"]);
const list = data.facilityarea.data.sort((a, b) => {
return calcArea(b) - calcArea(a);
});
const tbl = create("table");
sec.appendChild(tbl);
for (let i = 0; i < list.length; i++) {
const d = list[i];
const tr = create("tr");
tbl.appendChild(tr);
addtd(tr, (i + 1) + "位");
addtd(tr, d["事業所名"], getKosenLink(data, d["事業所名"]));
addtd(tr, Num.addComma(calcArea(d)) + "㎡");
addtd(tr, "校舎 " + Num.addComma(d["校舎(㎡)"]) + "㎡");
addtd(tr, "寮 " + Num.addComma(d["寄宿舎(㎡)"]) + "㎡");
}
};
onload = async () => {
css();
h1("高専ランキング (高専機構55キャンパス)");
const data = {
facilityarea: { url: "https://codeforkosen.github.io/kosen-opendata/data/kiko/kankyo2021/kankyo2021_facilityarea.csv" },
// energyinput: { url: "https://codeforkosen.github.io/kosen-opendata/data/kiko/kankyo2020/kankyo2020_energyinput.csv", },
co2: { url: "https://codeforkosen.github.io/kosen-opendata/data/kiko/kankyo2021/kankyo2021_co2.csv", },
campus: { url: "https://codeforkosen.github.io/kosen-opendata/data/kosen_campus.csv", },
facilityareaPast: { url: "https://codeforkosen.github.io/kosen-opendata/data/kiko/kankyo2020/kankyo2020_facilityarea.csv" },
co2Past: { url: "https://codeforkosen.github.io/kosen-opendata/data/kiko/kankyo2020/kankyo2020_co2.csv", },
};
for (const name in data) {
const d = data[name];
const json = CSV.toJSON(await CSV.fetch(d.url));
d.data = json.filter(d => d.事業所名 != "機構本部");
}
console.log(data);
style({
body: { "max-width": "90vw" },
section: { display: "inline-block", "font-size": "80%", "margin": "0 1em" },
td: { "font-size": "80%", "text-align": "left" },
});
makeRanking(data);
hr();
link("App: 福野泰介の一日一創", "https://fukuno.jig.jp/3353");
link("History: 高専ランキング2020", "ranking2020.html");
link("GitHub: Code for KOSEN", "https://github.com/codeforkosen/kosen-apps/");
link("Data: 高専オープンデータ - 環境報告書2021オープンデータ(国立高専別エネルギー収支状況)(令和3年9月)", "https://github.com/codeforkosen/kosen-opendata/tree/main/data/kiko/kankyo2021");
link("Data: 高専オープンデータ - 高専キャンパス", "https://github.com/codeforkosen/kosen-opendata");
};
const getKosenLink = (data, s) => {
const f = data.campus.data.find(c => s.indexOf(c.shortname2) >= 0);
return f.URL;
};
const addtd = (tr, s, url) => {
const td = create("td");
if (!url) {
td.textContent = s;
} else {
const a = create("a");
a.href = url;
a.textContent = s;
td.appendChild(a);
}
tr.appendChild(td);
};
</script>