From 5285c2ce4e4c2b11141165963081659e5de3f461 Mon Sep 17 00:00:00 2001 From: davidmunoznovoa Date: Tue, 8 Oct 2024 10:32:53 +0200 Subject: [PATCH 1/2] Convert magns into floats --- cchloader/adapters/corbagen.py | 2 +- cchloader/models/corbagen.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cchloader/adapters/corbagen.py b/cchloader/adapters/corbagen.py index 9e46866..bac0ba5 100644 --- a/cchloader/adapters/corbagen.py +++ b/cchloader/adapters/corbagen.py @@ -13,7 +13,7 @@ class CorbaGenBaseAdapter(Schema): @pre_load def fix_numbers(self, data): for attr, field in self.fields.items(): - if isinstance(field, fields.Integer): + if isinstance(field, (fields.Integer, fields.Float)): if not data.get(attr): data[attr] = None return data diff --git a/cchloader/models/corbagen.py b/cchloader/models/corbagen.py index b7ac8d2..38b8ad6 100644 --- a/cchloader/models/corbagen.py +++ b/cchloader/models/corbagen.py @@ -9,8 +9,8 @@ class CorbaGenSchema(Schema): name = fields.String(position=0, required=True) local_timestamp = fields.DateTime(position=1, format='%Y-%m-%d %H:%M', required=True) season = fields.Integer(position=2, validate=OneOf([0, 1]), required=True) - generacio = fields.Integer(position=3, required=True) - autocons = fields.Integer(position=4, required=True) - excedent = fields.Integer(position=5, required=True) + generacio = fields.Float(position=3, required=True) + autocons = fields.Float(position=4, required=True) + excedent = fields.Float(position=5, required=True) CorbaGenSchema() From a68ea5b36ad377559ae84b764aa0f5f24842277e Mon Sep 17 00:00:00 2001 From: davidmunoznovoa Date: Tue, 8 Oct 2024 10:42:44 +0200 Subject: [PATCH 2/2] Addapt tests --- spec/curve_files/CORBAGEN_202403.0 | 48 +++++++++++++++--------------- spec/test_parsers_spec.py | 10 +++++-- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/spec/curve_files/CORBAGEN_202403.0 b/spec/curve_files/CORBAGEN_202403.0 index d596bb4..d784d9f 100644 --- a/spec/curve_files/CORBAGEN_202403.0 +++ b/spec/curve_files/CORBAGEN_202403.0 @@ -1,24 +1,24 @@ -ES1234000000000001JN0F001;2024-03-01 01:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 02:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 03:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 04:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 05:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 06:00;0;40;0;40; -ES1234000000000001JN0F001;2024-03-01 07:00;0;80;0;80; -ES1234000000000001JN0F001;2024-03-01 08:00;0;100;40;60; -ES1234000000000001JN0F001;2024-03-01 09:00;0;100;40;60; -ES1234000000000001JN0F001;2024-03-01 10:00;0;150;40;110; -ES1234000000000001JN0F001;2024-03-01 11:00;0;150;40;110; -ES1234000000000001JN0F001;2024-03-01 12:00;0;200;40;160; -ES1234000000000001JN0F001;2024-03-01 13:00;0;200;40;160; -ES1234000000000001JN0F001;2024-03-01 14:00;0;150;40;110; -ES1234000000000001JN0F001;2024-03-01 15:00;0;150;40;110; -ES1234000000000001JN0F001;2024-03-01 16:00;0;100;40;60; -ES1234000000000001JN0F001;2024-03-01 17:00;0;100;40;60; -ES1234000000000001JN0F001;2024-03-01 18:00;0;80;40;40; -ES1234000000000001JN0F001;2024-03-01 19:00;0;40;40;0; -ES1234000000000001JN0F001;2024-03-01 20:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 21:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 22:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-01 23:00;0;0;0;0; -ES1234000000000001JN0F001;2024-03-02 00:00;0;0;0;0; +ES1234000000000001JN0F001;2024-03-01 01:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 02:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 03:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 04:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 05:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 06:00;0;40.4;0;40.4; +ES1234000000000001JN0F001;2024-03-01 07:00;0;80.534;0;80.534; +ES1234000000000001JN0F001;2024-03-01 08:00;0;100.0;40.0;60.0; +ES1234000000000001JN0F001;2024-03-01 09:00;0;100.0;40.0;60.0; +ES1234000000000001JN0F001;2024-03-01 10:00;0;150.0;40.0;110.0; +ES1234000000000001JN0F001;2024-03-01 11:00;0;150.0;40.0;110.0; +ES1234000000000001JN0F001;2024-03-01 12:00;0;200.0;40.0;160.0; +ES1234000000000001JN0F001;2024-03-01 13:00;0;200.0;40.0;160.0; +ES1234000000000001JN0F001;2024-03-01 14:00;0;150.0;40.0;110.0; +ES1234000000000001JN0F001;2024-03-01 15:00;0;150.0;40.0;110.0; +ES1234000000000001JN0F001;2024-03-01 16:00;0;100.0;40.0;60.0; +ES1234000000000001JN0F001;2024-03-01 17:00;0;100.0;40.0;60.0; +ES1234000000000001JN0F001;2024-03-01 18:00;0;80.0;40.0;40.0; +ES1234000000000001JN0F001;2024-03-01 19:00;0;40.0;40.0;0.0; +ES1234000000000001JN0F001;2024-03-01 20:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 21:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 22:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-01 23:00;0;0.0;0.0;0.0; +ES1234000000000001JN0F001;2024-03-02 00:00;0;0.0;0.0;0.0; diff --git a/spec/test_parsers_spec.py b/spec/test_parsers_spec.py index 9eb395b..a162801 100644 --- a/spec/test_parsers_spec.py +++ b/spec/test_parsers_spec.py @@ -172,11 +172,15 @@ expect(get_parser(filename)).to(equal(CorbaGen)) with it('CORBAGEN parser fits file format'): with CchFile('spec/curve_files/CORBAGEN_202403.0') as cch_file: + line_number = 0 for line in cch_file: - expected_corbagen = 'ES1234000000000001JN0F001;2024-03-01 01:00;0;0;0;0;\n' + expected_corbagen = 'ES1234000000000001JN0F001;2024-03-01 07:00;0;80.534;0;80.534;\n' result_corbagen = line['orig'] - assert result_corbagen == expected_corbagen - break + if line_number == 6: + assert result_corbagen == expected_corbagen + break + line_number += 1 + assert line_number == 6 with it('test to get INFPA parser'): for filename in self.infpa_filenames: