e-data 1.2.10__tar.gz → 1.2.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {e-data-1.2.10/e_data.egg-info → e-data-1.2.12}/PKG-INFO +1 -1
  2. {e-data-1.2.10 → e-data-1.2.12/e_data.egg-info}/PKG-INFO +1 -1
  3. {e-data-1.2.10 → e-data-1.2.12}/edata/definitions.py +18 -6
  4. {e-data-1.2.10 → e-data-1.2.12}/edata/helpers.py +13 -8
  5. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/base.py +4 -4
  6. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/billing.py +9 -15
  7. {e-data-1.2.10 → e-data-1.2.12}/setup.py +1 -1
  8. {e-data-1.2.10 → e-data-1.2.12}/LICENSE +0 -0
  9. {e-data-1.2.10 → e-data-1.2.12}/MANIFEST.in +0 -0
  10. {e-data-1.2.10 → e-data-1.2.12}/README.md +0 -0
  11. {e-data-1.2.10 → e-data-1.2.12}/e_data.egg-info/SOURCES.txt +0 -0
  12. {e-data-1.2.10 → e-data-1.2.12}/e_data.egg-info/dependency_links.txt +0 -0
  13. {e-data-1.2.10 → e-data-1.2.12}/e_data.egg-info/requires.txt +0 -0
  14. {e-data-1.2.10 → e-data-1.2.12}/e_data.egg-info/top_level.txt +0 -0
  15. {e-data-1.2.10 → e-data-1.2.12}/edata/__init__.py +0 -0
  16. {e-data-1.2.10 → e-data-1.2.12}/edata/connectors/__init__.py +0 -0
  17. {e-data-1.2.10 → e-data-1.2.12}/edata/connectors/datadis.py +0 -0
  18. {e-data-1.2.10 → e-data-1.2.12}/edata/connectors/redata.py +0 -0
  19. {e-data-1.2.10 → e-data-1.2.12}/edata/const.py +0 -0
  20. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/__init__.py +0 -0
  21. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/consumption.py +0 -0
  22. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/maximeter.py +0 -0
  23. {e-data-1.2.10 → e-data-1.2.12}/edata/processors/utils.py +0 -0
  24. {e-data-1.2.10 → e-data-1.2.12}/edata/storage.py +0 -0
  25. {e-data-1.2.10 → e-data-1.2.12}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: e-data
3
- Version: 1.2.10
3
+ Version: 1.2.12
4
4
  Summary: Python library for managing spanish energy data from various web providers
5
5
  Home-page: https://github.com/uvejota/python-edata
6
6
  Author: VMG
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: e-data
3
- Version: 1.2.10
3
+ Version: 1.2.12
4
4
  Summary: Python library for managing spanish energy data from various web providers
5
5
  Home-page: https://github.com/uvejota/python-edata
6
6
  Author: VMG
@@ -2,8 +2,7 @@
2
2
 
3
3
  import voluptuous as vol
4
4
  import datetime as dt
5
- from collections.abc import Iterable
6
- from typing import TypedDict, _TypedDictMeta
5
+ from typing import TypedDict
7
6
 
8
7
  ATTRIBUTES = {
9
8
  "cups": None,
@@ -56,12 +55,24 @@ ATTRIBUTES = {
56
55
  "max_power_90perc_kW": "kW",
57
56
  }
58
57
 
59
-
58
+ # Energy term with taxes
60
59
  DEFAULT_BILLING_ENERGY_FORMULA = "electricity_tax * iva_tax * kwh_eur * kwh"
60
+
61
+ # Power term with taxes
61
62
  DEFAULT_BILLING_POWER_FORMULA = "electricity_tax * iva_tax * (p1_kw * (p1_kw_year_eur + market_kw_year_eur) + p2_kw * p2_kw_year_eur) / 365 / 24"
63
+
64
+ # Others term with taxes
62
65
  DEFAULT_BILLING_OTHERS_FORMULA = "iva_tax * meter_month_eur / 30 / 24"
66
+
67
+ # Surplus term with taxes
63
68
  DEFAULT_BILLING_SURPLUS_FORMULA = (
64
- "electricity_tax * iva_tax * [surplus_kwh, kwh]|min * surplus_kwh_eur"
69
+ "electricity_tax * iva_tax * surplus_kwh * surplus_kwh_eur"
70
+ )
71
+
72
+ # Sum energy and power terms, and substract surplus until 0.
73
+ # An alternative would be "[(energy_term + power_term - surplus_term), 0]|max + others_term"
74
+ DEFAULT_BILLING_MAIN_FORMULA = (
75
+ "[(energy_term - surplus_term), 0]|max + power_term + others_term"
65
76
  )
66
77
 
67
78
 
@@ -113,8 +124,8 @@ ContractSchema = vol.Schema(
113
124
  vol.Required("date_end"): dt.datetime,
114
125
  vol.Required("marketer"): str,
115
126
  vol.Required("distributorCode"): str,
116
- vol.Required("power_p1"): vol.Union(float, None),
117
- vol.Required("power_p2"): vol.Union(float, None),
127
+ vol.Required("power_p1"): vol.Union(vol.Coerce(float), None),
128
+ vol.Required("power_p2"): vol.Union(vol.Coerce(float), None),
118
129
  }
119
130
  )
