Skip to content
Merged
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
15 changes: 13 additions & 2 deletions db_eplusout_reader/processing/esofile_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Parse the header and body of an EnergyPlus .eso file into raw output data."""

import logging
import re
from collections import defaultdict, namedtuple
from datetime import datetime
Expand All @@ -14,6 +15,8 @@
from db_eplusout_reader.processing.esofile_time import EsoTimestamp
from db_eplusout_reader.processing.raw_eso_data import RawOutputData

logger = logging.getLogger(__name__)

ENVIRONMENT_LINE = 1
TIMESTEP_OR_HOURLY_LINE = 2
DAILY_LINE = 3
Expand Down Expand Up @@ -308,8 +311,16 @@ def read_body(eso_file, highest_frequency_id, header, all_ids):
)
else:
# current line represents a result, replace nan values from the last step
res = float(line[0])
raw_outputs.outputs[frequency][line_id][-1] = res
slots = raw_outputs.outputs.get(frequency, {})
if line_id in slots:
slots[line_id][-1] = float(line[0])
else:
# id not declared for this frequency, see issue #39
logger.debug(
"Skipping result line with undeclared id %s (%s).",
line_id,
frequency,
)

except ValueError:
if "End of Data" in raw_line:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_esofile_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,31 @@ def test_duplicate_variable_with_and_without_schedule(self, tmp_path):
outputs = result[0].outputs["hourly"]
assert outputs[275] == [21.0]
assert outputs[276] == [22.0]


class TestUndeclaredReportId:
"""Result lines whose id has no slot for the current frequency (issue #39)."""

def test_unknown_id_is_skipped(self, tmp_path):
eso = tmp_path / "unknown_id.eso"
body = _VALID_BODY.replace("7,20.0\n", "7,20.0\n99999,42.0\n")
eso.write_text(_HEADER + body)
result = process_eso_file(str(eso))
assert result[0].outputs["hourly"][7] == [20.0]
assert 99999 not in result[0].outputs["hourly"]

def test_id_declared_for_another_frequency_is_skipped(self, tmp_path):
# Id 7 is declared hourly; a copy of it after a daily step has no slot.
eso = tmp_path / "wrong_frequency.eso"
header = _HEADER + (
"8,7,Environment,Site Day Type Index [] !Daily "
"[Value,Min,Hour,Minute,Max,Hour,Minute]\n"
)
body = _VALID_BODY.replace(
"7,20.0\n",
"7,20.0\n3,1, 1, 1, 0,Tuesday\n8,3.0,3.0,1,60,3.0,1,60\n7,99.0\n",
)
eso.write_text(header + body)
result = process_eso_file(str(eso))
assert result[0].outputs["hourly"][7] == [20.0]
assert result[0].outputs["daily"][8] == [3.0]
Loading