Skip to content

Commit b01e8bf

Browse files
authored
Handle code change for Videbæk (#114)
1 parent 98312cd commit b01e8bf

7 files changed

Lines changed: 85 additions & 32 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ updates:
55
schedule:
66
interval: weekly
77
- package-ecosystem: docker
8-
directory: /
8+
directory: /docker
99
schedule:
1010
interval: weekly

Makefile

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ test-dependabot:
1616
$(COMPOSE_RUN) runner check-jsonschema --builtin-schema dependabot .github/dependabot.yml
1717

1818
test-docker:
19-
$(COMPOSE_RUN) dockerlint Dockerfile
19+
$(COMPOSE_RUN) dockerlint docker/builder.Dockerfile
20+
$(COMPOSE_RUN) dockerlint docker/runner.Dockerfile
2021
docker compose config -q
2122

2223
test-editorcheck:
@@ -54,6 +55,42 @@ _unit-tests:
5455
swagger: ## Runs a local swagger
5556
docker compose up swagger
5657

58+
build:
59+
$(COMPOSE_RUN) builder make _build
60+
61+
_build:
62+
mkdir build
63+
echo '*' > build/.gitignore
64+
curl --fail --output build/datahub-prices.json "https://api.energidataservice.dk/dataset/DatahubPricelist/download?format=json&limit=0"
65+
jq 'group_by(.GLN_Number) | map({gln: .[0].GLN_Number, name:.[0].ChargeOwner}) | unique' < build/datahub-prices.json > build/gln-names.json
66+
67+
find-charge: build | guard-id ## Looks up charge type codes for a given id
68+
$(COMPOSE_RUN) runner make id=$(id) _find-charge
69+
70+
_find-charge:
71+
jq -r --arg id "$(id)" '.[] | select(.GLN_Number == $$id) |select(.ChargeType == "D03") | {uniq: "\(.ChargeTypeCode) / \(.Note)"}' < build/datahub-prices.json | grep '^ '| sort -u
72+
73+
find-charge-verbose: build | guard-id ## Looks up charge type codes for a given id, but with more data
74+
$(COMPOSE_RUN) runner make id=$(id) _find-charge-verbose
75+
76+
_find-charge-verbose:
77+
jq -r --arg id "$(id)" '[.[] | select(.GLN_Number == $$id) |select(.ChargeType == "D03")] | map(.from = (.ValidFrom + "Z"|fromdateiso8601) | .ValidTo = if .ValidTo == null or (.ValidTo|type) == "object" then null else .ValidTo end) | group_by(.ChargeTypeCode) | map(max_by(.from))[] | {item: "\(.ChargeTypeCode) / \(.Note) / \(.ValidFrom) / \(.ValidTo)"}' < build/datahub-prices.json| grep '^ '|cut -d\: -f2- | sort -u
78+
79+
view-glns: build ## View company names and their GLN numbers
80+
$(COMPOSE_RUN) runner cat build/gln-names.json
81+
82+
view-prices: build | guard-id guard-code ## View prices for a given id and code
83+
$(COMPOSE_RUN) runner make id=$(id) code=$(code) _view-prices
84+
85+
_view-prices:
86+
jq -r --arg id "$(id)" --arg code "$(code)" '[.[] | select(.GLN_Number == $$id) |select(.ChargeType == "D03")| select(.ChargeTypeCode == $$code)]' < build/datahub-prices.json
87+
88+
guard-%:
89+
@if [ "${${*}}" = "" ]; then \
90+
echo "Environment variable $* not set"; \
91+
exit 1; \
92+
fi
93+
5794
help: ## Display this help
5895
@$(COMPOSE_RUN) runner make _help
5996
_help:
@@ -62,5 +99,10 @@ _help:
6299
shell: ## Enters a shell on the runner
63100
@$(COMPOSE_RUN) runner sh
64101

65-
clean: ## Clears docker to trigger re-pulling and re-build images
66-
docker compose down --rmi all --remove-orphans
102+
clean: ## Clears data and docker to trigger re-pulling and re-build images
103+
@$(COMPOSE_RUN) builder make _clean
104+
docker compose down --rmi all --remove-orphans
105+
106+
_clean:
107+
@-rm -rf build.backup
108+
mv build build.backup

compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
services:
2+
builder:
3+
build:
4+
context: .
5+
dockerfile: docker/builder.Dockerfile
6+
volumes:
7+
- .:/workspace
8+
working_dir: /workspace
29
runner:
310
build:
411
context: .
5-
dockerfile: Dockerfile
12+
dockerfile: docker/runner.Dockerfile
613
volumes:
714
- .:/workspace:ro
815
working_dir: /workspace

configuration/networks.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@
110110
"codes": [
111111
{
112112
"from": 0,
113-
"to": null,
113+
"to": 1735686000,
114114
"code": "VE-NT-01"
115+
},
116+
{
117+
"from": 1735686000,
118+
"to": null,
119+
"code": "VE-VN-01"
115120
}
116121
]
117122
},

