def get_sleep_stats(cls, db, start_ts, end_ts): return { 'sleep_avg': Conversions.secs_to_dt_time( cls.get_col_avg(db, cls.sleep_secs, start_ts, end_ts, True)), 'sleep_min': Conversions.secs_to_dt_time( cls.get_col_min(db, cls.sleep_secs, start_ts, end_ts, True)), 'sleep_max': Conversions.secs_to_dt_time( cls.get_col_max(db, cls.sleep_secs, start_ts, end_ts)), }
def get_activity_mins_stats(cls, db, func, start_ts, end_ts): moderate_activity_time = Conversions.min_to_dt_time(func(db, cls.fairly_active_mins, start_ts, end_ts)) vigorous_activity_time = Conversions.min_to_dt_time(func(db, cls.very_active_mins, start_ts, end_ts)) intensity_time = datetime.time.min if moderate_activity_time: intensity_time = Conversions.add_time(intensity_time, moderate_activity_time) if vigorous_activity_time: intensity_time = Conversions.add_time(intensity_time, vigorous_activity_time, 2) stats = { 'intensity_time' : intensity_time, 'moderate_activity_time' : moderate_activity_time, 'vigorous_activity_time' : vigorous_activity_time, } return stats
def get_stats(cls, db, start_ts, end_ts): moderate_activity_time = cls.get_time_col_sum(db, cls.moderate_activity_time, start_ts, end_ts) vigorous_activity_time = cls.get_time_col_sum(db, cls.vigorous_activity_time, start_ts, end_ts) intensity_time = datetime.time.min if moderate_activity_time: intensity_time = Conversions.add_time(intensity_time, moderate_activity_time) if vigorous_activity_time: intensity_time = Conversions.add_time(intensity_time, vigorous_activity_time, 2) stats = { 'intensity_time' : intensity_time, 'moderate_activity_time' : moderate_activity_time, 'vigorous_activity_time' : vigorous_activity_time, } return stats
def get_time_col_func(cls, db, col, stat_func, start_ts=None, end_ts=None, ignore_le_zero=False): query = db.query_session().query(stat_func(func.strftime('%s', col) - func.strftime('%s', '00:00'))) if start_ts is not None: query = query.filter(cls.time_col >= start_ts) if end_ts is not None: query = query.filter(cls.time_col < end_ts) if ignore_le_zero: query = query.filter(col > 0) return Conversions.secs_to_dt_time(query.scalar())
def get_activity_mins_stats(cls, db, func, start_ts, end_ts): active_hours = func(db, cls.active_hours, start_ts, end_ts) if active_hours is not None: intensity_time = Conversions.min_to_dt_time(active_hours * 60) stats = { 'intensity_time': intensity_time, 'moderate_activity_time': intensity_time, # 'vigorous_activity_time' : None, Don't write where we have no data, may overwrite good data } else: stats = {} return stats
def get_weight(self): logger.info("get_weight") data = [] chunk_size = int((86400 * 365) * 1000) end = Conversions.dt_to_epoch_ms(datetime.datetime.now()) while True: start = end - chunk_size chunk_data = self.get_weight_chunk(start, end) if len(chunk_data) <= 1: break data.extend(chunk_data) end -= chunk_size return data
def get_activities(self, directory, count): logger.info("get_activities: '%s' (%d)" % (directory, count)) activities = self.get_activity_summaries(0, count) for activity in activities: activity_id_str = str(activity['activityId']) activity_name_str = Conversions.printable(activity['activityName']) logger.info("get_activities: %s (%s)" % (activity_name_str, activity_id_str)) json_filename = directory + '/activity_' + activity_id_str if not os.path.isfile(json_filename): logger.debug("get_activities: %s <- %s" % (json_filename, repr(activity))) self.save_json_file(json_filename, activity) self.save_activity_file(activity_id_str)
def get_monitoring_days(self, year): days = GarminDB.Monitoring.get_days(self.mondb, year) days_count = len(days) if days_count > 0: first_day = days[0] last_day = days[-1] span = last_day - first_day + 1 else: span = 0 GarminDB.Summary.set(self.garminsumdb, str(year) + '_days', days_count) GarminDB.Summary.set(self.garminsumdb, str(year) + '_days_span', span) logger.info("%d Days (%d count vs %d span): %s" % (year, days_count, span, str(days))) for index in xrange(days_count - 1): day = int(days[index]) next_day = int(days[index + 1]) if next_day != day + 1: day_str = str( Conversions.day_of_the_year_to_datetime(year, day)) next_day_str = str( Conversions.day_of_the_year_to_datetime(year, next_day)) logger.info("Days gap between %d (%s) and %d (%s)" % (day, day_str, next_day, next_day_str))
def get_weight(self): logger.info("get_weight") data = [] chunk_size = int((86400 * 365) * 1000) end = Conversions.dt_to_epoch_ms(datetime.datetime.now()) while True: start = end - chunk_size chunk_data = self.get_weight_chunk(start, end) if len(chunk_data) <= 1: break data.extend(chunk_data) end -= chunk_size # pause for a second between every page access time.sleep(1) return data
def get_activities(self, directory, count, overwite=False): logger.info("get_activities: '%s' (%d)", directory, count) activities = self.get_activity_summaries(0, count) for activity in activities: activity_id_str = str(activity['activityId']) activity_name_str = Conversions.printable(activity['activityName']) logger.info("get_activities: %s (%s)" % (activity_name_str, activity_id_str)) json_filename = directory + '/activity_' + activity_id_str if not os.path.isfile(json_filename + '.json') or overwite: logger.debug("get_activities: %s <- %s" % (json_filename, repr(activity))) self.save_activity_details(directory, activity_id_str) self.save_json_file(json_filename, activity) self.save_activity_file(activity_id_str) # pause for a second between every page access time.sleep(1)
def get_weight_day(self, directory, day, overwite=False): date_str = day.strftime('%Y-%m-%d') json_filename = directory + '/weight_' + date_str if not os.path.isfile(json_filename + '.json') or overwite: logger.info("get_weight_day: %s", date_str) params = { 'startDate': date_str, 'endDate': date_str, '_': str(Conversions.dt_to_epoch_ms(day)) } response = self.get(self.garmin_connect_weight_url, params=params) if response.status_code == 200: self.save_json_file(json_filename, response.json()) return True logger.error("get_weight_day failed (%d): %s", response.status_code, response.url) return False