Skip to content

Commit

Permalink
Changed reading to interval_reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamFinkle committed Aug 14, 2024
1 parent b08b4e3 commit d1cfcaf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ venv/
# PyCharm
.idea/

# Mac
.DS_Store

# Distribution / packaging
build/
dist/
Expand Down
2 changes: 1 addition & 1 deletion src/greenbutton_objects/feed/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def build(self, entry_forest: EntryForest) -> "ObjectFeed":
uri=mr_node.uri,
reading_type=reading_type if reading_type else espi.ReadingType(),
intervalBlock=tuple(interval_blocks),
readings=tuple(combined_readings),
interval_readings=tuple(combined_readings),
)

for ib in reading.intervalBlock:
Expand Down
4 changes: 2 additions & 2 deletions src/greenbutton_objects/objects/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ class MeterReading:
title: str
uri: str
reading_type: espi.ReadingType
readings: Tuple[IntervalReading, ...] = field(default_factory=tuple)
interval_readings: Tuple[IntervalReading, ...] = field(default_factory=tuple)
intervalBlock: Tuple[IntervalBlock, ...] = field(default_factory=tuple)

__uom_symbol = None
__uom_description = None

def patch(self) -> None:
for r in self.readings:
for r in self.interval_readings:
r.reading_type = self.reading_type

@property
Expand Down
16 changes: 8 additions & 8 deletions tests/helpers/feed_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ def parse_feed_representation(feed: ObjectFeed) -> str:
result.append("Meter Reading (%s) %s:" % (mr.title, mr.uom_description))
result.append("\n")

for reading in mr.readings:
for interval_reading in mr.interval_readings:
result.append(
" %s, %s: %g%s"
% (
reading.start.strftime("%Y-%m-%d %H:%M:%S+00:00"),
str(timedelta(seconds=reading.time_period.duration)), # type: ignore
reading.value,
interval_reading.start.strftime("%Y-%m-%d %H:%M:%S+00:00"),
str(timedelta(seconds=interval_reading.time_period.duration)), # type: ignore
interval_reading.value,
mr.uom_symbol,
)
)
if not isnan(reading.cost):
result.append("(%s%s)" % ("$", reading.cost / 100000))
if not isnan(interval_reading.cost):
result.append("(%s%s)" % ("$", interval_reading.cost / 100000))
# TODO: Hard-coding $ for now as current code does
# not handle currency correctly
if reading.quality_of_reading != ob.QualityOfReading.MISSING:
result.append(" [%s]" % reading.quality_of_reading.name)
if interval_reading.quality_of_reading != ob.QualityOfReading.MISSING:
result.append(" [%s]" % interval_reading.quality_of_reading.name)
result.append("\n\n")

return "".join(result)
30 changes: 15 additions & 15 deletions tests/test_digested.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ def test_electric_containerized(data_dir):
assert mr.title == "Hourly Electricity Consumption"
assert "Point/1/MeterReading/0" in mr.uri
assert len(mr.intervalBlock) == 2
assert len(mr.readings) == 8
assert len(mr.interval_readings) == 8

assert mr.readings[0].value == 450
assert isnan(mr.readings[0].cost)
assert mr.readings[0].quality_of_reading == QualityOfReading.MISSING
assert mr.interval_readings[0].value == 450
assert isnan(mr.interval_readings[0].cost)
assert mr.interval_readings[0].quality_of_reading == QualityOfReading.MISSING

iblock = mr.intervalBlock[0]
assert len(iblock.readings) == 4

assert mr.readings[0].parent == iblock
assert mr.interval_readings[0].parent == iblock


def test_gas_containerized(data_dir):
Expand Down Expand Up @@ -76,17 +76,17 @@ def test_gas_containerized(data_dir):
assert mr.title == ""
assert "Point/01/MeterReading/01" in mr.uri
assert len(mr.intervalBlock) == 3
assert len(mr.readings) == 3
assert len(mr.interval_readings) == 3

# Not this is not normalized
assert mr.readings[0].value == 12.000
assert mr.readings[0].cost == 2806000
assert mr.readings[0].quality_of_reading == QualityOfReading.VALIDATED
assert mr.interval_readings[0].value == 12.000
assert mr.interval_readings[0].cost == 2806000
assert mr.interval_readings[0].quality_of_reading == QualityOfReading.VALIDATED

iblock = mr.intervalBlock[0]
assert len(iblock.readings) == 1

assert mr.readings[0].parent == iblock
assert mr.interval_readings[0].parent == iblock


def test_gas_direct(data_dir):
Expand All @@ -112,17 +112,17 @@ def test_gas_direct(data_dir):
assert mr.title == ""
assert "Point/NET_USAGE/MeterReading/1" in mr.uri
assert len(mr.intervalBlock) == 1
assert len(mr.readings) == 5
assert len(mr.interval_readings) == 5

# Not this is not normalized
assert mr.readings[0].value == 37.000
assert mr.readings[0].cost == 5100000
assert mr.readings[0].quality_of_reading == QualityOfReading.MISSING
assert mr.interval_readings[0].value == 37.000
assert mr.interval_readings[0].cost == 5100000
assert mr.interval_readings[0].quality_of_reading == QualityOfReading.MISSING

iblock = mr.intervalBlock[0]
assert len(iblock.readings) == 5

assert mr.readings[0].parent == iblock
assert mr.interval_readings[0].parent == iblock


def test_gas_direct_pb(data_dir):
Expand Down

0 comments on commit d1cfcaf

Please sign in to comment.