{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://dashremix.com/spec/health/1.4.0/health@1.schema.json",
 "title": "health@1 v1.4.0",
 "description": "One property per table (an array of rows). Generated from schema.sql by spec/build.py. Extension tables (x_<owner>_*) belong to forks and board-derived tables (d_*) to the board that rebuilds them; both are allowed as additional properties.",
 "type": "object",
 "properties": {
  "meta": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "key": {
      "type": [
       "string",
       "null"
      ]
     },
     "value": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [],
    "additionalProperties": false
   }
  },
  "metric_codes": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string",
      "enum": [
       "rhr",
       "hrv_sdnn",
       "hrv_unverified",
       "hrv_rmssd",
       "resp_rate",
       "spo2",
       "wrist_temp",
       "skin_temp_dev",
       "steps",
       "active_kcal",
       "exercise_time",
       "weight",
       "vo2max",
       "sleep_score",
       "readiness"
      ]
     },
     "name": {
      "type": "string"
     },
     "unit": {
      "type": "string",
      "enum": [
       "bpm",
       "ms",
       "breaths_min",
       "share",
       "degC",
       "count",
       "kcal",
       "s",
       "kg",
       "ml_kg_min",
       "score"
      ]
     },
     "agg": {
      "type": "string"
     },
     "sources": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "code",
     "name",
     "unit",
     "agg"
    ],
    "additionalProperties": false
   }
  },
  "daily_metrics": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "code": {
      "type": "string",
      "enum": [
       "rhr",
       "hrv_sdnn",
       "hrv_unverified",
       "hrv_rmssd",
       "resp_rate",
       "spo2",
       "wrist_temp",
       "skin_temp_dev",
       "steps",
       "active_kcal",
       "exercise_time",
       "weight",
       "vo2max",
       "sleep_score",
       "readiness"
      ]
     },
     "value": {
      "type": "number"
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "device": {
      "type": "string"
     },
     "n_samples": {
      "type": [
       "integer",
       "null"
      ]
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "date",
     "code",
     "value",
     "device",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "sleep_sessions": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "sleep_id": {
      "type": "string"
     },
     "start_utc": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "end_utc": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "tz": {
      "type": "string"
     },
     "start_local": {
      "type": [
       "string",
       "null"
      ]
     },
     "end_local": {
      "type": [
       "string",
       "null"
      ]
     },
     "night_of": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "in_bed_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "asleep_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "awake_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "light_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "deep_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "rem_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "asleep_unspecified_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "latency_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "efficiency": {
      "type": [
       "number",
       "null"
      ]
     },
     "hr_min": {
      "type": [
       "number",
       "null"
      ]
     },
     "hrv_sdnn_ms": {
      "type": [
       "number",
       "null"
      ]
     },
     "hrv_rmssd_ms": {
      "type": [
       "number",
       "null"
      ]
     },
     "rhr": {
      "type": [
       "number",
       "null"
      ]
     },
     "resp_rate": {
      "type": [
       "number",
       "null"
      ]
     },
     "score": {
      "type": [
       "number",
       "null"
      ]
     },
     "is_nap": {
      "type": "integer"
     },
     "n_segments": {
      "type": [
       "integer",
       "null"
      ]
     },
     "device": {
      "type": "string"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "sleep_id",
     "start_utc",
     "end_utc",
     "tz",
     "night_of",
     "is_nap",
     "device",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workouts": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "start_utc": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "end_utc": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "tz": {
      "type": "string"
     },
     "date": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "sport": {
      "type": "string",
      "enum": [
       "run",
       "ride",
       "swim",
       "walk",
       "hike",
       "strength",
       "yoga",
       "row",
       "ski",
       "other"
      ]
     },
     "duration_s": {
      "type": "integer"
     },
     "moving_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "distance_m": {
      "type": [
       "number",
       "null"
      ]
     },
     "elev_gain_m": {
      "type": [
       "number",
       "null"
      ]
     },
     "kcal": {
      "type": [
       "number",
       "null"
      ]
     },
     "avg_hr": {
      "type": [
       "number",
       "null"
      ]
     },
     "max_hr": {
      "type": [
       "number",
       "null"
      ]
     },
     "load": {
      "type": [
       "number",
       "null"
      ]
     },
     "rpe": {
      "type": [
       "number",
       "null"
      ]
     },
     "name": {
      "type": [
       "string",
       "null"
      ]
     },
     "gear": {
      "type": [
       "string",
       "null"
      ]
     },
     "is_race": {
      "type": [
       "integer",
       "null"
      ]
     },
     "route_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "external_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "sport_raw": {
      "type": [
       "string",
       "null"
      ]
     },
     "indoor": {
      "type": [
       "integer",
       "null"
      ]
     },
     "laps_n": {
      "type": [
       "integer",
       "null"
      ]
     },
     "device": {
      "type": "string"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "start_utc",
     "tz",
     "sport",
     "duration_s",
     "device",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workout_zones": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "zone": {
      "type": "integer"
     },
     "seconds": {
      "type": "integer"
     },
     "lo_bpm": {
      "type": [
       "number",
       "null"
      ]
     },
     "hi_bpm": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "zone",
     "seconds",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workout_laps": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "lap_n": {
      "type": "integer"
     },
     "start_utc": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "duration_s": {
      "type": "integer"
     },
     "distance_m": {
      "type": [
       "number",
       "null"
      ]
     },
     "avg_hr": {
      "type": [
       "number",
       "null"
      ]
     },
     "max_hr": {
      "type": [
       "number",
       "null"
      ]
     },
     "elev_gain_m": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "lap_n",
     "duration_s",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workout_streams": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "stream": {
      "type": "string",
      "enum": [
       "power",
       "heart_rate",
       "speed",
       "cadence"
      ]
     },
     "seconds": {
      "type": [
       "integer",
       "null"
      ]
     },
     "avg": {
      "type": [
       "number",
       "null"
      ]
     },
     "max": {
      "type": [
       "number",
       "null"
      ]
     },
     "weighted": {
      "type": [
       "number",
       "null"
      ]
     },
     "max_gap_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "stream",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workout_efforts": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "measure": {
      "type": "string",
      "enum": [
       "power",
       "speed",
       "heart_rate",
       "time"
      ]
     },
     "span": {
      "type": "number"
     },
     "value": {
      "type": "number"
     },
     "offset_s": {
      "type": [
       "integer",
       "null"
      ]
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "measure",
     "span",
     "value",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "workout_histograms": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "workout_id": {
      "type": "string"
     },
     "stream": {
      "type": "string",
      "enum": [
       "power",
       "heart_rate",
       "speed",
       "cadence"
      ]
     },
     "lo": {
      "type": "number"
     },
     "width": {
      "type": "number"
     },
     "seconds": {
      "type": "integer"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "workout_id",
     "stream",
     "lo",
     "width",
     "seconds",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "body": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "weight_kg": {
      "type": [
       "number",
       "null"
      ]
     },
     "body_fat": {
      "type": [
       "number",
       "null"
      ]
     },
     "waist_m": {
      "type": [
       "number",
       "null"
      ]
     },
     "device": {
      "type": "string"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ]
     },
     "measured_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "n_samples": {
      "type": [
       "integer",
       "null"
      ]
     }
    },
    "required": [
     "date",
     "device",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "nutrition": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "kcal": {
      "type": [
       "number",
       "null"
      ]
     },
     "protein_g": {
      "type": [
       "number",
       "null"
      ]
     },
     "carbs_g": {
      "type": [
       "number",
       "null"
      ]
     },
     "fat_g": {
      "type": [
       "number",
       "null"
      ]
     },
     "fiber_g": {
      "type": [
       "number",
       "null"
      ]
     },
     "n_entries": {
      "type": "integer"
     },
     "completed": {
      "type": [
       "integer",
       "null"
      ]
     },
     "device": {
      "type": "string"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "imported_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "date",
     "n_entries",
     "device",
     "source"
    ],
    "additionalProperties": false
   }
  },
  "import_counts": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "file": {
      "type": "string"
     },
     "record_type": {
      "type": "string"
     },
     "source": {
      "type": "string",
      "enum": [
       "apple-health",
       "health-csv",
       "oura",
       "whoop",
       "google-health",
       "strava-archive",
       "garmin-archive",
       "fit-file",
       "manual",
       "myfitnesspal",
       "cronometer",
       "withings",
       "weigh-ins-csv",
       "neverchill-export"
      ]
     },
     "n_read": {
      "type": "integer"
     },
     "n_used": {
      "type": "integer"
     },
     "n_duplicate": {
      "type": "integer"
     },
     "n_skipped": {
      "type": "integer"
     },
     "n_out_of_scope": {
      "type": "integer"
     },
     "raw_sum": {
      "type": [
       "number",
       "null"
      ]
     }
    },
    "required": [
     "file",
     "record_type",
     "source",
     "n_read",
     "n_used",
     "n_duplicate",
     "n_skipped",
     "n_out_of_scope"
    ],
    "additionalProperties": false
   }
  },
  "data_issues": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "issue_id": {
      "type": "string"
     },
     "severity": {
      "type": "string",
      "enum": [
       "info",
       "warn",
       "error"
      ]
     },
     "kind": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "detail": {
      "type": "string"
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "handling": {
      "type": "string"
     }
    },
    "required": [
     "issue_id",
     "severity",
     "kind",
     "title",
     "detail",
     "handling"
    ],
    "additionalProperties": false
   }
  },
  "annotations": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "annotation_id": {
      "type": "string"
     },
     "target": {
      "type": "string"
     },
     "kind": {
      "type": "string"
     },
     "body": {
      "type": "string"
     },
     "author": {
      "type": [
       "string",
       "null"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ]
     },
     "data_hash": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "annotation_id",
     "target",
     "kind",
     "body"
    ],
    "additionalProperties": false
   }
  },
  "metric_registry": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "metric_id": {
      "type": "string"
     },
     "version": {
      "type": [
       "integer",
       "null"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "params": {
      "type": [
       "string",
       "null"
      ]
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "sql": {
      "type": [
       "string",
       "null"
      ]
     },
     "test": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "metric_id"
    ],
    "additionalProperties": false
   }
  }
 },
 "required": [
  "meta",
  "metric_codes",
  "daily_metrics",
  "sleep_sessions",
  "workouts"
 ],
 "patternProperties": {
  "^x_[a-z0-9_]+$": {
   "type": "array"
  },
  "^d_[a-z0-9_]+$": {
   "type": "array"
  }
 },
 "additionalProperties": false
}
