@x12i/countex 1.0.0 → 1.5.0

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.
Files changed (317) hide show
  1. package/README.md +215 -4
  2. package/dist/backup/export.d.ts +2 -0
  3. package/dist/backup/export.d.ts.map +1 -1
  4. package/dist/backup/export.js +2 -0
  5. package/dist/backup/export.js.map +1 -1
  6. package/dist/backup/manifest.d.ts +49 -0
  7. package/dist/backup/manifest.d.ts.map +1 -0
  8. package/dist/backup/manifest.js +103 -0
  9. package/dist/backup/manifest.js.map +1 -0
  10. package/dist/backup/snapshot-encoding.d.ts +8 -0
  11. package/dist/backup/snapshot-encoding.d.ts.map +1 -0
  12. package/dist/backup/snapshot-encoding.js +27 -0
  13. package/dist/backup/snapshot-encoding.js.map +1 -0
  14. package/dist/cli.d.ts +12 -0
  15. package/dist/cli.d.ts.map +1 -0
  16. package/dist/cli.js +206 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/core/buffer.d.ts +4 -3
  19. package/dist/core/buffer.d.ts.map +1 -1
  20. package/dist/core/buffer.js +65 -9
  21. package/dist/core/buffer.js.map +1 -1
  22. package/dist/core/countex.d.ts +14 -1
  23. package/dist/core/countex.d.ts.map +1 -1
  24. package/dist/core/countex.js +171 -48
  25. package/dist/core/countex.js.map +1 -1
  26. package/dist/core/extraction.d.ts +14 -6
  27. package/dist/core/extraction.d.ts.map +1 -1
  28. package/dist/core/extraction.js +117 -1
  29. package/dist/core/extraction.js.map +1 -1
  30. package/dist/core/mapping.d.ts +5 -0
  31. package/dist/core/mapping.d.ts.map +1 -1
  32. package/dist/core/mapping.js +71 -1
  33. package/dist/core/mapping.js.map +1 -1
  34. package/dist/core/timeframe.d.ts +7 -0
  35. package/dist/core/timeframe.d.ts.map +1 -1
  36. package/dist/core/timeframe.js +88 -0
  37. package/dist/core/timeframe.js.map +1 -1
  38. package/dist/index.d.ts +4 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/insights/advisors/fanout-health.d.ts +3 -0
  43. package/dist/insights/advisors/fanout-health.d.ts.map +1 -0
  44. package/dist/insights/advisors/fanout-health.js +3 -0
  45. package/dist/insights/advisors/fanout-health.js.map +1 -0
  46. package/dist/insights/advisors/map-health.d.ts +6 -0
  47. package/dist/insights/advisors/map-health.d.ts.map +1 -0
  48. package/dist/insights/advisors/map-health.js +154 -0
  49. package/dist/insights/advisors/map-health.js.map +1 -0
  50. package/dist/insights/advisors/resource-advisor.d.ts +4 -0
  51. package/dist/insights/advisors/resource-advisor.d.ts.map +1 -0
  52. package/dist/insights/advisors/resource-advisor.js +102 -0
  53. package/dist/insights/advisors/resource-advisor.js.map +1 -0
  54. package/dist/insights/advisors/retention-advisor.d.ts +2 -0
  55. package/dist/insights/advisors/retention-advisor.d.ts.map +1 -0
  56. package/dist/insights/advisors/retention-advisor.js +6 -0
  57. package/dist/insights/advisors/retention-advisor.js.map +1 -0
  58. package/dist/insights/advisors-subpath.d.ts +4 -0
  59. package/dist/insights/advisors-subpath.d.ts.map +1 -0
  60. package/dist/insights/advisors-subpath.js +10 -0
  61. package/dist/insights/advisors-subpath.js.map +1 -0
  62. package/dist/insights/anomaly/baseline.d.ts +4 -0
  63. package/dist/insights/anomaly/baseline.d.ts.map +1 -0
  64. package/dist/insights/anomaly/baseline.js +54 -0
  65. package/dist/insights/anomaly/baseline.js.map +1 -0
  66. package/dist/insights/anomaly/detect-anomalies.d.ts +6 -0
  67. package/dist/insights/anomaly/detect-anomalies.d.ts.map +1 -0
  68. package/dist/insights/anomaly/detect-anomalies.js +245 -0
  69. package/dist/insights/anomaly/detect-anomalies.js.map +1 -0
  70. package/dist/insights/anomaly/ewma.d.ts +2 -0
  71. package/dist/insights/anomaly/ewma.d.ts.map +1 -0
  72. package/dist/insights/anomaly/ewma.js +15 -0
  73. package/dist/insights/anomaly/ewma.js.map +1 -0
  74. package/dist/insights/anomaly/missing-activity.d.ts +3 -0
  75. package/dist/insights/anomaly/missing-activity.d.ts.map +1 -0
  76. package/dist/insights/anomaly/missing-activity.js +8 -0
  77. package/dist/insights/anomaly/missing-activity.js.map +1 -0
  78. package/dist/insights/anomaly/robust-zscore.d.ts +2 -0
  79. package/dist/insights/anomaly/robust-zscore.d.ts.map +1 -0
  80. package/dist/insights/anomaly/robust-zscore.js +9 -0
  81. package/dist/insights/anomaly/robust-zscore.js.map +1 -0
  82. package/dist/insights/anomaly-subpath.d.ts +7 -0
  83. package/dist/insights/anomaly-subpath.d.ts.map +1 -0
  84. package/dist/insights/anomaly-subpath.js +20 -0
  85. package/dist/insights/anomaly-subpath.js.map +1 -0
  86. package/dist/insights/comparison/compare-periods.d.ts +5 -0
  87. package/dist/insights/comparison/compare-periods.d.ts.map +1 -0
  88. package/dist/insights/comparison/compare-periods.js +64 -0
  89. package/dist/insights/comparison/compare-periods.js.map +1 -0
  90. package/dist/insights/comparison/growth-rate.d.ts +3 -0
  91. package/dist/insights/comparison/growth-rate.d.ts.map +1 -0
  92. package/dist/insights/comparison/growth-rate.js +3 -0
  93. package/dist/insights/comparison/growth-rate.js.map +1 -0
  94. package/dist/insights/comparison/moving-average.d.ts +2 -0
  95. package/dist/insights/comparison/moving-average.d.ts.map +1 -0
  96. package/dist/insights/comparison/moving-average.js +6 -0
  97. package/dist/insights/comparison/moving-average.js.map +1 -0
  98. package/dist/insights/comparison/trend.d.ts +5 -0
  99. package/dist/insights/comparison/trend.d.ts.map +1 -0
  100. package/dist/insights/comparison/trend.js +84 -0
  101. package/dist/insights/comparison/trend.js.map +1 -0
  102. package/dist/insights/errors.d.ts +25 -0
  103. package/dist/insights/errors.d.ts.map +1 -0
  104. package/dist/insights/errors.js +54 -0
  105. package/dist/insights/errors.js.map +1 -0
  106. package/dist/insights/forecast/budget.d.ts +2 -0
  107. package/dist/insights/forecast/budget.d.ts.map +1 -0
  108. package/dist/insights/forecast/budget.js +6 -0
  109. package/dist/insights/forecast/budget.js.map +1 -0
  110. package/dist/insights/forecast/capacity.d.ts +2 -0
  111. package/dist/insights/forecast/capacity.d.ts.map +1 -0
  112. package/dist/insights/forecast/capacity.js +3 -0
  113. package/dist/insights/forecast/capacity.js.map +1 -0
  114. package/dist/insights/forecast/forecast.d.ts +5 -0
  115. package/dist/insights/forecast/forecast.d.ts.map +1 -0
  116. package/dist/insights/forecast/forecast.js +103 -0
  117. package/dist/insights/forecast/forecast.js.map +1 -0
  118. package/dist/insights/forecast/retention.d.ts +2 -0
  119. package/dist/insights/forecast/retention.d.ts.map +1 -0
  120. package/dist/insights/forecast/retention.js +3 -0
  121. package/dist/insights/forecast/retention.js.map +1 -0
  122. package/dist/insights/index.d.ts +4 -0
  123. package/dist/insights/index.d.ts.map +1 -0
  124. package/dist/insights/index.js +23 -0
  125. package/dist/insights/index.js.map +1 -0
  126. package/dist/insights/insights-client.d.ts +33 -0
  127. package/dist/insights/insights-client.d.ts.map +1 -0
  128. package/dist/insights/insights-client.js +344 -0
  129. package/dist/insights/insights-client.js.map +1 -0
  130. package/dist/insights/llm-subpath.d.ts +4 -0
  131. package/dist/insights/llm-subpath.d.ts.map +1 -0
  132. package/dist/insights/llm-subpath.js +10 -0
  133. package/dist/insights/llm-subpath.js.map +1 -0
  134. package/dist/insights/optimization/cost-optimizer.d.ts +6 -0
  135. package/dist/insights/optimization/cost-optimizer.d.ts.map +1 -0
  136. package/dist/insights/optimization/cost-optimizer.js +98 -0
  137. package/dist/insights/optimization/cost-optimizer.js.map +1 -0
  138. package/dist/insights/optimization/latency-optimizer.d.ts +3 -0
  139. package/dist/insights/optimization/latency-optimizer.d.ts.map +1 -0
  140. package/dist/insights/optimization/latency-optimizer.js +3 -0
  141. package/dist/insights/optimization/latency-optimizer.js.map +1 -0
  142. package/dist/insights/optimization/threshold-advisor.d.ts +2 -0
  143. package/dist/insights/optimization/threshold-advisor.d.ts.map +1 -0
  144. package/dist/insights/optimization/threshold-advisor.js +3 -0
  145. package/dist/insights/optimization/threshold-advisor.js.map +1 -0
  146. package/dist/insights/optimization/token-optimizer.d.ts +4 -0
  147. package/dist/insights/optimization/token-optimizer.d.ts.map +1 -0
  148. package/dist/insights/optimization/token-optimizer.js +133 -0
  149. package/dist/insights/optimization/token-optimizer.js.map +1 -0
  150. package/dist/insights/ranking/contribution.d.ts +2 -0
  151. package/dist/insights/ranking/contribution.d.ts.map +1 -0
  152. package/dist/insights/ranking/contribution.js +6 -0
  153. package/dist/insights/ranking/contribution.js.map +1 -0
  154. package/dist/insights/ranking/helpers.d.ts +22 -0
  155. package/dist/insights/ranking/helpers.d.ts.map +1 -0
  156. package/dist/insights/ranking/helpers.js +88 -0
  157. package/dist/insights/ranking/helpers.js.map +1 -0
  158. package/dist/insights/ranking/pareto.d.ts +2 -0
  159. package/dist/insights/ranking/pareto.d.ts.map +1 -0
  160. package/dist/insights/ranking/pareto.js +6 -0
  161. package/dist/insights/ranking/pareto.js.map +1 -0
  162. package/dist/insights/ranking/slices.d.ts +2 -0
  163. package/dist/insights/ranking/slices.d.ts.map +1 -0
  164. package/dist/insights/ranking/slices.js +6 -0
  165. package/dist/insights/ranking/slices.js.map +1 -0
  166. package/dist/insights/ranking/top-bottom.d.ts +2 -0
  167. package/dist/insights/ranking/top-bottom.d.ts.map +1 -0
  168. package/dist/insights/ranking/top-bottom.js +7 -0
  169. package/dist/insights/ranking/top-bottom.js.map +1 -0
  170. package/dist/insights/recommendations/evidence.d.ts +2 -0
  171. package/dist/insights/recommendations/evidence.d.ts.map +1 -0
  172. package/dist/insights/recommendations/evidence.js +3 -0
  173. package/dist/insights/recommendations/evidence.js.map +1 -0
  174. package/dist/insights/recommendations/recommendation.d.ts +6 -0
  175. package/dist/insights/recommendations/recommendation.d.ts.map +1 -0
  176. package/dist/insights/recommendations/recommendation.js +25 -0
  177. package/dist/insights/recommendations/recommendation.js.map +1 -0
  178. package/dist/insights/recommendations/severity.d.ts +2 -0
  179. package/dist/insights/recommendations/severity.d.ts.map +1 -0
  180. package/dist/insights/recommendations/severity.js +3 -0
  181. package/dist/insights/recommendations/severity.js.map +1 -0
  182. package/dist/insights/rules/evaluate-rules.d.ts +5 -0
  183. package/dist/insights/rules/evaluate-rules.d.ts.map +1 -0
  184. package/dist/insights/rules/evaluate-rules.js +156 -0
  185. package/dist/insights/rules/evaluate-rules.js.map +1 -0
  186. package/dist/insights/types.d.ts +405 -0
  187. package/dist/insights/types.d.ts.map +1 -0
  188. package/dist/insights/types.js +3 -0
  189. package/dist/insights/types.js.map +1 -0
  190. package/dist/insights/utils/formatting.d.ts +4 -0
  191. package/dist/insights/utils/formatting.d.ts.map +1 -0
  192. package/dist/insights/utils/formatting.js +21 -0
  193. package/dist/insights/utils/formatting.js.map +1 -0
  194. package/dist/insights/utils/grouping.d.ts +2 -0
  195. package/dist/insights/utils/grouping.d.ts.map +1 -0
  196. package/dist/insights/utils/grouping.js +8 -0
  197. package/dist/insights/utils/grouping.js.map +1 -0
  198. package/dist/insights/utils/query-builder.d.ts +21 -0
  199. package/dist/insights/utils/query-builder.d.ts.map +1 -0
  200. package/dist/insights/utils/query-builder.js +107 -0
  201. package/dist/insights/utils/query-builder.js.map +1 -0
  202. package/dist/insights/utils/row-value.d.ts +5 -0
  203. package/dist/insights/utils/row-value.d.ts.map +1 -0
  204. package/dist/insights/utils/row-value.js +36 -0
  205. package/dist/insights/utils/row-value.js.map +1 -0
  206. package/dist/insights/utils/stats.d.ts +28 -0
  207. package/dist/insights/utils/stats.d.ts.map +1 -0
  208. package/dist/insights/utils/stats.js +125 -0
  209. package/dist/insights/utils/stats.js.map +1 -0
  210. package/dist/query/formatter.d.ts +2 -2
  211. package/dist/query/formatter.d.ts.map +1 -1
  212. package/dist/query/formatter.js +211 -30
  213. package/dist/query/formatter.js.map +1 -1
  214. package/dist/query/planner.d.ts +10 -2
  215. package/dist/query/planner.d.ts.map +1 -1
  216. package/dist/query/planner.js +55 -4
  217. package/dist/query/planner.js.map +1 -1
  218. package/dist/simulation/context.d.ts +5 -0
  219. package/dist/simulation/context.d.ts.map +1 -0
  220. package/dist/simulation/context.js +56 -0
  221. package/dist/simulation/context.js.map +1 -0
  222. package/dist/simulation/events.d.ts +3 -0
  223. package/dist/simulation/events.d.ts.map +1 -0
  224. package/dist/simulation/events.js +67 -0
  225. package/dist/simulation/events.js.map +1 -0
  226. package/dist/simulation/index.d.ts +7 -0
  227. package/dist/simulation/index.d.ts.map +1 -0
  228. package/dist/simulation/index.js +16 -0
  229. package/dist/simulation/index.js.map +1 -0
  230. package/dist/simulation/prng.d.ts +4 -0
  231. package/dist/simulation/prng.d.ts.map +1 -0
  232. package/dist/simulation/prng.js +18 -0
  233. package/dist/simulation/prng.js.map +1 -0
  234. package/dist/simulation/resource-estimate.d.ts +6 -0
  235. package/dist/simulation/resource-estimate.d.ts.map +1 -0
  236. package/dist/simulation/resource-estimate.js +11 -0
  237. package/dist/simulation/resource-estimate.js.map +1 -0
  238. package/dist/simulation/simulator.d.ts +15 -0
  239. package/dist/simulation/simulator.d.ts.map +1 -0
  240. package/dist/simulation/simulator.js +67 -0
  241. package/dist/simulation/simulator.js.map +1 -0
  242. package/dist/simulation/tracker.d.ts +8 -0
  243. package/dist/simulation/tracker.d.ts.map +1 -0
  244. package/dist/simulation/tracker.js +18 -0
  245. package/dist/simulation/tracker.js.map +1 -0
  246. package/dist/simulation/types.d.ts +49 -0
  247. package/dist/simulation/types.d.ts.map +1 -0
  248. package/dist/simulation/types.js +21 -0
  249. package/dist/simulation/types.js.map +1 -0
  250. package/dist/storage/memory.d.ts +3 -0
  251. package/dist/storage/memory.d.ts.map +1 -1
  252. package/dist/storage/memory.js +113 -4
  253. package/dist/storage/memory.js.map +1 -1
  254. package/dist/storage/mongo.d.ts +5 -0
  255. package/dist/storage/mongo.d.ts.map +1 -1
  256. package/dist/storage/mongo.js +129 -17
  257. package/dist/storage/mongo.js.map +1 -1
  258. package/dist/storage/redis.d.ts +12 -9
  259. package/dist/storage/redis.d.ts.map +1 -1
  260. package/dist/storage/redis.js +126 -47
  261. package/dist/storage/redis.js.map +1 -1
  262. package/dist/types/index.d.ts +139 -4
  263. package/dist/types/index.d.ts.map +1 -1
  264. package/docs/DEPLOYMENT.md +40 -2
  265. package/docs/INSIGHTS.md +59 -0
  266. package/docs/INSIGHTS_ANOMALY_DETECTION.md +33 -0
  267. package/docs/INSIGHTS_LLM_COST_AND_TOKENS.md +26 -0
  268. package/docs/INSIGHTS_RESOURCE_ADVISOR.md +31 -0
  269. package/docs/countex_gap_analysis_complete_checklist.md +1340 -0
  270. package/docs/guides/README.md +34 -0
  271. package/docs/guides/adapter-memory.md +48 -0
  272. package/docs/guides/adapter-mongo.md +62 -0
  273. package/docs/guides/adapter-redis.md +53 -0
  274. package/docs/guides/backup-export.md +83 -0
  275. package/docs/guides/cardinality.md +50 -0
  276. package/docs/guides/cli.md +53 -0
  277. package/docs/guides/client-events.md +49 -0
  278. package/docs/guides/counter-maps.md +122 -0
  279. package/docs/guides/idempotency.md +39 -0
  280. package/docs/guides/ingestion-and-flush.md +67 -0
  281. package/docs/guides/insights-advisors-and-optimization.md +39 -0
  282. package/docs/guides/insights-anomalies-and-rules.md +48 -0
  283. package/docs/guides/insights-comparison-and-trends.md +47 -0
  284. package/docs/guides/insights-forecasting-and-budget.md +61 -0
  285. package/docs/guides/insights-overview.md +82 -0
  286. package/docs/guides/insights-ranking.md +81 -0
  287. package/docs/guides/measures.md +71 -0
  288. package/docs/guides/querying.md +119 -0
  289. package/docs/guides/simulation-profiles.md +33 -0
  290. package/docs/guides/simulation-resource-estimation.md +30 -0
  291. package/docs/guides/simulation.md +36 -0
  292. package/docs/guides/timeframes-and-bucketing.md +55 -0
  293. package/docs/internals/README.md +21 -0
  294. package/docs/internals/internal-architecture-overview.md +65 -0
  295. package/docs/internals/internal-backup-stream.md +23 -0
  296. package/docs/internals/internal-buffer-merge-and-flush.md +51 -0
  297. package/docs/internals/internal-cardinality.md +30 -0
  298. package/docs/internals/internal-dimension-hash.md +34 -0
  299. package/docs/internals/internal-idempotency.md +36 -0
  300. package/docs/internals/internal-ingest-pipeline.md +52 -0
  301. package/docs/internals/internal-insights-layer.md +36 -0
  302. package/docs/internals/internal-mapping-validation-and-extraction.md +59 -0
  303. package/docs/internals/internal-measures-and-scales.md +35 -0
  304. package/docs/internals/internal-query-path.md +46 -0
  305. package/docs/internals/internal-storage-memory.md +13 -0
  306. package/docs/internals/internal-storage-mongo.md +24 -0
  307. package/docs/internals/internal-storage-redis.md +31 -0
  308. package/docs/internals/internal-timeframe-bucketing.md +33 -0
  309. package/docs/use-cases/README.md +56 -0
  310. package/docs/use-cases/audit-security-log-counts.md +550 -0
  311. package/docs/use-cases/llm-cost-and-token-metering.md +255 -0
  312. package/docs/use-cases/multi-tenant-isolation.md +203 -0
  313. package/docs/use-cases/ops-dashboard-daily-rollups.md +255 -0
  314. package/docs/use-cases/processing-workflow-activity.md +165 -0
  315. package/docs/use-cases/product-feature-usage.md +240 -0
  316. package/docs/use-cases/webhook-idempotent-ingestion.md +188 -0
  317. package/package.json +61 -2
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeComparePeriods = mergeComparePeriods;
4
+ const row_value_js_1 = require("../utils/row-value.js");
5
+ function rowKey(keys) {
6
+ const sorted = {};
7
+ for (const k of Object.keys(keys).sort()) {
8
+ sorted[k] = keys[k];
9
+ }
10
+ return JSON.stringify(sorted);
11
+ }
12
+ function mergeComparePeriods(currentRows, previousRows, parsed, minAbs, minPct) {
13
+ const prevMap = new Map();
14
+ for (const r of previousRows)
15
+ prevMap.set(rowKey(r.keys), r);
16
+ const curMap = new Map();
17
+ for (const r of currentRows)
18
+ curMap.set(rowKey(r.keys), r);
19
+ const keys = new Set([...prevMap.keys(), ...curMap.keys()]);
20
+ const out = [];
21
+ for (const k of keys) {
22
+ const cur = curMap.get(k);
23
+ const prev = prevMap.get(k);
24
+ const c = cur ? (0, row_value_js_1.rowValue)(cur, parsed) : 0;
25
+ const p = prev ? (0, row_value_js_1.rowValue)(prev, parsed) : 0;
26
+ const keysObj = (cur ?? prev).keys;
27
+ const absoluteChange = c - p;
28
+ let direction;
29
+ if (p === 0 && c === 0)
30
+ direction = "flat";
31
+ else if (p === 0 && c > 0)
32
+ direction = "new";
33
+ else if (c === 0 && p > 0)
34
+ direction = "missing";
35
+ else if (absoluteChange > 0)
36
+ direction = "up";
37
+ else if (absoluteChange < 0)
38
+ direction = "down";
39
+ else
40
+ direction = "flat";
41
+ const percentChange = p === 0 ? null : ((c - p) / p) * 100;
42
+ let significance = "low";
43
+ const pct = percentChange === null ? 0 : Math.abs(percentChange);
44
+ if (pct >= 50)
45
+ significance = "high";
46
+ else if (pct >= 20)
47
+ significance = "medium";
48
+ if (minAbs !== undefined && Math.abs(absoluteChange) < minAbs)
49
+ continue;
50
+ if (minPct !== undefined && percentChange !== null && Math.abs(percentChange) < minPct)
51
+ continue;
52
+ out.push({
53
+ keys: keysObj,
54
+ current: c,
55
+ previous: p,
56
+ absoluteChange,
57
+ percentChange,
58
+ direction,
59
+ significance,
60
+ });
61
+ }
62
+ return out;
63
+ }
64
+ //# sourceMappingURL=compare-periods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-periods.js","sourceRoot":"","sources":["../../../src/insights/comparison/compare-periods.ts"],"names":[],"mappings":";;AAaA,kDAqDC;AA/DD,wDAAiD;AAEjD,SAAS,MAAM,CAAC,IAAqC;IACnD,MAAM,MAAM,GAAoC,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACzC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,mBAAmB,CACjC,WAAuB,EACvB,YAAwB,EACxB,MAAqB,EACrB,MAAe,EACf,MAAe;IAEf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# sourceMappingURL=growth-rate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"growth-rate.d.ts","sourceRoot":"","sources":["../../../src/insights/comparison/growth-rate.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,OAAO,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=growth-rate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"growth-rate.js","sourceRoot":"","sources":["../../../src/insights/comparison/growth-rate.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { movingAverage } from "../utils/stats.js";
2
+ //# sourceMappingURL=moving-average.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moving-average.d.ts","sourceRoot":"","sources":["../../../src/insights/comparison/moving-average.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.movingAverage = void 0;
4
+ var stats_js_1 = require("../utils/stats.js");
5
+ Object.defineProperty(exports, "movingAverage", { enumerable: true, get: function () { return stats_js_1.movingAverage; } });
6
+ //# sourceMappingURL=moving-average.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moving-average.js","sourceRoot":"","sources":["../../../src/insights/comparison/moving-average.ts"],"names":[],"mappings":";;;AAAA,8CAAkD;AAAzC,yGAAA,aAAa,OAAA"}
@@ -0,0 +1,5 @@
1
+ import type { TimeseriesPoint } from "../../types/index.js";
2
+ import type { TrendResult } from "../types.js";
3
+ import type { ParsedMeasure } from "../utils/query-builder.js";
4
+ export declare function trendFromTimeseries(points: TimeseriesPoint[], parsed: ParsedMeasure, method: "linear" | "moving_average" | "simple_growth", movingWindow?: number): TrendResult["rows"];
5
+ //# sourceMappingURL=trend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trend.d.ts","sourceRoot":"","sources":["../../../src/insights/comparison/trend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA+B/D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,eAAe,EAAE,EACzB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,QAAQ,GAAG,gBAAgB,GAAG,eAAe,EACrD,YAAY,CAAC,EAAE,MAAM,GACpB,WAAW,CAAC,MAAM,CAAC,CAqDrB"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trendFromTimeseries = trendFromTimeseries;
4
+ const formatting_js_1 = require("../utils/formatting.js");
5
+ const stats_js_1 = require("../utils/stats.js");
6
+ function tsValue(pt, parsed) {
7
+ if (parsed.kind === "count")
8
+ return pt.count;
9
+ if (parsed.kind === "rate")
10
+ return pt.rate ?? 0;
11
+ const m = pt.measures?.[parsed.name];
12
+ if (!m)
13
+ return 0;
14
+ switch (parsed.agg) {
15
+ case "sum":
16
+ return m.sum ?? 0;
17
+ case "count":
18
+ return m.count ?? 0;
19
+ case "min":
20
+ return m.min ?? 0;
21
+ case "max":
22
+ return m.max ?? 0;
23
+ case "avg":
24
+ if (m.avg !== undefined)
25
+ return m.avg;
26
+ if (m.sum !== undefined && m.count !== undefined && m.count !== 0)
27
+ return m.sum / m.count;
28
+ return 0;
29
+ default:
30
+ return 0;
31
+ }
32
+ }
33
+ function seriesKey(pt) {
34
+ return (0, formatting_js_1.stableSerializedGroupKeys)(pt.keys);
35
+ }
36
+ function trendFromTimeseries(points, parsed, method, movingWindow) {
37
+ const clusters = new Map();
38
+ for (const p of points) {
39
+ const k = seriesKey(p);
40
+ const arr = clusters.get(k) ?? [];
41
+ arr.push(p);
42
+ clusters.set(k, arr);
43
+ }
44
+ const rows = [];
45
+ for (const [, series] of clusters) {
46
+ series.sort((a, b) => (a.timeframeKey < b.timeframeKey ? -1 : 1));
47
+ let ys = series.map((p) => tsValue(p, parsed));
48
+ const xs = series.map((_, i) => i);
49
+ if (method === "moving_average" && (movingWindow ?? 3) > 1) {
50
+ ys = (0, stats_js_1.movingAverage)(ys, movingWindow ?? 3);
51
+ }
52
+ let slope = 0;
53
+ let r2;
54
+ if (method === "linear" || method === "moving_average") {
55
+ const reg = (0, stats_js_1.linearRegression)(xs, ys);
56
+ slope = reg.slope;
57
+ r2 = reg.r2;
58
+ }
59
+ else if (method === "simple_growth") {
60
+ const a = ys[0] ?? 0;
61
+ const b = ys[ys.length - 1] ?? 0;
62
+ slope = ys.length > 1 ? (b - a) / (ys.length - 1) : 0;
63
+ }
64
+ const startValue = ys[0] ?? 0;
65
+ const endValue = ys[ys.length - 1] ?? 0;
66
+ let direction = "flat";
67
+ if (slope > 1e-9)
68
+ direction = "up";
69
+ else if (slope < -1e-9)
70
+ direction = "down";
71
+ const changePercent = startValue === 0 ? null : ((endValue - startValue) / Math.abs(startValue)) * 100;
72
+ rows.push({
73
+ keys: (series[0]?.keys ?? {}),
74
+ slope,
75
+ direction,
76
+ startValue,
77
+ endValue,
78
+ changePercent,
79
+ r2,
80
+ });
81
+ }
82
+ return rows;
83
+ }
84
+ //# sourceMappingURL=trend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trend.js","sourceRoot":"","sources":["../../../src/insights/comparison/trend.ts"],"names":[],"mappings":";;AAiCA,kDA0DC;AAxFD,0DAAmE;AACnE,gDAAoE;AAEpE,SAAS,OAAO,CAAC,EAAmB,EAAE,MAAqB;IACzD,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC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AAG,EAAE,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;YACjC,KAAK,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,SAAS,GAA2B,MAAM,CAAC;QAC/C,IAAI,KAAK,GAAG,IAAI;YAAE,SAAS,GAAG,IAAI,CAAC;aAC9B,IAAI,KAAK,GAAG,CAAC,IAAI;YAAE,SAAS,GAAG,MAAM,CAAC;QAE3C,MAAM,aAAa,GACjB,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,GAAG,CAAC;QAEnF,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAA4B;YACxD,KAAK;YACL,SAAS;YACT,UAAU;YACV,QAAQ;YACR,aAAa;YACb,EAAE;SACH,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { CountexError } from "../utils/errors.js";
2
+ export declare class CountexInsightError extends CountexError {
3
+ constructor(message: string, meta?: Record<string, unknown>);
4
+ }
5
+ export declare class InsightQueryTooBroadError extends CountexInsightError {
6
+ constructor(message: string, meta?: Record<string, unknown>);
7
+ }
8
+ export declare class InsufficientDataError extends CountexInsightError {
9
+ constructor(message: string, meta?: Record<string, unknown>);
10
+ }
11
+ export declare class UnsupportedMeasureError extends CountexInsightError {
12
+ constructor(message: string, meta?: Record<string, unknown>);
13
+ }
14
+ export declare class InvalidBaselineError extends CountexInsightError {
15
+ constructor(message: string, meta?: Record<string, unknown>);
16
+ }
17
+ export declare class InsightStorageError extends CountexInsightError {
18
+ constructor(message: string, meta?: Record<string, unknown> & {
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ export declare class InvalidInsightInputError extends CountexInsightError {
23
+ constructor(message: string, meta?: Record<string, unknown>);
24
+ }
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/insights/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D;AAED,qBAAa,yBAA0B,SAAQ,mBAAmB;gBACpD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D;AAED,qBAAa,qBAAsB,SAAQ,mBAAmB;gBAChD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D;AAED,qBAAa,uBAAwB,SAAQ,mBAAmB;gBAClD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D;AAED,qBAAa,oBAAqB,SAAQ,mBAAmB;gBAC/C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D;AAED,qBAAa,mBAAoB,SAAQ,mBAAmB;gBAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIlF;AAED,qBAAa,wBAAyB,SAAQ,mBAAmB;gBACnD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI5D"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidInsightInputError = exports.InsightStorageError = exports.InvalidBaselineError = exports.UnsupportedMeasureError = exports.InsufficientDataError = exports.InsightQueryTooBroadError = exports.CountexInsightError = void 0;
4
+ const errors_js_1 = require("../utils/errors.js");
5
+ class CountexInsightError extends errors_js_1.CountexError {
6
+ constructor(message, meta) {
7
+ super(message, meta);
8
+ this.name = "CountexInsightError";
9
+ }
10
+ }
11
+ exports.CountexInsightError = CountexInsightError;
12
+ class InsightQueryTooBroadError extends CountexInsightError {
13
+ constructor(message, meta) {
14
+ super(message, meta);
15
+ this.name = "InsightQueryTooBroadError";
16
+ }
17
+ }
18
+ exports.InsightQueryTooBroadError = InsightQueryTooBroadError;
19
+ class InsufficientDataError extends CountexInsightError {
20
+ constructor(message, meta) {
21
+ super(message, meta);
22
+ this.name = "InsufficientDataError";
23
+ }
24
+ }
25
+ exports.InsufficientDataError = InsufficientDataError;
26
+ class UnsupportedMeasureError extends CountexInsightError {
27
+ constructor(message, meta) {
28
+ super(message, meta);
29
+ this.name = "UnsupportedMeasureError";
30
+ }
31
+ }
32
+ exports.UnsupportedMeasureError = UnsupportedMeasureError;
33
+ class InvalidBaselineError extends CountexInsightError {
34
+ constructor(message, meta) {
35
+ super(message, meta);
36
+ this.name = "InvalidBaselineError";
37
+ }
38
+ }
39
+ exports.InvalidBaselineError = InvalidBaselineError;
40
+ class InsightStorageError extends CountexInsightError {
41
+ constructor(message, meta) {
42
+ super(message, meta);
43
+ this.name = "InsightStorageError";
44
+ }
45
+ }
46
+ exports.InsightStorageError = InsightStorageError;
47
+ class InvalidInsightInputError extends CountexInsightError {
48
+ constructor(message, meta) {
49
+ super(message, meta);
50
+ this.name = "InvalidInsightInputError";
51
+ }
52
+ }
53
+ exports.InvalidInsightInputError = InvalidInsightInputError;
54
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/insights/errors.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAElD,MAAa,mBAAoB,SAAQ,wBAAY;IACnD,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED,MAAa,yBAA0B,SAAQ,mBAAmB;IAChE,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AALD,8DAKC;AAED,MAAa,qBAAsB,SAAQ,mBAAmB;IAC5D,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC;AAED,MAAa,uBAAwB,SAAQ,mBAAmB;IAC9D,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AALD,0DAKC;AAED,MAAa,oBAAqB,SAAQ,mBAAmB;IAC3D,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAED,MAAa,mBAAoB,SAAQ,mBAAmB;IAC1D,YAAY,OAAe,EAAE,IAAoD;QAC/E,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED,MAAa,wBAAyB,SAAQ,mBAAmB;IAC/D,YAAY,OAAe,EAAE,IAA8B;QACzD,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AALD,4DAKC"}
@@ -0,0 +1,2 @@
1
+ export { runBudgetProjection } from "../optimization/cost-optimizer.js";
2
+ //# sourceMappingURL=budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../../src/insights/forecast/budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runBudgetProjection = void 0;
4
+ var cost_optimizer_js_1 = require("../optimization/cost-optimizer.js");
5
+ Object.defineProperty(exports, "runBudgetProjection", { enumerable: true, get: function () { return cost_optimizer_js_1.runBudgetProjection; } });
6
+ //# sourceMappingURL=budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../src/insights/forecast/budget.ts"],"names":[],"mappings":";;;AAAA,uEAAwE;AAA/D,wHAAA,mBAAmB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=capacity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacity.d.ts","sourceRoot":"","sources":["../../../src/insights/forecast/capacity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=capacity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacity.js","sourceRoot":"","sources":["../../../src/insights/forecast/capacity.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { QuerySpec } from "../../types/index.js";
2
+ import type { ForecastInput, ForecastResult } from "../types.js";
3
+ import type { InsightDefaults } from "../types.js";
4
+ export declare function runForecast(query: (s: QuerySpec) => Promise<import("../../types/index.js").QueryResult>, input: ForecastInput, defaults: InsightDefaults, maxGroups: number): Promise<ForecastResult>;
5
+ //# sourceMappingURL=forecast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forecast.d.ts","sourceRoot":"","sources":["../../../src/insights/forecast/forecast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAYnD,wBAAsB,WAAW,CAC/B,KAAK,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,sBAAsB,EAAE,WAAW,CAAC,EAC5E,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,CAAC,CA8GzB"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runForecast = runForecast;
4
+ const timeframe_js_1 = require("../../core/timeframe.js");
5
+ const query_builder_js_1 = require("../utils/query-builder.js");
6
+ const row_value_js_1 = require("../utils/row-value.js");
7
+ const stats_js_1 = require("../utils/stats.js");
8
+ const formatting_js_1 = require("../utils/formatting.js");
9
+ const recommendation_js_1 = require("../recommendations/recommendation.js");
10
+ async function runForecast(query, input, defaults, maxGroups) {
11
+ const parsed = (0, query_builder_js_1.parseMeasureSelector)(input.measure);
12
+ let spec = (0, query_builder_js_1.baseToQuerySpec)({
13
+ scope: input.scope,
14
+ counterId: input.counterId,
15
+ timeframe: input.history,
16
+ filters: input.filters,
17
+ groupBy: input.groupBy,
18
+ bypassCache: input.bypassCache,
19
+ signal: input.signal,
20
+ maxBuckets: input.maxBuckets,
21
+ }, defaults, { format: "timeseries", limit: undefined });
22
+ spec = (0, query_builder_js_1.applyParsedMeasureToSpec)(spec, parsed, "desc");
23
+ const res = await query(spec);
24
+ const points = res.rows;
25
+ const clusters = new Map();
26
+ for (const p of points) {
27
+ const k = (0, formatting_js_1.stableSerializedGroupKeys)(p.keys);
28
+ const arr = clusters.get(k) ?? [];
29
+ arr.push(p);
30
+ clusters.set(k, arr);
31
+ }
32
+ (0, query_builder_js_1.enforceMaxGroups)(clusters.size, maxGroups);
33
+ const histBuckets = (0, timeframe_js_1.bucketRange)(input.history.type, input.history.from, input.history.to);
34
+ const forecastEnd = input.forecastTo;
35
+ const allBuckets = (0, timeframe_js_1.bucketRange)(input.history.type, input.history.from, forecastEnd);
36
+ const extraBuckets = Math.max(0, allBuckets.length - histBuckets.length);
37
+ const rows = [];
38
+ const recommendations = [];
39
+ for (const [, series] of clusters) {
40
+ series.sort((a, b) => (a.timeframeKey < b.timeframeKey ? -1 : 1));
41
+ const ys = series.map((pt) => parsed.kind === "count"
42
+ ? pt.count
43
+ : parsed.kind === "rate"
44
+ ? pt.rate ?? 0
45
+ : (0, row_value_js_1.rowValue)({
46
+ keys: pt.keys ?? {},
47
+ count: pt.count,
48
+ measures: pt.measures,
49
+ rate: pt.rate,
50
+ }, parsed));
51
+ const xs = series.map((_, i) => i);
52
+ let projectedExtra = 0;
53
+ let method = input.method;
54
+ let confidence = "medium";
55
+ let explanation = "";
56
+ if (method === "linear") {
57
+ const { slope, intercept } = (0, stats_js_1.linearRegression)(xs, ys);
58
+ for (let i = 0; i < extraBuckets; i++) {
59
+ projectedExtra += slope * (xs.length + i) + intercept;
60
+ }
61
+ explanation = `Linear trend extrapolated ${extraBuckets} buckets.`;
62
+ }
63
+ else if (method === "moving_average") {
64
+ const w = ys.slice(-7);
65
+ const avg = w.reduce((a, b) => a + b, 0) / Math.max(1, w.length);
66
+ projectedExtra = avg * extraBuckets;
67
+ explanation = `Flat projection from recent moving average.`;
68
+ confidence = "low";
69
+ }
70
+ else {
71
+ const totalHist = ys.reduce((a, b) => a + b, 0);
72
+ const scale = extraBuckets / Math.max(1, ys.length);
73
+ projectedExtra = totalHist * scale;
74
+ explanation = `Scaled average bucket value over ${extraBuckets} future buckets.`;
75
+ method = "same_period_projection";
76
+ confidence = "low";
77
+ }
78
+ const observedToDate = ys.reduce((a, b) => a + b, 0);
79
+ const projectedTotal = observedToDate + Math.max(0, projectedExtra);
80
+ rows.push({
81
+ keys: (series[0]?.keys ?? {}),
82
+ observedToDate,
83
+ projectedTotal,
84
+ confidence,
85
+ method,
86
+ explanation,
87
+ });
88
+ }
89
+ if (rows.some((r) => r.confidence === "low")) {
90
+ recommendations.push((0, recommendation_js_1.recommendation)({
91
+ type: "forecast_low_confidence",
92
+ severity: "info",
93
+ confidence: "low",
94
+ scope: input.scope,
95
+ counterId: input.counterId,
96
+ title: "Forecast confidence is limited",
97
+ explanation: "Simple projection without seasonality or histogram signals.",
98
+ evidence: {},
99
+ }));
100
+ }
101
+ return { rows, recommendations };
102
+ }
103
+ //# sourceMappingURL=forecast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forecast.js","sourceRoot":"","sources":["../../../src/insights/forecast/forecast.ts"],"names":[],"mappings":";;AAeA,kCAmHC;AAlID,0DAAsD;AAItD,gEAKmC;AACnC,wDAAiD;AACjD,gDAAqD;AACrD,0DAAmE;AACnE,4EAAsE;AAE/D,KAAK,UAAU,WAAW,CAC/B,KAA4E,EAC5E,KAAoB,EACpB,QAAyB,EACzB,SAAiB;IAEjB,MAAM,MAAM,GAAG,IAAA,uCAAoB,EA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CAAC;YACpD,cAAc,GAAG,SAAS,GAAG,KAAK,CAAC;YACnC,WAAW,GAAG,oCAAoC,YAAY,kBAAkB,CAAC;YACjF,MAAM,GAAG,wBAAwB,CAAC;YAClC,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;QAED,MAAM,cAAc,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACrD,MAAM,cAAc,GAAG,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAA4B;YACxD,cAAc;YACd,cAAc;YACd,UAAU;YACV,MAAM;YACN,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,KAAK,CAAC,EAAE,CAAC;QAC7C,eAAe,CAAC,IAAI,CAClB,IAAA,kCAAc,EAAC;YACb,IAAI,EAAE,yBAAyB;YAC/B,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK,EAAE,gCAAgC;YACvC,WAAW,EAAE,6DAA6D;YAC1E,QAAQ,EAAE,EAAE;SACb,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=retention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../../src/insights/forecast/retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.js","sourceRoot":"","sources":["../../../src/insights/forecast/retention.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export { createCountexInsights, CountexInsights } from "./insights-client.js";
2
+ export * from "./types.js";
3
+ export * from "./errors.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/insights/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CountexInsights = exports.createCountexInsights = void 0;
18
+ var insights_client_js_1 = require("./insights-client.js");
19
+ Object.defineProperty(exports, "createCountexInsights", { enumerable: true, get: function () { return insights_client_js_1.createCountexInsights; } });
20
+ Object.defineProperty(exports, "CountexInsights", { enumerable: true, get: function () { return insights_client_js_1.CountexInsights; } });
21
+ __exportStar(require("./types.js"), exports);
22
+ __exportStar(require("./errors.js"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/insights/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAA8E;AAArE,2HAAA,qBAAqB,OAAA;AAAE,qHAAA,eAAe,OAAA;AAC/C,6CAA2B;AAC3B,8CAA4B"}
@@ -0,0 +1,33 @@
1
+ import { EventEmitter } from "node:events";
2
+ import type { Countex } from "../core/countex.js";
3
+ import type { CounterMap, DurableStorage } from "../types/index.js";
4
+ import type { AnomalyResult, BottomNInput, BudgetProjectionInput, BudgetProjectionResult, ComparePeriodsInput, ComparePeriodsResult, ContributionResult, CostDriversInput, CostDriversResult, CountexInsightsEvents, CreateCountexInsightsConfig, DetectAnomaliesInput, EvaluateRulesInput, ForecastInput, ForecastResult, InsightBaseInput, InsightDefaults, MapHealthInput, MapHealthResult, MaxTokenRecommendationResult, ParetoInput, ParetoResult, PercentSliceInput, PercentSliceResult, RankingResult, RecommendMaxTokensInput, ResourceAdvisorInput, ResourceAdvisorResult, RuleEvaluationResult, TopNInput, TrendInput, TrendResult } from "./types.js";
5
+ export declare class CountexInsights extends EventEmitter {
6
+ private readonly client;
7
+ private readonly defaults;
8
+ private readonly maps?;
9
+ private readonly durable?;
10
+ constructor(client: Countex, defaults: InsightDefaults, maps?: Map<string, CounterMap> | undefined, durable?: DurableStorage | undefined);
11
+ emit<K extends keyof CountexInsightsEvents>(event: K, payload: CountexInsightsEvents[K]): boolean;
12
+ private mg;
13
+ private timedQuery;
14
+ private mapFor;
15
+ topN(input: TopNInput): Promise<RankingResult>;
16
+ bottomN(input: BottomNInput): Promise<RankingResult>;
17
+ topPercent(input: PercentSliceInput): Promise<PercentSliceResult>;
18
+ bottomPercent(input: PercentSliceInput): Promise<PercentSliceResult>;
19
+ pareto(input: ParetoInput): Promise<ParetoResult>;
20
+ contribution(input: InsightBaseInput): Promise<ContributionResult>;
21
+ comparePeriods(input: ComparePeriodsInput): Promise<ComparePeriodsResult>;
22
+ trend(input: TrendInput): Promise<TrendResult>;
23
+ forecast(input: ForecastInput): Promise<ForecastResult>;
24
+ detectAnomalies(input: DetectAnomaliesInput): Promise<AnomalyResult>;
25
+ evaluateRules(input: EvaluateRulesInput): Promise<RuleEvaluationResult>;
26
+ recommendMaxTokens(input: RecommendMaxTokensInput): Promise<MaxTokenRecommendationResult>;
27
+ costDrivers(input: CostDriversInput): Promise<CostDriversResult>;
28
+ budgetProjection(input: BudgetProjectionInput): Promise<BudgetProjectionResult>;
29
+ analyzeMapHealth(input: MapHealthInput): Promise<MapHealthResult>;
30
+ estimateResourcesFromActuals(input: ResourceAdvisorInput): Promise<ResourceAdvisorResult>;
31
+ }
32
+ export declare function createCountexInsights(config: CreateCountexInsightsConfig): CountexInsights;
33
+ //# sourceMappingURL=insights-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insights-client.d.ts","sourceRoot":"","sources":["../../src/insights/insights-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAuB,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,eAAe,EACf,4BAA4B,EAC5B,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,qB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