StatsManager class

Manages stats collection, caching, and aggregation.

Usage:

final manager = Sint.put(StatsManager());
final stats = await manager.aggregateNeomageStats();
Inheritance

Constructors

StatsManager({String? configHomeDir, String? projectsDir})

Properties

hashCode int
The hash code for this object.
no setterinherited
initialized bool
Checks whether the controller has already been initialized.
no setterinherited
isClosed bool
Checks whether the controller has already been closed.
no setterinherited
isDisposed bool
no setterinherited
listenersLength int
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shotStatsEnabled → RxBool
Feature flags — default to false. Override in tests or config.
final

Methods

addListener(SintStateUpdate listener) → Disposer
Register a closure to be called when the object notifies its listeners.
inherited
addListenerId(Object? key, SintStateUpdate listener) → Disposer
inherited
aggregateNeomageStats() Future<NeomageStats>
Aggregates stats from all Neomage sessions across all projects. Uses a disk cache to avoid reprocessing historical data.
aggregateNeomageStatsForRange(StatsDateRange range) Future<NeomageStats>
Aggregates stats for a specific date range.
cacheToStats(PersistedStatsCache cache, ProcessedStats? todayStats) NeomageStats
Convert a PersistedStatsCache to NeomageStats by computing derived fields, optionally merging today's live stats.
containsListener(SintStateUpdate listener) bool
inherited
debounce<T>(RxInterface<T> rx, void callback(T), {Duration duration = const Duration(milliseconds: 400)}) → void
Calls callback after rx stops changing for duration. Useful for search-as-you-type, form validation, etc.
inherited
dispose() → void
inherited
ever<T>(RxInterface<T> rx, void callback(T)) → void
Calls callback every time rx changes. Auto-cancels on controller disposal.
inherited
getAllSessionFiles() Future<List<String>>
Get all session files from all project directories. Includes both main session files and subagent transcript files.
getStatsCachePath() String
interval<T>(RxInterface<T> rx, void callback(T), {Duration duration = const Duration(seconds: 1)}) → void
Calls callback at most once per duration, ignoring intermediate changes. Useful for rate-limiting UI updates.
inherited
loadStatsCache() Future<PersistedStatsCache>
Load the stats cache from disk. Returns an empty cache if the file doesn't exist or is invalid.
mergeCacheWithNewStats({required PersistedStatsCache existingCache, required ProcessedStats newStats, required String newLastComputedDate}) PersistedStatsCache
Merge new stats into an existing cache. Used when incrementally adding new days to the cache.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
once<T>(RxInterface<T> rx, void callback(T)) → void
Calls callback only the first time rx changes, then cancels.
inherited
onClose() → void
Called before onDelete method. onClose might be used to dispose resources used by the controller. Like closing events, or streams before the controller is destroyed. Or dispose objects that can potentially create some memory leaks, like TextEditingControllers, AnimationControllers. Might be useful as well to persist some data on disk.
inherited
onDelete() → void
inherited
onInit() → void
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
inherited
onReady() → void
Called 1 frame after onInit(). It is the perfect place to enter navigation events, like snackbar, dialogs, or a new route, or async request.
inherited
onStart() → void
Called at the exact moment the widget is allocated in memory. It uses an internal "callable" type, to avoid any @overrides in subclasses. This method should be internal and is required to define the lifetime cycle of the subclass.
inherited
processSessionFiles(List<String> sessionFiles, {ProcessOptions options = const ProcessOptions()}) Future<ProcessedStats>
Process session files and extract stats. Can filter by date range.
refresh() → void
inherited
refreshGroup(Object id) → void
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that the object notifies.
inherited
removeListenerId(Object id, VoidCallback listener) → void
inherited
reportAdd(VoidCallback disposer) → void
inherited
reportRead() → void
inherited
saveStatsCache(PersistedStatsCache cache) Future<void>
Save the stats cache to disk atomically. Uses a temp file + rename pattern to prevent corruption.
toString() String
A string representation of this object.
inherited
update([List<Object>? ids, bool condition = true]) → void
Notifies listeners to update the UI.
inherited
withStatsCacheLock<T>(Future<T> fn()) Future<T>
Execute fn while holding the stats cache lock. Only one operation can hold the lock at a time.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

calculateStreaks(List<DailyActivity> dailyActivity) StreakInfo
Calculate current and longest streaks from daily activity data.
getNextDay(String dateStr) String
Get the next day after dateStr (YYYY-MM-DD).
getTodayDateString() String
Get today's date in YYYY-MM-DD format.
getYesterdayDateString() String
Get yesterday's date in YYYY-MM-DD format.
isDateBefore(String date1, String date2) bool
Check if date1 is before date2. Both YYYY-MM-DD.
readSessionStartDate(String filePath) Future<String?>
Peeks at the head of a session file to get the session start date. Uses a small 4 KB read to avoid loading the full file.
toDateString(DateTime date) String
Extract the date portion (YYYY-MM-DD) from a DateTime object.