@latentminds/pi-quotas 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,11 +53,27 @@ export function getProjectedPercent(
53
53
  return Math.max(0, (usedPercent / effectivePace) * 100);
54
54
  }
55
55
 
56
+ function absoluteUsageSeverity(
57
+ window: QuotaWindow,
58
+ percent: number,
59
+ ): RiskSeverity {
60
+ if (window.limited || percent >= 100) return "critical";
61
+ if (percent >= 90) return "high";
62
+ if (percent >= 80) return "warning";
63
+ return "none";
64
+ }
65
+
66
+ function maxSeverity(a: RiskSeverity, b: RiskSeverity): RiskSeverity {
67
+ const order: RiskSeverity[] = ["none", "warning", "high", "critical"];
68
+ return order[Math.max(order.indexOf(a), order.indexOf(b))] ?? "none";
69
+ }
70
+
56
71
  export function assessWindow(window: QuotaWindow): RiskAssessment {
57
72
  const rawPace = window.showPace ? getPacePercent(window) : null;
58
73
  const pacePercent =
59
74
  rawPace !== null ? rawPace * (window.paceScale ?? 1) : null;
60
75
  const projectedPercent = getProjectedPercent(window.usedPercent, pacePercent);
76
+ const absoluteSeverity = absoluteUsageSeverity(window, window.usedPercent);
61
77
 
62
78
  let progress: number | null = null;
63
79
  if (pacePercent !== null) progress = pacePercent / 100;
@@ -70,10 +86,7 @@ export function assessWindow(window: QuotaWindow): RiskAssessment {
70
86
  };
71
87
 
72
88
  if (progress === null) {
73
- let severity: RiskSeverity = "none";
74
- if (window.limited || projectedPercent >= 100) severity = "critical";
75
- else if (projectedPercent >= 90) severity = "high";
76
- else if (projectedPercent >= 80) severity = "warning";
89
+ const severity = absoluteUsageSeverity(window, projectedPercent);
77
90
 
78
91
  return {
79
92
  ...base,
@@ -121,7 +134,7 @@ export function assessWindow(window: QuotaWindow): RiskAssessment {
121
134
  warnProjectedPercent,
122
135
  highProjectedPercent,
123
136
  criticalProjectedPercent,
124
- severity,
137
+ severity: maxSeverity(severity, absoluteSeverity),
125
138
  };
126
139
  }
127
140
 
@@ -129,8 +142,17 @@ export function formatTimeRemaining(date: Date): string {
129
142
  const ms = date.getTime() - Date.now();
130
143
  if (ms <= 0) return "now";
131
144
  const totalMins = Math.ceil(ms / (1000 * 60));
132
- const hours = Math.floor(totalMins / 60);
145
+ const totalHours = Math.floor(totalMins / 60);
146
+ const days = Math.floor(totalHours / 24);
147
+ const hours = totalHours % 24;
133
148
  const mins = totalMins % 60;
149
+
150
+ if (days >= 1) {
151
+ const parts: string[] = [`${days}d`];
152
+ if (hours > 0) parts.push(`${hours}h`);
153
+ if (mins > 0) parts.push(`${mins}m`);
154
+ return parts.join("");
155
+ }
134
156
  if (hours >= 1) return mins > 0 ? `${hours}h${mins}m` : `${hours}h`;
135
157
  const totalSecs = Math.ceil(ms / 1000);
136
158
  return totalMins >= 1 ? `${totalMins}m` : `${totalSecs}s`;