120
131
 
@@ -218,6 +229,7 @@ PricingRulesSchema = vol.Schema(
218
229
  vol.Optional("power_formula", default=DEFAULT_BILLING_POWER_FORMULA): str,
219
230
  vol.Optional("others_formula", default=DEFAULT_BILLING_OTHERS_FORMULA): str,
220
231
  vol.Optional("surplus_formula", default=DEFAULT_BILLING_SURPLUS_FORMULA): str,
232
+ vol.Optional("main_formula", default=DEFAULT_BILLING_MAIN_FORMULA): str,
221
233
  vol.Optional("cycle_start_day", default=1): vol.Range(1, 30),
222
234
  }
223
235
  )
@@ -58,6 +58,7 @@ class EdataHelper:
58
58
  self._date_from = datetime(1970, 1, 1)
59
59
  self._date_to = datetime.today()
60
60
  self._must_dump = True
61
+ self._incremental_update = True
61
62
 
62
63
  if data is not None:
63
64
  data = check_storage_integrity(data)
@@ -107,10 +108,12 @@ class EdataHelper:
107
108
  self,
108
109
  date_from: datetime = datetime(1970, 1, 1),
109
110
  date_to: datetime = datetime.today(),
111
+ incremental_update: bool = True,
110
112
  ):
111
113
  """Synchronous update."""
112
114
  self._date_from = date_from
113
115
  self._date_to = date_to
116
+ self._incremental_update = incremental_update
114
117
 
115
118
  # update datadis resources
116
119
  self.update_datadis(self._cups, date_from, date_to)
@@ -423,10 +426,12 @@ class EdataHelper:
423
426
  def process_consumptions(self):
424
427
  """Process consumptions data."""
425
428
  if len(self.data["consumptions"]) > 0:
426
- try:
427
- new_data_from = self.data["consumptions_monthly_sum"][-1]["datetime"]
428
- except Exception:
429
- new_data_from = self._date_from
429
+ new_data_from = self._date_from
430
+ if self._incremental_update:
431
+ with contextlib.suppress(Exception):
432
+ new_data_from = self.data["consumptions_monthly_sum"][-1][
433
+ "datetime"
434
+ ]
430
435
 
