@formant/ava 3.4.1-formant

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 (534) hide show
  1. package/README.md +72 -0
  2. package/dist/ava.min.js +1 -0
  3. package/esm/advisor/advise-pipeline/advicesForChart.js +68 -0
  4. package/esm/advisor/advise-pipeline/data-to-advices.js +241 -0
  5. package/esm/advisor/advise-pipeline/index.js +1 -0
  6. package/esm/advisor/advise-pipeline/spec-mapping.js +500 -0
  7. package/esm/advisor/advisor.js +35 -0
  8. package/esm/advisor/constants.js +13 -0
  9. package/esm/advisor/index.js +2 -0
  10. package/esm/advisor/lint-pipeline/check-rules.js +43 -0
  11. package/esm/advisor/lint-pipeline/getChartType.js +109 -0
  12. package/esm/advisor/lint-pipeline/index.js +0 -0
  13. package/esm/advisor/lint-pipeline/lintRules.js +32 -0
  14. package/esm/advisor/ruler/index.js +74 -0
  15. package/esm/advisor/ruler/rules/aggregation-single-row.js +21 -0
  16. package/esm/advisor/ruler/rules/all-can-be-table.js +17 -0
  17. package/esm/advisor/ruler/rules/bar-series-qty.js +36 -0
  18. package/esm/advisor/ruler/rules/bar-without-axis-min.js +41 -0
  19. package/esm/advisor/ruler/rules/constants.js +6 -0
  20. package/esm/advisor/ruler/rules/data-check.js +40 -0
  21. package/esm/advisor/ruler/rules/data-field-qty.js +26 -0
  22. package/esm/advisor/ruler/rules/diff-pie-sector.js +33 -0
  23. package/esm/advisor/ruler/rules/index.js +68 -0
  24. package/esm/advisor/ruler/rules/landscape-or-portrait.js +40 -0
  25. package/esm/advisor/ruler/rules/limit-series.js +47 -0
  26. package/esm/advisor/ruler/rules/line-field-time-ordinal.js +25 -0
  27. package/esm/advisor/ruler/rules/no-redundant-field.js +32 -0
  28. package/esm/advisor/ruler/rules/nominal-enum-combinatorial.js +54 -0
  29. package/esm/advisor/ruler/rules/purpose-check.js +27 -0
  30. package/esm/advisor/ruler/rules/series-qty-limit.js +34 -0
  31. package/esm/advisor/ruler/rules/x-axis-line-fading.js +41 -0
  32. package/esm/advisor/ruler/types.js +1 -0
  33. package/esm/advisor/ruler/utils.js +54 -0
  34. package/esm/advisor/types.js +1 -0
  35. package/esm/advisor/utils/clone.js +32 -0
  36. package/esm/advisor/utils/compare.js +14 -0
  37. package/esm/advisor/utils/computeScore.js +25 -0
  38. package/esm/advisor/utils/deep-mix.js +76 -0
  39. package/esm/advisor/utils/hasSubset.js +3 -0
  40. package/esm/advisor/utils/index.js +8 -0
  41. package/esm/advisor/utils/inferDataType.js +70 -0
  42. package/esm/advisor/utils/intersects.js +3 -0
  43. package/esm/advisor/utils/isNil.js +4 -0
  44. package/esm/ckb/base.js +1310 -0
  45. package/esm/ckb/ckb.js +55 -0
  46. package/esm/ckb/constants.js +197 -0
  47. package/esm/ckb/i18n/index.js +23 -0
  48. package/esm/ckb/i18n/types.js +1 -0
  49. package/esm/ckb/i18n/zh-CN.js +525 -0
  50. package/esm/ckb/index.js +14 -0
  51. package/esm/ckb/types.js +1 -0
  52. package/esm/common/types.js +1 -0
  53. package/esm/data/analysis/field/index.js +336 -0
  54. package/esm/data/analysis/field/types.js +1 -0
  55. package/esm/data/analysis/graph/index.js +170 -0
  56. package/esm/data/analysis/graph/types.js +1 -0
  57. package/esm/data/analysis/index.js +1 -0
  58. package/esm/data/analysis/types.js +1 -0
  59. package/esm/data/dataset/field/baseFrame.js +76 -0
  60. package/esm/data/dataset/field/dataFrame.js +556 -0
  61. package/esm/data/dataset/field/index.js +3 -0
  62. package/esm/data/dataset/field/series.js +149 -0
  63. package/esm/data/dataset/field/types.js +1 -0
  64. package/esm/data/dataset/field/utils.js +58 -0
  65. package/esm/data/dataset/graph/index.js +186 -0
  66. package/esm/data/dataset/graph/types.js +1 -0
  67. package/esm/data/dataset/graph/utils.js +15 -0
  68. package/esm/data/dataset/index.js +1 -0
  69. package/esm/data/dataset/types.js +1 -0
  70. package/esm/data/index.js +5 -0
  71. package/esm/data/statistics/IQR.js +49 -0
  72. package/esm/data/statistics/base.js +248 -0
  73. package/esm/data/statistics/bayesian.js +25 -0
  74. package/esm/data/statistics/buishand-u.js +19 -0
  75. package/esm/data/statistics/caches.js +28 -0
  76. package/esm/data/statistics/cdf.js +25 -0
  77. package/esm/data/statistics/constants.js +12 -0
  78. package/esm/data/statistics/index.js +7 -0
  79. package/esm/data/statistics/lowess.js +80 -0
  80. package/esm/data/statistics/mannkendall-test.js +50 -0
  81. package/esm/data/statistics/maxabs.js +9 -0
  82. package/esm/data/statistics/pcorrtest.js +76 -0
  83. package/esm/data/statistics/pettitt-test.js +33 -0
  84. package/esm/data/statistics/quantile.js +56 -0
  85. package/esm/data/statistics/types.js +1 -0
  86. package/esm/data/statistics/vector.js +67 -0
  87. package/esm/data/statistics/window.js +55 -0
  88. package/esm/data/types.js +2 -0
  89. package/esm/data/utils/common.js +58 -0
  90. package/esm/data/utils/index.js +5 -0
  91. package/esm/data/utils/isType/constants.js +24 -0
  92. package/esm/data/utils/isType/index.js +2 -0
  93. package/esm/data/utils/isType/isDateString.js +104 -0
  94. package/esm/data/utils/isType/isType.js +78 -0
  95. package/esm/index.js +11 -0
  96. package/esm/insight/algorithms/base/compare.js +40 -0
  97. package/esm/insight/algorithms/categoryOutlier.js +4 -0
  98. package/esm/insight/algorithms/changePoint.js +10 -0
  99. package/esm/insight/algorithms/index.js +3 -0
  100. package/esm/insight/algorithms/trendDirection.js +4 -0
  101. package/esm/insight/chart/constants.js +25 -0
  102. package/esm/insight/chart/generator/homogeneous.js +70 -0
  103. package/esm/insight/chart/generator/index.js +2 -0
  104. package/esm/insight/chart/generator/insights.js +16 -0
  105. package/esm/insight/chart/index.js +4 -0
  106. package/esm/insight/chart/strategy/augmentedMarks/categoryOutlier.js +30 -0
  107. package/esm/insight/chart/strategy/augmentedMarks/changePoint.js +42 -0
  108. package/esm/insight/chart/strategy/augmentedMarks/correlation.js +6 -0
  109. package/esm/insight/chart/strategy/augmentedMarks/homogeneous.js +5 -0
  110. package/esm/insight/chart/strategy/augmentedMarks/index.js +8 -0
  111. package/esm/insight/chart/strategy/augmentedMarks/lowVariance.js +23 -0
  112. package/esm/insight/chart/strategy/augmentedMarks/majority.js +5 -0
  113. package/esm/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +82 -0
  114. package/esm/insight/chart/strategy/augmentedMarks/trend.js +26 -0
  115. package/esm/insight/chart/strategy/chart.js +45 -0
  116. package/esm/insight/chart/strategy/commonMarks/areaMark.js +12 -0
  117. package/esm/insight/chart/strategy/commonMarks/index.js +5 -0
  118. package/esm/insight/chart/strategy/commonMarks/intervalMark.js +14 -0
  119. package/esm/insight/chart/strategy/commonMarks/lineMark.js +34 -0
  120. package/esm/insight/chart/strategy/commonMarks/pointMark.js +17 -0
  121. package/esm/insight/chart/strategy/commonMarks/textMark.js +28 -0
  122. package/esm/insight/chart/strategy/index.js +4 -0
  123. package/esm/insight/chart/strategy/viewSpec.js +16 -0
  124. package/esm/insight/chart/types.js +1 -0
  125. package/esm/insight/chart/utils.js +4 -0
  126. package/esm/insight/constant.js +21 -0
  127. package/esm/insight/index.js +5 -0
  128. package/esm/insight/insights/checkers.js +97 -0
  129. package/esm/insight/insights/extractors/categoryOutlier.js +90 -0
  130. package/esm/insight/insights/extractors/changePoint.js +55 -0
  131. package/esm/insight/insights/extractors/correlation.js +38 -0
  132. package/esm/insight/insights/extractors/homogeneous.js +98 -0
  133. package/esm/insight/insights/extractors/lowVariance.js +49 -0
  134. package/esm/insight/insights/extractors/majority.js +66 -0
  135. package/esm/insight/insights/extractors/timeSeriesOutlier.js +61 -0
  136. package/esm/insight/insights/extractors/trend.js +49 -0
  137. package/esm/insight/insights/index.js +28 -0
  138. package/esm/insight/insights/util.js +77 -0
  139. package/esm/insight/narrative/factory.js +22 -0
  140. package/esm/insight/narrative/index.js +14 -0
  141. package/esm/insight/narrative/strategy/base.js +6 -0
  142. package/esm/insight/narrative/strategy/categoryOutlier.js +74 -0
  143. package/esm/insight/narrative/strategy/changePoint.js +52 -0
  144. package/esm/insight/narrative/strategy/commonness.js +45 -0
  145. package/esm/insight/narrative/strategy/correlation.js +51 -0
  146. package/esm/insight/narrative/strategy/exception.js +70 -0
  147. package/esm/insight/narrative/strategy/helpers.js +25 -0
  148. package/esm/insight/narrative/strategy/index.js +13 -0
  149. package/esm/insight/narrative/strategy/lowVariance.js +48 -0
  150. package/esm/insight/narrative/strategy/majority.js +62 -0
  151. package/esm/insight/narrative/strategy/timeSeriesOutlier.js +92 -0
  152. package/esm/insight/narrative/strategy/trend.js +57 -0
  153. package/esm/insight/pipeline/extract.js +236 -0
  154. package/esm/insight/pipeline/index.js +11 -0
  155. package/esm/insight/pipeline/insight.js +81 -0
  156. package/esm/insight/pipeline/preprocess.js +33 -0
  157. package/esm/insight/pipeline/specificInsight.js +71 -0
  158. package/esm/insight/pipeline/util.js +14 -0
  159. package/esm/insight/pipeline/visualize.js +41 -0
  160. package/esm/insight/types.js +1 -0
  161. package/esm/insight/utils/aggregate.js +87 -0
  162. package/esm/insight/utils/common.js +35 -0
  163. package/esm/ntv/generate/generateTextSpec.js +157 -0
  164. package/esm/ntv/generate/index.js +5 -0
  165. package/esm/ntv/generate/types.js +1 -0
  166. package/esm/ntv/generate/utils.js +86 -0
  167. package/esm/ntv/index.js +4 -0
  168. package/esm/ntv/schema/common.js +1 -0
  169. package/esm/ntv/schema/index.js +4 -0
  170. package/esm/ntv/schema/paragraph.js +1 -0
  171. package/esm/ntv/schema/phrase.js +52 -0
  172. package/esm/ntv/schema/structure.js +1 -0
  173. package/esm/ntv/types.js +1 -0
  174. package/esm/ntv/utils/index.js +1 -0
  175. package/esm/ntv/utils/isSpecType.js +58 -0
  176. package/esm/utils/arr2map.js +7 -0
  177. package/esm/utils/dataFormat.js +32 -0
  178. package/esm/utils/index.js +3 -0
  179. package/esm/utils/isType.js +14 -0
  180. package/lib/advisor/advise-pipeline/advicesForChart.d.ts +13 -0
  181. package/lib/advisor/advise-pipeline/advicesForChart.js +73 -0
  182. package/lib/advisor/advise-pipeline/data-to-advices.d.ts +22 -0
  183. package/lib/advisor/advise-pipeline/data-to-advices.js +245 -0
  184. package/lib/advisor/advise-pipeline/index.d.ts +1 -0
  185. package/lib/advisor/advise-pipeline/index.js +5 -0
  186. package/lib/advisor/advise-pipeline/spec-mapping.d.ts +14 -0
  187. package/lib/advisor/advise-pipeline/spec-mapping.js +504 -0
  188. package/lib/advisor/advisor.d.ts +18 -0
  189. package/lib/advisor/advisor.js +38 -0
  190. package/lib/advisor/constants.d.ts +1 -0
  191. package/lib/advisor/constants.js +16 -0
  192. package/lib/advisor/index.d.ts +2 -0
  193. package/lib/advisor/index.js +7 -0
  194. package/lib/advisor/lint-pipeline/check-rules.d.ts +4 -0
  195. package/lib/advisor/lint-pipeline/check-rules.js +47 -0
  196. package/lib/advisor/lint-pipeline/getChartType.d.ts +7 -0
  197. package/lib/advisor/lint-pipeline/getChartType.js +113 -0
  198. package/lib/advisor/lint-pipeline/index.d.ts +0 -0
  199. package/lib/advisor/lint-pipeline/index.js +0 -0
  200. package/lib/advisor/lint-pipeline/lintRules.d.ts +5 -0
  201. package/lib/advisor/lint-pipeline/lintRules.js +36 -0
  202. package/lib/advisor/ruler/index.d.ts +21 -0
  203. package/lib/advisor/ruler/index.js +80 -0
  204. package/lib/advisor/ruler/rules/aggregation-single-row.d.ts +2 -0
  205. package/lib/advisor/ruler/rules/aggregation-single-row.js +24 -0
  206. package/lib/advisor/ruler/rules/all-can-be-table.d.ts +2 -0
  207. package/lib/advisor/ruler/rules/all-can-be-table.js +20 -0
  208. package/lib/advisor/ruler/rules/bar-series-qty.d.ts +2 -0
  209. package/lib/advisor/ruler/rules/bar-series-qty.js +39 -0
  210. package/lib/advisor/ruler/rules/bar-without-axis-min.d.ts +2 -0
  211. package/lib/advisor/ruler/rules/bar-without-axis-min.js +44 -0
  212. package/lib/advisor/ruler/rules/constants.d.ts +6 -0
  213. package/lib/advisor/ruler/rules/constants.js +9 -0
  214. package/lib/advisor/ruler/rules/data-check.d.ts +2 -0
  215. package/lib/advisor/ruler/rules/data-check.js +43 -0
  216. package/lib/advisor/ruler/rules/data-field-qty.d.ts +2 -0
  217. package/lib/advisor/ruler/rules/data-field-qty.js +29 -0
  218. package/lib/advisor/ruler/rules/diff-pie-sector.d.ts +2 -0
  219. package/lib/advisor/ruler/rules/diff-pie-sector.js +36 -0
  220. package/lib/advisor/ruler/rules/index.d.ts +19 -0
  221. package/lib/advisor/ruler/rules/index.js +71 -0
  222. package/lib/advisor/ruler/rules/landscape-or-portrait.d.ts +2 -0
  223. package/lib/advisor/ruler/rules/landscape-or-portrait.js +43 -0
  224. package/lib/advisor/ruler/rules/limit-series.d.ts +2 -0
  225. package/lib/advisor/ruler/rules/limit-series.js +50 -0
  226. package/lib/advisor/ruler/rules/line-field-time-ordinal.d.ts +2 -0
  227. package/lib/advisor/ruler/rules/line-field-time-ordinal.js +28 -0
  228. package/lib/advisor/ruler/rules/no-redundant-field.d.ts +2 -0
  229. package/lib/advisor/ruler/rules/no-redundant-field.js +35 -0
  230. package/lib/advisor/ruler/rules/nominal-enum-combinatorial.d.ts +2 -0
  231. package/lib/advisor/ruler/rules/nominal-enum-combinatorial.js +57 -0
  232. package/lib/advisor/ruler/rules/purpose-check.d.ts +2 -0
  233. package/lib/advisor/ruler/rules/purpose-check.js +30 -0
  234. package/lib/advisor/ruler/rules/series-qty-limit.d.ts +2 -0
  235. package/lib/advisor/ruler/rules/series-qty-limit.js +37 -0
  236. package/lib/advisor/ruler/rules/x-axis-line-fading.d.ts +2 -0
  237. package/lib/advisor/ruler/rules/x-axis-line-fading.js +44 -0
  238. package/lib/advisor/ruler/types.d.ts +125 -0
  239. package/lib/advisor/ruler/types.js +2 -0
  240. package/lib/advisor/ruler/utils.d.ts +10 -0
  241. package/lib/advisor/ruler/utils.js +61 -0
  242. package/lib/advisor/types.d.ts +218 -0
  243. package/lib/advisor/types.js +4 -0
  244. package/lib/advisor/utils/clone.d.ts +2 -0
  245. package/lib/advisor/utils/clone.js +34 -0
  246. package/lib/advisor/utils/compare.d.ts +3 -0
  247. package/lib/advisor/utils/compare.js +17 -0
  248. package/lib/advisor/utils/computeScore.d.ts +7 -0
  249. package/lib/advisor/utils/computeScore.js +27 -0
  250. package/lib/advisor/utils/deep-mix.d.ts +2 -0
  251. package/lib/advisor/utils/deep-mix.js +78 -0
  252. package/lib/advisor/utils/hasSubset.d.ts +1 -0
  253. package/lib/advisor/utils/hasSubset.js +7 -0
  254. package/lib/advisor/utils/index.d.ts +5 -0
  255. package/lib/advisor/utils/index.js +19 -0
  256. package/lib/advisor/utils/inferDataType.d.ts +6 -0
  257. package/lib/advisor/utils/inferDataType.js +75 -0
  258. package/lib/advisor/utils/intersects.d.ts +1 -0
  259. package/lib/advisor/utils/intersects.js +7 -0
  260. package/lib/advisor/utils/isNil.d.ts +2 -0
  261. package/lib/advisor/utils/isNil.js +6 -0
  262. package/lib/ckb/base.d.ts +2 -0
  263. package/lib/ckb/base.js +1313 -0
  264. package/lib/ckb/ckb.d.ts +8 -0
  265. package/lib/ckb/ckb.js +59 -0
  266. package/lib/ckb/constants.d.ts +79 -0
  267. package/lib/ckb/constants.js +200 -0
  268. package/lib/ckb/i18n/index.d.ts +10 -0
  269. package/lib/ckb/i18n/index.js +27 -0
  270. package/lib/ckb/i18n/types.d.ts +52 -0
  271. package/lib/ckb/i18n/types.js +2 -0
  272. package/lib/ckb/i18n/zh-CN.d.ts +7 -0
  273. package/lib/ckb/i18n/zh-CN.js +528 -0
  274. package/lib/ckb/index.d.ts +4 -0
  275. package/lib/ckb/index.js +20 -0
  276. package/lib/ckb/types.d.ts +185 -0
  277. package/lib/ckb/types.js +2 -0
  278. package/lib/common/types.d.ts +14 -0
  279. package/lib/common/types.js +2 -0
  280. package/lib/data/analysis/field/index.d.ts +79 -0
  281. package/lib/data/analysis/field/index.js +355 -0
  282. package/lib/data/analysis/field/types.d.ts +99 -0
  283. package/lib/data/analysis/field/types.js +2 -0
  284. package/lib/data/analysis/graph/index.d.ts +28 -0
  285. package/lib/data/analysis/graph/index.js +178 -0
  286. package/lib/data/analysis/graph/types.d.ts +62 -0
  287. package/lib/data/analysis/graph/types.js +2 -0
  288. package/lib/data/analysis/index.d.ts +1 -0
  289. package/lib/data/analysis/index.js +5 -0
  290. package/lib/data/analysis/types.d.ts +1 -0
  291. package/lib/data/analysis/types.js +2 -0
  292. package/lib/data/dataset/field/baseFrame.d.ts +30 -0
  293. package/lib/data/dataset/field/baseFrame.js +78 -0
  294. package/lib/data/dataset/field/dataFrame.d.ts +35 -0
  295. package/lib/data/dataset/field/dataFrame.js +558 -0
  296. package/lib/data/dataset/field/index.d.ts +3 -0
  297. package/lib/data/dataset/field/index.js +8 -0
  298. package/lib/data/dataset/field/series.d.ts +18 -0
  299. package/lib/data/dataset/field/series.js +151 -0
  300. package/lib/data/dataset/field/types.d.ts +54 -0
  301. package/lib/data/dataset/field/types.js +2 -0
  302. package/lib/data/dataset/field/utils.d.ts +13 -0
  303. package/lib/data/dataset/field/utils.js +68 -0
  304. package/lib/data/dataset/graph/index.d.ts +18 -0
  305. package/lib/data/dataset/graph/index.js +188 -0
  306. package/lib/data/dataset/graph/types.d.ts +35 -0
  307. package/lib/data/dataset/graph/types.js +2 -0
  308. package/lib/data/dataset/graph/utils.d.ts +1 -0
  309. package/lib/data/dataset/graph/utils.js +19 -0
  310. package/lib/data/dataset/index.d.ts +1 -0
  311. package/lib/data/dataset/index.js +4 -0
  312. package/lib/data/dataset/types.d.ts +1 -0
  313. package/lib/data/dataset/types.js +4 -0
  314. package/lib/data/index.d.ts +5 -0
  315. package/lib/data/index.js +8 -0
  316. package/lib/data/statistics/IQR.d.ts +21 -0
  317. package/lib/data/statistics/IQR.js +53 -0
  318. package/lib/data/statistics/base.d.ts +106 -0
  319. package/lib/data/statistics/base.js +271 -0
  320. package/lib/data/statistics/bayesian.d.ts +5 -0
  321. package/lib/data/statistics/bayesian.js +30 -0
  322. package/lib/data/statistics/buishand-u.d.ts +7 -0
  323. package/lib/data/statistics/buishand-u.js +23 -0
  324. package/lib/data/statistics/caches.d.ts +13 -0
  325. package/lib/data/statistics/caches.js +33 -0
  326. package/lib/data/statistics/cdf.d.ts +7 -0
  327. package/lib/data/statistics/cdf.js +29 -0
  328. package/lib/data/statistics/constants.d.ts +5 -0
  329. package/lib/data/statistics/constants.js +15 -0
  330. package/lib/data/statistics/index.d.ts +7 -0
  331. package/lib/data/statistics/index.js +14 -0
  332. package/lib/data/statistics/lowess.d.ts +10 -0
  333. package/lib/data/statistics/lowess.js +87 -0
  334. package/lib/data/statistics/mannkendall-test.d.ts +15 -0
  335. package/lib/data/statistics/mannkendall-test.js +54 -0
  336. package/lib/data/statistics/maxabs.d.ts +5 -0
  337. package/lib/data/statistics/maxabs.js +13 -0
  338. package/lib/data/statistics/pcorrtest.d.ts +3 -0
  339. package/lib/data/statistics/pcorrtest.js +80 -0
  340. package/lib/data/statistics/pettitt-test.d.ts +9 -0
  341. package/lib/data/statistics/pettitt-test.js +38 -0
  342. package/lib/data/statistics/quantile.d.ts +16 -0
  343. package/lib/data/statistics/quantile.js +61 -0
  344. package/lib/data/statistics/types.d.ts +70 -0
  345. package/lib/data/statistics/types.js +2 -0
  346. package/lib/data/statistics/vector.d.ts +15 -0
  347. package/lib/data/statistics/vector.js +78 -0
  348. package/lib/data/statistics/window.d.ts +12 -0
  349. package/lib/data/statistics/window.js +60 -0
  350. package/lib/data/types.d.ts +2 -0
  351. package/lib/data/types.js +5 -0
  352. package/lib/data/utils/common.d.ts +26 -0
  353. package/lib/data/utils/common.js +67 -0
  354. package/lib/data/utils/index.d.ts +2 -0
  355. package/lib/data/utils/index.js +8 -0
  356. package/lib/data/utils/isType/constants.d.ts +15 -0
  357. package/lib/data/utils/isType/constants.js +27 -0
  358. package/lib/data/utils/isType/index.d.ts +2 -0
  359. package/lib/data/utils/isType/index.js +5 -0
  360. package/lib/data/utils/isType/isDateString.d.ts +18 -0
  361. package/lib/data/utils/isType/isDateString.js +111 -0
  362. package/lib/data/utils/isType/isType.d.ts +13 -0
  363. package/lib/data/utils/isType/isType.js +94 -0
  364. package/lib/index.d.ts +10 -0
  365. package/lib/index.js +75 -0
  366. package/lib/insight/algorithms/base/compare.d.ts +14 -0
  367. package/lib/insight/algorithms/base/compare.js +45 -0
  368. package/lib/insight/algorithms/categoryOutlier.d.ts +4 -0
  369. package/lib/insight/algorithms/categoryOutlier.js +7 -0
  370. package/lib/insight/algorithms/changePoint.d.ts +10 -0
  371. package/lib/insight/algorithms/changePoint.js +13 -0
  372. package/lib/insight/algorithms/index.d.ts +3 -0
  373. package/lib/insight/algorithms/index.js +6 -0
  374. package/lib/insight/algorithms/trendDirection.d.ts +4 -0
  375. package/lib/insight/algorithms/trendDirection.js +7 -0
  376. package/lib/insight/chart/constants.d.ts +13 -0
  377. package/lib/insight/chart/constants.js +28 -0
  378. package/lib/insight/chart/generator/homogeneous.d.ts +3 -0
  379. package/lib/insight/chart/generator/homogeneous.js +75 -0
  380. package/lib/insight/chart/generator/index.d.ts +2 -0
  381. package/lib/insight/chart/generator/index.js +5 -0
  382. package/lib/insight/chart/generator/insights.d.ts +3 -0
  383. package/lib/insight/chart/generator/insights.js +20 -0
  384. package/lib/insight/chart/index.d.ts +4 -0
  385. package/lib/insight/chart/index.js +7 -0
  386. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.d.ts +5 -0
  387. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.js +35 -0
  388. package/lib/insight/chart/strategy/augmentedMarks/changePoint.d.ts +5 -0
  389. package/lib/insight/chart/strategy/augmentedMarks/changePoint.js +47 -0
  390. package/lib/insight/chart/strategy/augmentedMarks/correlation.d.ts +3 -0
  391. package/lib/insight/chart/strategy/augmentedMarks/correlation.js +10 -0
  392. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.d.ts +3 -0
  393. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.js +9 -0
  394. package/lib/insight/chart/strategy/augmentedMarks/index.d.ts +8 -0
  395. package/lib/insight/chart/strategy/augmentedMarks/index.js +24 -0
  396. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.d.ts +5 -0
  397. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.js +28 -0
  398. package/lib/insight/chart/strategy/augmentedMarks/majority.d.ts +3 -0
  399. package/lib/insight/chart/strategy/augmentedMarks/majority.js +9 -0
  400. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.d.ts +5 -0
  401. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +87 -0
  402. package/lib/insight/chart/strategy/augmentedMarks/trend.d.ts +5 -0
  403. package/lib/insight/chart/strategy/augmentedMarks/trend.js +31 -0
  404. package/lib/insight/chart/strategy/chart.d.ts +7 -0
  405. package/lib/insight/chart/strategy/chart.js +49 -0
  406. package/lib/insight/chart/strategy/commonMarks/areaMark.d.ts +3 -0
  407. package/lib/insight/chart/strategy/commonMarks/areaMark.js +16 -0
  408. package/lib/insight/chart/strategy/commonMarks/index.d.ts +5 -0
  409. package/lib/insight/chart/strategy/commonMarks/index.js +13 -0
  410. package/lib/insight/chart/strategy/commonMarks/intervalMark.d.ts +5 -0
  411. package/lib/insight/chart/strategy/commonMarks/intervalMark.js +18 -0
  412. package/lib/insight/chart/strategy/commonMarks/lineMark.d.ts +3 -0
  413. package/lib/insight/chart/strategy/commonMarks/lineMark.js +38 -0
  414. package/lib/insight/chart/strategy/commonMarks/pointMark.d.ts +5 -0
  415. package/lib/insight/chart/strategy/commonMarks/pointMark.js +21 -0
  416. package/lib/insight/chart/strategy/commonMarks/textMark.d.ts +5 -0
  417. package/lib/insight/chart/strategy/commonMarks/textMark.js +32 -0
  418. package/lib/insight/chart/strategy/index.d.ts +4 -0
  419. package/lib/insight/chart/strategy/index.js +10 -0
  420. package/lib/insight/chart/strategy/viewSpec.d.ts +3 -0
  421. package/lib/insight/chart/strategy/viewSpec.js +20 -0
  422. package/lib/insight/chart/types.d.ts +60 -0
  423. package/lib/insight/chart/types.js +2 -0
  424. package/lib/insight/chart/utils.d.ts +3 -0
  425. package/lib/insight/chart/utils.js +8 -0
  426. package/lib/insight/constant.d.ts +12 -0
  427. package/lib/insight/constant.js +24 -0
  428. package/lib/insight/index.d.ts +6 -0
  429. package/lib/insight/index.js +13 -0
  430. package/lib/insight/insights/checkers.d.ts +16 -0
  431. package/lib/insight/insights/checkers.js +107 -0
  432. package/lib/insight/insights/extractors/categoryOutlier.d.ts +12 -0
  433. package/lib/insight/insights/extractors/categoryOutlier.js +95 -0
  434. package/lib/insight/insights/extractors/changePoint.d.ts +8 -0
  435. package/lib/insight/insights/extractors/changePoint.js +60 -0
  436. package/lib/insight/insights/extractors/correlation.d.ts +9 -0
  437. package/lib/insight/insights/extractors/correlation.js +43 -0
  438. package/lib/insight/insights/extractors/homogeneous.d.ts +4 -0
  439. package/lib/insight/insights/extractors/homogeneous.js +103 -0
  440. package/lib/insight/insights/extractors/lowVariance.d.ts +8 -0
  441. package/lib/insight/insights/extractors/lowVariance.js +54 -0
  442. package/lib/insight/insights/extractors/majority.d.ts +10 -0
  443. package/lib/insight/insights/extractors/majority.js +71 -0
  444. package/lib/insight/insights/extractors/timeSeriesOutlier.d.ts +2 -0
  445. package/lib/insight/insights/extractors/timeSeriesOutlier.js +65 -0
  446. package/lib/insight/insights/extractors/trend.d.ts +9 -0
  447. package/lib/insight/insights/extractors/trend.js +54 -0
  448. package/lib/insight/insights/index.d.ts +12 -0
  449. package/lib/insight/insights/index.js +32 -0
  450. package/lib/insight/insights/util.d.ts +13 -0
  451. package/lib/insight/insights/util.js +87 -0
  452. package/lib/insight/narrative/factory.d.ts +6 -0
  453. package/lib/insight/narrative/factory.js +25 -0
  454. package/lib/insight/narrative/index.d.ts +3 -0
  455. package/lib/insight/narrative/index.js +18 -0
  456. package/lib/insight/narrative/strategy/base.d.ts +9 -0
  457. package/lib/insight/narrative/strategy/base.js +9 -0
  458. package/lib/insight/narrative/strategy/categoryOutlier.d.ts +9 -0
  459. package/lib/insight/narrative/strategy/categoryOutlier.js +76 -0
  460. package/lib/insight/narrative/strategy/changePoint.d.ts +8 -0
  461. package/lib/insight/narrative/strategy/changePoint.js +54 -0
  462. package/lib/insight/narrative/strategy/commonness.d.ts +9 -0
  463. package/lib/insight/narrative/strategy/commonness.js +47 -0
  464. package/lib/insight/narrative/strategy/correlation.d.ts +8 -0
  465. package/lib/insight/narrative/strategy/correlation.js +53 -0
  466. package/lib/insight/narrative/strategy/exception.d.ts +10 -0
  467. package/lib/insight/narrative/strategy/exception.js +72 -0
  468. package/lib/insight/narrative/strategy/helpers.d.ts +5 -0
  469. package/lib/insight/narrative/strategy/helpers.js +31 -0
  470. package/lib/insight/narrative/strategy/index.d.ts +9 -0
  471. package/lib/insight/narrative/strategy/index.js +28 -0
  472. package/lib/insight/narrative/strategy/lowVariance.d.ts +8 -0
  473. package/lib/insight/narrative/strategy/lowVariance.js +50 -0
  474. package/lib/insight/narrative/strategy/majority.d.ts +8 -0
  475. package/lib/insight/narrative/strategy/majority.js +64 -0
  476. package/lib/insight/narrative/strategy/timeSeriesOutlier.d.ts +8 -0
  477. package/lib/insight/narrative/strategy/timeSeriesOutlier.js +94 -0
  478. package/lib/insight/narrative/strategy/trend.d.ts +8 -0
  479. package/lib/insight/narrative/strategy/trend.js +59 -0
  480. package/lib/insight/pipeline/extract.d.ts +13 -0
  481. package/lib/insight/pipeline/extract.js +243 -0
  482. package/lib/insight/pipeline/index.d.ts +2 -0
  483. package/lib/insight/pipeline/index.js +15 -0
  484. package/lib/insight/pipeline/insight.d.ts +10 -0
  485. package/lib/insight/pipeline/insight.js +86 -0
  486. package/lib/insight/pipeline/preprocess.d.ts +6 -0
  487. package/lib/insight/pipeline/preprocess.js +39 -0
  488. package/lib/insight/pipeline/specificInsight.d.ts +11 -0
  489. package/lib/insight/pipeline/specificInsight.js +79 -0
  490. package/lib/insight/pipeline/util.d.ts +5 -0
  491. package/lib/insight/pipeline/util.js +20 -0
  492. package/lib/insight/pipeline/visualize.d.ts +3 -0
  493. package/lib/insight/pipeline/visualize.js +46 -0
  494. package/lib/insight/types.d.ts +238 -0
  495. package/lib/insight/types.js +2 -0
  496. package/lib/insight/utils/aggregate.d.ts +7 -0
  497. package/lib/insight/utils/aggregate.js +93 -0
  498. package/lib/insight/utils/common.d.ts +3 -0
  499. package/lib/insight/utils/common.js +41 -0
  500. package/lib/ntv/generate/generateTextSpec.d.ts +9 -0
  501. package/lib/ntv/generate/generateTextSpec.js +160 -0
  502. package/lib/ntv/generate/index.d.ts +2 -0
  503. package/lib/ntv/generate/index.js +12 -0
  504. package/lib/ntv/generate/types.d.ts +58 -0
  505. package/lib/ntv/generate/types.js +2 -0
  506. package/lib/ntv/generate/utils.d.ts +29 -0
  507. package/lib/ntv/generate/utils.js +96 -0
  508. package/lib/ntv/index.d.ts +4 -0
  509. package/lib/ntv/index.js +10 -0
  510. package/lib/ntv/schema/common.d.ts +17 -0
  511. package/lib/ntv/schema/common.js +2 -0
  512. package/lib/ntv/schema/index.d.ts +4 -0
  513. package/lib/ntv/schema/index.js +7 -0
  514. package/lib/ntv/schema/paragraph.d.ts +34 -0
  515. package/lib/ntv/schema/paragraph.js +2 -0
  516. package/lib/ntv/schema/phrase.d.ts +70 -0
  517. package/lib/ntv/schema/phrase.js +55 -0
  518. package/lib/ntv/schema/structure.d.ts +18 -0
  519. package/lib/ntv/schema/structure.js +2 -0
  520. package/lib/ntv/types.d.ts +2 -0
  521. package/lib/ntv/types.js +2 -0
  522. package/lib/ntv/utils/index.d.ts +1 -0
  523. package/lib/ntv/utils/index.js +4 -0
  524. package/lib/ntv/utils/isSpecType.d.ts +17 -0
  525. package/lib/ntv/utils/isSpecType.js +76 -0
  526. package/lib/utils/arr2map.d.ts +1 -0
  527. package/lib/utils/arr2map.js +11 -0
  528. package/lib/utils/dataFormat.d.ts +11 -0
  529. package/lib/utils/dataFormat.js +35 -0
  530. package/lib/utils/index.d.ts +3 -0
  531. package/lib/utils/index.js +8 -0
  532. package/lib/utils/isType.d.ts +4 -0
  533. package/lib/utils/isType.js +21 -0
  534. package/package.json +88 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ /* eslint-disable no-template-curly-in-string */
5
+ var lodash_1 = require("lodash");
6
+ var ntv_1 = require("../../../ntv");
7
+ var base_1 = require("./base");
8
+ var helpers_1 = require("./helpers");
9
+ var variableMetaMap = {
10
+ dateRange: {
11
+ varType: 'time_desc',
12
+ },
13
+ measure: {
14
+ varType: 'metric_name',
15
+ },
16
+ max: {
17
+ varType: 'metric_value',
18
+ },
19
+ min: {
20
+ varType: 'metric_value',
21
+ },
22
+ total: {
23
+ varType: 'metric_value',
24
+ },
25
+ '.x': {
26
+ varType: 'dim_value',
27
+ },
28
+ '.y': {
29
+ varType: 'metric_value',
30
+ },
31
+ '.base': {
32
+ varType: 'metric_value',
33
+ },
34
+ '.diff': {
35
+ varType: 'delta_value',
36
+ },
37
+ };
38
+ var TimeSeriesOutlierNarrativeStrategy = /** @class */ (function (_super) {
39
+ tslib_1.__extends(TimeSeriesOutlierNarrativeStrategy, _super);
40
+ function TimeSeriesOutlierNarrativeStrategy() {
41
+ return _super !== null && _super.apply(this, arguments) || this;
42
+ }
43
+ TimeSeriesOutlierNarrativeStrategy.prototype.generateTextSpec = function (insightInfo, lang) {
44
+ var patterns = insightInfo.patterns, data = insightInfo.data;
45
+ var _a = patterns[0], measure = _a.measure, dimension = _a.dimension;
46
+ var spec = (0, ntv_1.generateTextSpec)({
47
+ structures: TimeSeriesOutlierNarrativeStrategy.structures[lang],
48
+ variable: {
49
+ dateRange: "".concat((0, lodash_1.first)(data)[dimension], "~").concat((0, lodash_1.last)(data)[dimension]),
50
+ total: patterns.length,
51
+ measure: measure,
52
+ max: (0, lodash_1.maxBy)(data, measure)[measure],
53
+ min: (0, lodash_1.minBy)(data, measure)[measure],
54
+ outliers: patterns.map(function (point) {
55
+ var base = point.baselines[point.index];
56
+ var diff = point.y - base;
57
+ return tslib_1.__assign(tslib_1.__assign({}, point), { base: base, diffDesc: (0, helpers_1.getDiffDesc)(diff, lang), diff: diff });
58
+ }),
59
+ },
60
+ });
61
+ return spec.sections[0].paragraphs;
62
+ };
63
+ TimeSeriesOutlierNarrativeStrategy.insightType = 'time_series_outlier';
64
+ TimeSeriesOutlierNarrativeStrategy.structures = {
65
+ 'zh-CN': [
66
+ {
67
+ template: '${dateRange},${measure} 波动范围为最大值 ${max}, 最小值 ${min},有 ${total} 个异常点,按超过基线大小排序如下:',
68
+ variableMetaMap: variableMetaMap,
69
+ },
70
+ {
71
+ template: '${.x},${measure} 为 ${.y}, 相比基线(${.base})${.diffDesc} ${.diff}。',
72
+ displayType: 'bullet',
73
+ bulletOrder: true,
74
+ useVariable: 'outliers',
75
+ variableMetaMap: variableMetaMap,
76
+ },
77
+ ],
78
+ 'en-US': [
79
+ {
80
+ template: 'In ${dateRange}, ${measure} fluctuates within the range of ${max} to ${min}, with ${total} outliers, sorted by size above the baseline as follows.',
81
+ variableMetaMap: variableMetaMap,
82
+ },
83
+ {
84
+ template: '${.x}, ${measure} for ${.y}, compared to the baseline value ${.base}, ${.diffDesc} ${.diff}.',
85
+ displayType: 'bullet',
86
+ bulletOrder: true,
87
+ useVariable: 'outliers',
88
+ variableMetaMap: variableMetaMap,
89
+ },
90
+ ],
91
+ };
92
+ return TimeSeriesOutlierNarrativeStrategy;
93
+ }(base_1.InsightNarrativeStrategy));
94
+ exports.default = TimeSeriesOutlierNarrativeStrategy;
@@ -0,0 +1,8 @@
1
+ import { InsightNarrativeStrategy } from './base';
2
+ import type { InsightType, Language, InsightInfo, TrendInfo } from '../../types';
3
+ import type { ParagraphSpec, Structure } from '../../../ntv/types';
4
+ export default class TrendNarrativeStrategy extends InsightNarrativeStrategy<TrendInfo> {
5
+ static readonly insightType: InsightType;
6
+ protected static structures: Record<Language, Structure[]>;
7
+ generateTextSpec(insightInfo: InsightInfo<TrendInfo>, lang: Language): ParagraphSpec[];
8
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ /* eslint-disable no-template-curly-in-string */
5
+ var lodash_1 = require("lodash");
6
+ var ntv_1 = require("../../../ntv");
7
+ var base_1 = require("./base");
8
+ var trendMapping = {
9
+ decreasing: '下降',
10
+ increasing: '上升',
11
+ 'no trend': '无明显趋势。',
12
+ };
13
+ var variableMetaMap = {
14
+ dateRange: {
15
+ varType: 'time_desc',
16
+ },
17
+ trend: {
18
+ varType: 'trend_desc',
19
+ },
20
+ measure: {
21
+ varType: 'metric_name',
22
+ },
23
+ };
24
+ var TrendNarrativeStrategy = /** @class */ (function (_super) {
25
+ tslib_1.__extends(TrendNarrativeStrategy, _super);
26
+ function TrendNarrativeStrategy() {
27
+ return _super !== null && _super.apply(this, arguments) || this;
28
+ }
29
+ TrendNarrativeStrategy.prototype.generateTextSpec = function (insightInfo, lang) {
30
+ var patterns = insightInfo.patterns, data = insightInfo.data;
31
+ var _a = patterns[0], dimension = _a.dimension, measure = _a.measure, trend = _a.trend;
32
+ var spec = (0, ntv_1.generateTextSpec)({
33
+ structures: TrendNarrativeStrategy.structures[lang],
34
+ variable: {
35
+ dateRange: "".concat((0, lodash_1.first)(data)[dimension], "~").concat((0, lodash_1.last)(data)[dimension]),
36
+ measure: measure,
37
+ trend: lang === 'en-US' ? trend : trendMapping[trend],
38
+ },
39
+ });
40
+ return spec.sections[0].paragraphs;
41
+ };
42
+ TrendNarrativeStrategy.insightType = 'trend';
43
+ TrendNarrativeStrategy.structures = {
44
+ 'zh-CN': [
45
+ {
46
+ template: '${dateRange},${measure}${trend}。',
47
+ variableMetaMap: variableMetaMap,
48
+ },
49
+ ],
50
+ 'en-US': [
51
+ {
52
+ template: 'In ${dateRange}, the ${measure} goes ${trend}.',
53
+ variableMetaMap: variableMetaMap,
54
+ },
55
+ ],
56
+ };
57
+ return TrendNarrativeStrategy;
58
+ }(base_1.InsightNarrativeStrategy));
59
+ exports.default = TrendNarrativeStrategy;
@@ -0,0 +1,13 @@
1
+ import Heap from 'heap-js';
2
+ import type { Datum, InsightOptions, Measure, Subspace, InsightInfo, PatternInfo, HomogeneousPatternInfo, DataProperty } from '../types';
3
+ interface ReferenceInfo {
4
+ fieldPropsMap: Record<string, DataProperty>;
5
+ impactMeasureReferences: Record<string, number>;
6
+ }
7
+ export declare function extractInsightsFor1M1DCombination(data: Datum[], dimensions: string[], measures: Measure[], subspace: Subspace, referenceInfo: ReferenceInfo, options: InsightOptions): (InsightInfo<PatternInfo> | null)[][];
8
+ export declare function extractInsightsForCorrelation(data: Datum[], dimensions: string[], measures: Measure[], subspace: Subspace, referenceInfo: ReferenceInfo, options: InsightOptions): InsightInfo<PatternInfo>[];
9
+ /** recursive extraction in data subspace */
10
+ export declare function extractInsightsFromSubspace(data: Datum[], dimensions: string[], measures: Measure[], subspace: Subspace, referenceInfo: ReferenceInfo, insightsHeap: Heap<InsightInfo<PatternInfo>>, homogeneousInsightsHeap: Heap<InsightInfo<HomogeneousPatternInfo>>, options: InsightOptions): (InsightInfo<PatternInfo> | null)[];
11
+ /** insight subject enumeration in the data */
12
+ export declare function enumerateInsights(data: Datum[], dimensions: string[], measures: Measure[], referenceInfo: ReferenceInfo, insightsHeap: Heap<InsightInfo<PatternInfo>>, metaInsightsHeap: Heap<InsightInfo<HomogeneousPatternInfo>>, options?: InsightOptions): void;
13
+ export {};
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enumerateInsights = exports.extractInsightsFromSubspace = exports.extractInsightsForCorrelation = exports.extractInsightsFor1M1DCombination = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var lodash_1 = require("lodash");
6
+ var constant_1 = require("../constant");
7
+ var insights_1 = require("../insights");
8
+ var aggregate_1 = require("../utils/aggregate");
9
+ var homogeneous_1 = require("../insights/extractors/homogeneous");
10
+ var preprocess_1 = require("./preprocess");
11
+ var util_1 = require("./util");
12
+ /** calculate the Impact which reflects the importance of the subject of an insight against the entire dataset */
13
+ function computeSubspaceImpact(data, subspace, impactMeasureReferences, measures) {
14
+ if (!(measures === null || measures === void 0 ? void 0 : measures.length) || !subspace)
15
+ return 1;
16
+ var impactValues = measures.map(function (measure) {
17
+ var measureValue = (0, preprocess_1.calculateImpactValue)(data, measure);
18
+ var referenceKey = "".concat(measure.fieldName, "@").concat(measure.method);
19
+ var referenceValue = impactMeasureReferences[referenceKey];
20
+ return measureValue / referenceValue;
21
+ });
22
+ return Math.max.apply(Math, tslib_1.__spreadArray([], tslib_1.__read(impactValues), false));
23
+ }
24
+ /** extract patterns from a specific subject */
25
+ function extractPatternsFromSubject(data, subjectInfo, fieldPropsMap, options) {
26
+ var measures = subjectInfo.measures, dimensions = subjectInfo.dimensions;
27
+ var enumInsightTypes = (options === null || options === void 0 ? void 0 : options.insightTypes) || constant_1.PATTERN_TYPES;
28
+ var patterns = {};
29
+ enumInsightTypes.forEach(function (insightType) {
30
+ var insightExtractorChecker = insights_1.ExtractorCheckers[insightType];
31
+ var isValid = true;
32
+ // Check whether the data requirements of the extractor are met
33
+ if (insightExtractorChecker) {
34
+ if ((0, lodash_1.isString)(insightExtractorChecker({ data: data, subjectInfo: subjectInfo, fieldPropsMap: fieldPropsMap })))
35
+ isValid = false;
36
+ }
37
+ if (isValid && insights_1.insightPatternsExtractor) {
38
+ var _a = options || {}, algorithmParameter = _a.algorithmParameter, dataProcessInfo = _a.dataProcessInfo;
39
+ var extractorOptions = {
40
+ algorithmParameter: algorithmParameter,
41
+ dataProcessInfo: dataProcessInfo,
42
+ // Validation has been done in method extractInsights
43
+ dataValidation: false,
44
+ // Select only significant insights
45
+ filterInsight: true,
46
+ };
47
+ var extractedPatterns = (0, insights_1.insightPatternsExtractor)({
48
+ data: data,
49
+ dimensions: dimensions.map(function (dim) { return ({ fieldName: dim }); }),
50
+ measures: measures,
51
+ insightType: insightType,
52
+ options: extractorOptions,
53
+ });
54
+ patterns[insightType] = extractedPatterns;
55
+ }
56
+ else {
57
+ patterns[insightType] = undefined;
58
+ }
59
+ });
60
+ return patterns;
61
+ }
62
+ function extractInsightsFor1M1DCombination(data, dimensions, measures, subspace, referenceInfo, options) {
63
+ var fieldPropsMap = referenceInfo.fieldPropsMap;
64
+ var insights = [];
65
+ dimensions.forEach(function (dimension) {
66
+ var _a, _b;
67
+ var insightsPerDim = [];
68
+ var isTimeField = (_b = (_a = fieldPropsMap[dimension]) === null || _a === void 0 ? void 0 : _a.levelOfMeasurements) === null || _b === void 0 ? void 0 : _b.includes('Time');
69
+ measures.forEach(function (measure) {
70
+ var childSubjectInfo = { dimensions: [dimension], subspace: subspace, measures: [measure] };
71
+ var aggregatedData = (0, aggregate_1.aggregate)(data, dimension, [measure], isTimeField);
72
+ var patterns = extractPatternsFromSubject(aggregatedData, childSubjectInfo, fieldPropsMap, options);
73
+ var patternsArray = (0, lodash_1.flatten)(Object.values(patterns).filter(function (item) { return (item === null || item === void 0 ? void 0 : item.length) > 0; })).sort(function (a, b) { return b.significance - a.significance; });
74
+ if (patternsArray.length) {
75
+ var insight = {
76
+ subspace: subspace,
77
+ dimensions: [
78
+ {
79
+ fieldName: dimension,
80
+ },
81
+ ],
82
+ measures: [measure],
83
+ patterns: patternsArray,
84
+ data: aggregatedData,
85
+ score: patternsArray[0].significance,
86
+ };
87
+ insightsPerDim.push(insight);
88
+ }
89
+ else {
90
+ insightsPerDim.push(null);
91
+ }
92
+ });
93
+ insights.push(insightsPerDim);
94
+ });
95
+ return insights;
96
+ }
97
+ exports.extractInsightsFor1M1DCombination = extractInsightsFor1M1DCombination;
98
+ function extractInsightsForCorrelation(data, dimensions, measures, subspace, referenceInfo, options) {
99
+ var _a;
100
+ var fieldPropsMap = referenceInfo.fieldPropsMap;
101
+ var insights = [];
102
+ var measureNum = measures.length;
103
+ if (measureNum >= 2) {
104
+ for (var i = 0; i < measureNum - 1; i += 1) {
105
+ for (var j = i + 1; j < measureNum; j += 1) {
106
+ var childSubjectInfo = { dimensions: dimensions, subspace: subspace, measures: [measures[i], measures[j]] };
107
+ var patterns = extractPatternsFromSubject(data, childSubjectInfo, fieldPropsMap, tslib_1.__assign(tslib_1.__assign({}, options), { insightTypes: ['correlation'] }));
108
+ var patternsArray = (_a = patterns === null || patterns === void 0 ? void 0 : patterns.correlation) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return b.significance - a.significance; });
109
+ if (patternsArray === null || patternsArray === void 0 ? void 0 : patternsArray.length) {
110
+ var insight = {
111
+ subspace: subspace,
112
+ dimensions: dimensions.map(function (d) { return ({ fieldName: d }); }),
113
+ measures: [measures[i], measures[j]],
114
+ patterns: patternsArray,
115
+ data: data,
116
+ score: patternsArray[0].significance,
117
+ };
118
+ insights.push(insight);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ return insights;
124
+ }
125
+ exports.extractInsightsForCorrelation = extractInsightsForCorrelation;
126
+ /** recursive extraction in data subspace */
127
+ function extractInsightsFromSubspace(data, dimensions, measures, subspace, referenceInfo, insightsHeap, homogeneousInsightsHeap, options) {
128
+ var _a, _b;
129
+ /** subspace pruning */
130
+ if (!(data === null || data === void 0 ? void 0 : data.length)) {
131
+ return [];
132
+ }
133
+ // calculate impact score
134
+ var impactMeasureReferences = referenceInfo.impactMeasureReferences, fieldPropsMap = referenceInfo.fieldPropsMap;
135
+ var subspaceImpact = computeSubspaceImpact(data, subspace, impactMeasureReferences, options === null || options === void 0 ? void 0 : options.impactMeasures);
136
+ // pruning1: check the subpace impact limit
137
+ if (subspaceImpact < constant_1.INSIGHT_SCORE_BENCHMARK) {
138
+ return [];
139
+ }
140
+ // pruning2: check if the impact score is greater than the minimum score in heap
141
+ var impactScoreWeight = !!(options === null || options === void 0 ? void 0 : options.impactWeight) && options.impactWeight >= 0 && options.impactWeight < 1
142
+ ? options.impactWeight
143
+ : constant_1.IMPACT_SCORE_WEIGHT;
144
+ var optimalScore = subspaceImpact * impactScoreWeight + 1 * (1 - impactScoreWeight);
145
+ if (insightsHeap.length >= insightsHeap.limit) {
146
+ var minScoreInHeap = (_a = insightsHeap.peek()) === null || _a === void 0 ? void 0 : _a.score;
147
+ if (optimalScore <= minScoreInHeap) {
148
+ return [];
149
+ }
150
+ }
151
+ /** insight extraction */
152
+ var insights = [];
153
+ /** Combination: 1M * 1D */
154
+ var insightsFor1M1DCombination = extractInsightsFor1M1DCombination(data, dimensions, measures, subspace, referenceInfo, options);
155
+ insightsFor1M1DCombination.forEach(function (insightsPerDim) {
156
+ var insightsForMeasures = insightsPerDim
157
+ .filter(function (item) { return !!item; })
158
+ .map(function (item) { return (tslib_1.__assign(tslib_1.__assign({}, item), { score: item.score * (1 - impactScoreWeight) + subspaceImpact * impactScoreWeight })); });
159
+ insights.push.apply(insights, tslib_1.__spreadArray([], tslib_1.__read(insightsPerDim), false));
160
+ (0, util_1.addInsightsToHeap)(insightsForMeasures, insightsHeap);
161
+ });
162
+ // Combination 3: 1M * 1M */
163
+ if ((options.insightTypes || constant_1.PATTERN_TYPES).includes('correlation')) {
164
+ var extracted = extractInsightsForCorrelation(data, dimensions, measures, subspace, referenceInfo, options);
165
+ var insightsForCorrelation = extracted === null || extracted === void 0 ? void 0 : extracted.map(function (item) { return (tslib_1.__assign(tslib_1.__assign({}, item), { score: item.score * (1 - impactScoreWeight) + subspaceImpact * impactScoreWeight })); });
166
+ (0, util_1.addInsightsToHeap)(insightsForCorrelation, insightsHeap);
167
+ }
168
+ /** extract homogeneous insight in measures */
169
+ if (options === null || options === void 0 ? void 0 : options.homogeneous) {
170
+ insightsFor1M1DCombination.forEach(function (insightsPerDim, dimIndex) {
171
+ var homogeneousPatternsForMeasures = (0, homogeneous_1.extractHomogeneousPatternsForMeasures)(measures, insightsPerDim);
172
+ if (homogeneousPatternsForMeasures.length > 0) {
173
+ var homogeneousInsights = homogeneousPatternsForMeasures.map(function (pattern) { return ({
174
+ subspace: subspace,
175
+ dimensions: [{ fieldName: dimensions[dimIndex] }],
176
+ measures: measures,
177
+ patterns: [pattern],
178
+ data: data,
179
+ score: pattern.significance * (1 - impactScoreWeight) + subspaceImpact * impactScoreWeight,
180
+ }); });
181
+ homogeneousInsightsHeap.addAll(homogeneousInsights);
182
+ }
183
+ });
184
+ }
185
+ /** subspace search */
186
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreSubspace)) {
187
+ var searchedDimensions_1 = subspace.map(function (item) { return item.dimension; });
188
+ var remainDimensionFields_1 = (((_b = options === null || options === void 0 ? void 0 : options.dimensions) === null || _b === void 0 ? void 0 : _b.map(function (dimension) { return dimension.fieldName; })) ||
189
+ Object.values(fieldPropsMap)
190
+ .filter(function (item) { return item.domainType === 'dimension'; })
191
+ .map(function (item) { return item.name; })).filter(function (field) { return !searchedDimensions_1.includes(field); });
192
+ if (remainDimensionFields_1.length > 0) {
193
+ remainDimensionFields_1.forEach(function (dimension) {
194
+ var siblingGroupInsights = [];
195
+ var groupedData = (0, lodash_1.groupBy)(data, dimension);
196
+ var breakdownValues = (0, lodash_1.uniq)(fieldPropsMap[dimension].rawData);
197
+ var dimensionsInSubspace = remainDimensionFields_1.filter(function (item) { return item !== dimension; });
198
+ if (breakdownValues.length > 1) {
199
+ breakdownValues.forEach(function (value) {
200
+ var childSubspace = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(subspace), false), [{ dimension: dimension, value: value }], false);
201
+ var subspaceInsights = extractInsightsFromSubspace(groupedData[value], dimensionsInSubspace, measures, childSubspace, referenceInfo, insightsHeap, homogeneousInsightsHeap, options);
202
+ siblingGroupInsights.push(subspaceInsights);
203
+ });
204
+ }
205
+ /** extract homegenehous insight in sibling group */
206
+ if (options === null || options === void 0 ? void 0 : options.homogeneous) {
207
+ dimensionsInSubspace.forEach(function (dim) {
208
+ measures.forEach(function (measure) {
209
+ var siblingGroupInsightsArr = siblingGroupInsights.map(function (siblingItem) {
210
+ return (siblingItem.find(function (insight) {
211
+ return (!!insight &&
212
+ insight.dimensions.length === 1 &&
213
+ insight.dimensions[0].fieldName === dim &&
214
+ insight.measures.length === 1 &&
215
+ insight.measures[0].fieldName === measure.fieldName);
216
+ }) || null);
217
+ });
218
+ var homogeneousPatternsForSiblingGroups = (0, homogeneous_1.extractHomogeneousPatternsForSiblingGroups)(breakdownValues, siblingGroupInsightsArr);
219
+ var insightsForSiblingGroup = homogeneousPatternsForSiblingGroups.map(function (pattern) { return ({
220
+ subspace: subspace,
221
+ dimensions: [{ fieldName: dimension }, { fieldName: dim }],
222
+ measures: [measure],
223
+ patterns: [pattern],
224
+ data: data,
225
+ score: pattern.significance * (1 - impactScoreWeight) + subspaceImpact * impactScoreWeight,
226
+ }); });
227
+ homogeneousInsightsHeap.addAll(insightsForSiblingGroup);
228
+ });
229
+ });
230
+ }
231
+ });
232
+ }
233
+ }
234
+ return insights;
235
+ }
236
+ exports.extractInsightsFromSubspace = extractInsightsFromSubspace;
237
+ /** insight subject enumeration in the data */
238
+ function enumerateInsights(data, dimensions, measures, referenceInfo, insightsHeap, metaInsightsHeap, options) {
239
+ if (options === void 0) { options = {}; }
240
+ var initSubspace = [];
241
+ extractInsightsFromSubspace(data, dimensions, measures, initSubspace, referenceInfo, insightsHeap, metaInsightsHeap, options);
242
+ }
243
+ exports.enumerateInsights = enumerateInsights;
@@ -0,0 +1,2 @@
1
+ import type { Datum, InsightOptions, InsightsResult } from '../types';
2
+ export declare function getInsights(sourceData: Datum[], options?: InsightOptions): InsightsResult;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInsights = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var insight_1 = require("./insight");
6
+ function getInsights(sourceData, options) {
7
+ var extractResult = (0, insight_1.extractInsights)(sourceData, options);
8
+ if (options === null || options === void 0 ? void 0 : options.visualization) {
9
+ // Provide all vis options
10
+ var visOption = tslib_1.__assign({ lang: 'en-US' }, ((options === null || options === void 0 ? void 0 : options.visualization) === true ? {} : options === null || options === void 0 ? void 0 : options.visualization));
11
+ return (0, insight_1.generateInsightsWithVisualizationSpec)(extractResult, tslib_1.__assign(tslib_1.__assign({}, options), { visualization: visOption }));
12
+ }
13
+ return extractResult;
14
+ }
15
+ exports.getInsights = getInsights;
@@ -0,0 +1,10 @@
1
+ import type { Datum, InsightOptions, InsightInfo, PatternInfo, HomogeneousPatternInfo, InsightVisualizationOptions } from '../types';
2
+ type InsightsResult = {
3
+ insights: InsightInfo<PatternInfo>[];
4
+ homogeneousInsights?: InsightInfo<HomogeneousPatternInfo>[];
5
+ };
6
+ export declare function extractInsights(sourceData: Datum[], options?: InsightOptions): InsightsResult;
7
+ export declare function generateInsightsWithVisualizationSpec(extraction: InsightsResult, options?: InsightOptions & {
8
+ visualization: InsightVisualizationOptions;
9
+ }): InsightsResult;
10
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateInsightsWithVisualizationSpec = exports.extractInsights = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var heap_js_1 = tslib_1.__importDefault(require("heap-js"));
6
+ var constant_1 = require("../constant");
7
+ var aggregate_1 = require("../utils/aggregate");
8
+ var extract_1 = require("./extract");
9
+ var preprocess_1 = require("./preprocess");
10
+ var visualize_1 = require("./visualize");
11
+ var util_1 = require("./util");
12
+ function extractInsights(sourceData, options) {
13
+ var _a;
14
+ // get data columns infomations (column type, statistics, etc.)
15
+ var data = sourceData.filter(function (item) { return !Object.values(item).some(function (v) { return v === null || v === undefined; }); });
16
+ var dataProps = (0, preprocess_1.dataToDataProps)(data, options === null || options === void 0 ? void 0 : options.dataProcessInfo);
17
+ var fieldPropsMap = dataProps.reduce(function (acc, item) {
18
+ acc[item.name] = item;
19
+ return acc;
20
+ }, {});
21
+ var impactMeasureReferences = (0, preprocess_1.calculateImpactMeasureReferenceValues)(data, options === null || options === void 0 ? void 0 : options.impactMeasures);
22
+ var referenceInfo = {
23
+ fieldPropsMap: fieldPropsMap,
24
+ impactMeasureReferences: impactMeasureReferences,
25
+ };
26
+ var measures = (options === null || options === void 0 ? void 0 : options.measures) ||
27
+ dataProps
28
+ .filter(function (item) { return item.domainType === 'measure'; })
29
+ .map(function (item) { return ({
30
+ fieldName: item.name,
31
+ method: 'SUM',
32
+ }); });
33
+ var dimensions = ((_a = options === null || options === void 0 ? void 0 : options.dimensions) === null || _a === void 0 ? void 0 : _a.map(function (dimension) { return dimension.fieldName; })) ||
34
+ dataProps.filter(function (item) { return item.domainType === 'dimension'; }).map(function (item) { return item.name; });
35
+ // init insights storage
36
+ var insightsHeap = new heap_js_1.default(util_1.insightPriorityComparator);
37
+ var homogeneousInsightsHeap = new heap_js_1.default(util_1.homogeneousInsightPriorityComparator);
38
+ var insightsLimit = (options === null || options === void 0 ? void 0 : options.limit) || constant_1.INSIGHT_DEFAULT_LIMIT;
39
+ insightsHeap.limit = insightsLimit;
40
+ insightsHeap.init([]);
41
+ homogeneousInsightsHeap.init([]);
42
+ (0, extract_1.enumerateInsights)(data, dimensions, measures, referenceInfo, insightsHeap, homogeneousInsightsHeap, options);
43
+ // get top N results
44
+ var insights = [];
45
+ var heapSize = insightsHeap.size();
46
+ var insightsSize = heapSize > insightsLimit ? insightsLimit : heapSize;
47
+ for (var i = 0; i < insightsSize; i += 1) {
48
+ var top_1 = insightsHeap.pop();
49
+ insights.push(top_1);
50
+ }
51
+ var result = { insights: insights.reverse() };
52
+ if (options === null || options === void 0 ? void 0 : options.homogeneous) {
53
+ var homogeneousInsightsResult = [];
54
+ var homogeneousHeapSize = homogeneousInsightsHeap.size();
55
+ var homogeneousInsightsSize = homogeneousHeapSize > insightsLimit ? insightsLimit : homogeneousHeapSize;
56
+ for (var i = 0; i < homogeneousInsightsSize; i += 1) {
57
+ var top_2 = homogeneousInsightsHeap.pop();
58
+ homogeneousInsightsResult.push(top_2);
59
+ }
60
+ result.homogeneousInsights = homogeneousInsightsResult.reverse();
61
+ }
62
+ return result;
63
+ }
64
+ exports.extractInsights = extractInsights;
65
+ function generateInsightsWithVisualizationSpec(extraction, options) {
66
+ var insights = extraction.insights, homogeneousInsights = extraction.homogeneousInsights;
67
+ var insightsWithVis = insights.map(function (item) { return (tslib_1.__assign(tslib_1.__assign({}, item), { visualizationSpecs: (0, visualize_1.generateInsightVisualizationSpec)(item, options === null || options === void 0 ? void 0 : options.visualization) })); });
68
+ var result = { insights: insightsWithVis };
69
+ if (homogeneousInsights && (options === null || options === void 0 ? void 0 : options.homogeneous)) {
70
+ var homogeneousInsightsWithVis = homogeneousInsights.map(function (item) {
71
+ var visualizationSpecs = (0, visualize_1.generateHomogeneousInsightVisualizationSpec)(item, options.visualization);
72
+ var data = item.data, measures = item.measures, dimensions = item.dimensions;
73
+ var insight = tslib_1.__assign(tslib_1.__assign({}, item), { visualizationSpecs: visualizationSpecs });
74
+ if (measures.length > 1) {
75
+ insight.data = (0, aggregate_1.aggregateWithMeasures)(data, dimensions[0].fieldName, measures);
76
+ }
77
+ else {
78
+ insight.data = (0, aggregate_1.aggregateWithSeries)(data, dimensions[0].fieldName, measures[0], dimensions[1].fieldName);
79
+ }
80
+ return insight;
81
+ });
82
+ result.homogeneousInsights = homogeneousInsightsWithVis;
83
+ }
84
+ return result;
85
+ }
86
+ exports.generateInsightsWithVisualizationSpec = generateInsightsWithVisualizationSpec;
@@ -0,0 +1,6 @@
1
+ import { Extra } from '../../data';
2
+ import type { Datum, ImpactMeasure, DataProperty } from '../types';
3
+ export declare function dataToDataProps(data: Datum[], extra?: Extra): DataProperty[];
4
+ export declare function calculateImpactValue(data: Datum[], measure: ImpactMeasure): number;
5
+ /** calculate the reference values for impact measures */
6
+ export declare function calculateImpactMeasureReferenceValues(data: Datum[], measures?: ImpactMeasure[]): Record<string, number>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateImpactMeasureReferenceValues = exports.calculateImpactValue = exports.dataToDataProps = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var lodash_1 = require("lodash");
6
+ var data_1 = require("../../data");
7
+ var aggregate_1 = require("../utils/aggregate");
8
+ function dataToDataProps(data, extra) {
9
+ if (!data) {
10
+ throw new Error('Argument `data` is missing.');
11
+ }
12
+ var df = new data_1.DataFrame(data, extra);
13
+ var dataTypeInfos = df.info();
14
+ var dataProps = [];
15
+ dataTypeInfos.forEach(function (info) {
16
+ var _a;
17
+ var newInfo = tslib_1.__assign(tslib_1.__assign({}, info), { domainType: ((_a = (0, lodash_1.intersection)(['Interval', 'Continuous'], info.levelOfMeasurements)) === null || _a === void 0 ? void 0 : _a.length) ? 'measure' : 'dimension' });
18
+ dataProps.push(newInfo);
19
+ });
20
+ return dataProps;
21
+ }
22
+ exports.dataToDataProps = dataToDataProps;
23
+ function calculateImpactValue(data, measure) {
24
+ var measureAggregator = aggregate_1.AggregatorMap[measure.method];
25
+ var value = measureAggregator(data, measure.fieldName);
26
+ return value;
27
+ }
28
+ exports.calculateImpactValue = calculateImpactValue;
29
+ /** calculate the reference values for impact measures */
30
+ function calculateImpactMeasureReferenceValues(data, measures) {
31
+ var referenceMap = {};
32
+ measures === null || measures === void 0 ? void 0 : measures.forEach(function (measure) {
33
+ var measureKey = "".concat(measure.fieldName, "@").concat(measure.method);
34
+ var value = calculateImpactValue(data, measure);
35
+ referenceMap[measureKey] = value;
36
+ });
37
+ return referenceMap;
38
+ }
39
+ exports.calculateImpactMeasureReferenceValues = calculateImpactMeasureReferenceValues;
@@ -0,0 +1,11 @@
1
+ import { G2Spec } from '@antv/g2';
2
+ import { AugmentedMarks } from '../chart';
3
+ import { InsightInfo, InsightType, PatternInfo, PatternInfo2InsightInfoProps, SpecificInsightProps, SpecificInsightResult } from '../types';
4
+ export declare const patternInfo2InsightInfo: (props: PatternInfo2InsightInfoProps) => InsightInfo<PatternInfo>;
5
+ export declare const getAnnotationSpec: (insightInfo: InsightInfo<PatternInfo>) => AugmentedMarks;
6
+ export declare const getChartSpecWithoutAugmentedMarks: (insightInfo: InsightInfo<PatternInfo>, insightType: InsightType) => G2Spec;
7
+ export declare const filterValidInsightInfoForAnnotationSpec: ({ patternInfos, insightType, }: {
8
+ patternInfos: PatternInfo[];
9
+ insightType: InsightType;
10
+ }) => PatternInfo[];
11
+ export declare const getSpecificInsight: (props: SpecificInsightProps) => SpecificInsightResult;