1
1
import sys
2
2
import argparse
3
3
4
+ from PyQt5 import QtNetwork
4
5
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
6
7
from PyQt5 .QtWidgets import QPushButton , QFileDialog , QTreeWidget , QTreeWidgetItem , QAction , QSplitter , QTableWidgetItem
7
8
from PyQt5 .QtGui import QIcon
8
9
26
27
from pyqtgraph import ImageView
27
28
28
29
29
-
30
-
31
30
class dosparser ():
32
31
def __init__ (self ):
33
32
pass
@@ -45,6 +44,7 @@ def parse_file(file_path):
45
44
'log_info' : {}
46
45
}
47
46
df_lines = []
47
+ unique_events = []
48
48
df_metadata = []
49
49
50
50
with open (file_path , 'r' ) as file :
@@ -55,6 +55,9 @@ def parse_file(file_path):
55
55
match parts [0 ]:
56
56
case "$HIST" :
57
57
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 )]
58
61
case "$DOS" :
59
62
metadata ['log_runs_count' ] += 1
60
63
metadata ['log_device_info' ]['DOS' ] = {
@@ -68,27 +71,47 @@ def parse_file(file_path):
68
71
}
69
72
case "$DIG" | "$ADC" as device_type :
70
73
clean_type = device_type .strip ('$' )
71
- case "$ENV" | "$BATT" :
72
- df_metadata .append (parts )
74
+ case "$ENV" : # | "$BATT":
75
+ df_metadata .append (parts [ 2 :] )
73
76
case _:
74
77
print (f'Unknown row type: { parts [0 ]} ' )
75
78
76
79
77
80
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
+
78
89
time_column = np_spectrum [:, 1 ]
79
90
print (time_column )
80
91
np_spectrum = np_spectrum [:, 8 :]
81
92
print (np_spectrum )
82
93
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
+
83
102
sums = np .sum (np_spectrum [:, 1 :], axis = 1 )
84
103
hist = np .sum (np_spectrum [:, 1 :], axis = 0 )
85
104
86
105
minimal_time = time_column .min ()
87
106
maximal_time = time_column .max ()
88
107
duration = maximal_time - minimal_time
89
108
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 )
91
113
114
+
92
115
metadata ['log_info' ].update ({
93
116
'log_type' : 'xDOS_SPECTRAL' ,
94
117
'log_type_version' : '1.0' ,
@@ -97,11 +120,12 @@ def parse_file(file_path):
97
120
'log_duration' : duration ,
98
121
'spectral_count' : sums .shape [0 ],
99
122
'channels' : hist .shape [0 ],
123
+ 'hits_count' : len (unique_events ),
100
124
})
101
125
102
126
print ("Log file parsed in " , time .time ()- start_time , " seconds" )
103
127
104
- return [time_column , sums , hist , metadata , None , np_spectrum ]
128
+ return [time_column , sums , hist , metadata , np_metadata , np_spectrum ]
105
129
106
130
class LoadDataThread (QThread ):
107
131
data_loaded = pyqtSignal (list )
@@ -156,6 +180,14 @@ def plot(self, data):
156
180
plot_spectrum .setLabel ("left" , "Total count per channel" , units = "#" )
157
181
plot_spectrum .setLabel ("bottom" , "Channel" , units = "#" )
158
182
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
+
159
191
160
192
plot_spectrum .setLogMode (x = True , y = True )
161
193
plot_spectrum .showGrid (x = True , y = True )
@@ -1137,7 +1169,7 @@ def initUI(self):
1137
1169
1138
1170
self .upload_file_button = QPushButton ("Upload file" )
1139
1171
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_ () )
1141
1173
1142
1174
1143
1175
@@ -1229,6 +1261,64 @@ def open_spectrogram_view(self):
1229
1261
w .plot_data (matrix )
1230
1262
1231
1263
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
+
1232
1322
class PreferencesVindow (QDialog ):
1233
1323
def __init__ (self ):
1234
1324
super ().__init__ ()
0 commit comments