GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — progressioncontroller/PointBasedController.py at main · elder-athletes/progressioncontroller Expand file tree/ Copy pathPointBasedController.pyMore file actions 151 lines (119 loc) · 5.64 KB / Copy pathPointBasedController.pyFile metadata and controls151 lines (119 loc) · 5.64 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 import json from datetime import datetime # Define the ExtendedTask class class ExtendedTask: def __init__(self, task_type, initiated_today, cancelled_in_a_row, last_feedback, performed_this_week, completion_time, initial_completion_time, previous_completion_times, correction_cues, pressure_spread, game_points, weight_for_speed=1, weight_for_correction=1, weight_for_pressure=1, weight_for_points=1, last_updated=None): # Task properties self.task_type = task_type self.initiated_today = initiated_today self.cancelled_in_a_row = cancelled_in_a_row self.last_feedback = last_feedback self.performed_this_week = performed_this_week self.completion_time = completion_time self.initial_completion_time = initial_completion_time self.previous_completion_times = previous_completion_times self.correction_cues = correction_cues self.pressure_spread = pressure_spread self.game_points = game_points self.weight_for_speed = weight_for_speed self.weight_for_correction = weight_for_correction self.weight_for_pressure = weight_for_pressure self.weight_for_points = weight_for_points # Timestamp for last updated metrics self.last_updated = datetime.fromisoformat(last_updated) if last_updated else datetime.min self.points = 0 def calculate_competence_factor(self): # Avoid division by zero errors if not self.previous_completion_times or self.completion_time == 0: return 0 avg_previous_completion = sum(self.previous_completion_times) / len(self.previous_completion_times) if self.task_type == 'sit-up-down': correction_avg = sum(self.correction_cues) / len(self.correction_cues) if self.correction_cues and any( self.correction_cues) else 1 return self.weight_for_speed * ( avg_previous_completion / self.completion_time) - self.weight_for_correction * ( self.correction_cues[-1] / correction_avg) if self.task_type == 'balance': pressure_avg = sum(self.pressure_spread) / len(self.pressure_spread) if self.pressure_spread and any( self.pressure_spread) else 1 return self.weight_for_speed * ( avg_previous_completion / self.completion_time) - self.weight_for_pressure * ( self.pressure_spread[-1] / pressure_avg) if self.task_type == 'saccades': return 0 if self.task_type == 'memory': points_avg = sum(self.game_points) / len(self.game_points) if self.game_points and any( self.game_points) else 1 return self.weight_for_speed * (avg_previous_completion / self.completion_time) - self.weight_for_points * ( self.game_points[-1] / points_avg) return 0 def calculate_points(task): # Initialize points total_points = 0 # Assign points based on initiation frequency if task.initiated_today <= 2: total_points += 10 elif task.initiated_today <= 5: total_points += 5 else: total_points += 1 # Deduct points for cancellations cancel_penalty = task.cancelled_in_a_row * 2 total_points -= min(cancel_penalty, 10) # Add points for positive feedback if task.last_feedback == 'positive': total_points += 10 # Add points if task hasn't been performed this week if not task.performed_this_week: total_points += 15 # Add points based on competence factor competence_factor = task.calculate_competence_factor() total_points += competence_factor * 5 return total_points def recommend_next_task(tasks): # Sort tasks by points and select the one with highest points tasks_sorted = sorted(tasks, key=lambda t: t.points, reverse=True) return tasks_sorted[0] def load_points_from_memory(): # Load previously stored task points from file try: with open('task_points.json', 'r') as file: return json.load(file) except (FileNotFoundError, json.JSONDecodeError): return {} def update_memory(task_points_dict): # Save updated task points to file with open('task_points.json', 'w') as file: json.dump(task_points_dict, file) # Load previously stored points memory_points = load_points_from_memory() # Load tasks from the external JSON file with open('tasks.json', 'r') as file: tasks_data = json.load(file) all_tasks = [ExtendedTask(**task_data) for task_data in tasks_data] # Calculate or fetch points for each task for task in all_tasks: if task.last_updated > datetime.fromisoformat( memory_points.get(task.task_type, {}).get('timestamp', '1970-01-01T00:00:00')): task.points = calculate_points(task) memory_points[task.task_type] = { 'points': task.points, 'timestamp': task.last_updated.isoformat() } elif task.task_type in memory_points: task.points = memory_points[task.task_type]['points'] else: task.points = calculate_points(task) memory_points[task.task_type] = { 'points': task.points, 'timestamp': task.last_updated.isoformat() } # Update memory update_memory(memory_points) # Recommend next task based on highest points next_task = recommend_next_task(all_tasks) print(f"The recommended next task is: {next_task.task_type}") |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |