def create_statistics(cls, user_id, stat_date): histories = History.get_by_user_id(user_id, stat_date) pomos = [0] * 24 breaks = [0] * 24 total_pomos = 0 total_breaks = 0 interruptions = 0 day_start = datetime.strptime(stat_date, '%Y%m%d') for history in histories: start_time = history.start end_time = history.end index = ((start_time - day_start).seconds + history.utc_offset * 60) // 3600 minutes = (end_time - start_time).seconds // 60 if history.type == 'Pomodoro': pomos[index] += minutes total_pomos += minutes if history.status == 'Interrupted': interruptions += 1 else: breaks[index] += minutes total_breaks += minutes stat = Stat(stat_key=stat_date, pomos=json.dumps(pomos), breaks=json.dumps(breaks), totalPomos=total_pomos, totalBreaks=total_breaks, interruptions=interruptions, user_id=user_id) stat.save() return stat
def get(self, txn_date): current_user = get_jwt_identity() histories = History.get_by_user_id(current_user, txn_date) result = history_list_schema.dump(histories) return result, HTTPStatus.OK