@memberjunction/predictive-studio 6.2.2 → 6.3.0-edge.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.
Files changed (391) hide show
  1. package/README.md +16 -11
  2. package/dist/actions/base-predictive-studio.action.d.ts +7 -0
  3. package/dist/actions/base-predictive-studio.action.d.ts.map +1 -1
  4. package/dist/actions/base-predictive-studio.action.js +22 -0
  5. package/dist/actions/base-predictive-studio.action.js.map +1 -1
  6. package/dist/actions/driver-classes.d.ts +2 -0
  7. package/dist/actions/driver-classes.d.ts.map +1 -1
  8. package/dist/actions/driver-classes.js +2 -0
  9. package/dist/actions/driver-classes.js.map +1 -1
  10. package/dist/actions/evaluate-drift.action.d.ts +100 -0
  11. package/dist/actions/evaluate-drift.action.d.ts.map +1 -0
  12. package/dist/actions/evaluate-drift.action.js +512 -0
  13. package/dist/actions/evaluate-drift.action.js.map +1 -0
  14. package/dist/actions/index.d.ts +3 -0
  15. package/dist/actions/index.d.ts.map +1 -1
  16. package/dist/actions/index.js +7 -0
  17. package/dist/actions/index.js.map +1 -1
  18. package/dist/actions/migrate-pipelines.action.d.ts +19 -0
  19. package/dist/actions/migrate-pipelines.action.d.ts.map +1 -0
  20. package/dist/actions/migrate-pipelines.action.js +51 -0
  21. package/dist/actions/migrate-pipelines.action.js.map +1 -0
  22. package/dist/actions/promote-model.action.d.ts +12 -1
  23. package/dist/actions/promote-model.action.d.ts.map +1 -1
  24. package/dist/actions/promote-model.action.js +7 -2
  25. package/dist/actions/promote-model.action.js.map +1 -1
  26. package/dist/actions/promote-model.gate.d.ts +31 -2
  27. package/dist/actions/promote-model.gate.d.ts.map +1 -1
  28. package/dist/actions/promote-model.gate.js +84 -5
  29. package/dist/actions/promote-model.gate.js.map +1 -1
  30. package/dist/actions/run-experiment.action.d.ts.map +1 -1
  31. package/dist/actions/run-experiment.action.js +5 -4
  32. package/dist/actions/run-experiment.action.js.map +1 -1
  33. package/dist/actions/schedule-model-scoring.action.js +2 -2
  34. package/dist/actions/schedule-model-scoring.action.js.map +1 -1
  35. package/dist/actions/score-record-set.action.js +1 -1
  36. package/dist/actions/score-record-set.action.js.map +1 -1
  37. package/dist/actions/score-record-set.runner.d.ts +2 -2
  38. package/dist/actions/score-record-set.runner.js +3 -3
  39. package/dist/actions/score-record-set.runner.js.map +1 -1
  40. package/dist/actions/train-model.action.d.ts +28 -25
  41. package/dist/actions/train-model.action.d.ts.map +1 -1
  42. package/dist/actions/train-model.action.js +50 -39
  43. package/dist/actions/train-model.action.js.map +1 -1
  44. package/dist/agent/index.d.ts +1 -1
  45. package/dist/agent/index.js +1 -1
  46. package/dist/agent/modeling-plan-to-pipeline.d.ts +0 -2
  47. package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -1
  48. package/dist/agent/modeling-plan-to-pipeline.js +30 -39
  49. package/dist/agent/modeling-plan-to-pipeline.js.map +1 -1
  50. package/dist/agent/pipeline-builder-agent.d.ts +47 -18
  51. package/dist/agent/pipeline-builder-agent.d.ts.map +1 -1
  52. package/dist/agent/pipeline-builder-agent.js +161 -92
  53. package/dist/agent/pipeline-builder-agent.js.map +1 -1
  54. package/dist/agent/pipeline-builder.d.ts +178 -56
  55. package/dist/agent/pipeline-builder.d.ts.map +1 -1
  56. package/dist/agent/pipeline-builder.js +333 -234
  57. package/dist/agent/pipeline-builder.js.map +1 -1
  58. package/dist/experiment/budget.d.ts +61 -0
  59. package/dist/experiment/budget.d.ts.map +1 -0
  60. package/dist/experiment/budget.js +72 -0
  61. package/dist/experiment/budget.js.map +1 -0
  62. package/dist/experiment/experiment-orchestrator.d.ts +43 -7
  63. package/dist/experiment/experiment-orchestrator.d.ts.map +1 -1
  64. package/dist/experiment/experiment-orchestrator.js +130 -33
  65. package/dist/experiment/experiment-orchestrator.js.map +1 -1
  66. package/dist/experiment/index.d.ts +2 -0
  67. package/dist/experiment/index.d.ts.map +1 -1
  68. package/dist/experiment/index.js +2 -0
  69. package/dist/experiment/index.js.map +1 -1
  70. package/dist/experiment/leaderboard.d.ts +15 -15
  71. package/dist/experiment/leaderboard.d.ts.map +1 -1
  72. package/dist/experiment/leaderboard.js +44 -18
  73. package/dist/experiment/leaderboard.js.map +1 -1
  74. package/dist/experiment/scores.d.ts +32 -0
  75. package/dist/experiment/scores.d.ts.map +1 -0
  76. package/dist/experiment/scores.js +62 -0
  77. package/dist/experiment/scores.js.map +1 -0
  78. package/dist/experiment/seams.d.ts +23 -20
  79. package/dist/experiment/seams.d.ts.map +1 -1
  80. package/dist/experiment/seams.js +54 -56
  81. package/dist/experiment/seams.js.map +1 -1
  82. package/dist/experiment/types.d.ts +55 -10
  83. package/dist/experiment/types.d.ts.map +1 -1
  84. package/dist/experiment/types.js.map +1 -1
  85. package/dist/feature-assembly/as-of/as-of-assembler.d.ts +412 -0
  86. package/dist/feature-assembly/as-of/as-of-assembler.d.ts.map +1 -0
  87. package/dist/feature-assembly/as-of/as-of-assembler.js +1239 -0
  88. package/dist/feature-assembly/as-of/as-of-assembler.js.map +1 -0
  89. package/dist/feature-assembly/as-of/feature-resolution.d.ts +84 -0
  90. package/dist/feature-assembly/as-of/feature-resolution.d.ts.map +1 -0
  91. package/dist/feature-assembly/as-of/feature-resolution.js +229 -0
  92. package/dist/feature-assembly/as-of/feature-resolution.js.map +1 -0
  93. package/dist/feature-assembly/as-of/index.d.ts +15 -0
  94. package/dist/feature-assembly/as-of/index.d.ts.map +1 -0
  95. package/dist/feature-assembly/as-of/index.js +15 -0
  96. package/dist/feature-assembly/as-of/index.js.map +1 -0
  97. package/dist/feature-assembly/as-of/read-by-keys.d.ts +30 -0
  98. package/dist/feature-assembly/as-of/read-by-keys.d.ts.map +1 -0
  99. package/dist/feature-assembly/as-of/read-by-keys.js +51 -0
  100. package/dist/feature-assembly/as-of/read-by-keys.js.map +1 -0
  101. package/dist/feature-assembly/as-of/record-history.d.ts +256 -0
  102. package/dist/feature-assembly/as-of/record-history.d.ts.map +1 -0
  103. package/dist/feature-assembly/as-of/record-history.js +505 -0
  104. package/dist/feature-assembly/as-of/record-history.js.map +1 -0
  105. package/dist/feature-assembly/as-of/refusal.d.ts +19 -0
  106. package/dist/feature-assembly/as-of/refusal.d.ts.map +1 -0
  107. package/dist/feature-assembly/as-of/refusal.js +13 -0
  108. package/dist/feature-assembly/as-of/refusal.js.map +1 -0
  109. package/dist/feature-assembly/as-of/series-features.d.ts +65 -0
  110. package/dist/feature-assembly/as-of/series-features.d.ts.map +1 -0
  111. package/dist/feature-assembly/as-of/series-features.js +97 -0
  112. package/dist/feature-assembly/as-of/series-features.js.map +1 -0
  113. package/dist/feature-assembly/as-of/windowed-aggregate.d.ts +36 -0
  114. package/dist/feature-assembly/as-of/windowed-aggregate.d.ts.map +1 -0
  115. package/dist/feature-assembly/as-of/windowed-aggregate.js +99 -0
  116. package/dist/feature-assembly/as-of/windowed-aggregate.js.map +1 -0
  117. package/dist/feature-assembly/as-of.d.ts +1 -9
  118. package/dist/feature-assembly/as-of.d.ts.map +1 -1
  119. package/dist/feature-assembly/as-of.js +2 -19
  120. package/dist/feature-assembly/as-of.js.map +1 -1
  121. package/dist/feature-assembly/assembly-metadata.d.ts +34 -0
  122. package/dist/feature-assembly/assembly-metadata.d.ts.map +1 -0
  123. package/dist/feature-assembly/assembly-metadata.js +26 -0
  124. package/dist/feature-assembly/assembly-metadata.js.map +1 -0
  125. package/dist/feature-assembly/data-access.d.ts +21 -2
  126. package/dist/feature-assembly/data-access.d.ts.map +1 -1
  127. package/dist/feature-assembly/data-access.js +14 -0
  128. package/dist/feature-assembly/data-access.js.map +1 -1
  129. package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -1
  130. package/dist/feature-assembly/feature-assembly-executor.js +5 -2
  131. package/dist/feature-assembly/feature-assembly-executor.js.map +1 -1
  132. package/dist/feature-assembly/index.d.ts +3 -0
  133. package/dist/feature-assembly/index.d.ts.map +1 -1
  134. package/dist/feature-assembly/index.js +3 -0
  135. package/dist/feature-assembly/index.js.map +1 -1
  136. package/dist/feature-assembly/leakage-guard.d.ts +1 -1
  137. package/dist/feature-assembly/leakage-guard.js +1 -1
  138. package/dist/feature-assembly/read-policy.d.ts +27 -0
  139. package/dist/feature-assembly/read-policy.d.ts.map +1 -0
  140. package/dist/feature-assembly/read-policy.js +63 -0
  141. package/dist/feature-assembly/read-policy.js.map +1 -0
  142. package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -1
  143. package/dist/feature-pipelines/feature-pipeline-engine.js +3 -1
  144. package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -1
  145. package/dist/index.d.ts +5 -2
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +16 -4
  148. package/dist/index.js.map +1 -1
  149. package/dist/maintenance/index.d.ts +1 -0
  150. package/dist/maintenance/index.d.ts.map +1 -1
  151. package/dist/maintenance/index.js +1 -0
  152. package/dist/maintenance/index.js.map +1 -1
  153. package/dist/maintenance/maintenance-engine.d.ts +16 -19
  154. package/dist/maintenance/maintenance-engine.d.ts.map +1 -1
  155. package/dist/maintenance/maintenance-engine.js +53 -53
  156. package/dist/maintenance/maintenance-engine.js.map +1 -1
  157. package/dist/maintenance/metrics.d.ts +19 -15
  158. package/dist/maintenance/metrics.d.ts.map +1 -1
  159. package/dist/maintenance/metrics.js +29 -24
  160. package/dist/maintenance/metrics.js.map +1 -1
  161. package/dist/maintenance/psi-drift-detector.d.ts +246 -0
  162. package/dist/maintenance/psi-drift-detector.d.ts.map +1 -0
  163. package/dist/maintenance/psi-drift-detector.js +1002 -0
  164. package/dist/maintenance/psi-drift-detector.js.map +1 -0
  165. package/dist/maintenance/types.d.ts +11 -2
  166. package/dist/maintenance/types.d.ts.map +1 -1
  167. package/dist/maintenance/types.js.map +1 -1
  168. package/dist/migration/index.d.ts +8 -0
  169. package/dist/migration/index.d.ts.map +1 -0
  170. package/dist/migration/index.js +8 -0
  171. package/dist/migration/index.js.map +1 -0
  172. package/dist/migration/legacy-pipeline-migration.d.ts +138 -0
  173. package/dist/migration/legacy-pipeline-migration.d.ts.map +1 -0
  174. package/dist/migration/legacy-pipeline-migration.js +273 -0
  175. package/dist/migration/legacy-pipeline-migration.js.map +1 -0
  176. package/dist/operations/delegation.d.ts +58 -46
  177. package/dist/operations/delegation.d.ts.map +1 -1
  178. package/dist/operations/delegation.js +90 -77
  179. package/dist/operations/delegation.js.map +1 -1
  180. package/dist/operations/promote-model.operation.d.ts +2 -2
  181. package/dist/operations/promote-model.operation.d.ts.map +1 -1
  182. package/dist/operations/promote-model.operation.js +6 -2
  183. package/dist/operations/promote-model.operation.js.map +1 -1
  184. package/dist/operations/refusals.d.ts +5 -0
  185. package/dist/operations/refusals.d.ts.map +1 -1
  186. package/dist/operations/refusals.js +26 -1
  187. package/dist/operations/refusals.js.map +1 -1
  188. package/dist/operations/start-experiment-session.operation.js +3 -3
  189. package/dist/operations/train-model.mapping.d.ts +91 -0
  190. package/dist/operations/train-model.mapping.d.ts.map +1 -0
  191. package/dist/operations/train-model.mapping.js +145 -0
  192. package/dist/operations/train-model.mapping.js.map +1 -0
  193. package/dist/operations/train-model.operation.d.ts +14 -9
  194. package/dist/operations/train-model.operation.d.ts.map +1 -1
  195. package/dist/operations/train-model.operation.js +30 -51
  196. package/dist/operations/train-model.operation.js.map +1 -1
  197. package/dist/prediction-unit/decision-date-advance.d.ts +46 -0
  198. package/dist/prediction-unit/decision-date-advance.d.ts.map +1 -0
  199. package/dist/prediction-unit/decision-date-advance.js +79 -0
  200. package/dist/prediction-unit/decision-date-advance.js.map +1 -0
  201. package/dist/prediction-unit/index.d.ts +12 -0
  202. package/dist/prediction-unit/index.d.ts.map +1 -0
  203. package/dist/prediction-unit/index.js +12 -0
  204. package/dist/prediction-unit/index.js.map +1 -0
  205. package/dist/prediction-unit/target-validation.d.ts +21 -0
  206. package/dist/prediction-unit/target-validation.d.ts.map +1 -0
  207. package/dist/prediction-unit/target-validation.js +54 -0
  208. package/dist/prediction-unit/target-validation.js.map +1 -0
  209. package/dist/prediction-unit/unit-row-reader.d.ts +108 -0
  210. package/dist/prediction-unit/unit-row-reader.d.ts.map +1 -0
  211. package/dist/prediction-unit/unit-row-reader.js +348 -0
  212. package/dist/prediction-unit/unit-row-reader.js.map +1 -0
  213. package/dist/prediction-unit/unit-store.d.ts +28 -0
  214. package/dist/prediction-unit/unit-store.d.ts.map +1 -0
  215. package/dist/prediction-unit/unit-store.js +41 -0
  216. package/dist/prediction-unit/unit-store.js.map +1 -0
  217. package/dist/prediction-unit/unit-versioning.d.ts +43 -0
  218. package/dist/prediction-unit/unit-versioning.d.ts.map +1 -0
  219. package/dist/prediction-unit/unit-versioning.js +71 -0
  220. package/dist/prediction-unit/unit-versioning.js.map +1 -0
  221. package/dist/protocol/index.d.ts +9 -0
  222. package/dist/protocol/index.d.ts.map +1 -0
  223. package/dist/protocol/index.js +9 -0
  224. package/dist/protocol/index.js.map +1 -0
  225. package/dist/protocol/protocol-defaults.d.ts +37 -0
  226. package/dist/protocol/protocol-defaults.d.ts.map +1 -0
  227. package/dist/protocol/protocol-defaults.js +59 -0
  228. package/dist/protocol/protocol-defaults.js.map +1 -0
  229. package/dist/protocol/protocol-versioning.d.ts +46 -0
  230. package/dist/protocol/protocol-versioning.d.ts.map +1 -0
  231. package/dist/protocol/protocol-versioning.js +48 -0
  232. package/dist/protocol/protocol-versioning.js.map +1 -0
  233. package/dist/protocol/search-guard.d.ts +45 -0
  234. package/dist/protocol/search-guard.d.ts.map +1 -0
  235. package/dist/protocol/search-guard.js +50 -0
  236. package/dist/protocol/search-guard.js.map +1 -0
  237. package/dist/scoring/artifact-loader.d.ts +5 -32
  238. package/dist/scoring/artifact-loader.d.ts.map +1 -1
  239. package/dist/scoring/artifact-loader.js +4 -59
  240. package/dist/scoring/artifact-loader.js.map +1 -1
  241. package/dist/scoring/auto-train.d.ts +25 -5
  242. package/dist/scoring/auto-train.d.ts.map +1 -1
  243. package/dist/scoring/auto-train.js +48 -31
  244. package/dist/scoring/auto-train.js.map +1 -1
  245. package/dist/scoring/index.d.ts +3 -0
  246. package/dist/scoring/index.d.ts.map +1 -1
  247. package/dist/scoring/index.js +3 -0
  248. package/dist/scoring/index.js.map +1 -1
  249. package/dist/scoring/ml-model-inference-processor.d.ts +137 -10
  250. package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -1
  251. package/dist/scoring/ml-model-inference-processor.js +383 -40
  252. package/dist/scoring/ml-model-inference-processor.js.map +1 -1
  253. package/dist/scoring/model-readiness.d.ts +45 -0
  254. package/dist/scoring/model-readiness.d.ts.map +1 -1
  255. package/dist/scoring/model-readiness.js +49 -0
  256. package/dist/scoring/model-readiness.js.map +1 -1
  257. package/dist/scoring/register.d.ts +8 -3
  258. package/dist/scoring/register.d.ts.map +1 -1
  259. package/dist/scoring/register.js +28 -4
  260. package/dist/scoring/register.js.map +1 -1
  261. package/dist/scoring/seams.d.ts +18 -2
  262. package/dist/scoring/seams.d.ts.map +1 -1
  263. package/dist/scoring/seams.js +35 -10
  264. package/dist/scoring/seams.js.map +1 -1
  265. package/dist/scoring/shadow-scoring.d.ts +245 -0
  266. package/dist/scoring/shadow-scoring.d.ts.map +1 -0
  267. package/dist/scoring/shadow-scoring.js +510 -0
  268. package/dist/scoring/shadow-scoring.js.map +1 -0
  269. package/dist/scoring/startup-register.d.ts +3 -3
  270. package/dist/scoring/startup-register.d.ts.map +1 -1
  271. package/dist/scoring/startup-register.js +10 -4
  272. package/dist/scoring/startup-register.js.map +1 -1
  273. package/dist/scoring/storage-provider-artifact-loader.d.ts +14 -0
  274. package/dist/scoring/storage-provider-artifact-loader.d.ts.map +1 -0
  275. package/dist/scoring/storage-provider-artifact-loader.js +47 -0
  276. package/dist/scoring/storage-provider-artifact-loader.js.map +1 -0
  277. package/dist/scoring/training-keys.d.ts +27 -0
  278. package/dist/scoring/training-keys.d.ts.map +1 -0
  279. package/dist/scoring/training-keys.js +54 -0
  280. package/dist/scoring/training-keys.js.map +1 -0
  281. package/dist/scoring/types.d.ts +72 -7
  282. package/dist/scoring/types.d.ts.map +1 -1
  283. package/dist/scoring/types.js +4 -0
  284. package/dist/scoring/types.js.map +1 -1
  285. package/dist/sidecar-provider.d.ts +2 -2
  286. package/dist/sidecar-provider.js +3 -3
  287. package/dist/snapshot/code-version.d.ts +16 -0
  288. package/dist/snapshot/code-version.d.ts.map +1 -0
  289. package/dist/snapshot/code-version.js +39 -0
  290. package/dist/snapshot/code-version.js.map +1 -0
  291. package/dist/snapshot/holdout-carver.d.ts +110 -0
  292. package/dist/snapshot/holdout-carver.d.ts.map +1 -0
  293. package/dist/snapshot/holdout-carver.js +171 -0
  294. package/dist/snapshot/holdout-carver.js.map +1 -0
  295. package/dist/snapshot/index.d.ts +17 -0
  296. package/dist/snapshot/index.d.ts.map +1 -0
  297. package/dist/snapshot/index.js +17 -0
  298. package/dist/snapshot/index.js.map +1 -0
  299. package/dist/snapshot/snapshot-builder.d.ts +152 -0
  300. package/dist/snapshot/snapshot-builder.d.ts.map +1 -0
  301. package/dist/snapshot/snapshot-builder.js +286 -0
  302. package/dist/snapshot/snapshot-builder.js.map +1 -0
  303. package/dist/snapshot/snapshot-file-store.d.ts +161 -0
  304. package/dist/snapshot/snapshot-file-store.d.ts.map +1 -0
  305. package/dist/snapshot/snapshot-file-store.js +204 -0
  306. package/dist/snapshot/snapshot-file-store.js.map +1 -0
  307. package/dist/snapshot/snapshot-hash.d.ts +6 -0
  308. package/dist/snapshot/snapshot-hash.d.ts.map +1 -0
  309. package/dist/snapshot/snapshot-hash.js +16 -0
  310. package/dist/snapshot/snapshot-hash.js.map +1 -0
  311. package/dist/snapshot/snapshot-manifest.d.ts +43 -0
  312. package/dist/snapshot/snapshot-manifest.d.ts.map +1 -0
  313. package/dist/snapshot/snapshot-manifest.js +43 -0
  314. package/dist/snapshot/snapshot-manifest.js.map +1 -0
  315. package/dist/snapshot/snapshot-retrainer.d.ts +107 -0
  316. package/dist/snapshot/snapshot-retrainer.d.ts.map +1 -0
  317. package/dist/snapshot/snapshot-retrainer.js +194 -0
  318. package/dist/snapshot/snapshot-retrainer.js.map +1 -0
  319. package/dist/snapshot/snapshot-serialization.d.ts +99 -0
  320. package/dist/snapshot/snapshot-serialization.d.ts.map +1 -0
  321. package/dist/snapshot/snapshot-serialization.js +191 -0
  322. package/dist/snapshot/snapshot-serialization.js.map +1 -0
  323. package/dist/snapshot/training-snapshot-store.d.ts +38 -0
  324. package/dist/snapshot/training-snapshot-store.d.ts.map +1 -0
  325. package/dist/snapshot/training-snapshot-store.js +41 -0
  326. package/dist/snapshot/training-snapshot-store.js.map +1 -0
  327. package/dist/storage/ps-storage-provider.d.ts +108 -0
  328. package/dist/storage/ps-storage-provider.d.ts.map +1 -0
  329. package/dist/storage/ps-storage-provider.js +154 -0
  330. package/dist/storage/ps-storage-provider.js.map +1 -0
  331. package/dist/training/artifact-store.d.ts +12 -103
  332. package/dist/training/artifact-store.d.ts.map +1 -1
  333. package/dist/training/artifact-store.js +13 -137
  334. package/dist/training/artifact-store.js.map +1 -1
  335. package/dist/training/compute-cost.d.ts +23 -0
  336. package/dist/training/compute-cost.d.ts.map +1 -0
  337. package/dist/training/compute-cost.js +36 -0
  338. package/dist/training/compute-cost.js.map +1 -0
  339. package/dist/training/evaluation-protocol-store.d.ts +53 -0
  340. package/dist/training/evaluation-protocol-store.d.ts.map +1 -0
  341. package/dist/training/evaluation-protocol-store.js +54 -0
  342. package/dist/training/evaluation-protocol-store.js.map +1 -0
  343. package/dist/training/index.d.ts +9 -1
  344. package/dist/training/index.d.ts.map +1 -1
  345. package/dist/training/index.js +9 -1
  346. package/dist/training/index.js.map +1 -1
  347. package/dist/training/locked-holdout.d.ts +19 -4
  348. package/dist/training/locked-holdout.d.ts.map +1 -1
  349. package/dist/training/locked-holdout.js +29 -5
  350. package/dist/training/locked-holdout.js.map +1 -1
  351. package/dist/training/seams.d.ts +34 -8
  352. package/dist/training/seams.d.ts.map +1 -1
  353. package/dist/training/seams.js +74 -18
  354. package/dist/training/seams.js.map +1 -1
  355. package/dist/training/storage-provider-artifact-store.d.ts +49 -0
  356. package/dist/training/storage-provider-artifact-store.d.ts.map +1 -0
  357. package/dist/training/storage-provider-artifact-store.js +147 -0
  358. package/dist/training/storage-provider-artifact-store.js.map +1 -0
  359. package/dist/training/trainer-model-lineage.d.ts +32 -0
  360. package/dist/training/trainer-model-lineage.d.ts.map +1 -0
  361. package/dist/training/trainer-model-lineage.js +62 -0
  362. package/dist/training/trainer-model-lineage.js.map +1 -0
  363. package/dist/training/trainer-request.d.ts +50 -0
  364. package/dist/training/trainer-request.d.ts.map +1 -0
  365. package/dist/training/trainer-request.js +65 -0
  366. package/dist/training/trainer-request.js.map +1 -0
  367. package/dist/training/trainer-result.d.ts +30 -0
  368. package/dist/training/trainer-result.d.ts.map +1 -0
  369. package/dist/training/trainer-result.js +40 -0
  370. package/dist/training/trainer-result.js.map +1 -0
  371. package/dist/training/training-engine.d.ts +417 -64
  372. package/dist/training/training-engine.d.ts.map +1 -1
  373. package/dist/training/training-engine.js +869 -178
  374. package/dist/training/training-engine.js.map +1 -1
  375. package/dist/training/training-refusal.d.ts +15 -0
  376. package/dist/training/training-refusal.d.ts.map +1 -0
  377. package/dist/training/training-refusal.js +62 -0
  378. package/dist/training/training-refusal.js.map +1 -0
  379. package/dist/training/types.d.ts +133 -41
  380. package/dist/training/types.d.ts.map +1 -1
  381. package/dist/training/types.js +4 -4
  382. package/dist/training/unit-model-lineage.d.ts +72 -0
  383. package/dist/training/unit-model-lineage.d.ts.map +1 -0
  384. package/dist/training/unit-model-lineage.js +288 -0
  385. package/dist/training/unit-model-lineage.js.map +1 -0
  386. package/dist/tsconfig.tsbuildinfo +1 -0
  387. package/package.json +16 -13
  388. package/dist/operations/__tests__/helpers.d.ts +0 -30
  389. package/dist/operations/__tests__/helpers.d.ts.map +0 -1
  390. package/dist/operations/__tests__/helpers.js +0 -44
  391. package/dist/operations/__tests__/helpers.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision-date-advance.js","sourceRoot":"","sources":["../../src/prediction-un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,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3G,0BAA0B,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC5F,IAAI,MAAM,QAAQ,CAAC,IAAI,EAAE;gBAAE,OAAO,IAAI,CAAC;YACvC,OAAO,oBAAoB,QAAQ,CAAC,EAAE,YAAY,IAAI,CAAC,EAAE,YAAY,QAAQ,CAAC,YAAY,EAAE,eAAe,IAAI,aAAa,EAAE,CAAC;QACjI,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,oBAAoB,QAAQ,CAAC,EAAE,YAAY,IAAI,CAAC,EAAE,YAAY,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACpH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module prediction-unit
