Add range habits

This commit is contained in:
Marty Oehme 2021-08-28 22:03:45 +02:00
parent 21fd1e5aaf
commit 1a5004e333
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 19 additions and 3 deletions

View file

@ -7,6 +7,8 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
## [Unreleased] ## [Unreleased]
* Add range habits, translating nomie max value to range target in Loop
## [0.2.1] - 2021-08-28 ## [0.2.1] - 2021-08-28
### Fixed ### Fixed

View file

@ -1,3 +1,16 @@
# Nomie Habit Migrator
Can take an export of nomie habits in json format and convert it to be importable in Loop Habit Tracker.
Confirmed working for nomie version 5.6.4 and Loop Habit Tracker version 2.0.2.
Presumably works for other nomie 5.x versions and other Loop 2.x versions as well, but is untested.
## Usage
Currently takes a single argument, the nomie database file, and will output to `output.db` in present working directory.
Invoked like: `python migrate.py nomie-export.json`
# Schemas # Schemas
A collection of the schemas of Loop habit sqlite database for later migration A collection of the schemas of Loop habit sqlite database for later migration
@ -59,7 +72,7 @@ label + emoji | name
? | reminder_days (simple int, but i'm not sure how, saw 127) ? | 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) type | type (range,counter [more in nomie]; string in nomie, int in loop)
? | target_type (??) ? | target_type (??)
? | target_value (??) ? | target_value (maximum value for range habits afaik)
uom | unit (text description of value, in nomie set values with `num` being no-value count) uom | unit (text description of value, in nomie set values with `num` being no-value count)
? | question (text question tracker asks) ? | question (text question tracker asks)
id | uuid (unique id, must be unique surprisingly) id | uuid (unique id, must be unique surprisingly)

View file

@ -15,7 +15,6 @@ def migrate(db, trackers):
def trackers_to_habits(trackers): def trackers_to_habits(trackers):
habits = [] habits = []
# for each list entry tracker dict transform to habit dict
for tracker_name in trackers.keys(): for tracker_name in trackers.keys():
t = trackers[tracker_name] t = trackers[tracker_name]
habits.append( habits.append(
@ -32,8 +31,10 @@ def trackers_to_habits(trackers):
"unit": "" if t["uom"] == "num" else t["uom"], "unit": "" if t["uom"] == "num" else t["uom"],
"uuid": t["id"], "uuid": t["id"],
} }
# FIXME conditional for ranges (if type = range > habits[-1]['type'] = intforrangetype; habits[-1]['max'] =)
) )
if t["type"] == "range" and len(habits) > 0:
habits[-1]["type"] = "1"
habits[-1]["target_value"] = t["max"]
return habits return habits