-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathomie_dataset.js
36 lines (29 loc) · 1.1 KB
/
omie_dataset.js
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
import { writeJSON } from 'https://deno.land/x/[email protected]/src/json.ts'
import { readTXT } from 'https://deno.land/x/[email protected]/src/txt.ts'
const json_all_prices_yesterday = await readTXT('public/data/omie_prices.json');
let json_all_prices_replace = json_all_prices_yesterday.replaceAll(';', ',')
json_all_prices_replace = json_all_prices_replace.replace('MARGINALPDBC,', 'year;month;day;hour;pricemax;pricemin;')
/*https://stackoverflow.com/a/61474145*/
const parseCsv = csv => {
let lines = csv.split("\n");
const header = lines.shift().split(";")
return lines.map(line => {
const bits = line.split(",")
let obj = {};
header.forEach((h, i) => obj[h] = bits[i]);
return obj;
})
};
const prices_csv_to_json = parseCsv(json_all_prices_replace)
let omie_data = prices_csv_to_json.map(({ year, month, day, hour, pricemax, pricemin }) => {
return {
year: year,
month: month,
day: day,
hour: (+(hour) - 1),
price: (pricemax / 1000),
pricemin: (pricemin / 1000)
};
});
omie_data = omie_data.filter(({ year }) => year);
await writeJSON('public/data/omie_data.json', omie_data)