Update antfarm, dashboard, memory +1 more (+20 ~12 -6)
This commit is contained in:
@@ -1759,20 +1759,33 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
||||
all_checks = all(c.get('type') == 'check' for c in recent_completions)
|
||||
if all_checks:
|
||||
habit['lives'] = min(habit['lives'] + 1, 3)
|
||||
|
||||
|
||||
# Update timestamp
|
||||
habit['updatedAt'] = datetime.now().isoformat()
|
||||
habits_data['lastUpdated'] = habit['updatedAt']
|
||||
|
||||
|
||||
# Save to file
|
||||
with open(HABITS_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(habits_data, f, indent=2)
|
||||
|
||||
# Return updated habit
|
||||
self.send_json(habit, 200)
|
||||
|
||||
# Enrich habit with calculated stats before returning
|
||||
current_streak = habits_helpers.calculate_streak(habit)
|
||||
best_streak = habit.get('streak', {}).get('best', 0)
|
||||
completion_rate = habits_helpers.get_completion_rate(habit, days=30)
|
||||
weekly_summary = habits_helpers.get_weekly_summary(habit)
|
||||
|
||||
enriched_habit = habit.copy()
|
||||
enriched_habit['current_streak'] = current_streak
|
||||
enriched_habit['best_streak'] = best_streak
|
||||
enriched_habit['completion_rate_30d'] = completion_rate
|
||||
enriched_habit['weekly_summary'] = weekly_summary
|
||||
enriched_habit['should_check_today'] = habits_helpers.should_check_today(habit)
|
||||
|
||||
# Return enriched habit
|
||||
self.send_json(enriched_habit, 200)
|
||||
except Exception as e:
|
||||
self.send_json({'error': str(e)}, 500)
|
||||
|
||||
|
||||
def handle_habits_uncheck(self):
|
||||
"""Uncheck a habit (remove completion for a specific date)."""
|
||||
try:
|
||||
@@ -1841,20 +1854,32 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
||||
# Update best streak if needed (best never decreases, but we keep it for consistency)
|
||||
if current_streak > habit['streak']['best']:
|
||||
habit['streak']['best'] = current_streak
|
||||
|
||||
|
||||
# Update timestamp
|
||||
habit['updatedAt'] = datetime.now().isoformat()
|
||||
habits_data['lastUpdated'] = habit['updatedAt']
|
||||
|
||||
|
||||
# Save to file
|
||||
with open(HABITS_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(habits_data, f, indent=2)
|
||||
|
||||
# Return updated habit
|
||||
self.send_json(habit, 200)
|
||||
|
||||
# Enrich habit with calculated stats before returning
|
||||
best_streak = habit.get('streak', {}).get('best', 0)
|
||||
completion_rate = habits_helpers.get_completion_rate(habit, days=30)
|
||||
weekly_summary = habits_helpers.get_weekly_summary(habit)
|
||||
|
||||
enriched_habit = habit.copy()
|
||||
enriched_habit['current_streak'] = current_streak
|
||||
enriched_habit['best_streak'] = best_streak
|
||||
enriched_habit['completion_rate_30d'] = completion_rate
|
||||
enriched_habit['weekly_summary'] = weekly_summary
|
||||
enriched_habit['should_check_today'] = habits_helpers.should_check_today(habit)
|
||||
|
||||
# Return enriched habit
|
||||
self.send_json(enriched_habit, 200)
|
||||
except Exception as e:
|
||||
self.send_json({'error': str(e)}, 500)
|
||||
|
||||
|
||||
def handle_habits_skip(self):
|
||||
"""Skip a day using a life to preserve streak."""
|
||||
try:
|
||||
@@ -1901,17 +1926,30 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
||||
'type': 'skip'
|
||||
}
|
||||
habit['completions'].append(completion_entry)
|
||||
|
||||
|
||||
# Update timestamp
|
||||
habit['updatedAt'] = datetime.now().isoformat()
|
||||
habits_data['lastUpdated'] = habit['updatedAt']
|
||||
|
||||
|
||||
# Save to file
|
||||
with open(HABITS_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(habits_data, f, indent=2)
|
||||
|
||||
# Return updated habit
|
||||
self.send_json(habit, 200)
|
||||
|
||||
# Enrich habit with calculated stats before returning
|
||||
current_streak = habits_helpers.calculate_streak(habit)
|
||||
best_streak = habit.get('streak', {}).get('best', 0)
|
||||
completion_rate = habits_helpers.get_completion_rate(habit, days=30)
|
||||
weekly_summary = habits_helpers.get_weekly_summary(habit)
|
||||
|
||||
enriched_habit = habit.copy()
|
||||
enriched_habit['current_streak'] = current_streak
|
||||
enriched_habit['best_streak'] = best_streak
|
||||
enriched_habit['completion_rate_30d'] = completion_rate
|
||||
enriched_habit['weekly_summary'] = weekly_summary
|
||||
enriched_habit['should_check_today'] = habits_helpers.should_check_today(habit)
|
||||
|
||||
# Return enriched habit
|
||||
self.send_json(enriched_habit, 200)
|
||||
except Exception as e:
|
||||
self.send_json({'error': str(e)}, 500)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user