detquantlib 3.1.1__tar.gz → 3.2.0__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 (24) hide show
  1. {detquantlib-3.1.1 → detquantlib-3.2.0}/PKG-INFO +10 -1
  2. {detquantlib-3.1.1 → detquantlib-3.2.0}/README.md +9 -0
  3. detquantlib-3.2.0/detquantlib/dates/__init__.py +1 -0
  4. detquantlib-3.2.0/detquantlib/outputs/__init__.py +3 -0
  5. detquantlib-3.2.0/detquantlib/outputs/outputs_interface.py +182 -0
  6. detquantlib-3.2.0/detquantlib/tradable_products/__init__.py +1 -0
  7. detquantlib-3.2.0/detquantlib/utils/__init__.py +1 -0
  8. {detquantlib-3.1.1 → detquantlib-3.2.0}/pyproject.toml +1 -1
  9. detquantlib-3.1.1/detquantlib/stats/__init__.py +0 -1
  10. detquantlib-3.1.1/detquantlib/tradable_products/__init__.py +0 -1
  11. detquantlib-3.1.1/detquantlib/utils/__init__.py +0 -1
  12. {detquantlib-3.1.1 → detquantlib-3.2.0}/LICENSE.txt +0 -0
  13. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/__init__.py +0 -0
  14. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/data/__init__.py +0 -0
  15. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/data/databases/detdatabase.py +0 -0
  16. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/data/entsoe/entsoe.py +0 -0
  17. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/data/sftp/sftp.py +0 -0
  18. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/dates/dates.py +0 -0
  19. {detquantlib-3.1.1/detquantlib/dates → detquantlib-3.2.0/detquantlib/figures}/__init__.py +0 -0
  20. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/figures/plotly_figures.py +0 -0
  21. {detquantlib-3.1.1/detquantlib/figures → detquantlib-3.2.0/detquantlib/stats}/__init__.py +0 -0
  22. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/stats/data_analysis.py +0 -0
  23. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/tradable_products/tradable_products.py +0 -0
  24. {detquantlib-3.1.1 → detquantlib-3.2.0}/detquantlib/utils/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: detquantlib
3
- Version: 3.1.1
3
+ Version: 3.2.0
4
4
  Summary: An internal library containing functions and classes that can be used across Quant models.
5
5
  Author: DET
6
6
  Requires-Python: >=3.10,<4.0
@@ -80,6 +80,15 @@ Classes:
80
80
  - `Entsoe`:
81
81
  - `from detquantlib.data import Entsoe`
82
82
  - `from detquantlib.data.entsoe.entsoe import Entsoe`
83
+ - `OutputItem`:
84
+ - `from detquantlib.outputs import OutputItem`
85
+ - `from detquantlib.outputs.outputs_interface import OutputItem`
86
+ - `OutputSet`:
87
+ - `from detquantlib.outputs import OutputSet`
88
+ - `from detquantlib.outputs.outputs_interface import OutputSet`
89
+ - `PathDefinitions`:
90
+ - `from detquantlib.outputs import PathDefinitions`
91
+ - `from detquantlib.outputs.outputs_interface import PathDefinitions`
83
92
  - `Sftp`:
84
93
  - `from detquantlib.data import Sftp`
85
94
  - `from detquantlib.data.sftp.sftp import Sftp`
@@ -60,6 +60,15 @@ Classes:
60
60
  - `Entsoe`:
61
61
  - `from detquantlib.data import Entsoe`
62
62
  - `from detquantlib.data.entsoe.entsoe import Entsoe`
63
+ - `OutputItem`:
64
+ - `from detquantlib.outputs import OutputItem`
65
+ - `from detquantlib.outputs.outputs_interface import OutputItem`
66
+ - `OutputSet`:
67
+ - `from detquantlib.outputs import OutputSet`
68
+ - `from detquantlib.outputs.outputs_interface import OutputSet`
69
+ - `PathDefinitions`:
70
+ - `from detquantlib.outputs import PathDefinitions`
71
+ - `from detquantlib.outputs.outputs_interface import PathDefinitions`
63
72
  - `Sftp`:
