init workflow

This commit is contained in:
2025-04-20 23:23:41 +02:00
parent 05abcca6f5
commit ed7c1bf62e
12 changed files with 201 additions and 88 deletions

View File

@@ -0,0 +1,4 @@
from .device import Device
from .slider import Slider
from .entry import Entry

View File

@@ -1,7 +1,9 @@
from bleak import BleakClient, BleakScanner
import pandas as pd
from tkinter.ttk import Entry
from tkinter.messagebox import showerror, showinfo
import asyncio
from time import time
from ..config import MILLIS_UUID, WEIGHT_UUID
@@ -32,21 +34,26 @@ class Device:
def disconnect(self):
self.device = None
async def read_values(self, interval):
while await asyncio.sleep(interval, True):
if self.is_connected:
async with BleakClient(self.device.address) as client:
while await asyncio.sleep(interval, True):
millis = await client.read_gatt_char(MILLIS_UUID)
millis = int.from_bytes(millis, byteorder='little') # Adjust based on your data format
weight = await client.read_gatt_char(WEIGHT_UUID)
weight = int.from_bytes(weight, byteorder='little') # Adjust based on your data format
self.timestamps.append(millis)
self.weights.append(weight)
async def read_values(self, duration):
if not await self.connect():
showerror("Record Data", f"Device {self.device_name.get()} not found!")
return
self.clear_data()
async with BleakClient(self.device.address) as client:
showinfo("Recording Data", f"Recording data for {duration} seconds.")
time_start = time()
time_passed = 0
while time_passed < duration:
millis = await client.read_gatt_char(MILLIS_UUID)
millis = int.from_bytes(millis, byteorder='little') # Adjust based on your data format
weight = await client.read_gatt_char(WEIGHT_UUID)
weight = int.from_bytes(weight, byteorder='little') # Adjust based on your data format
self.timestamps.append(millis)
self.weights.append(weight)
if not self.is_connected:
break
time_passed = time() - time_start
def clear_data(self):

19
filter_dev/gui/entry.py Normal file
View File

@@ -0,0 +1,19 @@
from tkinter import ttk
class Entry:
def __init__(self, master, title, default_value):
self.label = ttk.Label(master, text=title)
self.entry = ttk.Entry(master)
self.entry.insert(0, default_value) # Set default value
def get(self):
return self.entry.get()
def pack(self, **kwargs):
self.label.pack(**kwargs)
self.entry.pack(**kwargs)
def pack_forget(self):
self.label.pack_forget()
self.entry.pack_forget()

View File

@@ -0,0 +1,3 @@
from .record_form import RecordForm
from .filter_form import FilterForm
from .data_stats import DataStats

View File

@@ -0,0 +1,26 @@
import tkinter as tk
from tkinter import ttk
import pandas as pd
class DataStats(tk.Frame):
def __init__(self, master, command, **kwargs):
super().__init__(master, **kwargs)
self.items = ttk.Label(self, text="Recorded Items:")
self.items.pack()
self.duration = ttk.Label(self, text="Time Delta:")
self.duration.pack()
self.std = ttk.Label(self, text="Raw Weights:")
self.std.pack()
self.reset_button = ttk.Button(self, text="Reset", command=command)
self.reset_button.pack()
def update_stats(self, df: pd.DataFrame):
self.items.config(text=f"Recorded Items: {df.size:01d}")
delta = df['timestamps'].diff().shift(-1)
self.duration.config(text=f"Time Delta: {delta.mean():.2f} ± {delta.std():.2f}")
self.std.config(text=f"Raw Weights: {df['weights'].mean():.2f} ± {df['weights'].std():.2f}")

View File

@@ -0,0 +1,15 @@
import tkinter as tk
from tkinter import ttk
class FilterForm(tk.Frame):
def __init__(self, master, command, **kwargs):
super().__init__(master, **kwargs)
self.filter_type_label = ttk.Label(self, text="Filter:")
self.filter_type_label.pack()
self.filter_type_combobox = ttk.Combobox(self, values=["MovAvg"])
self.filter_type_combobox.pack()
self.filter_type_combobox.set("MovAvg") # Set default value
self.change_filter = ttk.Button(self, text="Change Filter", command=command)
self.change_filter.pack()

View File

@@ -0,0 +1,19 @@
import tkinter as tk
from tkinter import ttk
from ..slider import Slider
class RecordForm(tk.Frame):
def __init__(self, master, record_command, **kwargs):
super().__init__(master, **kwargs)
self.device_label = ttk.Label(self, text="Device Name:")
self.device_label.pack(pady=10)
self.device_name = ttk.Entry(self)
self.device_name.insert(0, "Smaage") # Set default value
self.device_name.pack()
self.record_time = Slider(self, "Record Time:", 10, 30, 10, lambda: None)
self.record_time.pack(pady=10)
self.record_button = ttk.Button(self, text="Record Data", command=record_command)
self.record_button.pack(pady=10)