Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/s07 s08 integration #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
201 changes: 200 additions & 1 deletion primestg/report/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from primestg.message import MessageS
from primestg.utils import octet2name, octet2number

SUPPORTED_REPORTS = ['S02', 'S04', 'S05', 'S06', 'S09', 'S12', 'S13', 'S14', 'S15',
SUPPORTED_REPORTS = ['S02', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09', 'S12', 'S13', 'S14', 'S15',
'S17', 'S18', 'S23', 'S24', 'S27', 'S42', 'S52']


Expand Down Expand Up @@ -226,6 +226,99 @@ def values(self):
return values


class MeasureS07(Measure):
"""
Class for a set of measures of report S07.
"""

@property
def values(self):
"""
Set of measures of report S07.

:return: a dict with a set of measures of report S02
"""
values = {}
try:
values = {
'timestamp': self._get_timestamp('Fh'),
'season': self.objectified.get('Fh')[-1:],
'dc': get_integer_value(self.objectified.get('Dc')),
'nc': get_integer_value(self.objectified.get('Nc')),
'df': get_integer_value(self.objectified.get('Df')),
'hc': self._get_timestamp('Hc')
}
except Exception as e:
self._warnings.append('ERROR: Thrown exception: {}'.format(e))
return []

return [values]


class MeasureS08(Measure):
"""
Class for a set of measures of report S08.
"""

@property
def values(self):
"""
Set of measures of report S08.

:return: a dict with a set of measures of report S08
"""
values = {}
sub = self.objectified.Sub.get
sob = self.objectified.Sob.get
corte = self.objectified.Corte.get
try:
values = {
'timestamp': self._get_timestamp('Fh'),
'season': self.objectified.get('Fh')[-1:],
'nsubtt': get_integer_value(sub('NsubTt')),
'tsubtt': get_integer_value(sub('TsubTt')),
'tsubta': get_integer_value(sub('TsubTa')),
'nsubtf1': get_integer_value(sub('NsubTf1')),
'tsubtf1': get_integer_value(sub('TsubTf1')),
'tsubtf1a': get_integer_value(sub('TsubTf1a')),
'nsubtf2': get_integer_value(sub('NsubTf2')),
'tsubtf2': get_integer_value(sub('TsubTf2')),
'tsubtf2a': get_integer_value(sub('TsubTf2a')),
'nsubtf3': get_integer_value(sub('NsubTf3')),
'tsubtf3': get_integer_value(sub('TsubTf3')),
'tsubtf3a': get_integer_value(sub('TsubTf3a')),
'nsobtt': get_integer_value(sob('NsobTt')),
'tsobtt': get_integer_value(sob('TsobTt')),
'tsobta': get_integer_value(sob('TsobTa')),
'nsobtf1': get_integer_value(sob('NsobTf1')),
'tsobtf1': get_integer_value(sob('TsobTf1')),
'tsobtf1a': get_integer_value(sob('TsobTf1a')),
'nsobtf2': get_integer_value(sob('NsobTf2')),
'tsobtf2': get_integer_value(sob('TsobTf2')),
'tsobtf2a': get_integer_value(sob('TsobTf2a')),
'nsobtf3': get_integer_value(sob('NsobTf3')),
'tsobtf3': get_integer_value(sob('TsobTf3')),
'tsobtf3a': get_integer_value(sob('TsobTf3a')),
'ncortett': get_integer_value(corte('NcorteTt')),
'tcortett': get_integer_value(corte('TcorteTt')),
'tcorteta': get_integer_value(corte('TcorteTa')),
'ncortetf1': get_integer_value(corte('NcorteTf1')),
'tcortetf1': get_integer_value(corte('TcorteTf1')),
'tcortetf1a': get_integer_value(corte('TcorteTf1a')),
'ncortetf2': get_integer_value(corte('NcorteTf2')),
'tcortetf2': get_integer_value(corte('TcorteTf2')),
'tcortetf2a': get_integer_value(corte('TcorteTf2a')),
'ncortetf3': get_integer_value(corte('NcorteTf3')),
'tcortetf3': get_integer_value(corte('TcorteTf3')),
'tcortetf3a': get_integer_value(corte('TcorteTf3a')),
}
except Exception as e:
self._warnings.append('ERROR: Thrown exception: {}'.format(e))
return []

return [values]


class MeasureS14(MeasureAverageVoltageAndCurrent):
"""
Class for a set of measures of report S14.
Expand Down Expand Up @@ -1132,6 +1225,74 @@ def measure_class(self):
return MeasureS05


class MeterS07(MeterWithMagnitude):
"""
Class for a meter of report S07.
"""

@property
def report_type(self):
"""
The type of report for report S07.

:return: a string with 'S07'
"""
return 'S07'

@property
def measure_class(self):
"""
The class used to instance measure sets for report S07.

:return: a class to instance measure sets of report S07
"""
return MeasureS07

@property
def values(self):
"""
Values of measure sets of this meter of report that need the name of \
the concentrator and the meter,

:return: a list with the values of the measure sets
"""
return super(MeterS07, self).values


class MeterS08(MeterWithMagnitude):
"""
Class for a meter of report S08.
"""

@property
def report_type(self):
"""
The type of report for report S08.

:return: a string with 'S08'
"""
return 'S08'

@property
def measure_class(self):
"""
The class used to instance measure sets for report S07.

:return: a class to instance measure sets of report S07
"""
return MeasureS08

@property
def values(self):
"""
Values of measure sets of this meter of report that need the name of \
the concentrator and the meter,

:return: a list with the values of the measure sets
"""
return super(MeterS08, self).values


class MeterS14(MeterWithConcentratorName):
"""
Class for a meter of report S14.
Expand Down Expand Up @@ -1572,6 +1733,36 @@ def meter_class(self):
return MeterS05


class ConcentratorS07(ConcentratorWithMetersWithConcentratorName):
"""
Class for a concentrator of report S07.
"""

@property
def meter_class(self):
"""
The class used to instance meters for report S07.

:return: a class to instance meters of report S07
"""
return MeterS07


class ConcentratorS08(ConcentratorWithMetersWithConcentratorName):
"""
Class for a concentrator of report S08.
"""

@property
def meter_class(self):
"""
The class used to instance meters for report S08.

:return: a class to instance meters of report S08
"""
return MeterS08


class ConcentratorS27(ConcentratorWithMetersWithConcentratorName):
"""
Class for a concentrator of report S27.
Expand Down Expand Up @@ -2199,6 +2390,14 @@ def get_concentrator(self, objectified_concentrator):
self.request_id
]
},
'S07': {
'class': ConcentratorS07,
'args': [objectified_concentrator]
},
'S08': {
'class': ConcentratorS08,
'args': [objectified_concentrator]
},
'S09': {
'class': ConcentratorS09,
'args': [objectified_concentrator]
Expand Down
16 changes: 16 additions & 0 deletions primestg/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ def get_instant_data(self, meters):
"""
return self.send('S01', meters)

def get_voltage_failure(self, meters):
"""
Asks for a S07 report to the specified meter.
:param meters: a meter_id
:return: an S07 report for the corresponding meter
"""
return self.send('S07', meters)

def get_quality_power(self, meters):
"""
Asks for a S08 report to the specified meter.
:param meters: a meter_id
:return: an S08 report for the corresponding meter
"""
return self.send('S08', meters)

def get_advanced_instant_data(self, meters):
"""
Asks for a S21 report to the specified meter.
Expand Down
41 changes: 41 additions & 0 deletions spec/Report_S07_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from expects import expect, equal
from primestg.report import Report
from ast import literal_eval


with description('Report S07 example'):
with before.all:

self.data_filenames = [
'spec/data/S07.xml',
]

self.report = []
for data_filename in self.data_filenames:
with open(data_filename) as data_file:
self.report.append(Report(data_file))

with it('generates expected results for a value of the first meter of first concentrator'):

expected_first_value_first_meter = [
dict(
timestamp='2024-01-03 00:27:19',
season='W',
dc=180,
nc=54,
df=23433,
hc='2023-12-24 11:22:41',
cnc_name='CIR4622119033',
name='SAG0155354621'
)
]

concentrator = list(self.report[0].concentrators)[0]
values = concentrator.meters[0].values

expect(values).to(equal(expected_first_value_first_meter))

with it('generates expected result for a meter with error'):
concentrator = list(self.report[0].concentrators)[0]
result = concentrator.meters[-1].values
expect(result).to(equal([]))
73 changes: 73 additions & 0 deletions spec/Report_S08_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from expects import expect, equal
from primestg.report import Report
from ast import literal_eval


with description('Report S08 example'):
with before.all:

self.data_filenames = [
'spec/data/S08.xml',
]

self.report = []
for data_filename in self.data_filenames:
with open(data_filename) as data_file:
self.report.append(Report(data_file))

with it('generates expected results for a value of the first meter of first concentrator'):

expected_first_value_first_meter = [
{
'timestamp': '2024-01-02 18:36:58',
'season': 'W',
'cnc_name': 'CIR4622119033',
'name': 'SAG0155354713',
'nsubtt': 1142,
'tsubtt': 27944,
'tsubta': 14,
'nsubtf1': 1142,
'tsubtf1': 96672,
'tsubtf1a': 0,
'nsubtf2': 0,
'tsubtf2': 0,
'tsubtf2a': 0,
'nsubtf3': 0,
'tsubtf3': 0,
'tsubtf3a': 0,
'nsobtt': 5149,
'tsobtt': 64095,
'tsobta': 4,
'nsobtf1': 5149,
'tsobtf1': 64095,
'tsobtf1a': 0,
'nsobtf2': 0,
'tsobtf2': 0,
'tsobtf2a': 0,
'nsobtf3': 0,
'tsobtf3': 0,
'tsobtf3a': 0,
'ncortett': 52,
'tcortett': 178,
'tcorteta': 0,
'ncortetf1': 0,
'tcortetf1': 0,
'tcortetf1a': 0,
'ncortetf2': 0,
'tcortetf2': 0,
'tcortetf2a': 0,
'ncortetf3': 0,
'tcortetf3': 0,
'tcortetf3a': 0,
}
]

concentrator = list(self.report[0].concentrators)[0]
values = concentrator.meters[0].values

expect(values).to(equal(expected_first_value_first_meter))

with it('generates expected result for a meter with error'):
concentrator = list(self.report[0].concentrators)[0]
result = concentrator.meters[-1].values
expect(result).to(equal([]))
13 changes: 13 additions & 0 deletions spec/data/S07.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Report IdRpt="S07" IdPet="0" Version="3.1.c">
<Cnc Id="CIR4622119033">
<Cnt Id="SAG0155354621">
<S07 Fh="20240103002719000W" Dc="180" Nc="54" Df="23433" Hc="20231224112241000W"/>
</Cnt>
<Cnt Id="SAG0155354657">
<S07 Fh="20240103002757000W" Dc="180" Nc="49" Df="11317" Hc="20231224112057000W"/>
</Cnt>
<Cnt Id="CIR0141439819" ErrCat="2" ErrCode="0"/>
<Cnt Id="SAG0155354669" ErrCat="2" ErrCode="1"/>
<Cnt Id="SAG0176451808" ErrCat="2" ErrCode="1"/>
</Cnc>
</Report>
Loading
Loading