示例#1
0
    def build_lift_selected(self, lift=None):
        # TODO: Clean this mess up and make it pretty
        # TODO: Clear current workout stats
        if lift:
            if isinstance(lift, QtWidgets.QTreeWidgetItem):
                txt = lift.text(1)
            elif isinstance(lift, str):
                txt = lift
            else:
                txt = ''
        else:
            txt = self.build_lifts.currentItem().text(1)

        if txt:
            if txt == self._build_cur_lift:
                return
            else:
                self._build_cur_lift = txt
        else:
            return

        pre_workouts = analysis.get_max_e1RM(self.db.workout_log[self.db.workout_log.Lift == self._build_cur_lift])
        pre_e1RM = pre_workouts[pre_workouts.notnull()][-1]
        self._build_tgt_e1rm = pre_e1RM
        self.build_populate_rpe_table()
        self.build_target.setValue(int(self._build_tgt_e1rm))
        self.build_btn_add.setEnabled(True)
        self.build_workout_switch_tables()
        self.build_data_changed.emit()
示例#2
0
    def log_populate_stats(self, lift=None):
        if pd.isnull(self.log_date) or self._log_table_view.empty:
            return
        self.log_tree.clear()

        cur_wkt = self.db.workout_log[self.db.workout_log.index == self._log_date]

        pre_30d = self.db.workout_log[self.db.workout_log.index >= self._log_date - pd.Timedelta(days=30)]
        pre_30d = pre_30d[pre_30d.index < self._log_date]

        e1RM_node = QTreeWidgetItem()
        e1RM_node.setText(0, 'e1RMs:')
        for lift, lift_data in cur_wkt.groupby('Lift'):
            e1RM = max(analysis.get_max_e1RM(lift_data))
            if pre_30d.Lift.isin([lift]).any():
                e1RM_pre_30d = max(analysis.get_max_e1RM(pre_30d[pre_30d.Lift == lift]))
            else:
                e1RM_pre_30d = ''

            child_node = QTreeWidgetItem()
            child_node.setText(0, str(lift))
            child_node.setText(1, str(e1RM))
            child_node.setText(2, str(e1RM_pre_30d))
            e1RM_node.addChild(child_node)

        volume_node = QTreeWidgetItem()
        volume_node.setText(0, 'Volume:')
        for cat, cat_data in cur_wkt.groupby('Category'):
            vol = sum(cat_data.Volume)
            if pre_30d.Category.isin([cat]).any():
                vol_pre_30d = round(pre_30d[pre_30d.Category == cat].resample('1d', how=np.sum).Volume.mean())
            else:
                vol_pre_30d = ''

            child_node = QTreeWidgetItem()
            child_node.setText(0, str(cat))
            child_node.setText(1, str(vol))
            child_node.setText(2, str(vol_pre_30d))
            volume_node.addChild(child_node)

        nt_node = QTreeWidgetItem()
        nt_node.setText(0, 'Normalized Tonnage:')
        for cat, cat_data in cur_wkt.groupby('Category'):
            nt = round(analysis.calc_normalized_tonnage(cat_data).sum())
            if pre_30d.Category.isin([cat]).any():
                nt_pre_30d = round(analysis.calc_normalized_tonnage(
                    pre_30d[pre_30d.Category == cat]).resample('1d', how=np.sum).mean())
            else:
                nt_pre_30d = ''

            child_node = QTreeWidgetItem()
            child_node.setText(0, str(cat))
            child_node.setText(1, str(nt))
            child_node.setText(2, str(nt_pre_30d))
            nt_node.addChild(child_node)

        # TODO: Figure out why fatigue isn't being normalized to weekly average
        fatigue_node = QTreeWidgetItem()
        fatigue_node.setText(0, 'Fatigue:')
        for slot, slot_data in cur_wkt.groupby('Slot'):
            fatigue = analysis.get_fatigue(slot_data)
            fatigue = fatigue.resample('1d', how=np.sum)
            fatigue = fatigue.fillna(0).iloc[-7:].sum()

            if pre_30d.Slot.isin([slot]).any():
                fatigue_30d = analysis.get_fatigue(pre_30d[pre_30d.Slot == slot])
                fatigue_30d = fatigue_30d.resample('1d', how=np.sum)
                fatigue_30d = round(fatigue_30d.fillna(0).mean() * 7.0, 1)
            else:
                fatigue_30d = ''

            child_node = QTreeWidgetItem()
            child_node.setText(0, str(slot))
            child_node.setText(1, str(fatigue))
            child_node.setText(2, str(fatigue_30d))
            fatigue_node.addChild(child_node)

        self.log_tree.addTopLevelItems([e1RM_node, volume_node, fatigue_node, nt_node])
        self.log_tree.expandAll()