PyDPEET 0.2.0__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.
- pydpeet/__init__.py +56 -0
- pydpeet/citations/__init__.py +7 -0
- pydpeet/citations/citeme.py +397 -0
- pydpeet/citations/html_writer.py +137 -0
- pydpeet/dev_utils/__init__.py +7 -0
- pydpeet/dev_utils/generate_inits/__init__.py +7 -0
- pydpeet/dev_utils/generate_inits/generate_inits.py +327 -0
- pydpeet/io/__init__.py +7 -0
- pydpeet/io/configs/__init__.py +7 -0
- pydpeet/io/configs/config.py +227 -0
- pydpeet/io/configs/const.py +1 -0
- pydpeet/io/convert.py +594 -0
- pydpeet/io/device/__init__.py +7 -0
- pydpeet/io/device/arbin_4_23_PV090331/__init__.py +7 -0
- pydpeet/io/device/arbin_4_23_PV090331/formatter.py +22 -0
- pydpeet/io/device/arbin_4_23_PV090331/mapper.py +18 -0
- pydpeet/io/device/arbin_4_23_PV090331/reader.py +68 -0
- pydpeet/io/device/arbin_8_00_PV221201/__init__.py +7 -0
- pydpeet/io/device/arbin_8_00_PV221201/formatter.py +26 -0
- pydpeet/io/device/arbin_8_00_PV221201/mapper.py +18 -0
- pydpeet/io/device/arbin_8_00_PV221201/reader.py +66 -0
- pydpeet/io/device/basytec_6_3_1_0/__init__.py +7 -0
- pydpeet/io/device/basytec_6_3_1_0/formatter.py +18 -0
- pydpeet/io/device/basytec_6_3_1_0/mapper.py +18 -0
- pydpeet/io/device/basytec_6_3_1_0/reader.py +54 -0
- pydpeet/io/device/digatron_4_20_6_236/__init__.py +7 -0
- pydpeet/io/device/digatron_4_20_6_236/formatter.py +27 -0
- pydpeet/io/device/digatron_4_20_6_236/mapper.py +18 -0
- pydpeet/io/device/digatron_4_20_6_236/reader.py +45 -0
- pydpeet/io/device/digatron_eis_4_20_6_236/__init__.py +7 -0
- pydpeet/io/device/digatron_eis_4_20_6_236/formatter.py +39 -0
- pydpeet/io/device/digatron_eis_4_20_6_236/mapper.py +18 -0
- pydpeet/io/device/digatron_eis_4_20_6_236/reader.py +42 -0
- pydpeet/io/device/neware_8_0_0_516/__init__.py +7 -0
- pydpeet/io/device/neware_8_0_0_516/formatter.py +31 -0
- pydpeet/io/device/neware_8_0_0_516/mapper.py +18 -0
- pydpeet/io/device/neware_8_0_0_516/reader.py +397 -0
- pydpeet/io/device/parstat_2_63_3/__init__.py +7 -0
- pydpeet/io/device/parstat_2_63_3/formatter.py +34 -0
- pydpeet/io/device/parstat_2_63_3/mapper.py +18 -0
- pydpeet/io/device/parstat_2_63_3/reader.py +34 -0
- pydpeet/io/device/safion_1_9/__init__.py +7 -0
- pydpeet/io/device/safion_1_9/formatter.py +25 -0
- pydpeet/io/device/safion_1_9/mapper.py +18 -0
- pydpeet/io/device/safion_1_9/reader.py +89 -0
- pydpeet/io/device/zahner/__init__.py +7 -0
- pydpeet/io/device/zahner/formatter.py +73 -0
- pydpeet/io/device/zahner/mapper.py +34 -0
- pydpeet/io/device/zahner/reader.py +46 -0
- pydpeet/io/device/zahner_new/__init__.py +7 -0
- pydpeet/io/device/zahner_new/formatter.py +72 -0
- pydpeet/io/device/zahner_new/mapper.py +50 -0
- pydpeet/io/device/zahner_new/reader.py +46 -0
- pydpeet/io/map.py +69 -0
- pydpeet/io/read.py +50 -0
- pydpeet/io/utils/__init__.py +7 -0
- pydpeet/io/utils/ext_path.py +34 -0
- pydpeet/io/utils/formatter_utils.py +429 -0
- pydpeet/io/utils/load_custom_module.py +33 -0
- pydpeet/io/utils/timing.py +36 -0
- pydpeet/io/write.py +99 -0
- pydpeet/process/__init__.py +7 -0
- pydpeet/process/analyze/__init__.py +7 -0
- pydpeet/process/analyze/average.py +297 -0
- pydpeet/process/analyze/capacity.py +208 -0
- pydpeet/process/analyze/configs/__init__.py +7 -0
- pydpeet/process/analyze/configs/battery_config.py +38 -0
- pydpeet/process/analyze/configs/ocv_config.py +177 -0
- pydpeet/process/analyze/configs/step_analyzer_config.py +178 -0
- pydpeet/process/analyze/cycle.py +63 -0
- pydpeet/process/analyze/efficiency.py +182 -0
- pydpeet/process/analyze/energy.py +51 -0
- pydpeet/process/analyze/extract/__init__.py +7 -0
- pydpeet/process/analyze/extract/dva_ica.py +224 -0
- pydpeet/process/analyze/extract/ocv.py +196 -0
- pydpeet/process/analyze/power.py +32 -0
- pydpeet/process/analyze/resistance.py +87 -0
- pydpeet/process/analyze/soc.py +418 -0
- pydpeet/process/analyze/soh.py +72 -0
- pydpeet/process/analyze/utils.py +122 -0
- pydpeet/process/merge/__init__.py +7 -0
- pydpeet/process/merge/series.py +274 -0
- pydpeet/process/sequence/__init__.py +7 -0
- pydpeet/process/sequence/configs/__init__.py +7 -0
- pydpeet/process/sequence/configs/config.py +17 -0
- pydpeet/process/sequence/step_analyzer.py +440 -0
- pydpeet/process/sequence/utils/__init__.py +7 -0
- pydpeet/process/sequence/utils/annotate/__init__.py +7 -0
- pydpeet/process/sequence/utils/annotate/annotate_primitives.py +419 -0
- pydpeet/process/sequence/utils/configs/CONFIG_Fallback.py +231 -0
- pydpeet/process/sequence/utils/configs/CONFIG_preprocessing.py +243 -0
- pydpeet/process/sequence/utils/configs/__init__.py +7 -0
- pydpeet/process/sequence/utils/console_prints/__init__.py +7 -0
- pydpeet/process/sequence/utils/console_prints/log_time.py +30 -0
- pydpeet/process/sequence/utils/postprocessing/__init__.py +7 -0
- pydpeet/process/sequence/utils/postprocessing/df_primitives_correction.py +166 -0
- pydpeet/process/sequence/utils/postprocessing/filter_df.py +168 -0
- pydpeet/process/sequence/utils/postprocessing/generate_instructions.py +297 -0
- pydpeet/process/sequence/utils/preprocessing/__init__.py +7 -0
- pydpeet/process/sequence/utils/preprocessing/calculate_thresholds.py +27 -0
- pydpeet/process/sequence/utils/processing/__init__.py +7 -0
- pydpeet/process/sequence/utils/processing/analyze_segments.py +368 -0
- pydpeet/process/sequence/utils/processing/attempt_to_merge_neighboring_segments.py +122 -0
- pydpeet/process/sequence/utils/processing/check_CV_results.py +226 -0
- pydpeet/process/sequence/utils/processing/check_power_zero_watt_segments.py +85 -0
- pydpeet/process/sequence/utils/processing/check_zero_length.py +117 -0
- pydpeet/process/sequence/utils/processing/split_in_segments.py +97 -0
- pydpeet/process/sequence/utils/processing/supress_smaller_segments.py +99 -0
- pydpeet/process/sequence/utils/processing/widen_constant_segments.py +185 -0
- pydpeet/process/sequence/utils/visualize/__init__.py +7 -0
- pydpeet/process/sequence/utils/visualize/visualize_data.py +288 -0
- pydpeet/res/__init__.py +7 -0
- pydpeet/settings.py +0 -0
- pydpeet/utils/__init__.py +7 -0
- pydpeet/utils/logging_style.py +28 -0
- pydpeet/version.py +0 -0
- pydpeet-0.2.0.dist-info/METADATA +85 -0
- pydpeet-0.2.0.dist-info/RECORD +122 -0
- pydpeet-0.2.0.dist-info/WHEEL +5 -0
- pydpeet-0.2.0.dist-info/licenses/AUTHORS.md +0 -0
- pydpeet-0.2.0.dist-info/licenses/LICENCE.md +27 -0
- pydpeet-0.2.0.dist-info/top_level.txt +1 -0
pydpeet/__init__.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Auto-generated __init__ file.
|
|
3
|
+
Created: 2026-03-06 15:11:49
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# Re-export selected names from source modules
|
|
7
|
+
|
|
8
|
+
from pydpeet.citations.citeme import print_references, write_to_bibtex
|
|
9
|
+
from pydpeet.io.convert import convert
|
|
10
|
+
from pydpeet.io.map import mapping
|
|
11
|
+
from pydpeet.io.read import read
|
|
12
|
+
from pydpeet.io.write import write
|
|
13
|
+
from pydpeet.process.analyze.capacity import add_capacity
|
|
14
|
+
from pydpeet.process.analyze.configs.battery_config import (
|
|
15
|
+
BatteryConfig,
|
|
16
|
+
battery_config_default,
|
|
17
|
+
hakadi_nmc_1500,
|
|
18
|
+
lgm50lt_nmc_4800,
|
|
19
|
+
)
|
|
20
|
+
from pydpeet.process.analyze.extract.ocv import extract_ocv_iocv
|
|
21
|
+
from pydpeet.process.analyze.resistance import add_resistance_internal
|
|
22
|
+
from pydpeet.process.analyze.soc import SocMethod, add_soc
|
|
23
|
+
from pydpeet.process.merge.series import merge_into_series
|
|
24
|
+
from pydpeet.process.sequence.step_analyzer import add_primitive_segments, extract_sequence_overview
|
|
25
|
+
from pydpeet.process.sequence.utils.postprocessing.df_primitives_correction import df_primitives_correction
|
|
26
|
+
from pydpeet.process.sequence.utils.postprocessing.filter_df import filter_and_split_df_by_blocks
|
|
27
|
+
from pydpeet.process.sequence.utils.postprocessing.generate_instructions import generate_instructions
|
|
28
|
+
from pydpeet.process.sequence.utils.visualize.visualize_data import visualize_phases
|
|
29
|
+
from pydpeet.utils.logging_style import set_logging_style
|
|
30
|
+
|
|
31
|
+
# Public API for this package
|
|
32
|
+
__all__ = [
|
|
33
|
+
"BatteryConfig",
|
|
34
|
+
"SocMethod",
|
|
35
|
+
"add_capacity",
|
|
36
|
+
"add_primitive_segments",
|
|
37
|
+
"add_resistance_internal",
|
|
38
|
+
"add_soc",
|
|
39
|
+
"battery_config_default",
|
|
40
|
+
"convert",
|
|
41
|
+
"df_primitives_correction",
|
|
42
|
+
"extract_ocv_iocv",
|
|
43
|
+
"extract_sequence_overview",
|
|
44
|
+
"filter_and_split_df_by_blocks",
|
|
45
|
+
"generate_instructions",
|
|
46
|
+
"hakadi_nmc_1500",
|
|
47
|
+
"lgm50lt_nmc_4800",
|
|
48
|
+
"mapping",
|
|
49
|
+
"merge_into_series",
|
|
50
|
+
"print_references",
|
|
51
|
+
"read",
|
|
52
|
+
"set_logging_style",
|
|
53
|
+
"visualize_phases",
|
|
54
|
+
"write",
|
|
55
|
+
"write_to_bibtex",
|
|
56
|
+
]
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TODO Code taken from : https://github.com/citation-file-format/citeme/tree/master
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import functools
|
|
6
|
+
import json
|
|
7
|
+
import pathlib
|
|
8
|
+
|
|
9
|
+
from bibtexparser.bibdatabase import BibDatabase
|
|
10
|
+
from bibtexparser.bwriter import BibTexWriter
|
|
11
|
+
from six import iteritems
|
|
12
|
+
|
|
13
|
+
from .html_writer import BibHtmlWriter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Singleton!
|
|
17
|
+
class CiteMe:
|
|
18
|
+
# Class variable!
|
|
19
|
+
__instance = None
|
|
20
|
+
__check_fields = True
|
|
21
|
+
__pedantic = False
|
|
22
|
+
|
|
23
|
+
# Override new to make this a singleton class
|
|
24
|
+
# taken from http://python-3-patterns-idioms-test.readthedocs.io/en/latest/Singleton.html#id5
|
|
25
|
+
def __new__(cls):
|
|
26
|
+
if CiteMe.__instance is None:
|
|
27
|
+
CiteMe.__instance = object.__new__(cls)
|
|
28
|
+
# Initialization of class here, because
|
|
29
|
+
# __init__ gets called multiple times
|
|
30
|
+
CiteMe.__instance.references = {}
|
|
31
|
+
return CiteMe.__instance
|
|
32
|
+
|
|
33
|
+
def add_reference(self, citation):
|
|
34
|
+
if CiteMe.__check_fields:
|
|
35
|
+
citation.checkFields(CiteMe.__pedantic)
|
|
36
|
+
|
|
37
|
+
if citation.type not in self.references:
|
|
38
|
+
self.references[citation.type] = {}
|
|
39
|
+
|
|
40
|
+
if citation.handle not in self.references[citation.type]:
|
|
41
|
+
self.references[citation.type][citation.handle] = citation
|
|
42
|
+
|
|
43
|
+
def print_references(self):
|
|
44
|
+
for ref_type in self.references:
|
|
45
|
+
for _, citation in iteritems(self.references[ref_type]):
|
|
46
|
+
# print(ref_type, handle, citation.description)
|
|
47
|
+
print(citation.description)
|
|
48
|
+
|
|
49
|
+
def write_to_bibtex(self, filename):
|
|
50
|
+
db = BibDatabase()
|
|
51
|
+
db.entries = []
|
|
52
|
+
for ref_type in self.references:
|
|
53
|
+
for handle, citation in iteritems(self.references[ref_type]):
|
|
54
|
+
description = citation.description
|
|
55
|
+
description["ENTRYTYPE"] = citation.type
|
|
56
|
+
description["ID"] = handle
|
|
57
|
+
db.entries.append(description)
|
|
58
|
+
writer = BibTexWriter()
|
|
59
|
+
with open(filename, "w") as bibfile:
|
|
60
|
+
bibfile.write(writer.write(db))
|
|
61
|
+
|
|
62
|
+
def write_to_html(self, filename, full=False):
|
|
63
|
+
with open(filename, "w") as bibfile:
|
|
64
|
+
bibfile.write(self.get_html(full=full))
|
|
65
|
+
|
|
66
|
+
def get_html(self, full=False):
|
|
67
|
+
db = BibDatabase()
|
|
68
|
+
db.entries = []
|
|
69
|
+
for ref_type in self.references:
|
|
70
|
+
for handle, citation in iteritems(self.references[ref_type]):
|
|
71
|
+
description = citation.description
|
|
72
|
+
description["ENTRYTYPE"] = citation.type
|
|
73
|
+
description["ID"] = handle
|
|
74
|
+
db.entries.append(description)
|
|
75
|
+
writer = BibHtmlWriter()
|
|
76
|
+
return writer.write(db, full=full)
|
|
77
|
+
|
|
78
|
+
def references_by_type(self, ref_type):
|
|
79
|
+
if ref_type in self.references:
|
|
80
|
+
return self.references["ref_type"]
|
|
81
|
+
else:
|
|
82
|
+
return []
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def set_pedantic(value):
|
|
86
|
+
CiteMe.__pedantic = value
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def set_check_fields(value):
|
|
90
|
+
CiteMe.__check_fields = value
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Citation:
|
|
94
|
+
def __init__(self, handle, description, the_type):
|
|
95
|
+
self.handle = handle
|
|
96
|
+
self.description = description
|
|
97
|
+
self.type = the_type
|
|
98
|
+
|
|
99
|
+
# optional and required field
|
|
100
|
+
# from https://en.wikipedia.org/wiki/BibTeX
|
|
101
|
+
self._required = []
|
|
102
|
+
self._optional = []
|
|
103
|
+
self._general_options = ["url", "doi"]
|
|
104
|
+
|
|
105
|
+
def __call__(self, f):
|
|
106
|
+
def wrapped_f(*args, **kwargs):
|
|
107
|
+
CiteMe().add_reference(self)
|
|
108
|
+
return f(*args, **kwargs)
|
|
109
|
+
|
|
110
|
+
return wrapped_f
|
|
111
|
+
|
|
112
|
+
def checkFields(self, pedantic):
|
|
113
|
+
missing = []
|
|
114
|
+
too_many = []
|
|
115
|
+
if self._required:
|
|
116
|
+
for field in self._required:
|
|
117
|
+
if isinstance(field, tuple):
|
|
118
|
+
if not any(f in self.description for f in field):
|
|
119
|
+
missing.append(field)
|
|
120
|
+
elif field not in self.description:
|
|
121
|
+
missing.append(field)
|
|
122
|
+
|
|
123
|
+
if pedantic and self._optional:
|
|
124
|
+
self._optional.extend(self._general_options)
|
|
125
|
+
for field in self.description:
|
|
126
|
+
found = False
|
|
127
|
+
for option in self._optional:
|
|
128
|
+
if isinstance(option, tuple):
|
|
129
|
+
if field in option:
|
|
130
|
+
found = True
|
|
131
|
+
elif field == option:
|
|
132
|
+
found = True
|
|
133
|
+
for option in self._required:
|
|
134
|
+
if isinstance(option, tuple):
|
|
135
|
+
if field in option:
|
|
136
|
+
found = True
|
|
137
|
+
elif field == option:
|
|
138
|
+
found = True
|
|
139
|
+
if not found:
|
|
140
|
+
too_many.append(field)
|
|
141
|
+
|
|
142
|
+
if missing or too_many:
|
|
143
|
+
raise Exception(
|
|
144
|
+
f"Fields for citation of type {self.type} is not correct:\n"
|
|
145
|
+
f"required fields: {self._required}\n"
|
|
146
|
+
f"optional fields: {self._optional}\n\n"
|
|
147
|
+
f"missing fields: {missing}\n"
|
|
148
|
+
f"non supported fields: {too_many}\n\n"
|
|
149
|
+
f"found fields: {self.description.keys()}"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class article(Citation):
|
|
154
|
+
def __init__(self, handle, description):
|
|
155
|
+
super().__init__(handle, description, "article")
|
|
156
|
+
self._required = ["author", "title", "journal", "year", "volume"]
|
|
157
|
+
self._optional = ["number", "pages", "month", "note", "key"]
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class book(Citation):
|
|
161
|
+
def __init__(self, handle, description):
|
|
162
|
+
super().__init__(handle, description, "book")
|
|
163
|
+
self._required = [("author", "editor"), "title", "publisher", "year"]
|
|
164
|
+
self._optional = [("volume", "number"), "series", "address", "edition", "month", "note", "key"]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class booklet(Citation):
|
|
168
|
+
def __init__(self, handle, description):
|
|
169
|
+
super().__init__(handle, description, "booklet")
|
|
170
|
+
self._required = ["title"]
|
|
171
|
+
self._optional = ["author", "howpublished", "address", "month", "year", "note", "key"]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class inbook(Citation):
|
|
175
|
+
def __init__(self, handle, description):
|
|
176
|
+
super().__init__(handle, description, "inbook")
|
|
177
|
+
self._required = [("author", "editor"), "title", ("chapter", "pages"), "publisher", "year"]
|
|
178
|
+
self._optional = [("volume", "number"), "series", "type", "address", "edition", "month", "note", "key"]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class incollection(Citation):
|
|
182
|
+
def __init__(self, handle, description):
|
|
183
|
+
super().__init__(handle, description, "incollection")
|
|
184
|
+
self._required = ["author", "title", "booktitle", "publisher", "year"]
|
|
185
|
+
self._optional = [
|
|
186
|
+
"editor",
|
|
187
|
+
("volume", "number"),
|
|
188
|
+
"series",
|
|
189
|
+
"type",
|
|
190
|
+
"chapter",
|
|
191
|
+
"pages",
|
|
192
|
+
"address",
|
|
193
|
+
"edition",
|
|
194
|
+
"month",
|
|
195
|
+
"note",
|
|
196
|
+
"key",
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class inproceedings(Citation):
|
|
201
|
+
def __init__(self, handle, description):
|
|
202
|
+
super().__init__(handle, description, "inproceedings")
|
|
203
|
+
self._required = ["author", "title", "booktitle", "year"]
|
|
204
|
+
self._optional = [
|
|
205
|
+
"editor",
|
|
206
|
+
("volume", "number"),
|
|
207
|
+
"series",
|
|
208
|
+
"pages",
|
|
209
|
+
"address",
|
|
210
|
+
"month",
|
|
211
|
+
"organization",
|
|
212
|
+
"publisher",
|
|
213
|
+
"note",
|
|
214
|
+
"key",
|
|
215
|
+
]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# conference has the same fields as inproceedings
|
|
219
|
+
class conference(inproceedings):
|
|
220
|
+
def __init__(self, handle, description):
|
|
221
|
+
super().__init__(handle, description, "conference")
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class manual(Citation):
|
|
225
|
+
def __init__(self, handle, description):
|
|
226
|
+
super().__init__(handle, description, "manual")
|
|
227
|
+
self._required = ["title"]
|
|
228
|
+
self._optional = ["author", "organization", "address", "edition", "month", "year", "note", "key"]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class mastersthesis(Citation):
|
|
232
|
+
def __init__(self, handle, description):
|
|
233
|
+
super().__init__(handle, description, "mastersthesis")
|
|
234
|
+
self._required = ["author", "title", "school", "year"]
|
|
235
|
+
self._optional = ["type", "address", "month", "note", "key"]
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class bachelorthesis(Citation):
|
|
239
|
+
def __init__(self, handle, description):
|
|
240
|
+
super().__init__(handle, description, "bachelorthesis")
|
|
241
|
+
self._required = ["author", "title", "school", "year"]
|
|
242
|
+
self._optional = ["type", "address", "month", "note", "key"]
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class internship(Citation):
|
|
246
|
+
def __init__(self, handle, description):
|
|
247
|
+
super().__init__(handle, description, "internship")
|
|
248
|
+
self._required = ["author", "title", "school", "year"]
|
|
249
|
+
self._optional = ["type", "address", "month", "note", "key"]
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class misc(Citation):
|
|
253
|
+
def __init__(self, handle, description):
|
|
254
|
+
super().__init__(handle, description, "misc")
|
|
255
|
+
self._optional = ["author", "title", "howpublished", "month", "year", "note", "key"]
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class phdthesis(Citation):
|
|
259
|
+
def __init__(self, handle, description):
|
|
260
|
+
super().__init__(handle, description, "phdthesis")
|
|
261
|
+
self._required = ["author", "title", "school", "year"]
|
|
262
|
+
self._optional = ["type", "address", "month", "note", "key"]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class proceedings(Citation):
|
|
266
|
+
def __init__(self, handle, description):
|
|
267
|
+
super().__init__(handle, description, "proceedings")
|
|
268
|
+
self._required = ["title", "year"]
|
|
269
|
+
self._optional = [
|
|
270
|
+
"editor",
|
|
271
|
+
("volume", "number"),
|
|
272
|
+
"series",
|
|
273
|
+
"address",
|
|
274
|
+
"month",
|
|
275
|
+
"publisher",
|
|
276
|
+
"organization",
|
|
277
|
+
"note",
|
|
278
|
+
"key",
|
|
279
|
+
]
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class techreport(Citation):
|
|
283
|
+
def __init__(self, handle, description):
|
|
284
|
+
super().__init__(handle, description, "techreport")
|
|
285
|
+
self._required = ["author", "title", "institution", "year"]
|
|
286
|
+
self._optional = ["type", "number", "address", "month", "note", "key"]
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
class unpublished(Citation):
|
|
290
|
+
def __init__(self, handle, description):
|
|
291
|
+
super().__init__(handle, description, "unpublished")
|
|
292
|
+
self._required = ["author", "title", "note"]
|
|
293
|
+
self._optional = ["month", "year", "key"]
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
_CITATION_TYPES = {
|
|
297
|
+
"article": article,
|
|
298
|
+
"book": book,
|
|
299
|
+
"booklet": booklet,
|
|
300
|
+
"inbook": inbook,
|
|
301
|
+
"incollection": incollection,
|
|
302
|
+
"inproceedings": inproceedings,
|
|
303
|
+
"conference": conference,
|
|
304
|
+
"manual": manual,
|
|
305
|
+
"mastersthesis": mastersthesis,
|
|
306
|
+
"bachelorthesis": bachelorthesis,
|
|
307
|
+
"internship": internship,
|
|
308
|
+
"misc": misc,
|
|
309
|
+
"phdthesis": phdthesis,
|
|
310
|
+
"proceedings": proceedings,
|
|
311
|
+
"techreport": techreport,
|
|
312
|
+
"unpublished": unpublished,
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
_REFERENCE_CACHE = None
|
|
316
|
+
_REFERENCE_JSON_PATH = pathlib.Path(__file__).resolve().parent / "citations.json"
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def _load_reference_db():
|
|
320
|
+
global _REFERENCE_CACHE
|
|
321
|
+
|
|
322
|
+
if _REFERENCE_CACHE is None:
|
|
323
|
+
with open(_REFERENCE_JSON_PATH, encoding="utf-8") as f:
|
|
324
|
+
data = json.load(f)
|
|
325
|
+
|
|
326
|
+
_REFERENCE_CACHE = {entry["id"]: entry for entry in data}
|
|
327
|
+
_REFERENCE_CACHE["__source__"] = str(_REFERENCE_JSON_PATH)
|
|
328
|
+
|
|
329
|
+
return _REFERENCE_CACHE
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def from_id(ref_id):
|
|
333
|
+
"""
|
|
334
|
+
Usage:
|
|
335
|
+
@citeme.from_id("Daniel_BA")
|
|
336
|
+
def foo():
|
|
337
|
+
...
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
def _decorator(func):
|
|
341
|
+
db = _load_reference_db()
|
|
342
|
+
|
|
343
|
+
if ref_id not in db:
|
|
344
|
+
raise KeyError(f"Reference ID '{ref_id}' not found in {db.get('__source__')}")
|
|
345
|
+
|
|
346
|
+
entry = dict(db[ref_id]) # copy
|
|
347
|
+
ref_type = entry.pop("type")
|
|
348
|
+
handle = entry.pop("id")
|
|
349
|
+
|
|
350
|
+
if ref_type not in _CITATION_TYPES:
|
|
351
|
+
raise ValueError(f"Unsupported citation type '{ref_type}'")
|
|
352
|
+
|
|
353
|
+
citation_cls = _CITATION_TYPES[ref_type]
|
|
354
|
+
citation = citation_cls(handle, entry)
|
|
355
|
+
|
|
356
|
+
@functools.wraps(func)
|
|
357
|
+
def wrapped(*args, **kwargs):
|
|
358
|
+
CiteMe().add_reference(citation)
|
|
359
|
+
return func(*args, **kwargs)
|
|
360
|
+
|
|
361
|
+
return wrapped
|
|
362
|
+
|
|
363
|
+
return _decorator
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def set_pedantic(value):
|
|
367
|
+
CiteMe.set_pedantic(value)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def set_check_fields(value):
|
|
371
|
+
CiteMe.set_check_fields(value)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def print_references():
|
|
375
|
+
CiteMe().print_references()
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def write_to_bibtex(filename):
|
|
379
|
+
CiteMe().write_to_bibtex(filename)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def write_to_html(filename, full=False):
|
|
383
|
+
CiteMe().write_to_html(filename, full=full)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def get_html(full=False):
|
|
387
|
+
return CiteMe().get_html(full=full)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
try:
|
|
391
|
+
from IPython.core.display import HTML, display
|
|
392
|
+
except ImportError:
|
|
393
|
+
pass
|
|
394
|
+
else:
|
|
395
|
+
|
|
396
|
+
def display_bibliography():
|
|
397
|
+
display(HTML(get_html(full=False)))
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TODO Code taken from : https://github.com/citation-file-format/citeme/tree/master
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
from bibtexparser.bibdatabase import BibDatabase
|
|
8
|
+
from bibtexparser.bwriter import BibTexWriter
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import BeautifulSoup
|
|
12
|
+
except ImportError:
|
|
13
|
+
bs = None
|
|
14
|
+
try:
|
|
15
|
+
from bs4 import BeautifulSoup
|
|
16
|
+
except ImportError:
|
|
17
|
+
bs4 = None
|
|
18
|
+
else:
|
|
19
|
+
bs4 = BeautifulSoup
|
|
20
|
+
else:
|
|
21
|
+
bs = BeautifulSoup.BeautifulSoup
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BibHtmlWriter(BibTexWriter):
|
|
27
|
+
def __init__(self):
|
|
28
|
+
super().__init__()
|
|
29
|
+
self.display_order = [
|
|
30
|
+
"author",
|
|
31
|
+
"title",
|
|
32
|
+
"booktitle",
|
|
33
|
+
"journal",
|
|
34
|
+
"editor",
|
|
35
|
+
"volume",
|
|
36
|
+
"number",
|
|
37
|
+
"series",
|
|
38
|
+
"publisher",
|
|
39
|
+
"year",
|
|
40
|
+
"pages",
|
|
41
|
+
"url",
|
|
42
|
+
"doi",
|
|
43
|
+
]
|
|
44
|
+
self.html_template = """
|
|
45
|
+
<html>
|
|
46
|
+
<head>
|
|
47
|
+
<link rel="stylesheet" href="css/bibstyle.css" />
|
|
48
|
+
</head>
|
|
49
|
+
</html>
|
|
50
|
+
<body>
|
|
51
|
+
{0}
|
|
52
|
+
</body>
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def write(self, bib_database, full=False):
|
|
56
|
+
"""
|
|
57
|
+
Converts a bibliographic database to a html-formatted string.
|
|
58
|
+
:param bib_database: bibliographic database to be converted to a BibTeX string
|
|
59
|
+
:type bib_database: BibDatabase
|
|
60
|
+
:return: BibTeX-formatted string
|
|
61
|
+
:rtype: str or unicode
|
|
62
|
+
"""
|
|
63
|
+
html = super().write(bib_database)
|
|
64
|
+
if full:
|
|
65
|
+
html = self.html_template.format(html)
|
|
66
|
+
|
|
67
|
+
soup = None
|
|
68
|
+
if bs4:
|
|
69
|
+
soup = bs4(html, "html5lib")
|
|
70
|
+
if bs:
|
|
71
|
+
soup = bs(html)
|
|
72
|
+
|
|
73
|
+
if soup:
|
|
74
|
+
return soup.prettify()
|
|
75
|
+
else:
|
|
76
|
+
return html
|
|
77
|
+
|
|
78
|
+
def _entries_to_bibtex(self, bib_database):
|
|
79
|
+
html = '<fieldset class="the_bibliography">\n<legend>The Bibliography</legend>'
|
|
80
|
+
if self.order_entries_by:
|
|
81
|
+
# TODO: allow sort field does not exist for entry
|
|
82
|
+
entries = sorted(bib_database.entries, key=lambda x: BibDatabase.entry_sort_key(x, self.order_entries_by))
|
|
83
|
+
else:
|
|
84
|
+
entries = bib_database.entries
|
|
85
|
+
|
|
86
|
+
if self.align_values:
|
|
87
|
+
# determine maximum field width to be used
|
|
88
|
+
widths = [max(map(len, entry.keys())) for entry in entries]
|
|
89
|
+
self._max_field_width = max(widths)
|
|
90
|
+
|
|
91
|
+
html += '<ol class="references">'
|
|
92
|
+
for entry in entries:
|
|
93
|
+
html += "<li>" + self._entry_to_bibtex(entry) + "</li>"
|
|
94
|
+
|
|
95
|
+
html += "</ol>"
|
|
96
|
+
html += "</fieldset>"
|
|
97
|
+
return html
|
|
98
|
+
|
|
99
|
+
def _entry_to_bibtex(self, entry):
|
|
100
|
+
html = ""
|
|
101
|
+
# Write BibTeX key
|
|
102
|
+
html += '<cite id="' + entry["ID"] + '" class="bib-entry">'
|
|
103
|
+
|
|
104
|
+
# create display_order of fields for this entry
|
|
105
|
+
# only those keys which are both in self.display_order and in entry.keys
|
|
106
|
+
display_order = [i for i in self.display_order if i in entry]
|
|
107
|
+
|
|
108
|
+
# Write field = value lines
|
|
109
|
+
for field in [i for i in display_order if i not in ["ENTRYTYPE", "ID"]]:
|
|
110
|
+
try:
|
|
111
|
+
if field == "url":
|
|
112
|
+
html += (
|
|
113
|
+
"\n<span class='bib-entry-field bib-entry-url bib-entry-"
|
|
114
|
+
+ "{0:<{1}}".format(field, self._max_field_width)
|
|
115
|
+
+ f"'><a href='{entry[field]}'>{entry[field]}<a></span>"
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
html += (
|
|
119
|
+
"\n<span class='bib-entry-field bib-entry-"
|
|
120
|
+
+ "{0:<{1}}".format(field, self._max_field_width)
|
|
121
|
+
+ "'>"
|
|
122
|
+
+ entry[field]
|
|
123
|
+
+ "</span>"
|
|
124
|
+
)
|
|
125
|
+
except TypeError as t:
|
|
126
|
+
raise TypeError("The field {} in entry {} must be a string".format(field, entry["ID"])) from t
|
|
127
|
+
html += "\n</cite>\n" + self.entry_separator
|
|
128
|
+
|
|
129
|
+
return html
|
|
130
|
+
|
|
131
|
+
def _comments_to_bibtex(self, bib_database):
|
|
132
|
+
return "".join(
|
|
133
|
+
[f'<div class="bib-comment">{comment}</div>\n{self.entry_separator}' for comment in bib_database.comments]
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def _preambles_to_bibtex(self, bib_database):
|
|
137
|
+
return "".join([f"{preamble}\n{self.entry_separator}" for preamble in bib_database.preambles])
|