def commentAndRedirect(self, view: Ui_MainWindow): now = datetime.date.today() base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() trainingUrl = session.query(TrainingUrlModel).filter( TrainingUrlModel.id == int(view.video_id)).first() lastRecord = session.query(func.max( TrainingUrlModel.priority)).scalar() trainingUrl.priority = lastRecord + 1 comment = textwrap.shorten( view.f_exercise_declined_comment.toPlainText(), 100) ins = TrainingModel(comment=comment, date=now, createdAt=now, updatedAt=now, trainingUrl=trainingUrl, grade=None) session.add(ins) session.commit() EventDispatcher().getDispatcher().raise_event("onHomeViewReload", view=view) EventDispatcher().getDispatcher().raise_event("onVideoViewReload", view=view) view.page_main.setCurrentWidget(view.view_main)
def configViewVideo(self, view: Ui_MainWindow): self.view = view view.video_widget = QVideoWidget(view.video_box) view.video_box.show() view.video_widget.setFixedSize(view.video_box.size()) base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() trainingUrl = session.query(TrainingUrlModel).order_by( TrainingUrlModel.priority).first() view.video_id = trainingUrl.id view.video_media_player = QMediaPlayer(None, QMediaPlayer.StreamPlayback) view.f_video_length.setRange(0, 0) view.f_video_length.sliderMoved.connect(self.setPosition) view.video_media_player.setMedia( QMediaContent(QUrl.fromLocalFile(trainingUrl.url))) view.video_media_player.setVideoOutput(view.video_widget) view.video_media_player.positionChanged.connect(self.positionChanged) view.video_media_player.durationChanged.connect(self.durationChanged) view.b_video_play.setEnabled(True) view.b_video_play.clicked.connect(lambda: self.play(view)) view.b_video_exercise_yes.clicked.connect( lambda: view.page_main.setCurrentWidget(view.view_exercise_grade)) view.b_video_exercise_no.clicked.connect( lambda: view.page_main.setCurrentWidget(view.view_exercise_declined ))
def onKernelStart(self): from app.src.models.BaseModel import BaseModel baseModel = BaseModel() declarative = baseModel.getDeclarative() declarative.metadata.create_all(baseModel.getEngine()) fixture_loader = FixtureLoader() fixture_loader.load()
def generate(self): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() ins = SettingModel(startWithSystem=False, checkAbsence=True, exerciseInterval=30, timeAbsence=0) session.add(ins) session.commit()
def generate(self): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() config = Config().getConfig() ins = TrainingUrlModel(name="Triceps", url=os.path.join(Config().getConfig()["path"], 'video', 'Triceps.wmv'), description="Triceps exercise", priority=1) session.add(ins) ins = TrainingUrlModel(name="Biceps", url=os.path.join(Config().getConfig()["path"], 'video', 'Biceps.wmv'), description="Bending for overall back relaxation", priority=2) session.add(ins) ins = TrainingUrlModel(name="Side Bends", url=os.path.join(Config().getConfig()["path"], 'video' ,'Side-bends.wmv'), description="Sideways bending to train lats and obliques", priority=3) session.add(ins) ins = TrainingUrlModel(name="Biceps Stretch", url=os.path.join(Config().getConfig()["path"], 'video', 'Spotmarch.wmv'), description="Spot marching exercise", priority=4) session.add(ins) ins = TrainingUrlModel(name="Forearm Stretch", url=os.path.join(Config().getConfig()["path"], 'video', 'Forearm stretch.wmv'), description="Palm facing up / Palm facing down for forearm flexors exercise", priority=5) session.add(ins) ins = TrainingUrlModel(name="Hyperextension", url=os.path.join(Config().getConfig()["path"], 'video', 'Hyperextension.wmv'), description="Back extension and abs stretch exercise", priority=6) session.add(ins) ins = TrainingUrlModel(name="Neck Stretch", url=os.path.join(Config().getConfig()["path"], 'video', 'Neck stretch.wmv'), description="Front, back and side of the neck exercise", priority=7) session.add(ins) ins = TrainingUrlModel(name="Palming", url=os.path.join(Config().getConfig()["path"], 'video','Palming.wmv'), description="Eye and facial muscles relaxation exercise", priority=8) session.add(ins) ins = TrainingUrlModel(name="Shrugs", url=os.path.join(Config().getConfig()["path"], 'video','Shrugs.wmv'), description="Trapezius and neck muscles exercise", priority=9) session.add(ins) ins = TrainingUrlModel(name="Full Body Stretch", url=os.path.join(Config().getConfig()["path"], 'video', 'Full body stretch.wmv'), description="Overall body exercise", priority=10) session.add(ins) ins = TrainingUrlModel(name="Torso Twist", url=os.path.join(Config().getConfig()["path"], 'video', 'Torso-twist.wmv'), description="Spinal mobility exercise", priority=11) session.add(ins) ins = TrainingUrlModel(name="Forward bending", url=os.path.join(Config().getConfig()["path"], 'video', 'Forward bending.wmv'), description="Forward bending exercise", priority=12) session.add(ins) session.commit()
def findTrainingQuantityForDay(self, start: datetime): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() start_day = start.strftime("%Y-%m-%d 00:00:00") end = start + datetime.timedelta(days=1) end_day = end.strftime("%Y-%m-%d 00:00:00") query = session.query("app.src.models.TrainingModel") query = query.filter( and_( TrainingModel.grade != None, TrainingModel.createdAt >= start_day, TrainingModel.createdAt < end_day, )) return query.with_entities(func.count()).scalar()
def load(self): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() trainingUrl = session.query(TrainingUrlModel).first() if trainingUrl is None: # get all paths we use join to fix problem with "/" per os path = os.path.join(Config().getConfig()["path"], "app", "src", "fixtures") module_loader = ModuleLoader() for file in glob(os.path.join(path, "*.py")): module = module_loader.loadFromDir(file, "app.src.fixtures") module().generate()
def setupCamera(self): scheduler = BasicScheduler() base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() setting = session.query(SettingModel).first() time = 2 if setting.checkAbsence: scheduler.rescheduleJob(time, "absence_timer", self.runAbsenceTimer) # tutaj nie jestem pewien czy nie powinno się dodawać # rescheduleJob().add_job bo w zasadzie add_job # realizuje się wewnątrz tej funkcji else: job = scheduler.getScheduler().get_job("absence_timer") if job: job.remove()
def findMonthTrainingQuantity(self): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() start_date = date.today().replace(day=1) start_day = start_date.strftime("%Y-%m-%d 00:00:00") tomorrow = date.today() + datetime.timedelta(days=1) end_day = tomorrow.strftime("%Y-%m-%d 00:00:00") query = session.query("app.src.models.TrainingModel") query = query.filter( and_( TrainingModel.grade != None, TrainingModel.createdAt >= start_day, TrainingModel.createdAt < end_day, )) return query.with_entities(func.count()).scalar()
def gradeAndRedirect(self, view: Ui_MainWindow, grade: int): now = datetime.date.today() base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() trainingUrl = session.query(TrainingUrlModel).filter(TrainingUrlModel.id == int(view.video_id)).first() lastRecord = session.query(func.max(TrainingUrlModel.priority)).scalar() trainingUrl.priority = lastRecord + 1 ins = TrainingModel(grade=grade, date=now, createdAt=now, updatedAt=now, trainingUrl=trainingUrl) session.add(ins) session.commit() EventDispatcher().getDispatcher().raise_event("onHomeViewReload", view=view) EventDispatcher().getDispatcher().raise_event("onVideoViewReload", view=view) view.page_main.setCurrentWidget(view.view_main)
def setupNotifications(self): scheduler = BasicScheduler() base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() setting = session.query(SettingModel).first() time = setting.exerciseInterval if time > 2: # Inform one minute before scheduler.rescheduleJob(time - 1, "exercise_block_scn_0", self.notify) # inform a while before scheduler.rescheduleJob(time - 0.05, "exercise_block_scn_1", self.notify) # @todo block screen scheduler.rescheduleJob(time, "exercise_block_scn_2", self.notify) scheduler.getScheduler().add_job(self.changeView, 'interval', minutes=time, id="exercise_block_scn_3", replace_existing=True, )
def runAbsenceTimer(self, setting=SettingModel): base = BaseModel() Session = sessionmaker(bind=base.getEngine()) session = Session() setting = session.query(SettingModel).first() face_detector = FaceDetector() if not face_detector.isUserDetected(): setting.timeAbsence += 1 else: setting.timeAbsence = 0 if setting.timeAbsence == 3: # odpalenie drugiego listenera, który wszystko resetuje i kod biegnie od nowa EventDispatcher().getDispatcher().raise_event("onSettingsUpdate") setting.timeAbsence = 0 session.merge(setting) session.commit()
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey from sqlalchemy.orm import relationship from app.src.models.BaseModel import BaseModel base = BaseModel() Base = base.getDeclarative() class TrainingModel(Base): __tablename__ = "training" id = Column(Integer(), primary_key=True, nullable=False) grade = Column(Integer(), nullable=True, default=None) comment = Column(String(100), nullable=True) trainingUrlId = Column(Integer(), ForeignKey('training_url.id')) trainingUrl = relationship("TrainingUrlModel", back_populates="trainings") date = Column(DateTime(), nullable=False) createdAt = Column(DateTime(), nullable=False) updatedAt = Column(DateTime(), nullable=False)