Add range tracker conversion
This commit is contained in:
parent
595b4e4898
commit
b9c08758f9
2 changed files with 26 additions and 7 deletions
|
@ -9,9 +9,9 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
* Add range habits, translating nomie max value to range target in Loop
|
|
||||||
* Add repetition import, translated from events
|
* Add repetition import, translated from events
|
||||||
* Does not do ranged habits or multiple entries for simple trackers in nomie yet
|
* Does not do multiple entries for simple trackers in nomie yet
|
||||||
|
* Add range habits, using nomie maximum value for range targets in Loop
|
||||||
* Adding ranges defaults target value to half of maximum nomie value
|
* Adding ranges defaults target value to half of maximum nomie value
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -7,7 +7,12 @@ def migrate(db, habitlist, events):
|
||||||
habits = simple_habits_list(c, habitlist)
|
habits = simple_habits_list(c, habitlist)
|
||||||
repetitions = extract_all_repetitions(habits, events)
|
repetitions = extract_all_repetitions(habits, events)
|
||||||
for rep in repetitions:
|
for rep in repetitions:
|
||||||
add_to_database(c, rep["id"], rep["timestamp"])
|
add_to_database(
|
||||||
|
c, rep["id"], rep["timestamp"], 2 if "value" not in rep else rep["value"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
LOOP_RANGE_VALUE_MULTIPLIER = 1000
|
||||||
|
|
||||||
|
|
||||||
def extract_all_repetitions(habits, events):
|
def extract_all_repetitions(habits, events):
|
||||||
|
@ -26,8 +31,17 @@ def extract_all_repetitions(habits, events):
|
||||||
for habit in habits:
|
for habit in habits:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if habit["description"] in tag[0]:
|
if habit["description"] in tag[0]:
|
||||||
print(f"found event: {habit['name']} in {text} at {event['end']}")
|
print(
|
||||||
|
f"found repetition: {habit['name']} in {text} at {event['end']}"
|
||||||
|
)
|
||||||
repetitions.append({"id": habit["id"], "timestamp": event["end"]})
|
repetitions.append({"id": habit["id"], "timestamp": event["end"]})
|
||||||
|
if tag[1]:
|
||||||
|
print(f"repetition contains counter: {tag[0]} ({tag[1]})")
|
||||||
|
if "type" in habit and habit["type"] == 1:
|
||||||
|
repetitions[-1]["value"] = (
|
||||||
|
tag[1] * LOOP_RANGE_VALUE_MULTIPLIER
|
||||||
|
)
|
||||||
|
print(f"added counter to ranged habit.")
|
||||||
return repetitions
|
return repetitions
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,10 +53,14 @@ def extract_tags(text, tagmarker="#"):
|
||||||
Returns:
|
Returns:
|
||||||
tags (list): List of tuples in the form [('tag', '3'), ('anothertag', '')].
|
tags (list): List of tuples in the form [('tag', '3'), ('anothertag', '')].
|
||||||
"""
|
"""
|
||||||
found_tags = re.findall(rf"{tagmarker}(\w+)(?:\((\d+)\))?", text)
|
string_tags = re.findall(rf"{tagmarker}(\w+)(?:\((\d+)\))?", text)
|
||||||
return found_tags
|
tags_with_int_counters = []
|
||||||
|
for tag in string_tags:
|
||||||
|
tags_with_int_counters.append((tag[0], None if tag[1] == "" else int(tag[1])))
|
||||||
|
return tags_with_int_counters
|
||||||
|
|
||||||
|
|
||||||
|
# TODO possibly just get rid of this entirely
|
||||||
def simple_habits_list(c, habitlist):
|
def simple_habits_list(c, habitlist):
|
||||||
"""Return simplified collection of habits, only carrying name, tag, id.
|
"""Return simplified collection of habits, only carrying name, tag, id.
|
||||||
Parameters:
|
Parameters:
|
||||||
|
@ -61,6 +79,8 @@ def simple_habits_list(c, habitlist):
|
||||||
"id": fetch_habit_id(c, h["uuid"]),
|
"id": fetch_habit_id(c, h["uuid"]),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if "type" in h:
|
||||||
|
simple[-1]["type"] = h["type"]
|
||||||
return simple
|
return simple
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,4 +117,3 @@ def add_to_database(cursor, habit_id, timestamp, value=2):
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
# TODO better error handling
|
# TODO better error handling
|
||||||
print(f"fail to register {habit_id}: timestamp {timestamp} not unique")
|
print(f"fail to register {habit_id}: timestamp {timestamp} not unique")
|
||||||
pass
|
|
||||||
|
|
Loading…
Reference in a new issue