From f5e8861252611f86a71a830aae8ee70c248063d0 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 27 Aug 2021 10:11:00 +0200 Subject: [PATCH] Put loop code into own file --- README.md | 37 +++++++++++++++++++++++++------- migrate.py | 62 ++++++++++++++++++------------------------------------ toloop.py | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 49 deletions(-) create mode 100644 toloop.py diff --git a/README.md b/README.md index 682c2ec..79923f6 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,34 @@ id|habit|timestamp|value # Nomie +## Schema translation + +trackers: nomie -> loop + +? | id (primary key increasing id for each tracker, should autoincrement) +hidden | archived +color | color (but nomie: `#369DD3`, loop `2` of available selection) +label + emoji | name +? | description (a little one-liner extended description) +? | freq_den (frequency denominator, either 7 for per week or 30 for per month) +? | freq_num (frequency numerator, how often per week/month. Has to be one for ranges afaik?) +? | highlight (function ??) +label | name +? | position (which vertical position on screen tracker takes. must be unique?) +? | reminder_hour (simple int) +? | reminder_min (simple int) +? | reminder_days (simple int, but i'm not sure how, saw 127) +type | type (range,counter [more in nomie]; string in nomie, int in loop) +? | target_type (??) +? | target_value (??) +uom | unit (text description of value, in nomie set values with `num` being no-value count) +? | question (text question tracker asks) +id | uuid (unique id, must be unique surprisingly) + +nomie has no concept of 'ideal' repetitions (i.e. success if.. once a day; twice a week; 4 miles a month; ...) +nomie has no concept of reminder times for trackers +loop has no concept of 'score' associated to trackers (when e.g. tracking bad things) + ## Nomie trackers { @@ -57,14 +85,7 @@ id|habit|timestamp|value 'max': '10', 'min': '1', 'score': 'custom', - 'score_calc': [{'if': 'value', - 'is': 'gt', - 'v': 5, - 'sc': '1'}, - {'if': 'value', - 'is': 'lt', - 'v': 5, - 'sc': '-1'}], + 'score_calc': [{'if': 'value', 'is': 'gt', 'v': 5, 'sc': '1'}, {'if': 'value', 'is': 'lt', 'v': 5, 'sc': '-1'}], 'goal': None, 'one_tap': False, 'include': '', diff --git a/migrate.py b/migrate.py index 10904a3..9e10952 100755 --- a/migrate.py +++ b/migrate.py @@ -2,7 +2,7 @@ import json import pandas as pd -import sqlite3 +import toloop as loop def load_file(filename): @@ -33,49 +33,28 @@ def verify_continue(data): trackers = "" for t in data["trackers"]: trackers += t + ", " + print(f"Exporting from nomie {data['nomie']['number']}:") print(f"Found trackers: {trackers}") - print(f"with {len(data['events'])} event entries.") + print(f"Found events: {len(data['events'])} entries.") if not confirmation_question("Do you want to continue?", default_no=False): print("Aborted.") exit(0) -def create_database(name): - return sqlite3.connect(name) - - -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 - ); """ - ) +# better way to do this +# def create_connection(db_file): +# """create a database connection to the SQLite database +# specified by db_file +# :param db_file: database file +# :return: Connection object or None +# """ +# conn = None +# try: +# conn = sqlite3.connect(db_file) +# return conn +# except Error as e: +# print(e) +# return conn if __name__ == "__main__": @@ -83,10 +62,11 @@ if __name__ == "__main__": nomie_data = load_file("input.json") # DISABLED FOR DEBUGGING verify_continue(nomie_data) + trackers = nomie_data["trackers"] + events = nomie_data["events"] # bring up dataframe df = get_dataframe(nomie_data) - # prep sqlite database - db = create_database("output.db") - create_loop_tables(db) + # give it over to loop migrator + loop.migrate(trackers, events) diff --git a/toloop.py b/toloop.py new file mode 100644 index 0000000..b636a76 --- /dev/null +++ b/toloop.py @@ -0,0 +1,44 @@ +import sqlite3 + + +def create_database(name): + return sqlite3.connect(name) + + +def create_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 UNIQUE, + 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 + ); """ + ) + + +def migrate(trackers, events): + db = create_database("output.db") + create_tables(db)