def record_data(label: str, device: MetaWearClient) -> None: """ This function commits the data streamed to the database :param label: :param device: :return None: """ print(f"Logging data for {label}") acc, gyr = stream_data(device=device) print("Finished!") gx = gyr[0].replace('[', '').replace(']', '') gy = gyr[1].replace('[', '').replace(']', '') gz = gyr[2].replace('[', '').replace(']', '') ax = acc[0].replace('[', '').replace(']', '') ay = acc[1].replace('[', '').replace(']', '') az = acc[2].replace('[', '').replace(']', '') body_acc_x = BodyAccX(row_data=ax, label=label) body_acc_y = BodyAccY(row_data=ay, label=label) body_acc_z = BodyAccZ(row_data=az, label=label) body_gyr_x = BodyGyroX(row_data=gx, label=label) body_gyr_y = BodyGyroY(row_data=gy, label=label) body_gyr_z = BodyGyroZ(row_data=gz, label=label) print(f"Committing {label} data to database...") s = Session() s.add_all([ body_acc_x, body_acc_y, body_acc_z, body_gyr_x, body_gyr_y, body_gyr_z ]) s.commit() print("Finished!") s.close()
from dateutil import parser import utils from models import Zebra, Base, WateringHole from utils import Session, now, DAY Base.metadata.create_all(utils.engine) session = Session() session.add(Zebra(name='Stevie', when_born=parser.parse('2016-04-01'))) session.add( Zebra(name='Anya', when_born=parser.parse('2018-06-05'), number_of_stripes=73, when_stripes_counted=now() - 14 * DAY)) session.add( WateringHole( name="Ol' Watering Hole", # There are no watering holes in Berlin but Weißensee is pretty cool latitude=52.554133, longitude=13.463599, )) session.commit()