tesorotools-python 0.0.8__py2.py3-none-any.whl → 0.0.10__py2.py3-none-any.whl
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.
- tesorotools/__init__.py +6 -0
- tesorotools/artists/line_plot.py +130 -1
- tesorotools/assets/fonts/CabinetGrotesk-Black.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Bold.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Extrabold.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Extralight.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Light.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Medium.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Regular.otf +0 -0
- tesorotools/assets/fonts/CabinetGrotesk-Thin.otf +0 -0
- {tesorotools_python-0.0.8.dist-info → tesorotools_python-0.0.10.dist-info}/METADATA +1 -1
- {tesorotools_python-0.0.8.dist-info → tesorotools_python-0.0.10.dist-info}/RECORD +13 -5
- {tesorotools_python-0.0.8.dist-info → tesorotools_python-0.0.10.dist-info}/WHEEL +0 -0
tesorotools/__init__.py
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from tesorotools.artists.line_plot import Format, Legend, LinePlot
|
|
2
|
+
from tesorotools.utils.config import TemplateLoader
|
|
3
|
+
|
|
4
|
+
TemplateLoader.add_constructor("!line_plot", LinePlot.from_yaml)
|
|
5
|
+
TemplateLoader.add_constructor("!format", Format.from_yaml)
|
|
6
|
+
TemplateLoader.add_constructor("!legend", Legend.from_yaml)
|
tesorotools/artists/line_plot.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import datetime
|
|
1
2
|
import locale
|
|
2
3
|
from pathlib import Path
|
|
3
|
-
from typing import Any
|
|
4
|
+
from typing import Any, Self
|
|
4
5
|
|
|
5
6
|
import matplotlib.pyplot as plt
|
|
6
7
|
import pandas as pd
|
|
7
8
|
from matplotlib.ticker import FuncFormatter
|
|
9
|
+
from yaml.nodes import MappingNode
|
|
10
|
+
|
|
11
|
+
from tesorotools.utils.config import TemplateLoader
|
|
8
12
|
|
|
9
13
|
locale.setlocale(locale.LC_ALL, "")
|
|
10
14
|
|
|
@@ -112,3 +116,128 @@ def plot_line_charts(data: pd.DataFrame, config_dicts: dict[str, Any]):
|
|
|
112
116
|
trimmed_data = trimmed_data.rename(columns=series)
|
|
113
117
|
out_name: Path = DEBUG / "line" / f"{name}.png"
|
|
114
118
|
plot_line_chart(out_name, trimmed_data, **config)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class Format:
|
|
122
|
+
def __init__(self, units: str = "", decimals: int = 0):
|
|
123
|
+
self.units = units
|
|
124
|
+
self.decimals = decimals
|
|
125
|
+
|
|
126
|
+
@classmethod
|
|
127
|
+
def from_yaml(cls, loader: TemplateLoader, node: MappingNode) -> Self:
|
|
128
|
+
loader.flatten_mapping(node)
|
|
129
|
+
format_cfg: dict[str, Any] = loader.construct_mapping(node, deep=True)
|
|
130
|
+
format_cfg.pop("id")
|
|
131
|
+
return cls(**format_cfg)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class Legend:
|
|
135
|
+
def __init__(self, ncol: int = 5, sep: float = -0.125):
|
|
136
|
+
self.ncol = ncol
|
|
137
|
+
self.sep = sep
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def from_yaml(cls, loader: TemplateLoader, node: MappingNode) -> Self:
|
|
141
|
+
legend_cfg: dict[str, Any] = loader.construct_mapping(node, deep=True)
|
|
142
|
+
legend_cfg.pop("id")
|
|
143
|
+
return cls(**legend_cfg)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# as more stuff is needed, seems wise to make a class
|
|
147
|
+
class LinePlot:
|
|
148
|
+
def __init__(
|
|
149
|
+
self,
|
|
150
|
+
out_path: Path,
|
|
151
|
+
data_path: Path,
|
|
152
|
+
series: dict[str, str],
|
|
153
|
+
scale: float = 1,
|
|
154
|
+
start_date: datetime.datetime | None = None,
|
|
155
|
+
end_date: datetime.datetime | None = None,
|
|
156
|
+
base_100: bool = False,
|
|
157
|
+
annotate: bool = False,
|
|
158
|
+
baseline: bool = False,
|
|
159
|
+
format: Format | None = None,
|
|
160
|
+
legend: Legend | None = None,
|
|
161
|
+
) -> None:
|
|
162
|
+
|
|
163
|
+
if out_path.suffix != ".png":
|
|
164
|
+
raise ValueError(f"The out file {out_path} should be a .png file")
|
|
165
|
+
self.out_path = out_path
|
|
166
|
+
|
|
167
|
+
if data_path.suffix != ".feather":
|
|
168
|
+
raise ValueError(
|
|
169
|
+
f"The data file {data_path} must be a .feather file"
|
|
170
|
+
)
|
|
171
|
+
self.data = pd.read_feather(data_path)
|
|
172
|
+
|
|
173
|
+
self.base_100 = base_100
|
|
174
|
+
self.annotate = annotate # unused for the moment
|
|
175
|
+
self.format = format
|
|
176
|
+
self.start_date = start_date
|
|
177
|
+
self.end_date = end_date
|
|
178
|
+
self.series = series
|
|
179
|
+
self.legend = legend
|
|
180
|
+
self.baseline = baseline
|
|
181
|
+
self.scale = scale
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
def from_yaml(cls, loader: TemplateLoader, node: MappingNode) -> Self:
|
|
185
|
+
line_plot_cfg: dict[str, Any] = loader.construct_mapping(
|
|
186
|
+
node, deep=True
|
|
187
|
+
)
|
|
188
|
+
line_plot_cfg.pop("id")
|
|
189
|
+
line_plot_cfg["out_path"] = Path(line_plot_cfg["out_path"])
|
|
190
|
+
line_plot_cfg["data_path"] = Path(line_plot_cfg["data_path"])
|
|
191
|
+
return cls(**line_plot_cfg)
|
|
192
|
+
|
|
193
|
+
def plot(self) -> plt.Axes:
|
|
194
|
+
start_date: pd.Timestamp = (
|
|
195
|
+
self.data.index.min()
|
|
196
|
+
if self.start_date is None
|
|
197
|
+
else pd.to_datetime(self.start_date)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
end_date: pd.Timestamp = (
|
|
201
|
+
self.data.index.max()
|
|
202
|
+
if self.end_date is None
|
|
203
|
+
else pd.to_datetime(self.end_date)
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
plot_data: pd.DataFrame = self.data.loc[
|
|
207
|
+
slice(start_date, end_date), self.series.keys()
|
|
208
|
+
]
|
|
209
|
+
plot_data = plot_data.rename(columns=self.series)
|
|
210
|
+
|
|
211
|
+
plot_data = plot_data * self.scale
|
|
212
|
+
|
|
213
|
+
if self.base_100: # maybe more flexible in the future
|
|
214
|
+
plot_data = plot_data / plot_data.iloc[0, :] * 100
|
|
215
|
+
|
|
216
|
+
fig = plt.figure(**FIG_CONFIG)
|
|
217
|
+
ax = fig.add_subplot()
|
|
218
|
+
plot_data.plot(ax=ax)
|
|
219
|
+
|
|
220
|
+
if self.annotate: # not implemented yet
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
_style_spines( # maybe make this function accept a Format object
|
|
224
|
+
ax,
|
|
225
|
+
decimals=self.format.decimals,
|
|
226
|
+
units=self.format.units,
|
|
227
|
+
**AX_CONFIG["spines"],
|
|
228
|
+
)
|
|
229
|
+
if self.baseline:
|
|
230
|
+
reference = 100 if self.base_100 else 0
|
|
231
|
+
_style_baseline(ax, reference, **AX_CONFIG["baseline"])
|
|
232
|
+
|
|
233
|
+
if self.legend is not None:
|
|
234
|
+
ax.legend(
|
|
235
|
+
loc="upper center",
|
|
236
|
+
bbox_to_anchor=(0.5, LINE_PLOT_CONFIG["legend_sep"]),
|
|
237
|
+
ncol=self.legend.ncol,
|
|
238
|
+
)
|
|
239
|
+
else:
|
|
240
|
+
ax.legend().set_visible(False)
|
|
241
|
+
|
|
242
|
+
fig.savefig(self.out_path)
|
|
243
|
+
return ax
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
tesorotools/__init__.py,sha256=
|
|
1
|
+
tesorotools/__init__.py,sha256=rkjAQCbiNmcFq9qlYUZFEOhPGXd5ISqS2PSfu1V1khQ,311
|
|
2
2
|
tesorotools/convert.py,sha256=qk4N-AZpKlmTD9L9SG0E43jqW27DJTHTu_Y1wehvETQ,3334
|
|
3
3
|
tesorotools/main.py,sha256=ZxDyqBD_0zlfcdTZp84UPxlK3_O-9xfexDjLJVu4L5U,1357
|
|
4
4
|
tesorotools/artists/__init__.py,sha256=exObsPqXdP6IaRn4QPkLRXUN67iOPNXtDgDAOoMxJoA,105
|
|
5
5
|
tesorotools/artists/barh_plot.py,sha256=3KkoT0DLkctzYNMV3Pz1EcAT9i29YGYSkTLTFNb3dv8,9461
|
|
6
|
-
tesorotools/artists/line_plot.py,sha256=
|
|
6
|
+
tesorotools/artists/line_plot.py,sha256=TlQ5AFeQ5u4eNbjLkjJBH6ztKK8xAmccdVXqQiT4vpk,7553
|
|
7
7
|
tesorotools/artists/table.py,sha256=CjyjWivn5YrNP5m8_eWi-ZA7R1ts3aIhATrYMEgTuOU,7651
|
|
8
8
|
tesorotools/artists/type_curve.py,sha256=VGFCCyMVNwjliLK9usyw_nLC6emKcJYOSV1pmWJQNXk,6463
|
|
9
9
|
tesorotools/assets/README.md,sha256=pB77vD_MvE26ftVNcZuj3iS0y-6g-WzqHb5OScDkQ3I,289
|
|
10
10
|
tesorotools/assets/plots.yaml,sha256=O-6bFprWFNHJgMr-ehl_TPkDvr48XwK8V9k7CxL__ts,578
|
|
11
11
|
tesorotools/assets/tesoro.mplstyle,sha256=aDzJRln2EA7U-1yo_yHoAHikntEdpFSFTIvKJczN8To,477
|
|
12
|
+
tesorotools/assets/fonts/CabinetGrotesk-Black.otf,sha256=b7M_yFxz5IcGtmWWPMzLVkfx4RLhVALQDFeoq4T1YD0,37728
|
|
13
|
+
tesorotools/assets/fonts/CabinetGrotesk-Bold.otf,sha256=86oM6a9QVAjZoEIFFcbCbcIVEwtWrMBX0ks7_CzaKS4,38148
|
|
14
|
+
tesorotools/assets/fonts/CabinetGrotesk-Extrabold.otf,sha256=RmIwkz382lhAbMO72z4_u4jGIYghaBVlzYiO_Baxs4k,38392
|
|
15
|
+
tesorotools/assets/fonts/CabinetGrotesk-Extralight.otf,sha256=LCirXimxHxAnI5bKloiSXoFuQ8shqbX50fnx6QJ3AMo,38004
|
|
16
|
+
tesorotools/assets/fonts/CabinetGrotesk-Light.otf,sha256=MXsLPzs4QIYWWdUfxgtvgXBimlk9N_-z5P2HXB_chUw,37832
|
|
17
|
+
tesorotools/assets/fonts/CabinetGrotesk-Medium.otf,sha256=WfAWF9hgkNkk7xxl1545AsrZGa-zBAFzr_sxMUEYsPM,37812
|
|
18
|
+
tesorotools/assets/fonts/CabinetGrotesk-Regular.otf,sha256=iTJYvBNtfsdIczP6RRH3xXlPatfHfu4kN4gcbfmFwLE,37968
|
|
19
|
+
tesorotools/assets/fonts/CabinetGrotesk-Thin.otf,sha256=j_pm5xeEmBU3ikvKEQGPQY2FeN6Ee7DXeBuvlFOYmFw,37296
|
|
12
20
|
tesorotools/assets/fonts/README.md,sha256=o58YkAtgrA9fDmH6ZyYrBEDcwo78050N-yS7UdErN-A,71
|
|
13
21
|
tesorotools/data_sources/README.md,sha256=iMAeLsv9Xk3IogDh8nCt2pSeTqCHmXA66KPvV25Za7I,261
|
|
14
22
|
tesorotools/data_sources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -38,6 +46,6 @@ tesorotools/utils/globals.py,sha256=c5PBpZwpVO_nOetxyIk8j32Vx3GFlsgdYbwwfSSlv1M,
|
|
|
38
46
|
tesorotools/utils/matplotlib.py,sha256=tKidZIcDLKWgawIOJggWwVoaTMsrjw1WEJQouydSYbI,1197
|
|
39
47
|
tesorotools/utils/series.py,sha256=eUEUOdzDfA7YbgO4o6KtxwJOL5cQYdqLjrdvuQ7Hqhc,1168
|
|
40
48
|
tesorotools/utils/template.py,sha256=xpBVad28gG9ZLVwd9e0dTWsGsbujjmVcCPEW2mIKEJo,4917
|
|
41
|
-
tesorotools_python-0.0.
|
|
42
|
-
tesorotools_python-0.0.
|
|
43
|
-
tesorotools_python-0.0.
|
|
49
|
+
tesorotools_python-0.0.10.dist-info/METADATA,sha256=cykYk-1liWJTY2B1B5eXny4FWHqJ2DqtZfItiXA6qzY,324
|
|
50
|
+
tesorotools_python-0.0.10.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
|
51
|
+
tesorotools_python-0.0.10.dist-info/RECORD,,
|
|
File without changes
|