@jam-overture/loom 0.1.0 → 0.2.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 (290) hide show
  1. package/README.md +3 -1
  2. package/dist/application/application.d.ts +109 -0
  3. package/dist/application/application.js +97 -0
  4. package/dist/application/memory.d.ts +20 -0
  5. package/dist/application/memory.js +79 -0
  6. package/dist/application/store.d.ts +101 -0
  7. package/dist/application/store.js +25 -0
  8. package/dist/audience/audience.d.ts +36 -0
  9. package/dist/audience/audience.js +41 -0
  10. package/dist/cli/templates.js +19 -0
  11. package/dist/data/plan.js +0 -0
  12. package/dist/data/resolution.d.ts +23 -1
  13. package/dist/data/resolve.d.ts +30 -3
  14. package/dist/data/resolve.js +11 -3
  15. package/dist/ids.d.ts +10 -0
  16. package/dist/ids.js +11 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/patch.d.ts +54 -0
  20. package/dist/patch.js +44 -0
  21. package/dist/project/closing.d.ts +51 -0
  22. package/dist/project/closing.js +53 -0
  23. package/dist/project/memory.d.ts +20 -0
  24. package/dist/project/memory.js +97 -0
  25. package/dist/project/project.d.ts +90 -0
  26. package/dist/project/project.js +91 -0
  27. package/dist/project/store.d.ts +135 -0
  28. package/dist/project/store.js +41 -0
  29. package/dist/registered.d.ts +64 -0
  30. package/dist/registered.js +118 -0
  31. package/dist/render/behaviour-adjust.d.ts +11 -19
  32. package/dist/render/behaviour-adjust.js +75 -21
  33. package/dist/render/behaviour-present.d.ts +8 -0
  34. package/dist/render/behaviour-present.js +57 -6
  35. package/dist/render/behaviour.d.ts +98 -17
  36. package/dist/render/behaviour.js +91 -26
  37. package/dist/render/control-name.d.ts +68 -0
  38. package/dist/render/control-name.js +37 -0
  39. package/dist/render/diagnostics.d.ts +72 -0
  40. package/dist/render/diagnostics.js +7 -0
  41. package/dist/render/index.d.ts +2 -0
  42. package/dist/render/index.js +2 -0
  43. package/dist/render/reads.d.ts +11 -0
  44. package/dist/render/reads.js +12 -1
  45. package/dist/render/render.js +102 -7
  46. package/dist/render/slots.d.ts +52 -0
  47. package/dist/render/slots.js +24 -0
  48. package/dist/render/theme.d.ts +54 -1
  49. package/dist/render/theme.js +23 -1
  50. package/dist/render/unshown.d.ts +152 -0
  51. package/dist/render/unshown.js +80 -0
  52. package/dist/runtime/analysis.d.ts +94 -9
  53. package/dist/runtime/analysis.js +54 -9
  54. package/dist/runtime/assessment.d.ts +36 -2
  55. package/dist/runtime/assessment.js +27 -2
  56. package/dist/runtime/checks.d.ts +148 -0
  57. package/dist/runtime/checks.js +112 -0
  58. package/dist/runtime/disposition.d.ts +96 -0
  59. package/dist/runtime/disposition.js +46 -0
  60. package/dist/runtime/gate.js +22 -0
  61. package/dist/runtime/index.d.ts +3 -0
  62. package/dist/runtime/index.js +3 -0
  63. package/dist/runtime/irreversibility.d.ts +64 -0
  64. package/dist/runtime/irreversibility.js +45 -0
  65. package/dist/runtime/pipeline.d.ts +43 -0
  66. package/dist/runtime/pipeline.js +10 -2
  67. package/dist/runtime/policy-change.d.ts +93 -0
  68. package/dist/runtime/policy-change.js +299 -0
  69. package/dist/runtime/policy-log.d.ts +406 -0
  70. package/dist/runtime/policy-log.js +285 -0
  71. package/dist/runtime/reversibility.d.ts +11 -9
  72. package/dist/runtime/stakes.d.ts +129 -1
  73. package/dist/runtime/stakes.js +240 -26
  74. package/dist/runtime/vocabulary.d.ts +164 -7
  75. package/dist/runtime/vocabulary.js +181 -8
  76. package/dist/sdk/audit.d.ts +174 -3
  77. package/dist/sdk/audit.js +176 -17
  78. package/dist/sdk/catalogue.d.ts +9 -1
  79. package/dist/sdk/conformance.d.ts +37 -3
  80. package/dist/sdk/conformance.js +25 -4
  81. package/dist/sdk/definition.d.ts +65 -0
  82. package/dist/sdk/definition.js +22 -0
  83. package/dist/sdk/registry.d.ts +29 -2
  84. package/dist/sdk/registry.js +63 -1
  85. package/dist/signals/action-change.d.ts +507 -0
  86. package/dist/signals/action-change.js +265 -0
  87. package/dist/signals/action.d.ts +331 -0
  88. package/dist/signals/action.js +182 -0
  89. package/dist/signals/applied-window.contract.d.ts +23 -0
  90. package/dist/signals/applied-window.contract.js +160 -0
  91. package/dist/signals/arriving.d.ts +210 -0
  92. package/dist/signals/arriving.js +133 -0
  93. package/dist/signals/audiences.d.ts +528 -0
  94. package/dist/signals/audiences.js +255 -0
  95. package/dist/signals/broadcast.d.ts +8 -2
  96. package/dist/signals/broadcast.js +58 -8
  97. package/dist/signals/change.d.ts +378 -0
  98. package/dist/signals/change.js +327 -0
  99. package/dist/signals/collect.d.ts +41 -0
  100. package/dist/signals/collect.js +88 -7
  101. package/dist/signals/copy-change.d.ts +553 -0
  102. package/dist/signals/copy-change.js +377 -0
  103. package/dist/signals/copy.d.ts +337 -0
  104. package/dist/signals/copy.js +211 -0
  105. package/dist/signals/counters.d.ts +46 -0
  106. package/dist/signals/counters.js +102 -0
  107. package/dist/signals/deliver.d.ts +23 -4
  108. package/dist/signals/deliver.js +34 -6
  109. package/dist/signals/deployment-change.d.ts +371 -0
  110. package/dist/signals/deployment-change.js +268 -0
  111. package/dist/signals/deployment.d.ts +265 -0
  112. package/dist/signals/deployment.js +152 -0
  113. package/dist/signals/door.d.ts +92 -0
  114. package/dist/signals/door.js +53 -0
  115. package/dist/signals/fold.d.ts +10 -0
  116. package/dist/signals/fold.js +5 -1
  117. package/dist/signals/form-action.d.ts +302 -0
  118. package/dist/signals/form-action.js +169 -0
  119. package/dist/signals/form-copy.d.ts +523 -0
  120. package/dist/signals/form-copy.js +346 -0
  121. package/dist/signals/forms.d.ts +247 -0
  122. package/dist/signals/forms.js +147 -0
  123. package/dist/signals/funnel-change.d.ts +548 -0
  124. package/dist/signals/funnel-change.js +361 -0
  125. package/dist/signals/funnel.d.ts +532 -0
  126. package/dist/signals/funnel.js +216 -0
  127. package/dist/signals/health.d.ts +497 -0
  128. package/dist/signals/health.js +361 -0
  129. package/dist/signals/index.d.ts +41 -0
  130. package/dist/signals/index.js +41 -0
  131. package/dist/signals/ingest.d.ts +56 -1
  132. package/dist/signals/ingest.js +91 -1
  133. package/dist/signals/journal.d.ts +11 -0
  134. package/dist/signals/kinds.d.ts +8 -6
  135. package/dist/signals/kinds.js +14 -6
  136. package/dist/signals/library-action.d.ts +430 -0
  137. package/dist/signals/library-action.js +336 -0
  138. package/dist/signals/library-change.d.ts +477 -0
  139. package/dist/signals/library-change.js +335 -0
  140. package/dist/signals/library-copy-change.d.ts +498 -0
  141. package/dist/signals/library-copy-change.js +476 -0
  142. package/dist/signals/library-pace.d.ts +319 -0
  143. package/dist/signals/library-pace.js +305 -0
  144. package/dist/signals/library-reach-change.d.ts +636 -0
  145. package/dist/signals/library-reach-change.js +534 -0
  146. package/dist/signals/library-reach.d.ts +377 -0
  147. package/dist/signals/library-reach.js +227 -0
  148. package/dist/signals/library-word-reach-change.d.ts +567 -0
  149. package/dist/signals/library-word-reach-change.js +568 -0
  150. package/dist/signals/library.d.ts +306 -0
  151. package/dist/signals/library.js +178 -0
  152. package/dist/signals/memory.d.ts +9 -0
  153. package/dist/signals/memory.js +105 -14
  154. package/dist/signals/migrate.d.ts +17 -2
  155. package/dist/signals/migrate.js +122 -5
  156. package/dist/signals/notice.d.ts +334 -0
  157. package/dist/signals/notice.js +228 -0
  158. package/dist/signals/pace-change.d.ts +501 -0
  159. package/dist/signals/pace-change.js +310 -0
  160. package/dist/signals/pace.d.ts +296 -0
  161. package/dist/signals/pace.js +291 -0
  162. package/dist/signals/page-views.d.ts +365 -0
  163. package/dist/signals/page-views.js +218 -0
  164. package/dist/signals/parts.d.ts +344 -0
  165. package/dist/signals/parts.js +273 -0
  166. package/dist/signals/postgres.d.ts +16 -2
  167. package/dist/signals/postgres.js +390 -87
  168. package/dist/signals/progress.d.ts +212 -0
  169. package/dist/signals/progress.js +150 -0
  170. package/dist/signals/ratios.d.ts +108 -0
  171. package/dist/signals/ratios.js +40 -0
  172. package/dist/signals/reach.d.ts +309 -0
  173. package/dist/signals/reach.js +93 -0
  174. package/dist/signals/readable.d.ts +34 -0
  175. package/dist/signals/readable.js +34 -0
  176. package/dist/signals/readership.d.ts +381 -0
  177. package/dist/signals/readership.js +308 -0
  178. package/dist/signals/region-pages.d.ts +173 -0
  179. package/dist/signals/region-pages.js +62 -0
  180. package/dist/signals/region.d.ts +287 -0
  181. package/dist/signals/region.js +198 -0
  182. package/dist/signals/retention.d.ts +141 -0
  183. package/dist/signals/retention.js +58 -0
  184. package/dist/signals/rollup.d.ts +67 -3
  185. package/dist/signals/rollup.js +0 -0
  186. package/dist/signals/schema.d.ts +432 -1
  187. package/dist/signals/schema.js +157 -3
  188. package/dist/signals/signal.d.ts +237 -11
  189. package/dist/signals/signal.js +70 -10
  190. package/dist/signals/silence-census.d.ts +205 -0
  191. package/dist/signals/silence-census.js +87 -0
  192. package/dist/signals/silences.d.ts +848 -0
  193. package/dist/signals/silences.js +753 -0
  194. package/dist/signals/tally.d.ts +140 -11
  195. package/dist/signals/window-figures.d.ts +148 -0
  196. package/dist/signals/window-figures.js +42 -0
  197. package/dist/signals/window.d.ts +866 -0
  198. package/dist/signals/window.js +693 -0
  199. package/dist/signals/words.d.ts +24 -0
  200. package/dist/signals/words.js +24 -0
  201. package/dist/store/index.d.ts +19 -0
  202. package/dist/store/index.js +19 -0
  203. package/dist/store/memory.d.ts +2 -1
  204. package/dist/store/memory.js +48 -12
  205. package/dist/store/migrate.d.ts +80 -0
  206. package/dist/store/migrate.js +259 -7
  207. package/dist/store/postgres-applications.d.ts +4 -0
  208. package/dist/store/postgres-applications.js +197 -0
  209. package/dist/store/postgres-holds.d.ts +10 -1
  210. package/dist/store/postgres-holds.js +116 -101
  211. package/dist/store/postgres-policy-log.d.ts +14 -0
  212. package/dist/store/postgres-policy-log.js +240 -0
  213. package/dist/store/postgres-projects.d.ts +4 -0
  214. package/dist/store/postgres-projects.js +217 -0
  215. package/dist/store/postgres.d.ts +16 -1
  216. package/dist/store/postgres.js +59 -9
  217. package/dist/store/replay.d.ts +102 -1
  218. package/dist/store/replay.js +190 -19
  219. package/dist/store/reseed.d.ts +238 -0
  220. package/dist/store/reseed.js +308 -0
  221. package/dist/store/schema.d.ts +450 -2
  222. package/dist/store/schema.js +141 -5
  223. package/dist/store/store.d.ts +29 -6
  224. package/dist/submit/resolve.js +2 -1
  225. package/dist/telemetry/calibration.d.ts +25 -0
  226. package/dist/telemetry/calibration.js +27 -1
  227. package/dist/telemetry/event.d.ts +391 -33
  228. package/dist/telemetry/event.js +84 -20
  229. package/dist/telemetry/index.d.ts +1 -0
  230. package/dist/telemetry/index.js +1 -0
  231. package/dist/telemetry/journal.d.ts +72 -3
  232. package/dist/telemetry/journal.js +9 -0
  233. package/dist/telemetry/lookup.d.ts +27 -0
  234. package/dist/telemetry/lookup.js +18 -0
  235. package/dist/telemetry/memory.js +23 -0
  236. package/dist/telemetry/migrate.js +22 -1
  237. package/dist/telemetry/postgres.d.ts +10 -1
  238. package/dist/telemetry/postgres.js +172 -90
  239. package/dist/telemetry/remeasure.d.ts +78 -0
  240. package/dist/telemetry/remeasure.js +83 -0
  241. package/dist/telemetry/retention.d.ts +2 -2
  242. package/dist/telemetry/schema.d.ts +17 -0
  243. package/dist/telemetry/schema.js +27 -1
  244. package/dist/telemetry/sink.d.ts +2 -2
  245. package/dist/testing/application-contract.d.ts +14 -0
  246. package/dist/testing/application-contract.js +270 -0
  247. package/dist/testing/contracts.d.ts +12 -7
  248. package/dist/testing/contracts.js +12 -7
  249. package/dist/testing/definitions.d.ts +78 -0
  250. package/dist/testing/definitions.js +134 -9
  251. package/dist/testing/doubles.d.ts +103 -0
  252. package/dist/testing/doubles.js +143 -0
  253. package/dist/testing/index.d.ts +2 -2
  254. package/dist/testing/index.js +2 -2
  255. package/dist/testing/journal-contract.js +140 -2
  256. package/dist/testing/model-contract.d.ts +110 -0
  257. package/dist/testing/model-contract.js +150 -0
  258. package/dist/testing/policy-log-contract.d.ts +26 -0
  259. package/dist/testing/policy-log-contract.js +344 -0
  260. package/dist/testing/project-contract.d.ts +14 -0
  261. package/dist/testing/project-contract.js +266 -0
  262. package/dist/testing/reader-signal-contract.d.ts +27 -2
  263. package/dist/testing/reader-signal-contract.js +475 -5
  264. package/dist/testing/store-contract.d.ts +7 -1
  265. package/dist/testing/store-contract.js +84 -3
  266. package/dist/theme/apply.d.ts +20 -1
  267. package/dist/theme/apply.js +5 -3
  268. package/dist/theme/derive.d.ts +22 -0
  269. package/dist/theme/derive.js +54 -1
  270. package/dist/theme/library.js +1 -1
  271. package/dist/theme/measure.d.ts +34 -0
  272. package/dist/theme/measure.js +30 -1
  273. package/dist/theme/palettes.js +7 -7
  274. package/dist/theme/ramp.d.ts +64 -0
  275. package/dist/theme/ramp.js +114 -0
  276. package/dist/theme/registry.d.ts +9 -0
  277. package/dist/theme/registry.js +11 -1
  278. package/dist/theme/separation.d.ts +97 -3
  279. package/dist/theme/separation.js +75 -0
  280. package/dist/tree/compare.d.ts +9 -0
  281. package/dist/tree/compare.js +18 -0
  282. package/dist/write/computed.d.ts +60 -0
  283. package/dist/write/computed.js +61 -0
  284. package/dist/write/held.d.ts +59 -0
  285. package/dist/write/index.d.ts +5 -2
  286. package/dist/write/index.js +5 -2
  287. package/dist/write/reseed.d.ts +151 -0
  288. package/dist/write/reseed.js +184 -0
  289. package/dist/write/revert.js +2 -16
  290. package/package.json +98 -19
