Put loop code into own file

This commit is contained in:
Marty Oehme 2021-08-27 10:11:00 +02:00
parent c8f6e034a5
commit f5e8861252
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
3 changed files with 94 additions and 49 deletions

View File

@ -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': '',

View File

@ -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)

44
toloop.py Normal file
View File

@ -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)