64
73
  - `from detquantlib.data import Sftp`
65
74
  - `from detquantlib.data.sftp.sftp import Sftp`
@@ -0,0 +1 @@
1
+ from .dates import *
@@ -0,0 +1,3 @@
1
+ from .outputs_interface import OutputItem, OutputSet, PathDefinitions
2
+
3
+ __all__ = ["OutputItem", "OutputSet", "PathDefinitions"]
@@ -0,0 +1,182 @@
1
+ # Python built-in packages
2
+ import json
3
+ from pathlib import Path
4
+
5
+ # Third-party packages
6
+ import numpy as np
7
+ import pandas as pd
8
+ import plotly.graph_objects as go
9
+
10
+
11
+ class OutputItem:
12
+ """A class to easily manage, store and export a model output."""
13
+
14
+ def __init__(
15
+ self, data=None, filename: str = None, extension: str = None, sub_path: str = None
16
+ ):
17
+ """
18
+ Constructor method.
19
+
20
+ Args:
21
+ data: Output data
22
+ filename: Filename to be used when exporting the output data
23
+ extension: File extension to be used when exporting the output data
24
+ sub_path: Within the output base directory, indicates the sub-path (if any) of the
25
+ folder where the output data should be exported
26
+ """
27
+ self.data = data
28
+ self.filename = filename
29
+ self.extension = extension
30
+ self.sub_path = sub_path
31
+
32
+ def export_to_file(self, folder_dir: Path = None):
33
+ """
34
+ Exports the model output to a file.
35
+
36
+ Args:
37
+ folder_dir: Base directory of the folder containing all model outputs
38
+
39
+ Raises:
40
+ ValueError: Raises an error if the output file extension is not supported
41
+ """
42
+ # Define output folder directory, and create it if it doesn't exist yet
43
+ if folder_dir is None:
44
+ folder_dir = PathDefinitions.get_outputs_folder_dir()
45
+ if self.sub_path is not None:
46
+ folder_dir = folder_dir.joinpath(self.sub_path)
47
+ folder_dir.mkdir(parents=True, exist_ok=True)
48
+
49
+ # Define output file directory
50
+ filename = f"{self.filename}.{self.extension}"
51
+ file_dir = folder_dir.joinpath(filename)
52
+
53
+ # Create output file
54
+ if self.extension == "csv":
55
+ self.export_to_csv(file_dir)
56
+ elif self.extension == "json":
57
+ self.export_to_json(file_dir)
58
+ elif self.extension == "html":
59
+ self.export_to_html(file_dir)
60
+ elif self.extension == "npz":
61
+ self.export_to_npz(file_dir)
62
+ else:
63
+ raise ValueError("Invalid output file extension.")
64
+
65
+ def export_to_csv(self, file_dir: Path):
66
+ """
67
+ Exports the model output to a csv file.
68
+
69
+ Args:
70
+ file_dir: Directory of the output file
71
+
72
+ Raises:
73
+ TypeError: Raises an error if the data type is not supported
74
+ """
75
+ data_type = type(self.data)
76
+ if data_type is pd.DataFrame:
77
+ self.data.to_csv(file_dir, sep=",", index=False)
78
+ else:
79
+ raise TypeError(f"Exporting data type {data_type} to csv file is not supported.")
80
+
81
+ def export_to_json(self, file_dir: Path):
82
+ """
83
+ Exports the model output to a json file.
84
+
85
+ Args:
86
+ file_dir: Directory of the output file
87
+
88
+ Raises:
89
+ TypeError: Raises an error if the data type is not supported
90
+ """
91
+ data_type = type(self.data)
92
+ if data_type is dict:
93
+ with open(file_dir, "w") as f:
94
+ json.dump(self.data, f, indent=4)
95
+ else:
96
+ raise TypeError(f"Exporting data type {data_type} to json file is not supported.")
97
+
98
+ def export_to_html(self, file_dir: Path):
99
+ """
100
+ Exports the model output to a html file.
101
+
102
+ Args:
103
+ file_dir: Directory of the output file
104
+
105
+ Raises:
106
+ TypeError: Raises an error if the data type is not supported
107
+ """
108
+ data_type = type(self.data)
109
+ if data_type is go.Figure:
110
+ self.data.write_html(file_dir)
111
+ else:
112
+ raise TypeError(f"Exporting data type {data_type} to html file is not supported.")
113
+
114
+ def export_to_npz(self, file_dir: Path):
115
+ """
116
+ Exports the model output to a npz file.
117
+
118
+ Args:
119
+ file_dir: Directory of the output file
120
+
121
+ Raises:
122
+ TypeError: Raises an error if the data type is not supported
123
+ """
124
+ data_type = type(self.data)
125
+ if data_type is np.ndarray:
126
+ np.savez_compressed(file_dir, data=self.data)
127
+ else:
128
+ raise TypeError(f"Exporting data type {data_type} to npz file is not supported.")
129
+
130
+
131
+ class OutputSet:
132
+ """A short class to store all OutputItem objects into a single object."""
133
+
134
+ def __init__(self, output_items: list[OutputItem] = None):
135
+ """
136
+ Constructor method.
137
+
138
+ Args:
139
+ output_items: List of OutputItem objects
140
+ """
141
+ if output_items is None:
142
+ output_items = list()
143
+ self.output_items = output_items
144
+
145
+ def add_item(self, data, filename: str, extension: str, sub_path: str = None):
146
+ """
147
+ Creates an OutputItem object and adds it to the OutputSet list.
148
+
149
+ Args:
150
+ data: Output data
151
+ filename: Filename to be used when exporting the output data
152
+ extension: File extension to be used when exporting the output data
153
+ sub_path: Within the output base directory, indicates the sub-path (if any) of the
154
+ folder where the output data should be exported
155
+ """
156
+ # Create OutputItem object
157
+ item = OutputItem(data=data, filename=filename, extension=extension, sub_path=sub_path)
158
+ # Append to OutputSet list
159
+ self.output_items.append(item)
160
+
161
+
162
+ class PathDefinitions:
163
+ """A class containing hard-coded path definitions."""
164
+
165
+ @staticmethod
166
+ def outputs_folder():
167
+ return "Outputs"
168
+
169
+ @staticmethod
170
+ def outputs_plotly_folder():
171
+ return "PlotlyFigures"
172
+
173
+ @staticmethod
174
+ def get_outputs_folder_dir():
175
+ # Base directory of the folder containing all model outputs
176
+ return Path.cwd().joinpath(PathDefinitions.outputs_folder())
177
+
178
+ @staticmethod
179
+ def get_outputs_plotly_folder_dir():
180
+ # Directory of the output folder containing all plotly figures
181
+ base_dir = PathDefinitions.get_outputs_folder_dir()
182
+ return base_dir.joinpath(PathDefinitions.outputs_plotly_folder())
@@ -0,0 +1 @@
1
+ from .tradable_products import *
@@ -0,0 +1 @@
1
+ from .utils import *
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "detquantlib"
3
- version = "3.1.1"
3
+ version = "3.2.0"
4
4
  description = "An internal library containing functions and classes that can be used across Quant models."
5
5
  authors = ["DET"]
6
6
  readme = "README.md"
@@ -1 +0,0 @@
1
- # Empty file required by poetry. Do not delete.
@@ -1 +0,0 @@
1
- # Empty file required by poetry. Do not delete.
@@ -1 +0,0 @@
1
- # Empty file required by poetry. Do not delete.
File without changes