Skip to content

Commit

Permalink
Control endesa MEDIDAS format
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmunoznovoa committed Mar 19, 2024
1 parent b8f7cfc commit 30a9a7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
11 changes: 11 additions & 0 deletions cchloader/adapters/medidas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def fix_r2(self, data):
def fix_r3(self, data):
data['r3'] = data.get('r3', 0)

@pre_load
def fix_factor_potencia(self, data):
factor_potencia = data.get('factor_potencia', 0.0)
if ',' in factor_potencia:
factor_potencia = factor_potencia.replace(',', '.')
data['factor_potencia'] = factor_potencia

@pre_load
def fix_tipo_factor_potencia(self, data):
data['tipo_factor_potencia'] = data.get('tipo_factor_potencia', 0)

@pre_load
def fix_season(self, data):
valid_values = [0, 1]
Expand Down
19 changes: 8 additions & 11 deletions cchloader/models/medidas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@

class MedidasSchema(Schema):
cil = fields.String(position=0, required=True)
year = fields.Integer(position=1, required=True)
month = fields.Integer(position=2, required=True)
day = fields.Integer(position=3, required=True)
hour = fields.Integer(position=4, required=True)
season = fields.Integer(position=5, validate=OneOf([0, 1]))
ae = fields.Integer(position=6, allow_none=True)
r2 = fields.Integer(position=7, allow_none=True)
r3 = fields.Integer(position=8, allow_none=True)
factor_potencia = fields.Float(position=8, allow_none=True)
tipo_factor_potencia = fields.Integer(position=9, allow_none=True)
tipo_lectura = fields.String(position=9, validate=OneOf(['R', 'E']))
datetime = fields.DateTime(position=1, format='%Y/%m/%d %H:%M:%S')
season = fields.Integer(position=2, validate=OneOf([0, 1]))
ae = fields.Integer(position=3, allow_none=True)
r2 = fields.Integer(position=4, allow_none=True)
r3 = fields.Integer(position=5, allow_none=True)
factor_potencia = fields.Float(position=6, allow_none=True)
tipo_factor_potencia = fields.Integer(position=7, allow_none=True)
tipo_lectura = fields.String(position=8, validate=OneOf(['R', 'E']))


MedidasSchema()

0 comments on commit 30a9a7c

Please sign in to comment.