431
436
  proc = ConsumptionProcessor(
432
437
  {
@@ -624,10 +629,10 @@ class EdataHelper:
624
629
  def process_cost(self):
625
630
  """Process costs."""
626
631
  if self.enable_billing:
627
- try:
628
- new_data_from = self.data["cost_monthly_sum"][-1]["datetime"]
629
- except Exception:
630
- new_data_from = self._date_from
632
+ new_data_from = self._date_from
633
+ if self._incremental_update:
634
+ with contextlib.suppress(Exception):
635
+ new_data_from = self.data["cost_monthly_sum"][-1]["datetime"]
631
636
 
632
637
  proc = BillingProcessor(
633
638
  BillingInput(
@@ -1,4 +1,4 @@
1
- """Base definitions for processors"""
1
+ """Base definitions for processors."""
2
2
 
3
3
  from abc import ABC, abstractmethod
4
4
  from copy import deepcopy
@@ -6,11 +6,11 @@ from typing import Any
6
6
 
7
7
 
8
8
  class Processor(ABC):
9
- """A base class for data processors"""
9
+ """A base class for data processors."""
10
10
 
11
11
  _LABEL = "Processor"
12
12
 
13
- def __init__(self, input_data: Any, auto: bool = True):
13
+ def __init__(self, input_data: Any, auto: bool = True) -> None:
14
14
  """Init method."""
15
15
  self._input = deepcopy(input_data)
16
16
  self._output = None
@@ -19,7 +19,7 @@ class Processor(ABC):
19
19
 
20
20
  @abstractmethod
21
21
  def do_process(self):
22
- """The processing method."""
22
+ """Process method."""
23
23
 
24
24
  @property
25
25
  def output(self):
@@ -1,10 +1,11 @@
1
1
  """Billing data processors."""
2
2
 
3
- import logging
3
+ import contextlib
4
4
  from datetime import datetime, timedelta
5
+ import logging
5
6
  from typing import Optional, TypedDict
6
- from jinja2 import Environment
7
7
 
8
+ from jinja2 import Environment
8
9
  import voluptuous
9
10
 
10
11
  from ..definitions import (
@@ -20,7 +21,6 @@ from ..definitions import (
20
21
  )
21
22
  from ..processors import utils
22
23
  from ..processors.base import Processor
23
- import contextlib
24
24
 
25
25
  _LOGGER = logging.getLogger(__name__)
26
26
 
@@ -46,7 +46,7 @@ class BillingProcessor(Processor):
46
46
  """A billing processor for edata."""
47
47
 
48
48
  def do_process(self):
49
- """Main method for the BillingProcessor."""
49
+ """Process billing and get hourly/daily/monthly metrics."""
50
50
  self._output = BillingOutput(hourly=[], daily=[], monthly=[])
51
51
 
52
52
  _schema = voluptuous.Schema(
@@ -103,6 +103,9 @@ class BillingProcessor(Processor):
103
103
  surplus_expr = env.compile_expression(
104
104
  f'({self._input["rules"]["surplus_formula"]})|float|round(3)'
105
105
  )
106
+ main_expr = env.compile_expression(
107
+ f'({self._input["rules"]["main_formula"]})|float|round(3)'
108
+ )
106
109
 
107
110
  _data = sorted([_data[x] for x in _data], key=lambda x: x["datetime"])
108
111
  hourly = []
@@ -147,15 +150,6 @@ class BillingProcessor(Processor):
147
150
  value_eur=0,
148
151
  delta_h=1,
149
152
  )
150
-
151
- new_item["value_eur"] = round(
152
- new_item["energy_term"]
153
- + new_item["power_term"]
154
- + new_item["others_term"]
155
- - new_item["surplus_term"],
156
- 3,
157
- )
158
-
159
153
  hourly.append(new_item)
160
154
 
161
155
  self._output["hourly"] = hourly
@@ -186,8 +180,8 @@ class BillingProcessor(Processor):
186
180
  self._output["daily"][-1]["power_term"] += hour["power_term"]
187
181
  self._output["daily"][-1]["others_term"] += hour["others_term"]
188
182
  self._output["daily"][-1]["surplus_term"] += hour["surplus_term"]
189
- self._output["daily"][-1]["value_eur"] += hour["value_eur"]
190
183
  self._output["daily"][-1]["delta_h"] += hour["delta_h"]
184
+ self._output["daily"][-1]["value_eur"] += hour["value_eur"]
191
185
 
192
186
  if last_month_dt is None or curr_month_dt != last_month_dt:
193
187
  self._output["monthly"].append(
@@ -218,4 +212,4 @@ class BillingProcessor(Processor):
218
212
  cost["power_term"] = round(cost["power_term"], 3)
219
213
  cost["others_term"] = round(cost["others_term"], 3)
220
214
  cost["surplus_term"] = round(cost["surplus_term"], 3)
221
- cost["value_eur"] = round(cost["value_eur"], 3)
215
+ cost["value_eur"] = round(main_expr(**cost, **self._input["rules"]), 3)
@@ -20,7 +20,7 @@ URL = "https://github.com/uvejota/python-edata"
20
20
  EMAIL = "vmayorg@outlook.es"
21
21
  AUTHOR = "VMG"
22
22
  REQUIRES_PYTHON = ">=3.6.0"
23
- VERSION = "1.2.10"
23
+ VERSION = "1.2.12"
24
24
 
25
25
  # What packages are required for this module to be executed?
26
26
  REQUIRED = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes