Update app.py
Browse files
app.py
CHANGED
|
@@ -27,14 +27,9 @@ def process_file(file_obj, acc_sensitivity):
|
|
| 27 |
# 路徑字串或 NamedString
|
| 28 |
with open(str(file_obj), 'r', encoding='utf-8') as f:
|
| 29 |
lines = f.read().splitlines()
|
| 30 |
-
|
| 31 |
output = io.StringIO()
|
| 32 |
output.write('Timestamp,AccelX,AccelY,AccelZ\n')
|
| 33 |
data = []
|
| 34 |
-
|
| 35 |
-
# 保存第一行的時間戳
|
| 36 |
-
first_timestamp = None
|
| 37 |
-
|
| 38 |
for line in lines:
|
| 39 |
if 'INFO' not in line:
|
| 40 |
continue
|
|
@@ -42,16 +37,6 @@ def process_file(file_obj, acc_sensitivity):
|
|
| 42 |
if not parts:
|
| 43 |
continue
|
| 44 |
timestamp = parts[0]
|
| 45 |
-
|
| 46 |
-
# 記錄第一次的時間戳
|
| 47 |
-
if first_timestamp is None:
|
| 48 |
-
first_timestamp = pd.to_datetime(timestamp)
|
| 49 |
-
|
| 50 |
-
# 檢查是否過了五秒
|
| 51 |
-
current_time = pd.to_datetime(timestamp)
|
| 52 |
-
if (current_time - first_timestamp).total_seconds() <= 10:
|
| 53 |
-
continue
|
| 54 |
-
|
| 55 |
idx = line.find('value (0x):')
|
| 56 |
if idx == -1:
|
| 57 |
continue
|
|
@@ -66,6 +51,10 @@ def process_file(file_obj, acc_sensitivity):
|
|
| 66 |
output.write(f"{timestamp},{f_acc_x:.4f},{f_acc_y:.4f},{f_acc_z:.4f}\n")
|
| 67 |
data.append((timestamp, f_acc_x, f_acc_y, f_acc_z))
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
output.seek(0)
|
| 70 |
return output, data
|
| 71 |
|
|
@@ -111,4 +100,4 @@ with demo:
|
|
| 111 |
btn = gr.Button("執行轉換與繪圖")
|
| 112 |
btn.click(fn=gradio_interface, inputs=[file_input, acc_input], outputs=[csv_output, plot_output, msg_output])
|
| 113 |
|
| 114 |
-
demo.launch()
|
|
|
|
| 27 |
# 路徑字串或 NamedString
|
| 28 |
with open(str(file_obj), 'r', encoding='utf-8') as f:
|
| 29 |
lines = f.read().splitlines()
|
|
|
|
| 30 |
output = io.StringIO()
|
| 31 |
output.write('Timestamp,AccelX,AccelY,AccelZ\n')
|
| 32 |
data = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
for line in lines:
|
| 34 |
if 'INFO' not in line:
|
| 35 |
continue
|
|
|
|
| 37 |
if not parts:
|
| 38 |
continue
|
| 39 |
timestamp = parts[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
idx = line.find('value (0x):')
|
| 41 |
if idx == -1:
|
| 42 |
continue
|
|
|
|
| 51 |
output.write(f"{timestamp},{f_acc_x:.4f},{f_acc_y:.4f},{f_acc_z:.4f}\n")
|
| 52 |
data.append((timestamp, f_acc_x, f_acc_y, f_acc_z))
|
| 53 |
|
| 54 |
+
# 刪除第一筆資料
|
| 55 |
+
if data:
|
| 56 |
+
data.pop(0)
|
| 57 |
+
|
| 58 |
output.seek(0)
|
| 59 |
return output, data
|
| 60 |
|
|
|
|
| 100 |
btn = gr.Button("執行轉換與繪圖")
|
| 101 |
btn.click(fn=gradio_interface, inputs=[file_input, acc_input], outputs=[csv_output, plot_output, msg_output])
|
| 102 |
|
| 103 |
+
demo.launch()
|