CoreDataX 0.9.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.
- CoreDataX/CDX.py +3928 -0
- CoreDataX/example.csv +4 -0
- CoreDataX/loader.py +159 -0
- CoreDataX/requirements.txt +4 -0
- CoreDataX/server.py +38 -0
- coredatax-0.9.0.dist-info/METADATA +25 -0
- coredatax-0.9.0.dist-info/RECORD +8 -0
- coredatax-0.9.0.dist-info/WHEEL +4 -0
CoreDataX/example.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
magneticReference,setupReference,frequency,magneticFluxDensityPeak,magneticFieldDcBias,magneticFieldWaveformType,temperature,volumetricLosses,userId
|
|
2
|
+
3C94 --- TX-20-10-7,My setup,112160,0.0885929,0,Triangular,25,87198.16,1
|
|
3
|
+
3C94 --- TX-20-10-7,My setup,112160,0.0990441,0,Triangular,25,114103.336,1
|
|
4
|
+
3C94 --- TX-20-10-7,My setup,112160,0.110654,0,Triangular,25,150794.77,1
|
CoreDataX/loader.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import pandas
|
|
2
|
+
import numpy
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import datetime
|
|
6
|
+
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
|
|
7
|
+
import server
|
|
8
|
+
import CDX
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CsvLoader:
|
|
12
|
+
def __init__(self, token):
|
|
13
|
+
self.magnetics_data_cache = {}
|
|
14
|
+
self.setups_data_cache = {}
|
|
15
|
+
self.user_data = None
|
|
16
|
+
self.token = token
|
|
17
|
+
|
|
18
|
+
def check_columns(self, columns):
|
|
19
|
+
required_columns = ["magneticReference", "frequency", "magneticFluxDensityPeak", "temperature", "volumetricLosses"]
|
|
20
|
+
missing_columns = []
|
|
21
|
+
for column in required_columns:
|
|
22
|
+
if column not in columns:
|
|
23
|
+
missing_columns.append(column)
|
|
24
|
+
if len(missing_columns) > 0:
|
|
25
|
+
raise ImportError(f"Missing columns: {missing_columns}")
|
|
26
|
+
|
|
27
|
+
return True
|
|
28
|
+
|
|
29
|
+
def check_data(self, data):
|
|
30
|
+
columns_to_check = []
|
|
31
|
+
for column in data:
|
|
32
|
+
if column not in ["magneticReference", "setupReference", "magneticFieldWaveformType"]:
|
|
33
|
+
if not isinstance(data[column].dtype, (numpy.dtypes.Float64DType, numpy.dtypes.Int64DType)):
|
|
34
|
+
columns_to_check.append(column)
|
|
35
|
+
|
|
36
|
+
for column in columns_to_check:
|
|
37
|
+
for index, value in enumerate(data[column]):
|
|
38
|
+
print(value)
|
|
39
|
+
try:
|
|
40
|
+
float(value)
|
|
41
|
+
except ValueError:
|
|
42
|
+
raise ImportError(f"Error in column {column}, row {index}: {value} is not a number")
|
|
43
|
+
# print(value.dtype)
|
|
44
|
+
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
def get_magnetic_data(self, reference):
|
|
48
|
+
if reference not in self.magnetics_data_cache:
|
|
49
|
+
self.magnetics_data_cache[reference] = server.get_magnetic_data(reference, self.token)
|
|
50
|
+
return self.magnetics_data_cache[reference]
|
|
51
|
+
|
|
52
|
+
def get_setup_data(self, reference):
|
|
53
|
+
if reference not in self.setups_data_cache:
|
|
54
|
+
self.setups_data_cache[reference] = server.get_setup_data(reference, self.token)
|
|
55
|
+
return self.setups_data_cache[reference]
|
|
56
|
+
|
|
57
|
+
def get_user_data(self,):
|
|
58
|
+
if self.user_data is None:
|
|
59
|
+
self.user_data = server.get_user_data(self.token)
|
|
60
|
+
return self.user_data
|
|
61
|
+
|
|
62
|
+
def convert_data_to_cdx(self, data, where="N/A"):
|
|
63
|
+
results = []
|
|
64
|
+
for index, row in data.iterrows():
|
|
65
|
+
magnetic_data = self.get_magnetic_data(row["magneticReference"])
|
|
66
|
+
user_id = self.get_user_data()
|
|
67
|
+
magnetic = magnetic_data["magnetic"]
|
|
68
|
+
magnetic_index = magnetic_data["index"]
|
|
69
|
+
result = CDX.OutputsCoreLossesOutput(
|
|
70
|
+
coreLosses=row["volumetricLosses"] * magnetic["core"]["processedDescription"]["effectiveParameters"]["effectiveVolume"],
|
|
71
|
+
methodUsed=row["setupReference"],
|
|
72
|
+
origin=CDX.ResultOrigin.measurement)
|
|
73
|
+
result.temperature = row["temperature"]
|
|
74
|
+
result.volumetricLosses = row["volumetricLosses"]
|
|
75
|
+
metadata = CDX.Metadata(
|
|
76
|
+
date=str(datetime.datetime.now()),
|
|
77
|
+
where=where,
|
|
78
|
+
who=str(user_id),
|
|
79
|
+
)
|
|
80
|
+
conditions = CDX.OperatingConditions(ambientTemperature=row["temperature"])
|
|
81
|
+
|
|
82
|
+
excitation = CDX.OperatingPointExcitation(frequency=row["frequency"])
|
|
83
|
+
b_field_signal = CDX.SignalDescriptor()
|
|
84
|
+
b_field_processed = CDX.Processed(
|
|
85
|
+
offset=row["magneticFieldDcBias"],
|
|
86
|
+
label=CDX.WaveformLabel(row["magneticFieldWaveformType"]),
|
|
87
|
+
peak=row["magneticFluxDensityPeak"]
|
|
88
|
+
)
|
|
89
|
+
b_field_signal.processed = b_field_processed
|
|
90
|
+
excitation.magneticFluxDensity = b_field_signal
|
|
91
|
+
|
|
92
|
+
operatingPoint = CDX.OperatingPoint(
|
|
93
|
+
conditions=conditions,
|
|
94
|
+
excitationsPerWinding=[excitation]
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# cdx.result = result
|
|
98
|
+
cdx = CDX.Cdx(
|
|
99
|
+
magnetic=row["magneticReference"],
|
|
100
|
+
metadata=metadata,
|
|
101
|
+
setup=row["setupReference"],
|
|
102
|
+
operatingPoint=operatingPoint,
|
|
103
|
+
result=result,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
data = {
|
|
107
|
+
'cdx': cdx.to_dict(),
|
|
108
|
+
'magnetic_index': magnetic_index,
|
|
109
|
+
'user_id': user_id,
|
|
110
|
+
'volumetric_losses': row["volumetricLosses"],
|
|
111
|
+
'frequency': row["frequency"],
|
|
112
|
+
'temperature': row["temperature"],
|
|
113
|
+
'magnetic_flux_density_peak': row["magneticFluxDensityPeak"],
|
|
114
|
+
'created_at': str(datetime.datetime.now()),
|
|
115
|
+
'updated_at': str(datetime.datetime.now())
|
|
116
|
+
}
|
|
117
|
+
results.append(data)
|
|
118
|
+
return results
|
|
119
|
+
|
|
120
|
+
def load(self, filepath):
|
|
121
|
+
data = pandas.read_csv(filepath)
|
|
122
|
+
self.check_columns(data.columns)
|
|
123
|
+
self.check_data(data)
|
|
124
|
+
data_to_insert = self.convert_data_to_cdx(data)
|
|
125
|
+
print(len(data_to_insert))
|
|
126
|
+
server.insert_data(data_to_insert)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class CdxLoader:
|
|
130
|
+
def __init__(self, token):
|
|
131
|
+
self.user_data = None
|
|
132
|
+
self.token = token
|
|
133
|
+
|
|
134
|
+
def get_user_data(self,):
|
|
135
|
+
if self.user_data is None:
|
|
136
|
+
self.user_data = server.get_user_data(self.token)
|
|
137
|
+
return self.user_data
|
|
138
|
+
|
|
139
|
+
def convert_cdx_to_dict(self, data, where="N/A"):
|
|
140
|
+
# TODO
|
|
141
|
+
pass
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
if __name__ == '__main__': # pragma: no cover
|
|
145
|
+
|
|
146
|
+
if len(sys.argv) < 2:
|
|
147
|
+
raise AttributeError("Missing token. Execution syntax is: 'python3 csv_loader.py token file.csv/cdx'")
|
|
148
|
+
if len(sys.argv) < 3:
|
|
149
|
+
raise AttributeError("Missing CSV/CDX file. Execution syntax is: 'python3 csv_loader.py token file.csv/cdx'")
|
|
150
|
+
token = sys.argv[1]
|
|
151
|
+
filepath = sys.argv[2]
|
|
152
|
+
if os.path.splitext(filepath)[1].lower() == '.csv':
|
|
153
|
+
csv_loader = CsvLoader(token)
|
|
154
|
+
csv_loader.load(filepath)
|
|
155
|
+
elif os.path.splitext(filepath)[1].lower() == '.cdx':
|
|
156
|
+
cdx_loader = CdxLoader(token)
|
|
157
|
+
cdx_loader.load(filepath)
|
|
158
|
+
else:
|
|
159
|
+
raise ValueError(f"Unknown file format: {filepath}")
|
CoreDataX/server.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_magnetic_data(reference, token):
|
|
6
|
+
url = 'https://coredatax.com:4242/read_magnetic_by_reference'
|
|
7
|
+
body = {'reference': reference, 'token': token}
|
|
8
|
+
|
|
9
|
+
x = requests.post(url, json=body)
|
|
10
|
+
|
|
11
|
+
return json.loads(x.text)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_setup_data(reference, token):
|
|
15
|
+
url = 'https://coredatax.com:4242/read_setup_by_reference'
|
|
16
|
+
body = {'reference': reference, 'token': token}
|
|
17
|
+
|
|
18
|
+
x = requests.post(url, json=body)
|
|
19
|
+
|
|
20
|
+
return json.loads(x.text)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_user_data(token):
|
|
24
|
+
url = 'https://coredatax.com:4242/get_user_data_by_token'
|
|
25
|
+
body = {'token': token}
|
|
26
|
+
|
|
27
|
+
x = requests.post(url, json=body)
|
|
28
|
+
|
|
29
|
+
return x.text
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def insert_data(data):
|
|
33
|
+
url = 'https://coredatax.com:4242/insert_data'
|
|
34
|
+
body = {'data': data}
|
|
35
|
+
|
|
36
|
+
x = requests.post(url, json=body)
|
|
37
|
+
|
|
38
|
+
return x.text
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: CoreDataX
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: API for uploading data to the PSMA's CoreDataeXchange project.
|
|
5
|
+
Project-URL: Homepage, https://coredatax.com
|
|
6
|
+
Project-URL: Repository, https://github.com/CoreDataX/CoreDataX
|
|
7
|
+
Project-URL: Contact, https://coredatax.com
|
|
8
|
+
Author-email: George Slama <gslama@wat.midco.net>, Alfonso Martinez <Alfonso_VII@hotmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: pandas
|
|
22
|
+
Requires-Dist: requests
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
API for uploading data to the PSMA's CoreDataeXchange project.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
CoreDataX/CDX.py,sha256=3gA9modStW7_u71hN4Ge_lYR5fmQ_baluCEotUGi00g,169185
|
|
2
|
+
CoreDataX/example.csv,sha256=hcvxo1PFj0zlsjqGWnzQer4SV5YAgl4r1qWGeLQOVko,370
|
|
3
|
+
CoreDataX/loader.py,sha256=6f0E1l_05njK-hahJQ1ooB2vGkXGYfssEPrkMk_hkXg,6157
|
|
4
|
+
CoreDataX/requirements.txt,sha256=c2pErrxar6opsvTKaOovQgQyn2sc6_26VjqqWqFS-hs,28
|
|
5
|
+
CoreDataX/server.py,sha256=zCEuKs_auLQc07SuNTyEagY8ulKwzRbsNa6R2Gw2Kr4,858
|
|
6
|
+
coredatax-0.9.0.dist-info/METADATA,sha256=-PYhw1zjHvRvNxbr3gjaBkjATQTLIGAZ5YiNAnaIw7s,1069
|
|
7
|
+
coredatax-0.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
coredatax-0.9.0.dist-info/RECORD,,
|