Create loop sqlite tables

This commit is contained in:
Marty Oehme 2021-08-26 23:13:56 +02:00
parent a213afded4
commit c8f6e034a5
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 144 additions and 22 deletions

100
README.md Normal file
View file

@ -0,0 +1,100 @@
# Schemas
A collection of the schemas of Loop habit sqlite database for later migration
# Loop Habit Tracker
## Repetitions - 2021-08-26 -- seems to replace the older Chains table?
id|habit|timestamp|value
1|1|1629936000000|2
2|2|1629936000000|2
3|2|1629676800000|2
## Habits - from 2021-07-23
id | archived | color | description | freq_den | freq_num | highlight | name | position | reminder_hour | reminder_min | reminder_days | type | target_type | target_value | unit | question | uuid
1 | 0 | 4 | | 1 | 1 | 0 | mood | 0 | | | 0 | 1 | 0 | 10.0 | | How do you feel today? | d183a7dd755e44ce9a5782f518b402b4
2 | 0 | 1 | | 1 | 1 | 0 | reading | 1 | | | 0 | 0 | 0 | 0.0 | | Did you read today? | 6b361353e0914a698e896798d5ebca6e
3 | 0 | 15 | | 1 | 1 | 0 | sex 💏 | 2 | | | 0 | 0 | 0 | 0.0 | | Did you have sex today? | 41b646162dc542b3ba223993847d861b
## Habits - from 2021-08-26
id | archived | color | description | freq_den | freq_num | highlight | name | position | reminder_hour | reminder_min | reminder_days | type | target_type | target_value | unit | question | uuid
1 | 0 | 11 | | 1 | 1 | 0 | Gt | 0 | | | 0 | 0 | 0 | 0.0 | | | cfed6f97b67e435d8461ba1accf7457e
2 | 0 | 15 | And note | 3 | 1 | 0 | Iamtrack | 1 | 23 | 0 | 127 | 0 | 0 | 0.0 | | And have all fields? | 1ebe2d429e0d4cd293b1ea038c2b079a
## Chains - habit maps to habit table ID - 2021-07-23
id|habit|timestamp|value
1|1|1627257600000|5000
2|2|1627257600000|2
3|2|1627171200000|2
4|2|1626998400000|2
5|1|1626912000000|10000
6|1|1626998400000|3000
7|3|1627171200000|2
## EVENTS -- empty?
# Nomie
## Nomie trackers
{
'mood': {
'tag': 'mood',
'id': '02283493c7ed0b8dd08de38ae5ca4944',
'type': 'range',
'color': '#369DD3',
'math': 'mean',
'ignore_zeros': False,
'uom': 'num',
'emoji': '😉',
'default': '3',
'max': '10',
'min': '1',
'score': 'custom',
'score_calc': [{'if': 'value',
'is': 'gt',
'v': 5,
'sc': '1'},
{'if': 'value',
'is': 'lt',
'v': 5,
'sc': '-1'}],
'goal': None,
'one_tap': False,
'include': '',
'hidden': False,
'label': 'Mood'
},
'cigarette':
{
'tag': 'cigarette',
'id': '551faae2c5d865ca81e20d00c952b679',
'type': 'tick',
'color': '#EB144C',
'math': 'su m',
'ignore_zeros': False,
'uom': 'num',
'emoji': '🚬',
'default': None,
'score': '-1',
'one_tap': True,
'incl ude': '',
'hidden': False,
'label': 'Cigarette'
},
}
## DataFrame sample from Nomie
_id note end start score lat lng location offset modified source
0 a1a85aac2f #mood(7) #social #date #cigarette #alcohol #go... 1546282800000 1546282800000 0 NaN NaN -60 False importer
1 d717092fbd #mood(7) #reading #social #cigarette #good_mea... 1546209780000 1546209780000 0 NaN NaN -60 False importer
2 311a54f23e #mood(7) #work #social #date #cigarette #relax 1530381900000 1530381900000 0 NaN NaN -60 False importer
3 7f40cce690 #mood(7) #work #cigarette #good_meal #surfing 1530308340000 1530308340000 0 NaN NaN -60 False importer
4 d75e110fdc #mood(7) #reading #work #cigarette #good_meal ... 1530293580000 1530293580000 0 NaN NaN -60 False importer

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
import json
import pandas as pd
import sqlite3
@ -10,6 +11,11 @@ def load_file(filename):
return nomie_data
def get_dataframe(nomie_data):
return pd.DataFrame(nomie_data["events"])
# generate a yes/no cli question with a default answer
def confirmation_question(question, default_no=True):
choices = " [y/N]: " if default_no else " [Y/n]: "
default_answer = "n" if default_no else "y"
@ -22,6 +28,7 @@ def confirmation_question(question, default_no=True):
return False if default_no else True
# display stats and ask user to confirm if they seem okay
def verify_continue(data):
trackers = ""
for t in data["trackers"]:
@ -37,34 +44,49 @@ def create_database(name):
return sqlite3.connect(name)
def create_loop_tables(cursor):
cursor.execute("CREATE TABLE ")
# HABITS
# id|archived|color|description|freq_den|freq_num|highlight|name|position|reminder_hour|reminder_min|reminder_days|type|target_type|target_value|unit|question|uuid
# 1|0|4||1|1|0|mood|0|||0|1|0|10.0||How do you feel today?|d183a7dd755e44ce9a5782f518b402b4
# 2|0|1||1|1|0|reading|1|||0|0|0|0.0||Did you read today?|6b361353e0914a698e896798d5ebca6e
# 3|0|15||1|1|0|sex 💏|2|||0|0|0|0.0||Did you have sex today?|41b646162dc542b3ba223993847d861b
# CHAINS - habit maps to habit table ID
# id|habit|timestamp|value
# 1|1|1627257600000|5000
# 2|2|1627257600000|2
# 3|2|1627171200000|2
# 4|2|1626998400000|2
# 5|1|1626912000000|10000
# 6|1|1626998400000|3000
# 7|3|1627171200000|2
# EVENTS -- empty?
def create_loop_tables(db):
c = db.cursor()
c.execute(
""" CREATE TABLE IF NOT EXISTS Habits (
id integer PRIMARY KEY,
archived integer,
color integer,
description text,
freq_den integer,
freq_num integer,
highlight integer,
name text NOT NULL,
position integer,
reminder_hour integer,
reminder_min integer,
reminder_days integer,
type integer,
target_type integer,
target_value real,
unit text,
question text,
uuid text NOT NULL
); """
)
c.execute(
""" CREATE TABLE IF NOT EXISTS Repetitions (
id integer PRIMARY KEY,
habit integer,
timestamp integer,
value integer
); """
)
if __name__ == "__main__":
# load nomie json
nomie_data = load_file("input.json")
# DISABLED FOR DEBUGGING
verify_continue(nomie_data)
# bring up dataframe
df = get_dataframe(nomie_data)
# prep sqlite database
db = create_database("output.db")
c = db.cursor()
create_loop_tables(db)