diff --git a/app/mifit_to_influxdb.py b/app/mifit_to_influxdb.py
--- a/app/mifit_to_influxdb.py
+++ b/app/mifit_to_influxdb.py
#
@@ -134,8 +134,11 @@ def extract_sleep_data(ts, slp, day):
#
# If there are stages recorded, also log those
#
+ sleep_stages = len(slp['stage'])
#
for sleep in slp['stage']:
#
@@ -156,6 +159,29 @@ def extract_sleep_data(ts, slp, day):
#
+ # Increment the counter for the type
#
+ # initialising if not already present
#
+ if stage not in stages_counters:
#
+ stages_counters[stage] = 0
#
+ stages_counters[stage] += 1
#
+ # Record the number of sleep stages
#
+ "timestamp": int(ts) * 1000000000, # Convert to nanos
#
+ "recorded_sleep_stages" : sleep_stages
#
+ # Add a field for each of the recorded stages_counters
#
+ for stage in stages_counters:
#
+ row['fields'][f"recorded_{stage}_events"] = stages_counters[stage]
#
@@ -199,8 +225,11 @@ def extract_step_data(ts, stp, day):
#
+ activity_counters = {}
#
# Iterate through any listed stages
#
+ activity_count = len(stp['stage'])
#
for activity in stp['stage']:
#
if activity['mode'] == 1:
#
activity_type = 'slow_walking'
#
@@ -226,6 +255,26 @@ def extract_step_data(ts, stp, day):
#
+ # Increment the type specific counter
#
+ if activity_type not in activity_counters:
#
+ activity_counters[activity_type] = 0
#
+ activity_counters[activity_type] += 1
#
+ # Record the number of activities
#
+ "timestamp": int(ts) * 1000000000, # Convert to nanos
#
+ "recorded_activities" : activity_count
#
+ for activity in activity_counters:
#
+ row['fields'][f"recorded_{activity}_events"] = activity_counters[activity]
#
def minute_to_timestamp(minute, day):