Skip to content

Commit

Permalink
Merge pull request #43 from Som-Energia/IMP_query_velocity
Browse files Browse the repository at this point in the history
Imp query velocity
  • Loading branch information
JoanaFigueira authored Apr 20, 2022
2 parents b130d96 + 1c776db commit d7c330d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion infoenergia_api/api/cch/cch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def get(self, request, contractId, user):
if collection in ('P1', 'P2'):
collection = 'tg_p1'
cch_measure_json = [
await (await Cch.create(cch_id, collection)).cch_measures(user, request) for cch_id in cch_ids
await (await Cch.create(cch_id, collection)).cch_measures(user, request, contractId) for cch_id in cch_ids
]

response = {
Expand Down
21 changes: 16 additions & 5 deletions infoenergia_api/contrib/cch.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,28 @@ def measurements(self):
'dateUpdate': (self.update_at).strftime("%Y-%m-%d %H:%M:%S"),
}

async def cch_measures(self, user, request):
contractId = await request.app.loop.run_in_executor(
self._executor, get_contract_id, self._erp, self.name, user
)
async def cch_measures(self, user, request, contractId=None):
if contractId:
return {
'contractId': contractId,
'meteringPointId': make_uuid('giscedata.cups.ps', self.name),
'measurements': self.measurements
}
return {}
else:
contractId = await request.app.loop.run_in_executor(
self._executor,
get_contract_id,
self._erp,
self.name,
user,
)
if contractId:
return {
'contractId': contractId,
'meteringPointId': make_uuid('giscedata.cups.ps', self.name),
'measurements': self.measurements
}
return {}


async def async_get_cch(request, contractId=None):
Expand Down
7 changes: 6 additions & 1 deletion infoenergia_api/contrib/f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ def f1_maximeter(self):
'maxPower': 4.95,
'period': '2.0TD (P2)'
"""

maximeter_obj=self._erp.model('giscedata.f1.maximetre.consumidor')
maximeters = maximeter_obj.read(self.maximetre_consumidor_ids) or []
maximeters = maximeter_obj.read([
('polissa_id', '=', self.polissa_id[0]),
('data_final', '<=', self.data_final),
('data_final', '>=', self.data_inici)
]) or []

return[{
'dateStart':maximeter['data_inici'],
Expand Down
6 changes: 4 additions & 2 deletions infoenergia_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ def get_contract_id(erp_client, cups, user):
('active', '=', True),
('state', '=', 'activa'),
('emp_allow_send_data', '=', True),
('cups', 'ilike', cups[:20])
('cups.name', '=', cups)
]
filters = get_contract_user_filters(erp_client, user, filters)
contract = contract_obj.search(filters)

if not contract:
filters += [('cups.name', 'ilike', cups[:20])]
contract = contract_obj.search(filters)
if contract:
return contract_obj.read(contract, ['name'])[0]['name']
14 changes: 7 additions & 7 deletions tests/test_f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test__get_f1_measures_by_contract_id(self, get_invoices_mock):
token = self.get_auth_token(user.username, "123412345")

request, response = self.client.get(
'/f1/{}?limit=1'.format(self.json4test['invoices_f1_by_contract_id']['contractId']),
'/f1/{}'.format(self.json4test['invoices_f1_by_contract_id']['contractId']),
headers={
'Authorization': 'Bearer {}'.format(token)
},
Expand Down Expand Up @@ -387,15 +387,15 @@ def test__f1_maximeter(self):
self.assertListEqual(f1_maximeter, [
{
'dateStart':'2021-06-01',
'dateEnd':'2021-09-10',
'maxPower':4.956,
'period':'2.0TD (P2)'
'dateEnd':'2021-09-09',
'maxPower':4.352,
'period':'2.0TD (P1)'
},
{
'dateStart':'2021-06-01',
'dateEnd':'2021-09-11',
'maxPower':2.632,
'period':'2.0TD (P1)'
'dateEnd':'2021-09-09',
'maxPower':2.5,
'period':'2.0TD (P2)'
},
]
)
Expand Down

0 comments on commit d7c330d

Please sign in to comment.