Skip to content

Commit 9a3018a

Browse files
committed
Airdos parser updates, add support of HITS messages
1 parent b8ccf14 commit 9a3018a

File tree

1 file changed

+98
-8
lines changed

1 file changed

+98
-8
lines changed

dosview/__init__.py

+98-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import sys
22
import argparse
33

4+
from PyQt5 import QtNetwork
45
from PyQt5.QtCore import QThread, pyqtSignal, QSettings
5-
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QHBoxLayout
6+
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QHBoxLayout, QFormLayout
67
from PyQt5.QtWidgets import QPushButton, QFileDialog, QTreeWidget, QTreeWidgetItem, QAction, QSplitter, QTableWidgetItem
78
from PyQt5.QtGui import QIcon
89

@@ -26,8 +27,6 @@
2627
from pyqtgraph import ImageView
2728

2829

29-
30-
3130
class dosparser():
3231
def __init__(self):
3332
pass
@@ -45,6 +44,7 @@ def parse_file(file_path):
4544
'log_info': {}
4645
}
4746
df_lines = []
47+
unique_events = []
4848
df_metadata = []
4949

5050
with open(file_path, 'r') as file:
@@ -55,6 +55,9 @@ def parse_file(file_path):
5555
match parts[0]:
5656
case "$HIST":
5757
df_lines.append(parts[1:])
58+
case "$HITS":
59+
# $HITS,4,404028.86,68,404211.95,75,404317.81,65,404558.1,94, ...
60+
unique_events += [(float(parts[i]), int(parts[i+1])) for i in range(2, len(parts), 2)]
5861
case "$DOS":
5962
metadata['log_runs_count'] += 1
6063
metadata['log_device_info']['DOS'] = {
@@ -68,27 +71,47 @@ def parse_file(file_path):
6871
}
6972
case "$DIG" | "$ADC" as device_type:
7073
clean_type = device_type.strip('$')
71-
case "$ENV" | "$BATT":
72-
df_metadata.append(parts)
74+
case "$ENV":# | "$BATT":
75+
df_metadata.append(parts[2:])
7376
case _:
7477
print(f'Unknown row type: {parts[0]}')
7578

7679

7780
np_spectrum = np.array(df_lines, dtype=float)
81+
82+
zero_columns = np.zeros((np_spectrum.shape[0], 1000))
83+
84+
# Připojení nulových sloupců k původnímu poli
85+
np_spectrum = np.hstack((np_spectrum, zero_columns))
86+
87+
print(np_spectrum)
88+
7889
time_column = np_spectrum[:, 1]
7990
print(time_column)
8091
np_spectrum = np_spectrum[:, 8:]
8192
print(np_spectrum)
8293

94+
#print("Unique events: ", unique_events)
95+
96+
for i, event in enumerate(unique_events):
97+
time_index = np.searchsorted(time_column, event[0])
98+
print(event[0], event[1], time_index)
99+
np_spectrum[time_index, event[1]] += 1
100+
# np_spectrum[event[0], i] += event[1]
101+
83102
sums = np.sum(np_spectrum[:, 1:], axis=1)
84103
hist = np.sum(np_spectrum[:, 1:], axis=0)
85104

86105
minimal_time = time_column.min()
87106
maximal_time = time_column.max()
88107
duration = maximal_time - minimal_time
89108

90-
#df_metadata = pd.DataFrame(df_metadata, columns=range(9))
109+
np_metadata = np.array(df_metadata).astype(float)
110+
#np_metadata[:, 2] -= minimal_time
111+
print("METADATA")
112+
print(np_metadata)
91113

114+
92115
metadata['log_info'].update({
93116
'log_type': 'xDOS_SPECTRAL',
94117
'log_type_version': '1.0',
@@ -97,11 +120,12 @@ def parse_file(file_path):
97120
'log_duration': duration,
98121
'spectral_count': sums.shape[0],
99122
'channels': hist.shape[0],
123+
'hits_count': len(unique_events),
100124
})
101125

102126
print("Log file parsed in ", time.time()-start_time, " seconds")
103127

