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 # 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 ## Nomie trackers
{ {
@ -57,14 +85,7 @@ id|habit|timestamp|value
'max': '10', 'max': '10',
'min': '1', 'min': '1',
'score': 'custom', 'score': 'custom',
'score_calc': [{'if': 'value', 'score_calc': [{'if': 'value', 'is': 'gt', 'v': 5, 'sc': '1'}, {'if': 'value', 'is': 'lt', 'v': 5, 'sc': '-1'}],
'is': 'gt',
'v': 5,
'sc': '1'},
{'if': 'value',
'is': 'lt',
'v': 5,
'sc': '-1'}],
'goal': None, 'goal': None,
'one_tap': False, 'one_tap': False,
'include': '', 'include': '',

View file

@ -2,7 +2,7 @@
import json import json
import pandas as pd import pandas as pd
import sqlite3 import toloop as loop
def load_file(filename): def load_file(filename):
@ -33,49 +33,28 @@ def verify_continue(data):
trackers = "" trackers = ""
for t in data["trackers"]: for t in data["trackers"]:
trackers += t + ", " trackers += t + ", "
print(f"Exporting from nomie {data['nomie']['number']}:")
print(f"Found trackers: {trackers}") 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): if not confirmation_question("Do you want to continue?", default_no=False):
print("Aborted.") print("Aborted.")
exit(0) exit(0)
def create_database(name): # better way to do this
return sqlite3.connect(name) # def create_connection(db_file):
# """create a database connection to the SQLite database
# specified by db_file
def create_loop_tables(db): # :param db_file: database file
c = db.cursor() # :return: Connection object or None
c.execute( # """
""" CREATE TABLE IF NOT EXISTS Habits ( # conn = None
id integer PRIMARY KEY, # try:
archived integer, # conn = sqlite3.connect(db_file)
color integer, # return conn
description text, # except Error as e:
freq_den integer, # print(e)
freq_num integer, # return conn
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__": if __name__ == "__main__":
@ -83,10 +62,11 @@ if __name__ == "__main__":
nomie_data = load_file("input.json") nomie_data = load_file("input.json")
# DISABLED FOR DEBUGGING # DISABLED FOR DEBUGGING
verify_continue(nomie_data) verify_continue(nomie_data)
trackers = nomie_data["trackers"]
events = nomie_data["events"]
# bring up dataframe # bring up dataframe
df = get_dataframe(nomie_data) df = get_dataframe(nomie_data)
# prep sqlite database # give it over to loop migrator
db = create_database("output.db") loop.migrate(trackers, events)
create_loop_tables(db)

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)