docker/builder.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:3.21
2+
3+
RUN apk add --no-cache -q jq make curl
File renamed without changes.

documentation/resolving-datahub-prices.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
# Resolving Datahub Prices
1+
# Resolving DataHub Prices
22

3-
_Datahub contains only prices for Denmark and this document is scoped only for Denmark for that reason._
3+
_DataHub contains only prices for Denmark and this document is scoped only for Denmark for that reason._
44

55
## Prerequisites
66

77
### A list of network areas
88

99
The currently best known source for this is [this map](https://ens.dk/sites/ens.dk/files/Statistik/elnetgraenser_2023_04.pdf). There must be a better source...
1010

11-
### The tool `jq`
11+
### Software
1212

13-
[`jq`](https://jqlang.github.io/jq/) is json manipulation tool - you will find all tools are present in the [`devcontainer`](https://containers.dev) for this repo.
14-
15-
### A local copy of price data
16-
17-
We will prepare two files using these two commands:
18-
19-
```sh
20-
curl -v "https://api.energidataservice.dk/dataset/DatahubPricelist/download?format=json&limit=0" > list.json
21-
```
22-
23-
```sh
24-
jq 'group_by(.GLN_Number) | map({gln: .[0].GLN_Number, name:.[0].ChargeOwner}) | unique' < list.json > gln-names.json
25-
```
13+
- `make`
14+
- `docker`
2615

2716
## Searching data
2817

@@ -40,7 +29,13 @@ The company name ("Zero Power") must be used to search online for an actual pric
4029

4130
### Look up GLN
4231

43-
The prepared file `gls-names.json` should contain the name of the company and its GLN number, for instance:
32+
You can view the names of the companies and theirs GLN numbers by running:
33+
34+
```sh
35+
make view-glns
36+
```
37+
38+
The output should view the following example:
4439

4540
```jsonc
4641
// ...
@@ -53,16 +48,11 @@ The prepared file `gls-names.json` should contain the name of the company and it
5348

5449
### Look up available `ChargeTypeCode`
5550

56-
We can list available `ChargeTypeCode` with some description using the following command:
51+
We can list available `ChargeTypeCode` with some description using the following commands:
5752

5853
```sh
59-
jq -r '.[] | select(.GLN_Number == "5790000000000") |select(.ChargeType == "D03") | {uniq: "\(.ChargeTypeCode) / \(.Note)"}' < list.json | grep '^ '| sort -u
60-
```
61-
62-
Or attempt to list relevant `ChargeTypeCode` based on dates using the following command:
63-
64-
```sh
65-
jq -r '[.[] | select(.GLN_Number == "5790000000000") |select(.ChargeType == "D03")] | map(.from = (.ValidFrom + "Z"|fromdateiso8601) | .ValidTo = if .ValidTo == null or (.ValidTo|type) == "object" then null else .ValidTo end) | group_by(.ChargeTypeCode) | map(max_by(.from))[] | {item: "\(.ChargeTypeCode) / \(.Note) / \(.ValidFrom) / \(.ValidTo)"}' < list.json| grep '^ '|cut -d\: -f2- | sort -u
54+
make id=5790000000000 find-charge
55+
make id=5790000000000 find-charge-verbose # for additional data
6656
```
6757

6858
_Note that must replace 5790000000000 with the actual GLN number_.
@@ -105,6 +95,12 @@ The expected output will vary a lot, but here is an example:
10595
"uniq": "8070 / Nettarif indfødning A høj"
10696
```
10797

98+
The verbose output will include date ranges for the codes, like so:
99+
```text
100+
"8040 / Nettarif indfødning B høj / 2015-10-01T00:00:00 / 2015-10-03T00:00:00"
101+
"8070 / Nettarif indfødning A høj / 2025-02-01T00:00:00 / null"
102+
```
103+
108104
### Find class `C` `ChargeTypeCode`
109105

110106
One thing to note is that the `ChargeTypeCode` can be the same for multiple "notes".
@@ -123,7 +119,7 @@ At this point we have:
123119

124120
With these items we can execute a command to view the prices:
125121
```sh
126-
jq -r '[.[] | select(.GLN_Number == "5790000000000") |select(.ChargeType == "D03")| select(.ChargeTypeCode == "4000")]' < list.json|less
122+
make id=5790000000000 code=4000 view-prices |less
127123
```
128124

129125
_Note you can exit less by typing 'q'_.

0 commit comments

Comments
 (0)