Skip to content

Commit

Permalink
HH Data Importer: MPAN map from and to
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Dec 5, 2024
1 parent e1e21dd commit 0d2be01
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
41 changes: 29 additions & 12 deletions chellow/e/hh_parser_df2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

from werkzeug.exceptions import BadRequest

from chellow.utils import HH, parse_mpan_core, utc_datetime
from chellow.utils import HH, hh_format, parse_mpan_core, utc_datetime


def _append_new_message(messages, message):
if len(messages) == 0 or messages[-1] != message:
messages.append(message)


def create_parser(reader, mpan_map, messages):
Expand Down Expand Up @@ -41,14 +46,6 @@ def __next__(self):
if lline.startswith("#O"):
outstation_parts = lline[2:].split("-")
self.core = parse_mpan_core(outstation_parts[0])
if self.core in self.mpan_map and self.mpan_map[self.core] is None:
msg = f"The MPAN core {self.core} has been ignored"
if len(self.messages) == 0 or self.messages[-1] != msg:
self.messages.append(
f"The MPAN core {self.core} has been ignored"
)
self.core = None
continue

elif lline.startswith("#S"):
sensor = int(lline[2:].strip())
Expand Down Expand Up @@ -87,11 +84,31 @@ def __next__(self):
raise BadRequest("Problem parsing the value: " + fields[2])
status = fields[3][-1]

if self.core is None:
continue
mpan_core = self.core
if self.core in self.mpan_map:
mapping = self.mpan_map[self.core]
from_date = mapping["from"]
to_date = mapping["to"]
if from_date <= start_date <= to_date:
mpan_core = mapping["mpan"]

if mpan_core is None:
_append_new_message(
self.messages,
f"The MPAN core {self.core} is ignored from "
f"{hh_format(from_date)} to {hh_format(to_date)}",
)
continue
else:
_append_new_message(
self.messages,
f"The MPAN core {self.core} is changed to "
f"{mpan_core} from {hh_format(from_date)} to "
f"{hh_format(to_date)}",
)

local_datum = {
"mpan_core": self.core,
"mpan_core": mpan_core,
"channel_type": self.channel_type,
"start_date": start_date,
"value": value,
Expand Down
13 changes: 11 additions & 2 deletions chellow/templates/e/dc_contract_properties_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ <h4>Example</h4>
"private_key": "private_key", /* Remove if using password */
"directories": ["downloads1", "downloads2"],
"mpan_map": { /* Optional */
"99 0993 2821 985": null, /* Ignore MPAN */
},
"99 0993 2821 985": {
"mpan": null, /* Ignore MPAN */
"from": 2024-12-04T10:00:00Z,
"to": 2025-01-12:00:00Z,
},
"99 0873 1942 952": {
"mpan": "99 7821 8541 389",
"from": 2024-11-16T22:00:00Z,
"to": 2025-02-18:00:00Z,
},
},
}
</pre>
</code>
Expand Down

0 comments on commit 0d2be01

Please sign in to comment.