e-data 1.2.9__tar.gz → 1.2.11__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.
- {e-data-1.2.9/e_data.egg-info → e-data-1.2.11}/PKG-INFO +1 -1
- {e-data-1.2.9 → e-data-1.2.11/e_data.egg-info}/PKG-INFO +1 -1
- {e-data-1.2.9 → e-data-1.2.11}/edata/definitions.py +18 -6
- {e-data-1.2.9 → e-data-1.2.11}/edata/helpers.py +17 -11
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/base.py +4 -4
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/billing.py +9 -15
- {e-data-1.2.9 → e-data-1.2.11}/setup.py +1 -1
- {e-data-1.2.9 → e-data-1.2.11}/LICENSE +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/MANIFEST.in +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/README.md +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/e_data.egg-info/SOURCES.txt +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/e_data.egg-info/dependency_links.txt +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/e_data.egg-info/requires.txt +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/e_data.egg-info/top_level.txt +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/__init__.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/connectors/__init__.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/connectors/datadis.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/connectors/redata.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/const.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/__init__.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/consumption.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/maximeter.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/processors/utils.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/edata/storage.py +0 -0
- {e-data-1.2.9 → e-data-1.2.11}/setup.cfg +0 -0
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import voluptuous as vol
|
|
4
4
|
import datetime as dt
|
|
5
|
-
from
|
|
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 *
|
|
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
|
)
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"""A module for edata helpers."""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
-
import logging
|
|
5
|
-
from datetime import datetime, timedelta
|
|
6
4
|
import contextlib
|
|
5
|
+
from datetime import datetime, timedelta
|
|
6
|
+
import logging
|
|
7
7
|
import os
|
|
8
8
|
|
|
9
|
-
import requests
|
|
10
9
|
from dateutil.relativedelta import relativedelta
|
|
10
|
+
import requests
|
|
11
11
|
|
|
12
|
+
from . import const
|
|
12
13
|
from .connectors.datadis import DatadisConnector
|
|
13
14
|
from .connectors.redata import REDataConnector
|
|
14
15
|
from .definitions import ATTRIBUTES, EdataData, PricingRules
|
|
15
16
|
from .processors import utils
|
|
16
|
-
from .processors.billing import
|
|
17
|
-
BillingInput,
|
|
18
|
-
BillingProcessor,
|
|
19
|
-
)
|
|
17
|
+
from .processors.billing import BillingInput, BillingProcessor
|
|
20
18
|
from .processors.consumption import ConsumptionProcessor
|
|
21
19
|
from .processors.maximeter import MaximeterProcessor
|
|
22
|
-
from .storage import check_storage_integrity,
|
|
23
|
-
from . import const
|
|
24
|
-
|
|
20
|
+
from .storage import check_storage_integrity, dump_storage, load_storage
|
|
25
21
|
|
|
26
22
|
_LOGGER = logging.getLogger(__name__)
|
|
27
23
|
|
|
@@ -523,6 +519,11 @@ class EdataHelper:
|
|
|
523
519
|
)
|
|
524
520
|
|
|
525
521
|
for tariff in (1, 2, 3):
|
|
522
|
+
self.attributes[f"month_p{tariff}_kWh"] = (
|
|
523
|
+
month.get(f"value_p{tariff}_kWh", None)
|
|
524
|
+
if month is not None
|
|
525
|
+
else None
|
|
526
|
+
)
|
|
526
527
|
self.attributes[f"month_surplus_p{tariff}_kWh"] = (
|
|
527
528
|
month.get(f"surplus_p{tariff}_kWh", None)
|
|
528
529
|
if month is not None
|
|
@@ -561,7 +562,6 @@ class EdataHelper:
|
|
|
561
562
|
if last_month is not None
|
|
562
563
|
else None
|
|
563
564
|
)
|
|
564
|
-
for tariff in (1, 2, 3):
|
|
565
565
|
self.attributes[f"last_month_surplus_p{tariff}_kWh"] = (
|
|
566
566
|
last_month.get(f"surplus_p{tariff}_kWh", None)
|
|
567
567
|
if last_month is not None
|
|
@@ -587,6 +587,12 @@ class EdataHelper:
|
|
|
587
587
|
)
|
|
588
588
|
|
|
589
589
|
for tariff in (1, 2, 3):
|
|
590
|
+
self.attributes[f"last_registered_day_p{tariff}_kWh"] = (
|
|
591
|
+
last_day.get(f"value_p{tariff}_kWh", None)
|
|
592
|
+
if last_day is not None
|
|
593
|
+
else None
|
|
594
|
+
)
|
|
595
|
+
|
|
590
596
|
self.attributes[
|
|
591
597
|
f"last_registered_day_surplus_p{tariff}_kWh"
|
|
592
598
|
] = (
|
|
@@ -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
|
-
"""
|
|
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
|
|
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
|
-
"""
|
|
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["
|
|
215
|
+
cost["value_eur"] = round(main_expr(**cost, **self._input["rules"]), 3)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|