MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / get_direction_changes

Function get_direction_changes

skills/storage-helper/scripts/db_ops.py:1224–1261  ·  view source on GitHub ↗

Get direction weight changes compared to previous period Args: user_id: User ID days: Days to look back Returns: List of direction changes with delta information

(user_id: str, days: int = 7)

Source from the content-addressed store, hash-verified

1222 COUNT(*) as total,
1223 SUM(CASE WHEN action_type = 'selected' THEN 1 ELSE 0 END) as selected,
1224 SUM(CASE WHEN action_type = 'skipped' THEN 1 ELSE 0 END) as skipped
1225 FROM behavior_logs
1226 WHERE user_id = ? AND date(timestamp) >= ? AND category != ''
1227 GROUP BY category
1228 """, (user_id, since_date))
1229
1230 rows = cursor.fetchall()
1231 conn.close()
1232
1233 stats = {}
1234 for row in rows:
1235 category = row["category"] or "unknown"
1236 total = row["total"] or 0
1237 selected = row["selected"] or 0
1238 skipped = row["skipped"] or 0
1239
1240 stats[category] = {
1241 "total": total,
1242 "selected": selected,
1243 "skipped": skipped,
1244 "selection_rate": selected / total if total > 0 else 0.0
1245 }
1246
1247 return stats
1248
1249
1250def get_profile_snapshot(user_id: str, days_ago: int) -> Optional[Dict]:
1251 """Get user profile snapshot from N days ago"""
1252 conn = get_connection()
1253 cursor = conn.cursor()
1254
1255 target_date = datetime.now() - timedelta(days=days_ago)
1256 target_date_str = target_date.date().isoformat()
1257
1258 cursor.execute("""
1259 SELECT profile_json, updated_at FROM profiles
1260 WHERE user_id = ? AND date(updated_at) <= ?
1261 ORDER BY updated_at DESC
1262 LIMIT 1
1263 """, (user_id, target_date_str))
1264

Callers 1

generate_weekly_reportFunction · 0.85

Calls 3

get_profile_snapshotFunction · 0.85
getMethod · 0.80
get_profileFunction · 0.70

Tested by

no test coverage detected