104-
return [time_column, sums, hist, metadata, None, np_spectrum]
128+
return [time_column, sums, hist, metadata, np_metadata, np_spectrum]
105129

106130
class LoadDataThread(QThread):
107131
data_loaded = pyqtSignal(list)
@@ -156,6 +180,14 @@ def plot(self, data):
156180
plot_spectrum.setLabel("left", "Total count per channel", units="#")
157181
plot_spectrum.setLabel("bottom", "Channel", units="#")
158182

183+
np_metadata = data[4]
184+
##np_metadata[:,1] -=
185+
186+
print("METADATA")
187+
print(np_metadata[:,0]/60)
188+
print(np_metadata[:,6])
189+
plot_evolution.plot(np_metadata[:,0]/60, np_metadata[:,6], pen="b", symbol='p', symbolPen='b', symbolBrush=0.1, name="Pressure")
190+
159191

160192
plot_spectrum.setLogMode(x=True, y=True)
161193
plot_spectrum.showGrid(x=True, y=True)
@@ -1137,7 +1169,7 @@ def initUI(self):
11371169

11381170
self.upload_file_button = QPushButton("Upload file")
11391171
self.upload_file_button.setMaximumHeight(20)
1140-
#self.upload_file_button.clicked.connect(self.upload_file_dialog)
1172+
self.upload_file_button.clicked.connect(lambda: UploadFileDialog().exec_())
11411173

11421174

11431175

@@ -1229,6 +1261,64 @@ def open_spectrogram_view(self):
12291261
w.plot_data(matrix)
12301262

12311263

1264+
class UploadFileDialog(QDialog):
1265+
def __init__(self, parent=None):
1266+
super().__init__()
1267+
self._manager = QtNetwork.QNetworkAccessManager()
1268+
self._manager.finished.connect(self.on_request_finished)
1269+
self.initUI()
1270+
1271+
def initUI(self):
1272+
self.setWindowTitle("Upload file")
1273+
self.setGeometry(100, 100, 400, 300)
1274+
self.layout = QVBoxLayout()
1275+
self.setLayout(self.layout)
1276+
1277+
self.file_path = QLineEdit()
1278+
self.record_name = QLineEdit()
1279+
self.description = QTextEdit()
1280+
self.time_tracked = QCheckBox("Time tracked")
1281+
self.record_metadata = QTextEdit()
1282+
1283+
upload_button = QPushButton("Upload")
1284+
upload_button.clicked.connect(self.upload_file)
1285+
1286+
lay = QFormLayout()
1287+
lay.addRow("File path:", self.file_path)
1288+
lay.addRow("Record name:", self.record_name)
1289+
lay.addRow("Description:", self.description)
1290+
lay.addRow("Time tracked:", self.time_tracked)
1291+
lay.addRow("Record metadata:", self.record_metadata)
1292+
lay.addRow(upload_button)
1293+
1294+
self.upload_button = QPushButton("Upload")
1295+
self.upload_button.clicked.connect(self.upload_file)
1296+
self.layout.addLayout(lay)
1297+
1298+
def upload_file(self):
1299+
file_path = self.file_path.text()
1300+
print("Uploading file", file_path)
1301+
self.accept()
1302+
1303+
def on_request_finished(self, reply):
1304+
print("Upload finished")
1305+
self.accept()
1306+
1307+
@pyqtSlot()
1308+
def upload(self):
1309+
data = {
1310+
"name": self.record_name.text(),
1311+
"": ""
1312+
}
1313+
path = self.filepath_lineedit.text()
1314+
files = {"image": path}
1315+
multi_part = self.construct_multipart(data, files)
1316+
if multi_part:
1317+
url = QtCore.QUrl("http://127.0.0.1:8100/api/record/")
1318+
request = QtNetwork.QNetworkRequest(url)
1319+
reply = self._manager.post(request, multi_part)
1320+
multi_part.setParent(reply)
1321+
12321322
class PreferencesVindow(QDialog):
12331323
def __init__(self):
12341324
super().__init__()

0 commit comments

Comments
 (0)