3
+ *
4
+ * Prediction Units: reading a unit's rows (the unit row reader), validating its target,
5
+ * storing and versioning its rows.
6
+ */
7
+ export * from './unit-row-reader.js';
8
+ export * from './target-validation.js';
9
+ export * from './unit-store.js';
10
+ export * from './unit-versioning.js';
11
+ export * from './decision-date-advance.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prediction-unit/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module prediction-unit
3
+ *
4
+ * Prediction Units: reading a unit's rows (the unit row reader), validating its target,
5
+ * storing and versioning its rows.
6
+ */
7
+ export * from './unit-row-reader.js';
8
+ export * from './target-validation.js';
9
+ export * from './unit-store.js';
10
+ export * from './unit-versioning.js';
11
+ export * from './decision-date-advance.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prediction-unit/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module prediction-unit/target-validation
3
+ *
4
+ * Target validation before training: fewer than two classes, labels outside the declared class order, a count
5
+ * declared continuous, and negative values for count/non-negative tasks are refused with the unit refusal that
6
+ * names them. Empty labels never get here (the reader excludes and counts them).
7
+ */
8
+ import type { TaskType, UnitResolutionCounts, UnitValidation } from '@memberjunction/predictive-studio-core';
9
+ import type { UnitRow } from './unit-row-reader.js';
10
+ /** A continuous target that looks like this is a count: integers >= 0 that include 0 and take fewer distinct values. */
11
+ export declare const COUNT_SIGNATURE_MAX_DISTINCT = 50;
12
+ /** Target validation before training. */
13
+ export declare class UnitTargetValidator {
14
+ private static refused;
15
+ static ValidateUnitTargets(rows: readonly UnitRow[], task: TaskType, counts: UnitResolutionCounts): UnitValidation;
16
+ /** Classification: at least two observed classes, every one of them in the declared class order. */
17
+ private static validateClasses;
18
+ /** Numeric tasks: numbers only, more than one value, the count signature refused as continuous, no negatives where declared. */
19
+ private static validateNumeric;
20
+ }
21
+ //# sourceMappingURL=target-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target-validation.d.ts","sourceRoot":"","sources":["../../src/prediction-unit/target-validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC7G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,wHAAwH;AACxH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAI/C,yCAAyC;AACzC,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,OAAO;WAIR,mBAAmB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,oBAAoB,GAAG,cAAc;IAOzH,oGAAoG;IACpG,OAAO,CAAC,MAAM,CAAC,eAAe;IAc9B,gIAAgI;IAChI,OAAO,CAAC,MAAM,CAAC,eAAe;CAqB/B"}
@@ -0,0 +1,54 @@
1
+ /** A continuous target that looks like this is a count: integers >= 0 that include 0 and take fewer distinct values. */
2
+ export const COUNT_SIGNATURE_MAX_DISTINCT = 50;
3
+ /** Target validation before training. */
4
+ export class UnitTargetValidator {
5
+ static refused(reason) {
6
+ return { status: 'refused', reason };
7
+ }
8
+ static ValidateUnitTargets(rows, task, counts) {
9
+ if (rows.length === 0) {
10
+ return UnitTargetValidator.refused({ kind: 'no-resolved-rows', censored: counts.censoredRowsExcluded, labelKnown: counts.labelKnownRowsExcluded, gapOutcome: counts.gapOutcomeRowsExcluded || 0, emptyLabel: counts.emptyLabelRowsExcluded });
11
+ }
12
+ return task.kind === 'binary' || task.kind === 'multiclass' ? UnitTargetValidator.validateClasses(rows, task, counts) : UnitTargetValidator.validateNumeric(rows, task, counts);
13
+ }
14
+ /** Classification: at least two observed classes, every one of them in the declared class order. */
15
+ static validateClasses(rows, task, counts) {
16
+ const levels = new Map();
17
+ for (const r of rows)
18
+ levels.set(String(r.Label), (levels.get(String(r.Label)) || 0) + 1);
19
+ if (levels.size < 2) {
20
+ const [value, n] = [...levels.entries()][0];
21
+ return UnitTargetValidator.refused({ kind: 'single-valued-target', value, rows: n });
22
+ }
23
+ const unknown = [...levels.keys()].filter((l) => !task.classOrder.includes(l)).sort();
24
+ if (unknown.length > 0) {
25
+ return UnitTargetValidator.refused({ kind: 'task-type-mismatch', declared: task.kind, observed: `labels ${unknown.join(', ')} are not in classOrder [${task.classOrder.join(', ')}]` });
26
+ }
27
+ return { status: 'valid', observedLevels: levels.size, eligibleRows: rows.length, censoredRows: counts.censoredRowsExcluded };
28
+ }
29
+ /** Numeric tasks: numbers only, more than one value, the count signature refused as continuous, no negatives where declared. */
30
+ static validateNumeric(rows, task, counts) {
31
+ const values = [];
32
+ for (const r of rows) {
33
+ if (typeof r.Label !== 'number')
34
+ return UnitTargetValidator.refused({ kind: 'task-type-mismatch', declared: task.kind, observed: `non-numeric label "${r.Label}"` });
35
+ values.push(r.Label);
36
+ }
37
+ const distinct = new Set(values);
38
+ if (distinct.size < 2)
39
+ return UnitTargetValidator.refused({ kind: 'single-valued-target', value: String(values[0]), rows: values.length });
40
+ const valueKind = task.kind === 'forecast' ? task.valueKind : task.kind;
41
+ const allNonNegativeIntegers = values.every((v) => Number.isInteger(v) && v >= 0);
42
+ if (valueKind === 'continuous' && allNonNegativeIntegers && distinct.has(0) && distinct.size < COUNT_SIGNATURE_MAX_DISTINCT) {
43
+ return UnitTargetValidator.refused({ kind: 'task-type-mismatch', declared: task.kind, observed: `count (non-negative integers including 0, ${distinct.size} distinct values)` });
44
+ }
45
+ if (valueKind === 'count' && !allNonNegativeIntegers) {
46
+ return UnitTargetValidator.refused({ kind: 'task-type-mismatch', declared: task.kind, observed: values.some((v) => v < 0) ? 'negative values' : 'non-integer values (continuous)' });
47
+ }
48
+ if (valueKind === 'non-negative' && values.some((v) => v < 0)) {
49
+ return UnitTargetValidator.refused({ kind: 'task-type-mismatch', declared: task.kind, observed: 'negative values' });
50
+ }
51
+ return { status: 'valid', observedLevels: distinct.size, eligibleRows: rows.length, censoredRows: counts.censoredRowsExcluded };
52
+ }
53
+ }
54
+ //# sourceMappingURL=target-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target-validation.js","sourceRoot":"","sources":["../../src/prediction-unit/target-validation.ts"],"names":[],"mappings":"AAUA,wHAAwH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EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,iCAAiC,EAAE,CAAC,CAAC;QACvL,CAAC;QACD,IAAI,SAAS,KAAK,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC9D,OAAO,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC,CAAC;QACvH,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC;IAClI,CAAC;CACF"}
@@ -0,0 +1,108 @@
1
+ import { type CellValue, type PredictionUnitSpec, type ReadPolicy, type RowFilter, type TaskType, type TrainingRefusal, type UnitResolutionCounts } from '@memberjunction/predictive-studio-core';
2
+ import type { ICountingDataAccess, SourceRow } from '../feature-assembly/data-access.js';
3
+ import type { AssemblyEntityInfo, IAssemblyMetadata } from '../feature-assembly/assembly-metadata.js';
4
+ import type { AssemblyRowRef } from '../feature-assembly/as-of/as-of-assembler.js';
5
+ export type CanonicalLabelValue = string | number;
6
+ export interface UnitRow {
7
+ readonly RowID: string;
8
+ readonly EntityKey: string;
9
+ readonly DecisionDate: Date;
10
+ readonly WindowEnd: Date;
11
+ /** The row's group: its value of the unit's group key field, or its entity key when the unit declares none (lower-cased). */
12
+ readonly GroupKey: string;
13
+ readonly Period: Date | null;
14
+ readonly Label: CanonicalLabelValue;
15
+ readonly Source: SourceRow;
16
+ }
17
+ export interface UnitReadDeps {
18
+ readonly DataAccess: ICountingDataAccess;
19
+ readonly Metadata: IAssemblyMetadata;
20
+ readonly Read: ReadPolicy;
21
+ /** The clock for `cutoff.kind = 'now'` (injected so tests are deterministic). */
22
+ readonly Now: Date;
23
+ /**
24
+ * True only for a read whose rows become a series history at scoring: rows whose outcome window has not closed by the
25
+ * cutoff are kept instead of censored. A period's value is its resolved outcome, and a lag reads it only once its
26
+ * outcome window has closed by the row's decision day and the scoring day (`SeriesFeatures.ComputeSeriesFeature`), so
27
+ * a period whose window closed after the unit's cutoff but before the scoring day is read, and one still open is kept
28
+ * in the history but never read. A read that trains or labels never sets it.
29
+ */
30
+ readonly KeepOpenWindows?: boolean;
31
+ }
32
+ export type UnitRowReadResult = {
33
+ readonly Status: 'read';
34
+ readonly Rows: readonly UnitRow[];
35
+ readonly Counts: UnitResolutionCounts;
36
+ readonly DataCutoff: Date;
37
+ readonly RowEntity: AssemblyEntityInfo;
38
+ } | {
39
+ readonly Status: 'refused';
40
+ readonly Refusal: TrainingRefusal;
41
+ };
42
+ export declare class PredictionUnitRowReader {
43
+ /** Labels in one canonical form: classes are trimmed strings (booleans → '1'/'0'); numeric tasks are numbers. Empty → null. */
44
+ static CanonicalLabel(value: CellValue, task: TaskType): CanonicalLabelValue | null;
45
+ /** In-memory filter (no SQL is built from unit JSON). */
46
+ static MatchesRowFilters(row: SourceRow, filters: readonly RowFilter[]): boolean;
47
+ private static unitRefusal;
48
+ /** A day that the code path guarantees (validated date strings, Dates, rows already checked for a decision date). */
49
+ private static requireDay;
50
+ /**
51
+ * A row's key value as a string. An absent key would otherwise be coerced to the literal string "undefined"/"null"
52
+ * and group unrelated rows under one fake entity, so it fails loudly instead.
53
+ */
54
+ private static requireKey;
55
+ /** True for a cell with no value: null, undefined or the empty string. */
56
+ private static isEmptyCell;
57
+ /** A summed child-event value: an empty cell adds 0; a value that is not a number fails instead of making the label NaN. */
58
+ private static requireEventValue;
59
+ /**
60
+ * A row's period index as an integer. `Number()` coerces an absent index (null, '') to 0, which would label the row
61
+ * against the entity's first period, so an absent or non-integer index fails loudly instead.
62
+ */
63
+ private static requirePeriodIndex;
64
+ /** Lower-cased key for in-memory matching. `??` keeps a legitimate 0/false key value; only null/undefined become ''. */
65
+ private static keyOf;
66
+ Read(unit: PredictionUnitSpec, deps: UnitReadDeps): Promise<UnitRowReadResult>;
67
+ /**
68
+ * Applies the exclusions in their documented order — censored, label known at the decision, outcome inside the gap,
69
+ * empty label — and
70
+ * builds the unit rows, sorted by decision date then row id (ordinal). A null `cutoff` censors nothing.
71
+ */
72
+ private resolveRows;
73
+ /** Keeps the first row of each (entity key, decision date, period); the caller counts the rest as duplicates. */
74
+ private removeDuplicates;
75
+ private decisionDate;
76
+ /**
77
+ * A row as the assembly reads it, by the one rule training and scoring share: its key (the primary key), its entity
78
+ * key (the key itself for a grain unit, else the grain foreign key), the given decision day and its period (the
79
+ * period date of a grain × periods unit, else the Temporal Spec's time column, else null). Keys read as text; a date
80
+ * key reads as its UTC day.
81
+ */
82
+ static UnitRowRef(unit: PredictionUnitSpec, rowEntity: AssemblyEntityInfo, row: SourceRow, decision: Date): AssemblyRowRef;
83
+ /**
84
+ * A row's decision day by the unit's rule: the period date of a grain × periods unit, else the decision-date column
85
+ * (offset when the rule says so) or the fixed date. Null when the row has no date there. Training and scoring both
86
+ * date their rows with it.
87
+ */
88
+ static UnitDecisionDate(unit: PredictionUnitSpec, row: SourceRow): Date | null;
89
+ private resolveCutoff;
90
+ /** `keptRows` are the rows the unit's filter keeps; a next-period label reads only them. */
91
+ private buildLabeler;
92
+ /**
93
+ * next-period: 1 when the period `offset` later falls in the window; label known when it is on or before the decision;
94
+ * the row is excluded when it falls inside the gap (after the decision, on or before the window start). Only the
95
+ * kept rows are indexed, and two of them at one (grain key, period index) refuse the read: the label would otherwise
96
+ * depend on which of them was read last.
97
+ */
98
+ private nextPeriodLabeler;
99
+ /**
100
+ * child-event: exists / count / sum of the owner's child events inside the window. The gap (after the decision, on or
101
+ * before the window start) is treated by what the aggregate measures. For `exists` a row with an event in the gap is
102
+ * excluded: the event may be a terminal outcome that already happened (a cancellation), so labelling the window 0
103
+ * would mislabel the row. For `count` and `sum` the label is the volume inside the window: an event in the gap is
104
+ * simply not counted and the row is kept, since excluding it would drop most rows of an owner whose events recur.
105
+ */
106
+ private childEventLabeler;
107
+ }
108
+ //# sourceMappingURL=unit-row-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit-row-reader.d.ts","sourceRoot":"","sources":["../../src/prediction-unit/unit-row-reader.ts"],"names":[],"mappings":"AAcA,OAAO,EAAU,KAAK,SAAS,EAAiD,KAAK,kBAAkB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAoB,KAAK,oBAAoB,EAAiB,MAAM,wCAAwC,CAAC;AAC1R,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAEhF,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,6HAA6H;IAC7H,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,UAAU,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AkB,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA0C3F;;;;OAIG;IACH,OAAO,CAAC,WAAW;IA6BnB,iHAAiH;IACjH,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,YAAY;IAIpB;;;;;OAKG;WACW,UAAU,CAAC,IAAI,EAAE,kBAAkB,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,GAAG,cAAc;IAOjI;;;;OAIG;WACW,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI;YAavE,aAAa;IAc3B,4FAA4F;YAC9E,YAAY;IAc1B;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IA4BzB;;;;;;OAMG;YACW,iBAAiB;CA8BhC"}
@@ -0,0 +1,348 @@
1
+ /**
2
+ * @module prediction-unit/unit-row-reader
3
+ *
4
+ * Reads a Prediction Unit's rows: one per grain record, or one per grain record × period. Each row gets its
5
+ * decision date, outcome window end, group key, period and label. Rows are excluded — and counted — in this order:
6
+ * censored (window ends after the cutoff), label known at the decision (next-period rule: the outcome was recorded
7
+ * on or before the decision date), outcome inside the gap (the next period, or for a child-event `exists` label a child
8
+ * event, falls after the decision date and on or before the window start, so it was settled before the window opened;
9
+ * a child-event `count` or `sum` label does not count gap events and keeps the row), empty label. Exact duplicates
10
+ * of (entity key, decision date, period) are removed and counted. A next-period label reads only the rows the unit's
11
+ * filter keeps, and two kept rows at one (grain key, period index) refuse the read. The source is read completely or
12
+ * the read is refused.
13
+ */
14
+ import { OrdinalCompare } from '@memberjunction/global';
15
+ import { UtcDay, TaskTypeRules, PredictionUnit } from '@memberjunction/predictive-studio-core';
16
+ import { CompleteReader } from '../feature-assembly/read-policy.js';
17
+ export class PredictionUnitRowReader {
18
+ /** Labels in one canonical form: classes are trimmed strings (booleans → '1'/'0'); numeric tasks are numbers. Empty → null. */
19
+ static CanonicalLabel(value, task) {
20
+ if (value === null || value === undefined)
21
+ return null;
22
+ if (TaskTypeRules.IsClassificationTask(task))
23
+ return TaskTypeRules.ClassLabel(value);
24
+ if (typeof value === 'number')
25
+ return Number.isFinite(value) ? value : null;
26
+ if (typeof value === 'boolean')
27
+ return value ? 1 : 0;
28
+ if (value instanceof Date)
29
+ return null;
30
+ const t = value.trim();
31
+ if (t.length === 0)
32
+ return null;
33
+ const n = Number(t);
34
+ return Number.isFinite(n) ? n : t;
35
+ }
36
+ /** In-memory filter (no SQL is built from unit JSON). */
37
+ static MatchesRowFilters(row, filters) {
38
+ return filters.every((f) => {
39
+ const v = row[f.field];
40
+ const s = v instanceof Date ? UtcDay.UtcDayIso(v) : v;
41
+ switch (f.op) {
42
+ case 'not-null': return s !== null && s !== undefined && s !== '';
43
+ case 'is-null': return s === null || s === undefined || s === '';
44
+ case 'eq': return s === f.values[0] || String(s) === String(f.values[0]);
45
+ case 'neq': return !(s === f.values[0] || String(s) === String(f.values[0]));
46
+ case 'in': return f.values.some((x) => s === x || String(s) === String(x));
47
+ }
48
+ });
49
+ }
50
+ static unitRefusal(reason) {
51
+ return { Status: 'refused', Refusal: { stage: 'unit', reason } };
52
+ }
53
+ /** A day that the code path guarantees (validated date strings, Dates, rows already checked for a decision date). */
54
+ static requireDay(day, what) {
55
+ if (day === null)
56
+ throw new Error(`PredictionUnitRowReader: ${what} is not a date`);
57
+ return day;
58
+ }
59
+ /**
60
+ * A row's key value as a string. An absent key would otherwise be coerced to the literal string "undefined"/"null"
61
+ * and group unrelated rows under one fake entity, so it fails loudly instead.
62
+ */
63
+ static requireKey(value, what) {
64
+ if (value === null || value === undefined || value === '')
65
+ throw new Error(`PredictionUnitRowReader: ${what} is empty`);
66
+ return value instanceof Date ? UtcDay.UtcDayIso(value) : String(value);
67
+ }
68
+ /** True for a cell with no value: null, undefined or the empty string. */
69
+ static isEmptyCell(value) {
70
+ return value === null || value === undefined || value === '';
71
+ }
72
+ /** A summed child-event value: an empty cell adds 0; a value that is not a number fails instead of making the label NaN. */
73
+ static requireEventValue(value, what) {
74
+ if (PredictionUnitRowReader.isEmptyCell(value))
75
+ return 0;
76
+ const n = Number(value);
77
+ if (!Number.isFinite(n))
78
+ throw new Error(`PredictionUnitRowReader: ${what} is not a number`);
79
+ return n;
80
+ }
81
+ /**
82
+ * A row's period index as an integer. `Number()` coerces an absent index (null, '') to 0, which would label the row
83
+ * against the entity's first period, so an absent or non-integer index fails loudly instead.
84
+ */
85
+ static requirePeriodIndex(value, what) {
86
+ if (PredictionUnitRowReader.isEmptyCell(value))
87
+ throw new Error(`PredictionUnitRowReader: ${what} is empty`);
88
+ const idx = Number(value);
89
+ if (!Number.isInteger(idx))
90
+ throw new Error(`PredictionUnitRowReader: ${what} is not an integer`);
91
+ return idx;
92
+ }
93
+ /** Lower-cased key for in-memory matching. `??` keeps a legitimate 0/false key value; only null/undefined become ''. */
94
+ static keyOf(v) {
95
+ return (v instanceof Date ? UtcDay.UtcDayIso(v) : String(v ?? '')).toLowerCase();
96
+ }
97
+ async Read(unit, deps) {
98
+ const rowEntityName = PredictionUnit.UnitRowEntityName(unit.rows);
99
+ const rowEntity = deps.Metadata.Entity(rowEntityName);
100
+ if (!rowEntity)
101
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: rowEntityName, field: null });
102
+ if (!deps.Metadata.Entity(unit.rows.grainEntity))
103
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: unit.rows.grainEntity, field: null });
104
+ const read = await CompleteReader.ReadCompletely(deps.DataAccess, { EntityName: rowEntity.Name, KeyField: rowEntity.PrimaryKey }, deps.Read);
105
+ if (read.Status === 'refused')
106
+ return { Status: 'refused', Refusal: { stage: 'assembly', reason: read.Refusal } };
107
+ const cutoff = await this.resolveCutoff(unit, deps);
108
+ if ('Status' in cutoff)
109
+ return cutoff;
110
+ const candidates = read.Rows.filter((r) => PredictionUnitRowReader.MatchesRowFilters(r, unit.rows.filter));
111
+ const labeler = await this.buildLabeler(unit, rowEntity, candidates, deps);
112
+ if ('Status' in labeler)
113
+ return labeler;
114
+ const undated = candidates.filter((r) => this.decisionDate(unit, r) === null).length;
115
+ if (undated > 0)
116
+ return PredictionUnitRowReader.unitRefusal({ kind: 'missing-decision-date', entity: rowEntity.Name, rows: undated });
117
+ // A grain row's series period is its time column (a grain × periods row's is its period date, checked above).
118
+ const timeColumn = unit.temporal && unit.rows.kind === 'grain' ? unit.temporal.timeColumn : null;
119
+ const unperiodic = timeColumn === null ? 0 : candidates.filter((r) => UtcDay.ToUtcDay(r[timeColumn]) === null).length;
120
+ if (timeColumn !== null && unperiodic > 0)
121
+ return PredictionUnitRowReader.unitRefusal({ kind: 'missing-period', entity: rowEntity.Name, field: timeColumn, rows: unperiodic });
122
+ const resolved = this.resolveRows(unit, rowEntity, candidates, deps.KeepOpenWindows === true ? null : cutoff, labeler);
123
+ const rows = this.removeDuplicates(resolved.Rows);
124
+ return {
125
+ Status: 'read',
126
+ Rows: rows,
127
+ DataCutoff: cutoff,
128
+ RowEntity: rowEntity,
129
+ Counts: {
130
+ rowsRead: read.Rows.length,
131
+ censoredRowsExcluded: resolved.Censored,
132
+ labelKnownRowsExcluded: resolved.LabelKnown,
133
+ gapOutcomeRowsExcluded: resolved.GapOutcome,
134
+ emptyLabelRowsExcluded: resolved.EmptyLabel,
135
+ duplicateRowsRemoved: resolved.Rows.length - rows.length,
136
+ resolvedRows: rows.length,
137
+ dataCutoff: UtcDay.UtcDayIso(cutoff),
138
+ },
139
+ };
140
+ }
141
+ /**
142
+ * Applies the exclusions in their documented order — censored, label known at the decision, outcome inside the gap,
143
+ * empty label — and
144
+ * builds the unit rows, sorted by decision date then row id (ordinal). A null `cutoff` censors nothing.
145
+ */
146
+ resolveRows(unit, rowEntity, candidates, cutoff, labeler) {
147
+ let censored = 0;
148
+ let labelKnown = 0;
149
+ let gapOutcome = 0;
150
+ let emptyLabel = 0;
151
+ const resolved = [];
152
+ for (const row of candidates) {
153
+ const rowId = PredictionUnitRowReader.requireKey(row[rowEntity.PrimaryKey], `${rowEntity.Name}.${rowEntity.PrimaryKey}`);
154
+ const decision = PredictionUnitRowReader.requireDay(this.decisionDate(unit, row), `decision date of ${rowEntity.Name} ${rowId}`);
155
+ const windowStart = UtcDay.AddUtcDays(decision, unit.label.gapDays);
156
+ const windowEnd = UtcDay.AddUtcDays(windowStart, unit.label.windowDays);
157
+ if (cutoff !== null && windowEnd.getTime() > cutoff.getTime()) {
158
+ censored++;
159
+ continue;
160
+ }
161
+ const ref = PredictionUnitRowReader.UnitRowRef(unit, rowEntity, row, decision);
162
+ const label = labeler(row, ref.EntityKey, decision, windowStart, windowEnd);
163
+ if (label.Kind === 'known-at-decision') {
164
+ labelKnown++;
165
+ continue;
166
+ }
167
+ if (label.Kind === 'outcome-in-gap') {
168
+ gapOutcome++;
169
+ continue;
170
+ }
171
+ if (label.Label === null) {
172
+ emptyLabel++;
173
+ continue;
174
+ }
175
+ resolved.push({
176
+ ...ref,
177
+ WindowEnd: windowEnd,
178
+ GroupKey: unit.groupKey ? PredictionUnitRowReader.requireKey(row[unit.groupKey], `${rowEntity.Name}.${unit.groupKey} of ${rowId}`).toLowerCase() : ref.EntityKey.toLowerCase(),
179
+ Label: label.Label,
180
+ Source: row,
181
+ });
182
+ }
183
+ resolved.sort((a, b) => a.DecisionDate.getTime() - b.DecisionDate.getTime() || OrdinalCompare(a.RowID, b.RowID));
184
+ return { Rows: resolved, Censored: censored, LabelKnown: labelKnown, GapOutcome: gapOutcome, EmptyLabel: emptyLabel };
185
+ }
186
+ /** Keeps the first row of each (entity key, decision date, period); the caller counts the rest as duplicates. */
187
+ removeDuplicates(resolved) {
188
+ const seen = new Set();
189
+ const rows = [];
190
+ for (const r of resolved) {
191
+ const k = `${r.EntityKey.toLowerCase()}|${UtcDay.UtcDayIso(r.DecisionDate)}|${r.Period ? UtcDay.UtcDayIso(r.Period) : ''}`;
192
+ if (seen.has(k))
193
+ continue;
194
+ seen.add(k);
195
+ rows.push(r);
196
+ }
197
+ return rows;
198
+ }
199
+ decisionDate(unit, row) {
200
+ return PredictionUnitRowReader.UnitDecisionDate(unit, row);
201
+ }
202
+ /**
203
+ * A row as the assembly reads it, by the one rule training and scoring share: its key (the primary key), its entity
204
+ * key (the key itself for a grain unit, else the grain foreign key), the given decision day and its period (the
205
+ * period date of a grain × periods unit, else the Temporal Spec's time column, else null). Keys read as text; a date
206
+ * key reads as its UTC day.
207
+ */
208
+ static UnitRowRef(unit, rowEntity, row, decision) {
209
+ const rowId = PredictionUnitRowReader.requireKey(row[rowEntity.PrimaryKey], `${rowEntity.Name}.${rowEntity.PrimaryKey}`);
210
+ const entityKey = unit.rows.kind === 'grain' ? rowId : PredictionUnitRowReader.requireKey(row[unit.rows.foreignKey], `${rowEntity.Name}.${unit.rows.foreignKey} of ${rowId}`);
211
+ const period = unit.rows.kind === 'grain-x-periods' ? UtcDay.ToUtcDay(row[unit.rows.periodDate]) : unit.temporal ? UtcDay.ToUtcDay(row[unit.temporal.timeColumn]) : null;
212
+ return { RowID: rowId, EntityKey: entityKey, DecisionDate: decision, Period: period };
213
+ }
214
+ /**
215
+ * A row's decision day by the unit's rule: the period date of a grain × periods unit, else the decision-date column
216
+ * (offset when the rule says so) or the fixed date. Null when the row has no date there. Training and scoring both
217
+ * date their rows with it.
218
+ */
219
+ static UnitDecisionDate(unit, row) {
220
+ if (unit.rows.kind === 'grain-x-periods')
221
+ return UtcDay.ToUtcDay(row[unit.rows.periodDate]);
222
+ const rule = unit.rows.decisionDate;
223
+ switch (rule.kind) {
224
+ case 'column': return UtcDay.ToUtcDay(row[rule.column]);
225
+ case 'column-offset': {
226
+ const d = UtcDay.ToUtcDay(row[rule.column]);
227
+ return d === null ? null : UtcDay.AddUtcDays(d, rule.offsetDays);
228
+ }
229
+ case 'fixed': return UtcDay.ToUtcDay(rule.date);
230
+ }
231
+ }
232
+ async resolveCutoff(unit, deps) {
233
+ const cutoff = unit.censoring.cutoff;
234
+ if (cutoff.kind === 'now')
235
+ return PredictionUnitRowReader.requireDay(UtcDay.ToUtcDay(deps.Now), 'the current day');
236
+ if (cutoff.kind === 'fixed')
237
+ return PredictionUnitRowReader.requireDay(UtcDay.ToUtcDay(cutoff.at), `the fixed cutoff ${cutoff.at}`);
238
+ const entity = deps.Metadata.Entity(cutoff.entity);
239
+ // The field name comes from unit JSON; it is used in SQL text only after it matched a metadata field name.
240
+ if (!entity || !entity.Fields.some((f) => f.Name === cutoff.field))
241
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: cutoff.entity, field: cutoff.field });
242
+ const res = await deps.DataAccess.fetchRows({ EntityName: entity.Name, Fields: [cutoff.field], ExtraFilter: `[${cutoff.field}] IS NOT NULL`, OrderBy: `[${cutoff.field}] DESC`, MaxRows: 1 });
243
+ if (!res.Success)
244
+ throw new Error(`Reading the corpus end from ${entity.Name}.${cutoff.field} failed: ${res.ErrorMessage || 'unknown error'}`);
245
+ const end = res.Rows.length > 0 ? UtcDay.ToUtcDay(res.Rows[0][cutoff.field]) : null;
246
+ if (end === null)
247
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: cutoff.entity, field: cutoff.field });
248
+ return end;
249
+ }
250
+ /** `keptRows` are the rows the unit's filter keeps; a next-period label reads only them. */
251
+ async buildLabeler(unit, rowEntity, keptRows, deps) {
252
+ const rule = unit.label.rule;
253
+ switch (rule.kind) {
254
+ case 'column':
255
+ if (!rowEntity.Fields.some((f) => f.Name === rule.column))
256
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: rowEntity.Name, field: rule.column });
257
+ return (row) => ({ Kind: 'label', Label: PredictionUnitRowReader.CanonicalLabel(row[rule.column], unit.label.outcome) });
258
+ case 'next-period':
259
+ if (unit.rows.kind !== 'grain-x-periods')
260
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: rowEntity.Name, field: rule.periodIndexField });
261
+ return this.nextPeriodLabeler(rule, unit.rows, rowEntity, keptRows);
262
+ case 'child-event':
263
+ return this.childEventLabeler(rule, unit.label.outcome, deps);
264
+ }
265
+ }
266
+ /**
267
+ * next-period: 1 when the period `offset` later falls in the window; label known when it is on or before the decision;
268
+ * the row is excluded when it falls inside the gap (after the decision, on or before the window start). Only the
269
+ * kept rows are indexed, and two of them at one (grain key, period index) refuse the read: the label would otherwise
270
+ * depend on which of them was read last.
271
+ */
272
+ nextPeriodLabeler(rule, unitRows, rowEntity, keptRows) {
273
+ const byKey = new Map();
274
+ for (const r of keptRows) {
275
+ // A row without an index is never a "next period"; it is not indexed (a candidate without one fails when labelled).
276
+ if (PredictionUnitRowReader.isEmptyCell(r[rule.periodIndexField]))
277
+ continue;
278
+ const idx = Number(r[rule.periodIndexField]);
279
+ const d = UtcDay.ToUtcDay(r[unitRows.periodDate]);
280
+ if (!Number.isInteger(idx) || d === null)
281
+ continue;
282
+ const k = PredictionUnitRowReader.keyOf(r[unitRows.foreignKey]);
283
+ const m = byKey.get(k) || new Map();
284
+ if (m.has(idx)) {
285
+ const entityKey = PredictionUnitRowReader.requireKey(r[unitRows.foreignKey], `${rowEntity.Name}.${unitRows.foreignKey}`);
286
+ return PredictionUnitRowReader.unitRefusal({ kind: 'duplicate-period-index', entity: rowEntity.Name, field: rule.periodIndexField, entityKey, periodIndex: idx });
287
+ }
288
+ m.set(idx, d);
289
+ byKey.set(k, m);
290
+ }
291
+ return (row, entityKey, decision, windowStart, windowEnd) => {
292
+ const rowId = PredictionUnitRowReader.requireKey(row[rowEntity.PrimaryKey], `${rowEntity.Name}.${rowEntity.PrimaryKey}`);
293
+ const idx = PredictionUnitRowReader.requirePeriodIndex(row[rule.periodIndexField], `${rowEntity.Name}.${rule.periodIndexField} of ${rowId}`);
294
+ const next = byKey.get(entityKey.toLowerCase())?.get(idx + rule.offset);
295
+ if (next === undefined)
296
+ return { Kind: 'label', Label: '0' };
297
+ if (next.getTime() <= decision.getTime())
298
+ return { Kind: 'known-at-decision' };
299
+ if (next.getTime() <= windowStart.getTime())
300
+ return { Kind: 'outcome-in-gap' };
301
+ return { Kind: 'label', Label: next.getTime() <= windowEnd.getTime() ? '1' : '0' };
302
+ };
303
+ }
304
+ /**
305
+ * child-event: exists / count / sum of the owner's child events inside the window. The gap (after the decision, on or
306
+ * before the window start) is treated by what the aggregate measures. For `exists` a row with an event in the gap is
307
+ * excluded: the event may be a terminal outcome that already happened (a cancellation), so labelling the window 0
308
+ * would mislabel the row. For `count` and `sum` the label is the volume inside the window: an event in the gap is
309
+ * simply not counted and the row is kept, since excluding it would drop most rows of an owner whose events recur.
310
+ */
311
+ async childEventLabeler(rule, task, deps) {
312
+ const child = deps.Metadata.Entity(rule.childEntity);
313
+ if (!child)
314
+ return PredictionUnitRowReader.unitRefusal({ kind: 'unresolved-reference', entity: rule.childEntity, field: null });
315
+ const read = await CompleteReader.ReadCompletely(deps.DataAccess, { EntityName: child.Name, KeyField: child.PrimaryKey }, deps.Read);
316
+ if (read.Status === 'refused')
317
+ return { Status: 'refused', Refusal: { stage: 'assembly', reason: read.Refusal } };
318
+ const events = new Map();
319
+ for (const r of read.Rows) {
320
+ if (!PredictionUnitRowReader.MatchesRowFilters(r, rule.filter))
321
+ continue;
322
+ const d = UtcDay.ToUtcDay(r[rule.dateField]);
323
+ if (d === null)
324
+ continue;
325
+ const k = PredictionUnitRowReader.keyOf(r[rule.foreignKey]);
326
+ const list = events.get(k) || [];
327
+ const value = rule.valueField
328
+ ? PredictionUnitRowReader.requireEventValue(r[rule.valueField], `${child.Name}.${rule.valueField} of ${PredictionUnitRowReader.keyOf(r[child.PrimaryKey])}`)
329
+ : 1;
330
+ list.push({ Day: d, Value: value });
331
+ events.set(k, list);
332
+ }
333
+ return (row, entityKey, decision, windowStart, windowEnd) => {
334
+ const owner = rule.ownerKeyField ? PredictionUnitRowReader.keyOf(row[rule.ownerKeyField]) : entityKey.toLowerCase();
335
+ const ownerEvents = events.get(owner) || [];
336
+ const hits = ownerEvents.filter((e) => e.Day.getTime() > windowStart.getTime() && e.Day.getTime() <= windowEnd.getTime());
337
+ if (rule.aggregate === 'exists') {
338
+ if (ownerEvents.some((e) => e.Day.getTime() > decision.getTime() && e.Day.getTime() <= windowStart.getTime()))
339
+ return { Kind: 'outcome-in-gap' };
340
+ return { Kind: 'label', Label: PredictionUnitRowReader.CanonicalLabel(hits.length > 0 ? '1' : '0', task) };
341
+ }
342
+ if (rule.aggregate === 'count')
343
+ return { Kind: 'label', Label: hits.length };
344
+ return { Kind: 'label', Label: hits.reduce((s, e) => s + e.Value, 0) };
345
+ };
346
+ }
347
+ }
348
+ //# sourceMappingURL=unit-row-reader.js.map