@@ -0,0 +1,361 @@
1
+ import { everyMemberOf } from "../closed-set.js";
2
+ import { audienceScopeRead, comparedAudiencesOf, crossesAudiences, } from "./audiences.js";
3
+ import { funnelPairKey } from "./funnel.js";
4
+ import { ratioOf } from "./ratios.js";
5
+ /** The closed set, for a surface that has to account for every absent figure. */
6
+ export const FUNNEL_CHANGE_SILENCES = everyMemberOf()([
7
+ "different-trees",
8
+ "different-audiences",
9
+ "audiences-mixed",
10
+ "unscaled",
11
+ "unopened",
12
+ "uncounted",
13
+ "unasked",
14
+ ]);
15
+ /** One line per silence, for a surface saying why a figure is not there. */
16
+ export const describeFunnelChangeSilence = (silence) => {
17
+ switch (silence) {
18
+ case "different-trees":
19
+ return "the two readings are of different pages";
20
+ case "different-audiences":
21
+ return "the two readings are of different audiences, and so of different readers";
22
+ case "audiences-mixed":
23
+ return "one of the two windows holds two forms of the page and says which readers neither";
24
+ case "unscaled":
25
+ return "one of the two windows has no count of the readers who arrived";
26
+ case "unopened":
27
+ return "one of the two windows has nothing saying a page view began";
28
+ case "uncounted":
29
+ return "one of the two windows has arrivals no rollup has counted yet";
30
+ case "unasked":
31
+ return "the two windows have no funnel question in common";
32
+ }
33
+ };
34
+ /** The closed set, for a surface accounting for every pair it was handed. */
35
+ export const FUNNEL_MOVEMENTS = everyMemberOf()([
36
+ "taken-up",
37
+ "abandoned",
38
+ "still-unconverted",
39
+ "held",
40
+ "unknown",
41
+ ]);
42
+ /** One line per movement, for a surface putting a funnel in front of a person. */
43
+ export const describeFunnelMovement = (movement) => {
44
+ switch (movement) {
45
+ case "taken-up":
46
+ return "readers got to the start of this funnel and none finished it, and now some do";
47
+ case "abandoned":
48
+ return "readers finished this funnel, and now they get to its start and do not";
49
+ case "still-unconverted":
50
+ return "readers get to the start of this funnel and do not finish it, before and after";
51
+ case "held":
52
+ return "readers finished this funnel, before and after";
53
+ case "unknown":
54
+ return "one of the two windows cannot say whether readers finished it";
55
+ }
56
+ };
57
+ /** The closed set, for a surface accounting for every compared pair. */
58
+ export const QUESTION_MOVEMENTS = everyMemberOf()([
59
+ "asked",
60
+ "broken",
61
+ "restored",
62
+ "stale",
63
+ ]);
64
+ /** One line per movement, for a surface saying what a change did to a question. */
65
+ export const describeQuestionMovement = (movement) => {
66
+ switch (movement) {
67
+ case "asked":
68
+ return "both revisions have the parts this question names";
69
+ case "broken":
70
+ return "the change removed a part this question names, so it can no longer be answered";
71
+ case "restored":
72
+ return "the change put back a part this question names, so it can be answered again";
73
+ case "stale":
74
+ return "neither revision has a part this question names";
75
+ }
76
+ };
77
+ /**
78
+ * The closed set, and it is **one member shorter than every other
79
+ * counterfactual here**, which is a property of the arithmetic rather than a
80
+ * decision.
81
+ *
82
+ * 0244 and 0279 both publish a fourth answer — *neither alone was enough and
83
+ * the two together were* — and both need it, because the figure they split is a
84
+ * sum: traffic can move toward the places whose reading moved, and the
85
+ * interaction is then the whole of the movement.
86
+ *
87
+ * **A product has no such case.** The two counterfactuals of a product multiply
88
+ * to the product of the two levels: `(entryNow × rateWas) × (entryWas ×
89
+ * rateNow) = conversionWas × conversionNow`. So if the conversion share rose,
90
+ * the two counterfactuals multiply to more than `conversionWas` squared and at
91
+ * least one of them is above it; if it fell, at least one is below. Neither
92
+ * being enough is arithmetically unreachable, and publishing a member for it
93
+ * would be a state a surface had to handle and nothing could ever produce.
94
+ */
95
+ export const CONVERSION_CAUSES = everyMemberOf()([
96
+ "entry",
97
+ "closing",
98
+ "either",
99
+ ]);
100
+ /** One line per cause, for a surface saying what moved a conversion share. */
101
+ export const describeConversionCause = (cause) => {
102
+ switch (cause) {
103
+ case "entry":
104
+ return "the readers who got to the start of the funnel would have moved it on their own";
105
+ case "closing":
106
+ return "the share of them who finished would have moved it on its own";
107
+ case "either":
108
+ return "either would have moved it on its own";
109
+ }
110
+ };
111
+ const NO_MOVEMENTS = Object.freeze({
112
+ "taken-up": 0,
113
+ abandoned: 0,
114
+ "still-unconverted": 0,
115
+ held: 0,
116
+ unknown: 0,
117
+ });
118
+ const NO_QUESTIONS = Object.freeze({
119
+ asked: 0,
120
+ broken: 0,
121
+ restored: 0,
122
+ stale: 0,
123
+ });
124
+ /**
125
+ * The door's state, said of the pair rather than of either window.
126
+ *
127
+ * Taken in the set's own order so that two windows in two different states
128
+ * report the worse of them, which is the rule a deployment reading reports one
129
+ * state for a pair of pages by (0240): the condition is what the two sides have
130
+ * in common and no more, and each side's own reading carries which it was.
131
+ */
132
+ const doorSilenceOf = (was, now) => {
133
+ const sides = [was.silence, now.silence];
134
+ if (sides.includes("unmeasured"))
135
+ return "unscaled";
136
+ if (sides.includes("unopened"))
137
+ return "unopened";
138
+ if (sides.includes("uncounted"))
139
+ return "uncounted";
140
+ return null;
141
+ };
142
+ const questionMovementOf = (was, now) => {
143
+ if (!was.stale && !now.stale)
144
+ return "asked";
145
+ if (!was.stale)
146
+ return "broken";
147
+ return now.stale ? "stale" : "restored";
148
+ };
149
+ const movementOf = (was, now) => {
150
+ if (was.rate === null || now.rate === null)
151
+ return "unknown";
152
+ const before = was.converted > 0;
153
+ const after = now.converted > 0;
154
+ if (before && after)
155
+ return "held";
156
+ if (after)
157
+ return "taken-up";
158
+ return before ? "abandoned" : "still-unconverted";
159
+ };
160
+ /**
161
+ * Which side was enough on its own, by the direction each counterfactual
162
+ * carries — the sufficiency rule the two earlier counterfactuals here publish
163
+ * (0244, 0279), asked of a product.
164
+ *
165
+ * Published rather than private so that the one answer a funnel cannot produce
166
+ * can be shown to be handled rather than argued away: handed four numbers that
167
+ * are not a funnel's two factors, where neither counterfactual carries the
168
+ * movement, it returns `null` rather than attributing the movement to a side
169
+ * that did not cause it.
170
+ *
171
+ * `null` where nothing moved, which is the rule both earlier counterfactuals
172
+ * state: a figure that did not move has nothing to attribute.
173
+ */
174
+ export const conversionCauseOf = (was, now, ifOnlyEntryMoved, ifOnlyClosingMoved) => {
175
+ const direction = Math.sign(now - was);
176
+ if (direction === 0)
177
+ return null;
178
+ const entry = Math.sign(ifOnlyEntryMoved - was) === direction;
179
+ const closing = Math.sign(ifOnlyClosingMoved - was) === direction;
180
+ if (entry && closing)
181
+ return "either";
182
+ if (entry)
183
+ return "entry";
184
+ return closing ? "closing" : null;
185
+ };
186
+ const comparedOf = (pair, was, now, opened) => {
187
+ const rateRatio = ratioOf(was.rate, now.rate);
188
+ /**
189
+ * Both ends of the bracket or neither, because half of an interval is a
190
+ * figure a surface would draw as a bound. `was.rateAtMost` is at least
191
+ * `was.rate` and `was.rate` is above nought wherever there is a ratio at all,
192
+ * so neither division here can be by nought.
193
+ */
194
+ const bracket = rateRatio.ratio !== null && was.rate !== null && now.rate !== null
195
+ ? was.rateAtMost !== null && now.rateAtMost !== null
196
+ ? {
197
+ atLeast: now.rate / was.rateAtMost,
198
+ atMost: now.rateAtMost / was.rate,
199
+ }
200
+ : null
201
+ : null;
202
+ /**
203
+ * The counterfactuals use each side's own `rate`, which is the figure the
204
+ * reading publishes as its estimate: a sufficiency verdict needs the two
205
+ * diagonals of one table, and mixing an estimate on one diagonal with a
206
+ * ceiling on the other would answer a question neither window was asked.
207
+ */
208
+ const entryWas = was.entry.share;
209
+ const entryNow = now.entry.share;
210
+ const conversionWas = was.conversion.share;
211
+ const conversionNow = now.conversion.share;
212
+ const measured = entryWas !== null &&
213
+ entryNow !== null &&
214
+ conversionWas !== null &&
215
+ conversionNow !== null &&
216
+ was.rate !== null &&
217
+ now.rate !== null;
218
+ const ifOnlyEntryMoved = measured ? entryNow * was.rate : null;
219
+ const ifOnlyClosingMoved = measured ? entryWas * now.rate : null;
220
+ return {
221
+ pair,
222
+ was,
223
+ now,
224
+ movement: movementOf(was, now),
225
+ question: questionMovementOf(was, now),
226
+ rateRatio,
227
+ rateRatioAtLeast: bracket?.atLeast ?? null,
228
+ rateRatioAtMost: bracket?.atMost ?? null,
229
+ rateMoved: bracket === null ? null : bracket.atLeast > 1 || bracket.atMost < 1,
230
+ entryRatio: ratioOf(entryWas, entryNow),
231
+ conversionRatio: ratioOf(conversionWas, conversionNow),
232
+ ifOnlyEntryMoved,
233
+ ifOnlyClosingMoved,
234
+ cause: conversionWas === null ||
235
+ conversionNow === null ||
236
+ ifOnlyEntryMoved === null ||
237
+ ifOnlyClosingMoved === null
238
+ ? null
239
+ : conversionCauseOf(conversionWas, conversionNow, ifOnlyEntryMoved, ifOnlyClosingMoved),
240
+ readersMoved: conversionWas === null || conversionNow === null
241
+ ? null
242
+ : (conversionNow - conversionWas) * opened,
243
+ };
244
+ };
245
+ /** One question per key, later occurrences dropped and counted (0158). */
246
+ const byQuestion = (pairs) => {
247
+ const byKey = new Map();
248
+ let duplicated = 0;
249
+ for (const pair of pairs) {
250
+ const key = funnelPairKey(pair.pair);
251
+ if (byKey.has(key)) {
252
+ duplicated += 1;
253
+ continue;
254
+ }
255
+ byKey.set(key, pair);
256
+ }
257
+ return { pairs: byKey, duplicated };
258
+ };
259
+ /** The one that moved more, `>` keeping the first in the compared order on a tie. */
260
+ const furtherOf = (standing, next, sign) => {
261
+ const moved = next.readersMoved;
262
+ if (moved === null || moved * sign <= 0)
263
+ return standing;
264
+ if (standing === null)
265
+ return next;
266
+ return moved * sign > (standing.readersMoved ?? 0) * sign ? next : standing;
267
+ };
268
+ /**
269
+ * Hold two windows of one page's funnels against each other.
270
+ *
271
+ * Both sides are readings `funnelReachOf` built, so the revision each belongs
272
+ * to, the rows it dropped and the arrivals it was read against travel with it
273
+ * and nothing is inferred here (0231).
274
+ *
275
+ * Linear in the pairs of the two readings, with one pass over each.
276
+ */
277
+ export const funnelChangeOf = (was, now) => {
278
+ const earlier = byQuestion(was.pairs);
279
+ const later = byQuestion(now.pairs);
280
+ const duplicated = earlier.duplicated + later.duplicated;
281
+ const empty = {
282
+ treeId: was.treeId,
283
+ revisions: { was: was.revision, now: now.revision },
284
+ audiences: comparedAudiencesOf(was, now),
285
+ readings: { was, now },
286
+ movements: NO_MOVEMENTS,
287
+ questions: NO_QUESTIONS,
288
+ mostGained: null,
289
+ mostLost: null,
290
+ undecided: 0,
291
+ exact: false,
292
+ duplicated,
293
+ };
294
+ /** The two states in which no question is held against any other. */
295
+ const refusing = (silence) => ({
296
+ ...empty,
297
+ compared: [],
298
+ added: [],
299
+ removed: [],
300
+ silence,
301
+ });
302
+ if (was.treeId !== now.treeId)
303
+ return refusing("different-trees");
304
+ if (crossesAudiences(was, now))
305
+ return refusing("different-audiences");
306
+ /**
307
+ * Refused rather than paired, because an empty side **pairs cleanly**: a
308
+ * reading that was read as neither form holds no question, so every question
309
+ * of the other side comes back as added or removed and the comparison reads
310
+ * as *the change added every funnel question you ask* about a window that was
311
+ * simply never read. Taken beside the other two refusals, so that all three
312
+ * states of the pair are settled before any question is held against any
313
+ * other.
314
+ */
315
+ if (audienceScopeRead(was).reading === "mixed" || audienceScopeRead(now).reading === "mixed")
316
+ return refusing("audiences-mixed");
317
+ const keys = [...earlier.pairs.keys(), ...later.pairs.keys()].sort((one, other) => one.localeCompare(other));
318
+ const added = [...later.pairs].filter(([key]) => !earlier.pairs.has(key)).map(([, pair]) => pair);
319
+ const removed = [...earlier.pairs]
320
+ .filter(([key]) => !later.pairs.has(key))
321
+ .map(([, pair]) => pair);
322
+ const door = doorSilenceOf(was, now);
323
+ const movements = { ...NO_MOVEMENTS };
324
+ const questions = { ...NO_QUESTIONS };
325
+ const compared = [];
326
+ let mostGained = null;
327
+ let mostLost = null;
328
+ let undecided = 0;
329
+ const seen = new Set();
330
+ for (const key of keys) {
331
+ if (seen.has(key))
332
+ continue;
333
+ seen.add(key);
334
+ const before = earlier.pairs.get(key);
335
+ const after = later.pairs.get(key);
336
+ if (before === undefined || after === undefined)
337
+ continue;
338
+ const row = comparedOf(after.pair, before, after, now.opened);
339
+ compared.push(row);
340
+ movements[row.movement] += 1;
341
+ questions[row.question] += 1;
342
+ if (row.rateMoved === false)
343
+ undecided += 1;
344
+ mostGained = furtherOf(mostGained, row, 1);
345
+ mostLost = furtherOf(mostLost, row, -1);
346
+ }
347
+ return {
348
+ ...empty,
349
+ compared,
350
+ added,
351
+ removed,
352
+ movements,
353
+ questions,
354
+ mostGained,
355
+ mostLost,
356
+ undecided,
357
+ exact: door === null && was.exact && now.exact,
358
+ silence: door ?? (compared.length === 0 ? "unasked" : null),
359
+ };
360
+ };
361
+ //# sourceMappingURL=funnel-change.js.map