@eagleoutice/flowr 1.5.2 → 2.0.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 (570) hide show
  1. package/abstract-interpretation/handler/binop/binop.d.ts +3 -4
  2. package/abstract-interpretation/handler/binop/binop.js +4 -2
  3. package/abstract-interpretation/handler/binop/operators.d.ts +2 -2
  4. package/abstract-interpretation/handler/binop/operators.js +14 -28
  5. package/abstract-interpretation/processor.d.ts +3 -2
  6. package/abstract-interpretation/processor.js +2 -2
  7. package/benchmark/slicer.d.ts +101 -0
  8. package/benchmark/slicer.js +214 -0
  9. package/benchmark/stats/print.d.ts +7 -0
  10. package/benchmark/stats/print.js +151 -0
  11. package/benchmark/stats/stats.d.ts +42 -0
  12. package/benchmark/stats/stats.js +6 -0
  13. package/benchmark/stopwatch.d.ts +35 -0
  14. package/benchmark/stopwatch.js +79 -0
  15. package/benchmark/summarizer/data.d.ts +54 -0
  16. package/benchmark/summarizer/first-phase/input.d.ts +3 -0
  17. package/benchmark/summarizer/first-phase/input.js +76 -0
  18. package/benchmark/summarizer/first-phase/process.d.ts +11 -0
  19. package/benchmark/summarizer/first-phase/process.js +205 -0
  20. package/benchmark/summarizer/second-phase/graph.d.ts +2 -0
  21. package/benchmark/summarizer/second-phase/graph.js +54 -0
  22. package/benchmark/summarizer/second-phase/process.d.ts +6 -0
  23. package/benchmark/summarizer/second-phase/process.js +127 -0
  24. package/benchmark/summarizer/summarizer.d.ts +31 -0
  25. package/benchmark/summarizer/summarizer.js +58 -0
  26. package/cli/benchmark-app.d.ts +10 -0
  27. package/cli/benchmark-app.js +67 -0
  28. package/cli/benchmark-helper-app.d.ts +9 -0
  29. package/cli/benchmark-helper-app.js +69 -0
  30. package/cli/common/features.d.ts +3 -0
  31. package/cli/common/features.js +30 -0
  32. package/cli/common/options.d.ts +20 -0
  33. package/cli/common/options.js +85 -0
  34. package/cli/common/script.d.ts +21 -0
  35. package/cli/common/script.js +61 -0
  36. package/cli/common/scripts-info.d.ts +25 -0
  37. package/cli/common/scripts-info.js +83 -0
  38. package/cli/export-quads-app.d.ts +7 -0
  39. package/cli/export-quads-app.js +43 -0
  40. package/cli/flowr.d.ts +29 -0
  41. package/cli/flowr.js +141 -0
  42. package/cli/repl/commands/cfg.d.ts +3 -0
  43. package/cli/repl/commands/cfg.js +37 -0
  44. package/cli/repl/commands/commands.d.ts +13 -0
  45. package/cli/repl/commands/commands.js +142 -0
  46. package/cli/repl/commands/dataflow.d.ts +3 -0
  47. package/cli/repl/commands/dataflow.js +34 -0
  48. package/cli/repl/commands/execute.d.ts +4 -0
  49. package/cli/repl/commands/execute.js +27 -0
  50. package/cli/repl/commands/main.d.ts +39 -0
  51. package/cli/repl/commands/main.js +14 -0
  52. package/cli/repl/commands/normalize.d.ts +3 -0
  53. package/cli/repl/commands/normalize.js +34 -0
  54. package/cli/repl/commands/parse.d.ts +2 -0
  55. package/cli/repl/commands/parse.js +110 -0
  56. package/cli/repl/commands/quit.d.ts +2 -0
  57. package/cli/repl/commands/quit.js +15 -0
  58. package/cli/repl/commands/version.d.ts +16 -0
  59. package/cli/repl/commands/version.js +28 -0
  60. package/cli/repl/core.d.ts +36 -0
  61. package/cli/repl/core.js +174 -0
  62. package/cli/repl/execute.d.ts +28 -0
  63. package/cli/repl/execute.js +79 -0
  64. package/cli/repl/print-version.d.ts +2 -0
  65. package/cli/repl/print-version.js +10 -0
  66. package/cli/repl/prompt.d.ts +2 -0
  67. package/cli/repl/prompt.js +9 -0
  68. package/cli/repl/server/connection.d.ts +21 -0
  69. package/cli/repl/server/connection.js +218 -0
  70. package/cli/repl/server/messages/analysis.d.ts +72 -0
  71. package/cli/repl/server/messages/analysis.js +21 -0
  72. package/cli/repl/server/messages/error.d.ts +11 -0
  73. package/{core/input.js → cli/repl/server/messages/error.js} +1 -1
  74. package/cli/repl/server/messages/hello.d.ts +20 -0
  75. package/{core/output.js → cli/repl/server/messages/hello.js} +1 -1
  76. package/cli/repl/server/messages/messages.d.ts +35 -0
  77. package/cli/repl/server/messages/messages.js +40 -0
  78. package/cli/repl/server/messages/repl.d.ts +33 -0
  79. package/cli/repl/server/messages/repl.js +37 -0
  80. package/cli/repl/server/messages/slice.d.ts +26 -0
  81. package/cli/repl/server/messages/slice.js +37 -0
  82. package/cli/repl/server/net.d.ts +49 -0
  83. package/cli/repl/server/net.js +63 -0
  84. package/cli/repl/server/send.d.ts +4 -0
  85. package/cli/repl/server/send.js +18 -0
  86. package/cli/repl/server/server.d.ts +20 -0
  87. package/cli/repl/server/server.js +66 -0
  88. package/cli/repl/server/validate.d.ts +15 -0
  89. package/cli/repl/server/validate.js +34 -0
  90. package/cli/slicer-app.d.ts +11 -0
  91. package/cli/slicer-app.js +83 -0
  92. package/cli/statistics-app.d.ts +11 -0
  93. package/cli/statistics-app.js +99 -0
  94. package/cli/statistics-helper-app.d.ts +11 -0
  95. package/cli/statistics-helper-app.js +87 -0
  96. package/cli/summarizer-app.d.ts +18 -0
  97. package/cli/summarizer-app.js +66 -0
  98. package/core/pipeline-executor.d.ts +154 -0
  99. package/core/pipeline-executor.js +221 -0
  100. package/core/print/dataflow-printer.d.ts +3 -4
  101. package/core/print/dataflow-printer.js +5 -5
  102. package/core/print/normalize-printer.d.ts +1 -1
  103. package/core/print/normalize-printer.js +3 -3
  104. package/core/print/parse-printer.js +3 -3
  105. package/core/print/print.d.ts +13 -4
  106. package/core/print/print.js +13 -2
  107. package/core/print/slice-diff-ansi.d.ts +3 -2
  108. package/core/print/slice-diff-ansi.js +4 -4
  109. package/core/steps/all/core/00-parse.d.ts +28 -0
  110. package/core/steps/all/core/00-parse.js +24 -0
  111. package/core/steps/all/core/10-normalize.d.ts +29 -0
  112. package/core/steps/all/core/10-normalize.js +26 -0
  113. package/core/steps/all/core/20-dataflow.d.ts +27 -0
  114. package/core/steps/all/core/20-dataflow.js +29 -0
  115. package/core/steps/all/static-slicing/00-slice.d.ts +28 -0
  116. package/core/steps/all/static-slicing/00-slice.js +21 -0
  117. package/core/steps/all/static-slicing/10-reconstruct.d.ts +25 -0
  118. package/core/steps/all/static-slicing/10-reconstruct.js +21 -0
  119. package/core/steps/pipeline/create-pipeline.d.ts +6 -0
  120. package/core/steps/pipeline/create-pipeline.js +130 -0
  121. package/core/steps/pipeline/default-pipelines.d.ts +251 -0
  122. package/core/steps/pipeline/default-pipelines.js +18 -0
  123. package/core/steps/pipeline/invalid-pipeline-error.d.ts +6 -0
  124. package/core/steps/pipeline/invalid-pipeline-error.js +14 -0
  125. package/core/steps/pipeline/pipeline.d.ts +60 -0
  126. package/core/steps/pipeline/pipeline.js +28 -0
  127. package/core/steps/pipeline-step.d.ts +85 -0
  128. package/core/steps/pipeline-step.js +8 -0
  129. package/dataflow/environments/append.d.ts +4 -4
  130. package/dataflow/environments/append.js +4 -4
  131. package/dataflow/environments/built-in.d.ts +25 -0
  132. package/dataflow/environments/built-in.js +123 -0
  133. package/dataflow/environments/clone.d.ts +2 -0
  134. package/dataflow/environments/clone.js +23 -0
  135. package/dataflow/environments/{register.d.ts → define.d.ts} +3 -3
  136. package/dataflow/environments/define.js +51 -0
  137. package/dataflow/environments/diff.d.ts +6 -0
  138. package/dataflow/environments/diff.js +85 -0
  139. package/dataflow/environments/environment.d.ts +10 -43
  140. package/dataflow/environments/environment.js +32 -138
  141. package/dataflow/environments/identifier.d.ts +31 -0
  142. package/dataflow/environments/identifier.js +3 -0
  143. package/dataflow/environments/overwrite.d.ts +4 -4
  144. package/dataflow/environments/overwrite.js +9 -22
  145. package/dataflow/environments/resolve-by-name.d.ts +7 -6
  146. package/dataflow/environments/resolve-by-name.js +35 -19
  147. package/dataflow/environments/scoping.js +1 -4
  148. package/dataflow/extractor.d.ts +6 -6
  149. package/dataflow/extractor.js +47 -57
  150. package/dataflow/graph/diff.d.ts +24 -7
  151. package/dataflow/graph/diff.js +114 -74
  152. package/dataflow/graph/edge.d.ts +66 -20
  153. package/dataflow/graph/edge.js +73 -27
  154. package/dataflow/graph/graph.d.ts +53 -29
  155. package/dataflow/graph/graph.js +84 -89
  156. package/dataflow/graph/quads.js +2 -2
  157. package/dataflow/graph/vertex.d.ts +37 -34
  158. package/dataflow/info.d.ts +49 -0
  159. package/dataflow/info.js +29 -0
  160. package/dataflow/internal/linker.d.ts +11 -10
  161. package/dataflow/internal/linker.js +64 -90
  162. package/dataflow/internal/process/functions/call/argument/make-argument.d.ts +6 -0
  163. package/dataflow/internal/process/functions/call/argument/make-argument.js +31 -0
  164. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +3 -0
  165. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +18 -0
  166. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +9 -0
  167. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +82 -0
  168. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +29 -0
  169. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +167 -0
  170. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +11 -0
  171. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +165 -0
  172. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +7 -0
  173. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +97 -0
  174. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +7 -0
  175. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +165 -0
  176. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +7 -0
  177. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +36 -0
  178. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +7 -0
  179. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +100 -0
  180. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +7 -0
  181. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +32 -0
  182. package/dataflow/internal/process/functions/call/built-in/built-in-logical-bin-op.d.ts +9 -0
  183. package/dataflow/internal/process/functions/call/built-in/built-in-logical-bin-op.js +35 -0
  184. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.d.ts +7 -0
  185. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +35 -0
  186. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +9 -0
  187. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +29 -0
  188. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.d.ts +7 -0
  189. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +32 -0
  190. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +12 -0
  191. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +45 -0
  192. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +11 -0
  193. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +72 -0
  194. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +7 -0
  195. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +61 -0
  196. package/dataflow/internal/process/functions/call/common.d.ts +35 -0
  197. package/dataflow/internal/process/functions/call/common.js +70 -0
  198. package/dataflow/internal/process/functions/call/default-call-handling.d.ts +5 -0
  199. package/dataflow/internal/process/functions/call/default-call-handling.js +15 -0
  200. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +26 -0
  201. package/dataflow/internal/process/functions/call/known-call-handling.js +62 -0
  202. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +7 -0
  203. package/dataflow/internal/process/functions/call/named-call-handling.js +53 -0
  204. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +6 -0
  205. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +58 -0
  206. package/dataflow/internal/process/functions/process-argument.d.ts +9 -0
  207. package/dataflow/internal/process/functions/{argument.js → process-argument.js} +25 -20
  208. package/dataflow/internal/process/functions/{parameter.d.ts → process-parameter.d.ts} +3 -2
  209. package/dataflow/internal/process/functions/{parameter.js → process-parameter.js} +10 -13
  210. package/dataflow/internal/process/process-named-call.d.ts +6 -0
  211. package/dataflow/internal/process/process-named-call.js +17 -0
  212. package/dataflow/internal/process/process-symbol.d.ts +5 -0
  213. package/dataflow/internal/process/process-symbol.js +26 -0
  214. package/dataflow/internal/process/process-uninteresting-leaf.d.ts +4 -0
  215. package/dataflow/internal/process/process-uninteresting-leaf.js +9 -0
  216. package/dataflow/internal/process/process-value.d.ts +4 -0
  217. package/dataflow/internal/process/process-value.js +22 -0
  218. package/dataflow/logger.d.ts +1 -0
  219. package/dataflow/logger.js +6 -0
  220. package/dataflow/processor.d.ts +18 -13
  221. package/dataflow/processor.js +1 -1
  222. package/package.json +48 -85
  223. package/r-bridge/data/data.d.ts +603 -0
  224. package/r-bridge/data/data.js +753 -0
  225. package/r-bridge/data/get.d.ts +19 -0
  226. package/r-bridge/data/get.js +51 -0
  227. package/r-bridge/data/print.d.ts +1 -0
  228. package/r-bridge/data/print.js +58 -0
  229. package/r-bridge/data/types.d.ts +33 -0
  230. package/r-bridge/data/types.js +3 -0
  231. package/r-bridge/init.d.ts +3 -0
  232. package/r-bridge/init.js +22 -0
  233. package/r-bridge/lang-4.x/ast/model/collect.d.ts +2 -1
  234. package/r-bridge/lang-4.x/ast/model/collect.js +2 -2
  235. package/r-bridge/lang-4.x/ast/model/model.d.ts +26 -5
  236. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +4 -3
  237. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +4 -0
  238. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +0 -17
  239. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -1
  240. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -4
  241. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +2 -0
  242. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -3
  243. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -1
  244. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -1
  245. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +2 -2
  246. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +0 -11
  247. package/r-bridge/lang-4.x/ast/model/operators.d.ts +6 -18
  248. package/r-bridge/lang-4.x/ast/model/operators.js +36 -48
  249. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +19 -15
  250. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +59 -54
  251. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +8 -0
  252. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +18 -0
  253. package/r-bridge/lang-4.x/ast/model/processing/role.d.ts +2 -2
  254. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +28 -17
  255. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +7 -34
  256. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +5 -2
  257. package/r-bridge/lang-4.x/ast/model/type.js +13 -6
  258. package/r-bridge/lang-4.x/ast/parser/json/format.d.ts +4 -1
  259. package/r-bridge/lang-4.x/ast/parser/json/format.js +9 -2
  260. package/r-bridge/lang-4.x/ast/parser/json/parser.d.ts +5 -5
  261. package/r-bridge/lang-4.x/ast/parser/json/parser.js +22 -27
  262. package/r-bridge/lang-4.x/ast/parser/xml/input-format.d.ts +10 -7
  263. package/r-bridge/lang-4.x/ast/parser/xml/input-format.js +19 -11
  264. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/{if-then-else.d.ts → normalize-if-then-else.d.ts} +3 -3
  265. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/{if-then-else.js → normalize-if-then-else.js} +10 -13
  266. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/{if-then.d.ts → normalize-if-then.d.ts} +3 -3
  267. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/{if-then.js → normalize-if-then.js} +9 -12
  268. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/normalize-expression.d.ts +10 -0
  269. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/normalize-expression.js +64 -0
  270. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{argument.d.ts → normalize-argument.d.ts} +4 -4
  271. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{argument.js → normalize-argument.js} +13 -17
  272. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{call.d.ts → normalize-call.d.ts} +6 -4
  273. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{call.js → normalize-call.js} +24 -29
  274. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/normalize-definition.d.ts +12 -0
  275. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{definition.js → normalize-definition.js} +14 -19
  276. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{parameter.d.ts → normalize-parameter.d.ts} +4 -4
  277. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/{parameter.js → normalize-parameter.js} +12 -16
  278. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-break.d.ts +4 -0
  279. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/{break.js → normalize-break.js} +6 -8
  280. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-for.d.ts +4 -0
  281. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/{for.js → normalize-for.js} +18 -20
  282. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-next.d.ts +4 -0
  283. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/{next.js → normalize-next.js} +6 -8
  284. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-repeat.d.ts +13 -0
  285. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/{repeat.js → normalize-repeat.js} +13 -16
  286. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-while.d.ts +4 -0
  287. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/{while.js → normalize-while.js} +10 -12
  288. package/r-bridge/lang-4.x/ast/parser/xml/internal/{access.d.ts → normalize-access.d.ts} +4 -4
  289. package/r-bridge/lang-4.x/ast/parser/xml/internal/{access.js → normalize-access.js} +44 -45
  290. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/{binary.d.ts → normalize-binary.d.ts} +3 -3
  291. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/{binary.js → normalize-binary.js} +23 -73
  292. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/normalize-unary.d.ts +13 -0
  293. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/normalize-unary.js +47 -0
  294. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/normalize-comment.d.ts +11 -0
  295. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/{comment.js → normalize-comment.js} +5 -10
  296. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/normalize-line-directive.d.ts +13 -0
  297. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/{line-directive.js → normalize-line-directive.js} +7 -12
  298. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-delimiter.d.ts +3 -0
  299. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-delimiter.js +15 -0
  300. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-expressions.d.ts +10 -0
  301. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-expressions.js +182 -0
  302. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-root.d.ts +4 -0
  303. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-root.js +34 -0
  304. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-single-node.d.ts +13 -0
  305. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-single-node.js +59 -0
  306. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/normalize-number.d.ts +16 -0
  307. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/{number.js → normalize-number.js} +12 -18
  308. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/normalize-string.d.ts +11 -0
  309. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/{string.js → normalize-string.js} +7 -12
  310. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/{symbol.d.ts → normalize-symbol.d.ts} +4 -4
  311. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/{symbol.js → normalize-symbol.js} +12 -15
  312. package/r-bridge/lang-4.x/ast/parser/xml/{internal/meta.d.ts → normalize-meta.d.ts} +5 -3
  313. package/r-bridge/lang-4.x/ast/parser/xml/{internal/meta.js → normalize-meta.js} +8 -8
  314. package/r-bridge/lang-4.x/ast/parser/xml/{data.d.ts → normalizer-data.d.ts} +1 -5
  315. package/r-bridge/lang-4.x/ast/parser/xml/normalizer-data.js +3 -0
  316. package/r-bridge/lang-4.x/{values.d.ts → convert-values.d.ts} +2 -2
  317. package/r-bridge/lang-4.x/{values.js → convert-values.js} +5 -5
  318. package/r-bridge/retriever.d.ts +5 -5
  319. package/r-bridge/retriever.js +11 -24
  320. package/r-bridge/shell-executor.d.ts +0 -1
  321. package/r-bridge/shell-executor.js +7 -12
  322. package/r-bridge/shell.d.ts +14 -12
  323. package/r-bridge/shell.js +50 -45
  324. package/reconstruct/reconstruct.d.ts +4 -2
  325. package/reconstruct/reconstruct.js +193 -185
  326. package/slicing/criterion/collect-all.d.ts +4 -3
  327. package/slicing/criterion/collect-all.js +5 -1
  328. package/slicing/criterion/filters/all-variables.js +14 -22
  329. package/slicing/criterion/parse.d.ts +4 -2
  330. package/slicing/criterion/parse.js +13 -11
  331. package/slicing/static/fingerprint.d.ts +5 -0
  332. package/slicing/static/fingerprint.js +17 -0
  333. package/slicing/static/slice-call.d.ts +10 -0
  334. package/slicing/static/slice-call.js +86 -0
  335. package/slicing/static/slicer-types.d.ts +33 -0
  336. package/slicing/static/slicer-types.js +3 -0
  337. package/slicing/static/static-slicer.d.ts +6 -24
  338. package/slicing/static/static-slicer.js +54 -155
  339. package/slicing/static/visiting-queue.d.ts +23 -0
  340. package/slicing/static/visiting-queue.js +53 -0
  341. package/statistics/features/common-syntax-probability.d.ts +29 -0
  342. package/statistics/features/common-syntax-probability.js +159 -0
  343. package/statistics/features/feature.d.ts +182 -0
  344. package/statistics/features/feature.js +39 -0
  345. package/statistics/features/post-processing.d.ts +12 -0
  346. package/statistics/features/post-processing.js +21 -0
  347. package/statistics/features/supported/assignments/assignments.d.ts +12 -0
  348. package/statistics/features/supported/assignments/assignments.js +55 -0
  349. package/statistics/features/supported/assignments/post-process.d.ts +3 -0
  350. package/statistics/features/supported/assignments/post-process.js +124 -0
  351. package/statistics/features/supported/comments/comments.d.ts +18 -0
  352. package/statistics/features/supported/comments/comments.js +133 -0
  353. package/statistics/features/supported/comments/post-process.d.ts +3 -0
  354. package/statistics/features/supported/comments/post-process.js +49 -0
  355. package/statistics/features/supported/control-flow/control-flow.d.ts +17 -0
  356. package/statistics/features/supported/control-flow/control-flow.js +68 -0
  357. package/statistics/features/supported/control-flow/post-process.d.ts +3 -0
  358. package/statistics/features/supported/control-flow/post-process.js +64 -0
  359. package/statistics/features/supported/data-access/data-access.d.ts +15 -0
  360. package/statistics/features/supported/data-access/data-access.js +120 -0
  361. package/statistics/features/supported/data-access/post-process.d.ts +3 -0
  362. package/statistics/features/supported/data-access/post-process.js +106 -0
  363. package/statistics/features/supported/defined-functions/defined-functions.d.ts +34 -0
  364. package/statistics/features/supported/defined-functions/defined-functions.js +142 -0
  365. package/statistics/features/supported/defined-functions/post-process.d.ts +6 -0
  366. package/statistics/features/supported/defined-functions/post-process.js +169 -0
  367. package/statistics/features/supported/expression-list/expression-list.d.ts +9 -0
  368. package/statistics/features/supported/expression-list/expression-list.js +36 -0
  369. package/statistics/features/supported/expression-list/post-process.d.ts +3 -0
  370. package/statistics/features/supported/expression-list/post-process.js +43 -0
  371. package/statistics/features/supported/loops/loops.d.ts +20 -0
  372. package/statistics/features/supported/loops/loops.js +79 -0
  373. package/statistics/features/supported/loops/post-process.d.ts +3 -0
  374. package/statistics/features/supported/loops/post-process.js +71 -0
  375. package/statistics/features/supported/used-functions/post-process.d.ts +6 -0
  376. package/statistics/features/supported/used-functions/post-process.js +178 -0
  377. package/statistics/features/supported/used-functions/used-functions.d.ts +24 -0
  378. package/statistics/features/supported/used-functions/used-functions.js +97 -0
  379. package/statistics/features/supported/used-packages/post-process.d.ts +3 -0
  380. package/statistics/features/supported/used-packages/post-process.js +120 -0
  381. package/statistics/features/supported/used-packages/used-packages.d.ts +16 -0
  382. package/statistics/features/supported/used-packages/used-packages.js +130 -0
  383. package/statistics/features/supported/values/post-process.d.ts +3 -0
  384. package/statistics/features/supported/values/post-process.js +71 -0
  385. package/statistics/features/supported/values/values.d.ts +14 -0
  386. package/statistics/features/supported/values/values.js +101 -0
  387. package/statistics/features/supported/variables/post-process.d.ts +9 -0
  388. package/statistics/features/supported/variables/post-process.js +121 -0
  389. package/statistics/features/supported/variables/variables.d.ts +15 -0
  390. package/statistics/features/supported/variables/variables.js +60 -0
  391. package/statistics/meta-statistics.d.ts +33 -0
  392. package/statistics/meta-statistics.js +17 -0
  393. package/statistics/output/file-provider.d.ts +37 -0
  394. package/statistics/output/file-provider.js +97 -0
  395. package/statistics/output/print-stats.d.ts +17 -0
  396. package/statistics/output/print-stats.js +69 -0
  397. package/statistics/output/statistics-file.d.ts +37 -0
  398. package/statistics/output/statistics-file.js +69 -0
  399. package/statistics/statistics.d.ts +28 -0
  400. package/statistics/statistics.js +108 -0
  401. package/statistics/summarizer/auto-detect.d.ts +2 -0
  402. package/statistics/summarizer/auto-detect.js +32 -0
  403. package/statistics/summarizer/first-phase/process.d.ts +6 -0
  404. package/statistics/summarizer/first-phase/process.js +81 -0
  405. package/statistics/summarizer/post-process/clusterer.d.ts +26 -0
  406. package/statistics/summarizer/post-process/clusterer.js +43 -0
  407. package/statistics/summarizer/post-process/file-based-count.d.ts +17 -0
  408. package/statistics/summarizer/post-process/file-based-count.js +49 -0
  409. package/statistics/summarizer/post-process/histogram.d.ts +59 -0
  410. package/statistics/summarizer/post-process/histogram.js +128 -0
  411. package/statistics/summarizer/post-process/post-process-output.d.ts +16 -0
  412. package/statistics/summarizer/post-process/post-process-output.js +105 -0
  413. package/statistics/summarizer/second-phase/process.d.ts +11 -0
  414. package/statistics/summarizer/second-phase/process.js +116 -0
  415. package/statistics/summarizer/summarizer.d.ts +35 -0
  416. package/statistics/summarizer/summarizer.js +135 -0
  417. package/util/ansi.d.ts +2 -2
  418. package/util/ansi.js +2 -2
  419. package/util/arrays.d.ts +11 -1
  420. package/util/arrays.js +34 -1
  421. package/util/assert.d.ts +1 -0
  422. package/util/assert.js +5 -1
  423. package/util/cfg/cfg.d.ts +3 -2
  424. package/util/cfg/cfg.js +17 -28
  425. package/util/cfg/visitor.d.ts +1 -1
  426. package/util/defaultmap.d.ts +1 -1
  427. package/util/defaultmap.js +1 -1
  428. package/util/diff.d.ts +4 -4
  429. package/util/files.d.ts +2 -2
  430. package/util/files.js +1 -1
  431. package/util/log.d.ts +1 -0
  432. package/util/log.js +7 -1
  433. package/util/logic.d.ts +1 -0
  434. package/util/logic.js +3 -0
  435. package/util/mermaid/ast.d.ts +1 -1
  436. package/util/mermaid/ast.js +2 -2
  437. package/util/mermaid/cfg.d.ts +1 -1
  438. package/util/mermaid/dfg.d.ts +34 -8
  439. package/util/mermaid/dfg.js +99 -70
  440. package/util/mermaid/mermaid.d.ts +1 -1
  441. package/util/mermaid/mermaid.js +6 -7
  442. package/util/objects.js +4 -0
  443. package/util/quads.d.ts +3 -3
  444. package/util/quads.js +0 -1
  445. package/util/range.d.ts +27 -14
  446. package/util/range.js +31 -27
  447. package/util/version.js +1 -1
  448. package/core/index.d.ts +0 -4
  449. package/core/index.js +0 -23
  450. package/core/input.d.ts +0 -42
  451. package/core/output.d.ts +0 -15
  452. package/core/slicer.d.ts +0 -124
  453. package/core/slicer.js +0 -227
  454. package/core/steps.d.ts +0 -508
  455. package/core/steps.js +0 -100
  456. package/dataflow/environments/index.d.ts +0 -7
  457. package/dataflow/environments/index.js +0 -23
  458. package/dataflow/environments/register.js +0 -40
  459. package/dataflow/environments/scopes.d.ts +0 -6
  460. package/dataflow/environments/scopes.js +0 -6
  461. package/dataflow/graph/index.d.ts +0 -4
  462. package/dataflow/graph/index.js +0 -21
  463. package/dataflow/index.d.ts +0 -5
  464. package/dataflow/index.js +0 -24
  465. package/dataflow/internal/info.d.ts +0 -21
  466. package/dataflow/internal/info.js +0 -16
  467. package/dataflow/internal/process/access.d.ts +0 -4
  468. package/dataflow/internal/process/access.js +0 -53
  469. package/dataflow/internal/process/expression-list.d.ts +0 -8
  470. package/dataflow/internal/process/expression-list.js +0 -144
  471. package/dataflow/internal/process/functions/argument.d.ts +0 -8
  472. package/dataflow/internal/process/functions/exit-points.d.ts +0 -2
  473. package/dataflow/internal/process/functions/exit-points.js +0 -121
  474. package/dataflow/internal/process/functions/function-call.d.ts +0 -5
  475. package/dataflow/internal/process/functions/function-call.js +0 -105
  476. package/dataflow/internal/process/functions/function-definition.d.ts +0 -4
  477. package/dataflow/internal/process/functions/function-definition.js +0 -176
  478. package/dataflow/internal/process/functions/source.d.ts +0 -8
  479. package/dataflow/internal/process/functions/source.js +0 -81
  480. package/dataflow/internal/process/if-then-else.d.ts +0 -4
  481. package/dataflow/internal/process/if-then-else.js +0 -56
  482. package/dataflow/internal/process/loops/for-loop.d.ts +0 -4
  483. package/dataflow/internal/process/loops/for-loop.js +0 -54
  484. package/dataflow/internal/process/loops/repeat-loop.d.ts +0 -4
  485. package/dataflow/internal/process/loops/repeat-loop.js +0 -21
  486. package/dataflow/internal/process/loops/while-loop.d.ts +0 -4
  487. package/dataflow/internal/process/loops/while-loop.js +0 -31
  488. package/dataflow/internal/process/operators/assignment.d.ts +0 -4
  489. package/dataflow/internal/process/operators/assignment.js +0 -129
  490. package/dataflow/internal/process/operators/non-assignment-binary-op.d.ts +0 -4
  491. package/dataflow/internal/process/operators/non-assignment-binary-op.js +0 -25
  492. package/dataflow/internal/process/operators/pipe.d.ts +0 -4
  493. package/dataflow/internal/process/operators/pipe.js +0 -46
  494. package/dataflow/internal/process/operators/unary-op.d.ts +0 -4
  495. package/dataflow/internal/process/operators/unary-op.js +0 -10
  496. package/dataflow/internal/process/symbol.d.ts +0 -4
  497. package/dataflow/internal/process/symbol.js +0 -21
  498. package/dataflow/internal/process/uninteresting-leaf.d.ts +0 -3
  499. package/dataflow/internal/process/uninteresting-leaf.js +0 -9
  500. package/index.d.ts +0 -4
  501. package/index.js +0 -21
  502. package/r-bridge/index.d.ts +0 -11
  503. package/r-bridge/index.js +0 -28
  504. package/r-bridge/lang-4.x/ast/index.d.ts +0 -3
  505. package/r-bridge/lang-4.x/ast/index.js +0 -22
  506. package/r-bridge/lang-4.x/ast/model/index.d.ts +0 -6
  507. package/r-bridge/lang-4.x/ast/model/index.js +0 -23
  508. package/r-bridge/lang-4.x/ast/model/nodes/index.d.ts +0 -21
  509. package/r-bridge/lang-4.x/ast/model/nodes/index.js +0 -38
  510. package/r-bridge/lang-4.x/ast/model/nodes/info/index.d.ts +0 -13
  511. package/r-bridge/lang-4.x/ast/model/nodes/info/index.js +0 -27
  512. package/r-bridge/lang-4.x/ast/model/processing/index.d.ts +0 -5
  513. package/r-bridge/lang-4.x/ast/model/processing/index.js +0 -22
  514. package/r-bridge/lang-4.x/ast/parser/xml/hooks.d.ts +0 -292
  515. package/r-bridge/lang-4.x/ast/parser/xml/hooks.js +0 -136
  516. package/r-bridge/lang-4.x/ast/parser/xml/index.d.ts +0 -3
  517. package/r-bridge/lang-4.x/ast/parser/xml/index.js +0 -20
  518. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/index.d.ts +0 -2
  519. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/index.js +0 -19
  520. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/expression.d.ts +0 -10
  521. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/expression.js +0 -65
  522. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/index.d.ts +0 -1
  523. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/index.js +0 -18
  524. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/definition.d.ts +0 -12
  525. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/index.d.ts +0 -2
  526. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/index.js +0 -20
  527. package/r-bridge/lang-4.x/ast/parser/xml/internal/index.d.ts +0 -9
  528. package/r-bridge/lang-4.x/ast/parser/xml/internal/index.js +0 -26
  529. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/break.d.ts +0 -4
  530. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/for.d.ts +0 -4
  531. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/index.d.ts +0 -5
  532. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/index.js +0 -22
  533. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/next.d.ts +0 -4
  534. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/repeat.d.ts +0 -13
  535. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/while.d.ts +0 -4
  536. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/index.d.ts +0 -3
  537. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/index.js +0 -20
  538. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/special.d.ts +0 -6
  539. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/special.js +0 -24
  540. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/unary.d.ts +0 -13
  541. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/unary.js +0 -59
  542. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/comment.d.ts +0 -11
  543. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/index.d.ts +0 -1
  544. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/index.js +0 -18
  545. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/line-directive.d.ts +0 -12
  546. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/elements.d.ts +0 -10
  547. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/elements.js +0 -159
  548. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/index.d.ts +0 -3
  549. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/index.js +0 -20
  550. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/root.d.ts +0 -4
  551. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/root.js +0 -33
  552. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/single-element.d.ts +0 -13
  553. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/single-element.js +0 -64
  554. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/index.d.ts +0 -3
  555. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/index.js +0 -20
  556. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/number.d.ts +0 -13
  557. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/string.d.ts +0 -11
  558. package/r-bridge/lang-4.x/index.d.ts +0 -2
  559. package/r-bridge/lang-4.x/index.js +0 -19
  560. package/slicing/criterion/filters/index.d.ts +0 -1
  561. package/slicing/criterion/filters/index.js +0 -18
  562. package/slicing/criterion/index.d.ts +0 -3
  563. package/slicing/criterion/index.js +0 -20
  564. package/slicing/index.d.ts +0 -3
  565. package/slicing/index.js +0 -20
  566. package/slicing/static/index.d.ts +0 -1
  567. package/slicing/static/index.js +0 -18
  568. package/util/mermaid/index.d.ts +0 -3
  569. package/util/mermaid/index.js +0 -20
  570. /package/{r-bridge/lang-4.x/ast/parser/xml → benchmark/summarizer}/data.js +0 -0
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendStatisticsFile = exports.initDummyFileProvider = exports.initFileProvider = exports.statisticsFileProvider = exports.extractNodeContent = void 0;
4
+ const file_provider_1 = require("./file-provider");
5
+ const log_1 = require("../../util/log");
6
+ /**
7
+ * Requires source information to be attached on parsing!
8
+ * <p>
9
+ * Returns the content of the node (i.e., the text content excluding the children)
10
+ */
11
+ function extractNodeContent(node) {
12
+ let result = node.textContent;
13
+ if (node.hasChildNodes()) {
14
+ const firstChild = node.childNodes.item(0);
15
+ if (firstChild.nodeType === 3 /* text node */) {
16
+ result = firstChild.textContent;
17
+ }
18
+ }
19
+ return result?.trim()?.replaceAll('\n', '\\n') ?? '<unknown>';
20
+ }
21
+ exports.extractNodeContent = extractNodeContent;
22
+ initDummyFileProvider();
23
+ /**
24
+ * Make the statistics write to a given output directory.
25
+ */
26
+ function initFileProvider(outputDirectory) {
27
+ log_1.log.debug(`Initializing file provider for output directory ${outputDirectory}`);
28
+ exports.statisticsFileProvider = new file_provider_1.StatisticFileProvider(outputDirectory);
29
+ }
30
+ exports.initFileProvider = initFileProvider;
31
+ /**
32
+ * Either ignore the statistics or write them to a given map (e.g., for testing).
33
+ *
34
+ * @param map - The map to write to, will not persist calls if no map is given
35
+ */
36
+ function initDummyFileProvider(map) {
37
+ exports.statisticsFileProvider = new file_provider_1.DummyAppendProvider(map);
38
+ }
39
+ exports.initDummyFileProvider = initDummyFileProvider;
40
+ /**
41
+ * Append the content of all nodes to the storage file for the given feature
42
+ * @param name - The name of the feature {@link Feature#name}
43
+ * @param fn - The name of the feature-aspect to record
44
+ * @param nodes - The nodes to append, you may pass already transformed string contents
45
+ * @param context - The context of the information retrieval (e.g. the name of the file that contained the R source code)
46
+ * @param unique - Should duplicate entries be removed on addition
47
+ */
48
+ function appendStatisticsFile(name, fn, nodes, context, unique = false) {
49
+ if (nodes.length === 0) {
50
+ return;
51
+ }
52
+ let values;
53
+ if (typeof nodes[0] === 'string') {
54
+ values = nodes;
55
+ }
56
+ else if ('nodeType' in nodes[0]) {
57
+ values = nodes.map(extractNodeContent);
58
+ }
59
+ else {
60
+ values = nodes;
61
+ }
62
+ if (unique) {
63
+ values = [...new Set(values)];
64
+ }
65
+ values = values.map(value => JSON.stringify(context === undefined ? [value] : [value, context]));
66
+ exports.statisticsFileProvider.append(name, fn, values.join('\n'));
67
+ }
68
+ exports.appendStatisticsFile = appendStatisticsFile;
69
+ //# sourceMappingURL=statistics-file.js.map
@@ -0,0 +1,28 @@
1
+ import type { MetaStatistics } from './meta-statistics';
2
+ import type { RParseRequestFromFile, RParseRequestFromText } from '../r-bridge/retriever';
3
+ import type { PipelineOutput } from '../core/steps/pipeline/pipeline';
4
+ import { DEFAULT_DATAFLOW_PIPELINE } from '../core/steps/pipeline/default-pipelines';
5
+ import type { RShell } from '../r-bridge/shell';
6
+ import type { FeatureSelection, FeatureStatistics } from './features/feature';
7
+ /**
8
+ * By default, {@link extractUsageStatistics} requires a generator, but sometimes you already know all the files
9
+ * that you want to process. This function simply reps your requests as a generator.
10
+ */
11
+ export declare function staticRequests(...requests: (RParseRequestFromText | RParseRequestFromFile)[]): AsyncGenerator<RParseRequestFromText | RParseRequestFromFile>;
12
+ type DataflowResult = PipelineOutput<typeof DEFAULT_DATAFLOW_PIPELINE>;
13
+ /**
14
+ * Extract all wanted statistic information from a set of requests using the presented R session.
15
+ *
16
+ * @param shell - The R session to use
17
+ * @param onRequest - A callback that is called at the beginning of each request, this may be used to debug the requests.
18
+ * @param features - The features to extract (see {@link allFeatureNames}).
19
+ * @param requests - The requests to extract the features from. May generate them on demand (e.g., by traversing a folder).
20
+ * If your request is statically known, you can use {@link staticRequests} to create this generator.
21
+ * @param rootPath - The root path to the project, this is used to relativize the file paths in the statistics.
22
+ */
23
+ export declare function extractUsageStatistics<T extends RParseRequestFromText | RParseRequestFromFile>(shell: RShell, onRequest: (request: T) => void, features: FeatureSelection, requests: AsyncGenerator<T>, rootPath?: string): Promise<{
24
+ features: FeatureStatistics;
25
+ meta: MetaStatistics;
26
+ outputs: Map<T, DataflowResult>;
27
+ }>;
28
+ export {};
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractUsageStatistics = exports.staticRequests = void 0;
7
+ const xmldom_1 = require("@xmldom/xmldom");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const meta_statistics_1 = require("./meta-statistics");
10
+ const log_1 = require("../util/log");
11
+ const json_1 = require("../util/json");
12
+ const pipeline_executor_1 = require("../core/pipeline-executor");
13
+ const default_pipelines_1 = require("../core/steps/pipeline/default-pipelines");
14
+ const feature_1 = require("./features/feature");
15
+ const convert_values_1 = require("../r-bridge/lang-4.x/convert-values");
16
+ /**
17
+ * By default, {@link extractUsageStatistics} requires a generator, but sometimes you already know all the files
18
+ * that you want to process. This function simply reps your requests as a generator.
19
+ */
20
+ function staticRequests(...requests) {
21
+ // eslint-disable-next-line @typescript-eslint/require-await
22
+ return async function* () {
23
+ for (const request of requests) {
24
+ yield request;
25
+ }
26
+ }();
27
+ }
28
+ exports.staticRequests = staticRequests;
29
+ /**
30
+ * Extract all wanted statistic information from a set of requests using the presented R session.
31
+ *
32
+ * @param shell - The R session to use
33
+ * @param onRequest - A callback that is called at the beginning of each request, this may be used to debug the requests.
34
+ * @param features - The features to extract (see {@link allFeatureNames}).
35
+ * @param requests - The requests to extract the features from. May generate them on demand (e.g., by traversing a folder).
36
+ * If your request is statically known, you can use {@link staticRequests} to create this generator.
37
+ * @param rootPath - The root path to the project, this is used to relativize the file paths in the statistics.
38
+ */
39
+ async function extractUsageStatistics(shell, onRequest, features, requests, rootPath) {
40
+ let result = initializeFeatureStatistics();
41
+ const meta = (0, meta_statistics_1.initialMetaStatistics)();
42
+ const outputs = new Map();
43
+ for await (const request of requests) {
44
+ onRequest(request);
45
+ const start = performance.now();
46
+ const suffix = request.request === 'file' ? request.content.replace(new RegExp('^' + (rootPath ?? '')), '') : undefined;
47
+ try {
48
+ let output;
49
+ ({ stats: result, output } = await extractSingle(result, shell, request, features, suffix));
50
+ outputs.set(request, output);
51
+ processMetaOnSuccessful(meta, request);
52
+ meta.numberOfNormalizedNodes.push(output.normalize.idMap.size);
53
+ }
54
+ catch (e) {
55
+ log_1.log.error('for request: ', request, e);
56
+ processMetaOnUnsuccessful(meta, request);
57
+ }
58
+ meta.processingTimeMs.push(performance.now() - start);
59
+ }
60
+ return { features: result, meta, outputs };
61
+ }
62
+ exports.extractUsageStatistics = extractUsageStatistics;
63
+ function initializeFeatureStatistics() {
64
+ const result = {};
65
+ for (const key of feature_1.allFeatureNames) {
66
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
67
+ result[key] = JSON.parse(JSON.stringify(feature_1.ALL_FEATURES[key].initialValue, json_1.jsonReplacer), json_1.jsonRetriever);
68
+ }
69
+ return result;
70
+ }
71
+ function processMetaOnUnsuccessful(meta, request) {
72
+ meta.failedRequests.push(request);
73
+ }
74
+ function processMetaOnSuccessful(meta, request) {
75
+ meta.successfulParsed++;
76
+ if (request.request === 'text') {
77
+ meta.lines.push(request.content.split('\n').map(l => l.length));
78
+ }
79
+ else {
80
+ meta.lines.push(fs_1.default.readFileSync(request.content, 'utf-8').split('\n').map(l => l.length));
81
+ }
82
+ }
83
+ const parser = new xmldom_1.DOMParser();
84
+ async function extractSingle(result, shell, request, features, suffixFilePath) {
85
+ const slicerOutput = await new pipeline_executor_1.PipelineExecutor(default_pipelines_1.DEFAULT_DATAFLOW_PIPELINE, {
86
+ request, shell
87
+ }).allRemainingSteps();
88
+ // retrieve parsed xml through (legacy) xmlparsedata
89
+ const suffix = request.request === 'file' ? ', encoding="utf-8"' : '';
90
+ shell.sendCommands(`try(flowr_parsed<-parse(${request.request}=${JSON.stringify(request.content)},keep.source=TRUE${suffix}),silent=FALSE)`, 'try(flowr_output<-xmlparsedata::xml_parse_data(flowr_parsed,includeText=TRUE,pretty=FALSE),silent=FALSE)');
91
+ const parsed = (await shell.sendCommandWithOutput(`cat(flowr_output,${(0, convert_values_1.ts2r)(shell.options.eol)})`)).join(shell.options.eol);
92
+ const doc = parser.parseFromString(parsed, 'text/xml');
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ for (const [key, feature] of Object.entries(feature_1.ALL_FEATURES)) {
95
+ if (features !== 'all' && !features.has(key)) {
96
+ continue;
97
+ }
98
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
99
+ result[key] = feature.process(result[key], {
100
+ parsedRAst: doc,
101
+ dataflow: slicerOutput.dataflow,
102
+ normalizedRAst: slicerOutput.normalize,
103
+ filepath: suffixFilePath
104
+ });
105
+ }
106
+ return { stats: result, output: slicerOutput };
107
+ }
108
+ //# sourceMappingURL=statistics.js.map
@@ -0,0 +1,2 @@
1
+ import { SummarizerType } from '../../util/summarizer';
2
+ export declare function detectSummarizationType(inputPath: string): Promise<SummarizerType>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.detectSummarizationType = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const summarizer_1 = require("./summarizer");
9
+ const log_1 = require("../../util/log");
10
+ async function detectSummarizationType(inputPath) {
11
+ if (fs_1.default.statSync(inputPath).isFile()) {
12
+ log_1.log.info(`Detected benchmark summarization with single file ${inputPath}`);
13
+ return "benchmark" /* SummarizerType.Benchmark */;
14
+ }
15
+ // current heuristic: search for a tar.gz with two minus signs :D
16
+ const dir = await fs_1.default.promises.opendir(inputPath);
17
+ const thresholdInit = 60;
18
+ let threshold = thresholdInit;
19
+ for await (const dirent of dir) {
20
+ if (summarizer_1.statisticsFileNameRegex.test(dirent.name)) {
21
+ log_1.log.info(`Detected statistics summarization by file ${dirent.name} matching ${summarizer_1.statisticsFileNameRegex.source}`);
22
+ return "statistics" /* SummarizerType.Statistics */;
23
+ }
24
+ else if (threshold-- < 0) {
25
+ break;
26
+ }
27
+ }
28
+ log_1.log.info(`Detected benchmark summarization with no file (first ${thresholdInit}) matching ${summarizer_1.statisticsFileNameRegex.source}`);
29
+ return "benchmark" /* SummarizerType.Benchmark */;
30
+ }
31
+ exports.detectSummarizationType = detectSummarizationType;
32
+ //# sourceMappingURL=auto-detect.js.map
@@ -0,0 +1,6 @@
1
+ export declare class FileMigrator {
2
+ private readonly writeHandles;
3
+ private finished;
4
+ migrate(sourceFolderContent: Map<string, string>, targetFolder: string, originalFile: string | undefined): Promise<void>;
5
+ finish(): void;
6
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FileMigrator = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const assert_1 = require("../../../util/assert");
10
+ class FileMigrator {
11
+ writeHandles = new Map();
12
+ finished = false;
13
+ async migrate(sourceFolderContent, targetFolder, originalFile) {
14
+ (0, assert_1.guard)(!this.finished, () => 'migrator is already marked as finished!');
15
+ if (!fs_1.default.existsSync(targetFolder)) {
16
+ fs_1.default.mkdirSync(targetFolder, { recursive: true });
17
+ }
18
+ const promises = [];
19
+ for (const [filepath, content] of sourceFolderContent.entries()) {
20
+ const target = path_1.default.join(targetFolder, filepath);
21
+ let targetStream = this.writeHandles.get(target);
22
+ if (targetStream === undefined) {
23
+ if (!fs_1.default.existsSync(path_1.default.dirname(target))) {
24
+ fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
25
+ }
26
+ targetStream = fs_1.default.createWriteStream(target, { flags: 'a' });
27
+ this.writeHandles.set(target, targetStream);
28
+ }
29
+ // before we write said content we have to group {value: string, context: string} by context (while we can safely assume that there is only one context per file,
30
+ // i want to be sure
31
+ let data;
32
+ // regex matches failed due to encoding errors
33
+ if (filepath.endsWith('meta/stats.txt') || filepath.endsWith('meta/features.txt')) {
34
+ data = `{"file":"${originalFile ?? ''}","content":${content.trimEnd()}}\n`;
35
+ }
36
+ else {
37
+ const grouped = groupByContext(content);
38
+ data = grouped === undefined ? content : grouped.map(s => JSON.stringify(s)).join('\n') + '\n';
39
+ }
40
+ promises.push(new Promise((resolve, reject) => targetStream.write(data, 'utf-8', err => {
41
+ if (err) {
42
+ reject(err);
43
+ }
44
+ else {
45
+ resolve();
46
+ }
47
+ })));
48
+ }
49
+ await Promise.all(promises);
50
+ }
51
+ finish() {
52
+ for (const handle of this.writeHandles.values()) {
53
+ handle.close();
54
+ }
55
+ this.finished = true;
56
+ }
57
+ }
58
+ exports.FileMigrator = FileMigrator;
59
+ function groupByContext(input) {
60
+ if (input === undefined) {
61
+ return [];
62
+ }
63
+ const parsed = input.split('\n').filter(s => s && s !== '').map(s => JSON.parse(s));
64
+ const grouped = new Map();
65
+ for (const content of parsed) {
66
+ if (!Array.isArray(content)) {
67
+ // in this case it is a meta file or other which does not have to be grouped
68
+ return undefined;
69
+ }
70
+ const [value, context] = content;
71
+ const get = grouped.get(context);
72
+ if (get === undefined) {
73
+ grouped.set(context, [value]);
74
+ }
75
+ else {
76
+ get.push(value);
77
+ }
78
+ }
79
+ return [...grouped.entries()].map(([context, values]) => [values, context]);
80
+ }
81
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1,26 @@
1
+ import { DefaultMap } from '../../../util/defaultmap';
2
+ import type { MergeableRecord } from '../../../util/objects';
3
+ import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ export type ContextsWithCount = DefaultMap<NodeId, number>;
5
+ export type ClusterContextIdMap = DefaultMap<string | undefined, NodeId>;
6
+ export type ClusterValueInfoMap = DefaultMap<string, ContextsWithCount>;
7
+ /** Produced by {@link clusterStatisticsOutput} */
8
+ export interface ClusterReport extends MergeableRecord {
9
+ /** The input file which has been clustered */
10
+ readonly filepath: string;
11
+ /** Maps each context encountered (i.e., every file which contains something associated with the feature) to a unique id, used in the {@link ClusterReport#valueInfoMap | valueInfoMap}. */
12
+ contextIdMap: ClusterContextIdMap;
13
+ /**
14
+ * Counts which contexts contained which values of a feature.
15
+ * For example, that `<-` occurred in files with ids `[12, 42, 19, 19]` (i.e., the context with the id 19 contained it twice).
16
+ */
17
+ valueInfoMap: ClusterValueInfoMap;
18
+ }
19
+ /**
20
+ * Takes a statistics file like `statistics-out/top-2023-01-01-00-00-00/Assignments/assignmentOperator.txt` and clusters the values by context
21
+ *
22
+ * @param filepath - Filepath of the statistics file
23
+ * @param contextIdMap - The id map to use, can use an existing one to reuse ids for same contexts spreading over multiple input files.
24
+ * `undefined` is used for unknown contexts. This map allows us to reference contexts with a way shorter identifier (vs. the full file path).
25
+ */
26
+ export declare function clusterStatisticsOutput(filepath: string, contextIdMap?: ClusterContextIdMap): ClusterReport;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clusterStatisticsOutput = void 0;
7
+ /**
8
+ * Reading the given file line by line and expecting constructs of {@link StatisticsOutputFormat},
9
+ * this module is responsible for identifying interesting groups of same data.
10
+ *
11
+ * @module
12
+ */
13
+ const n_readlines_1 = __importDefault(require("n-readlines"));
14
+ const defaultmap_1 = require("../../../util/defaultmap");
15
+ const decorate_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/decorate");
16
+ /**
17
+ * Takes a statistics file like `statistics-out/top-2023-01-01-00-00-00/Assignments/assignmentOperator.txt` and clusters the values by context
18
+ *
19
+ * @param filepath - Filepath of the statistics file
20
+ * @param contextIdMap - The id map to use, can use an existing one to reuse ids for same contexts spreading over multiple input files.
21
+ * `undefined` is used for unknown contexts. This map allows us to reference contexts with a way shorter identifier (vs. the full file path).
22
+ */
23
+ function clusterStatisticsOutput(filepath, contextIdMap = new defaultmap_1.DefaultMap((0, decorate_1.deterministicCountingIdGenerator)())) {
24
+ const lineReader = new n_readlines_1.default(filepath);
25
+ // for each value we store the context ids it was seen in (may list the same context multiple times if more often) - this serves as a counter as well
26
+ const valueInfoMap = new defaultmap_1.DefaultMap(() => new defaultmap_1.DefaultMap(() => 0));
27
+ let line;
28
+ // eslint-disable-next-line no-cond-assign
29
+ while (line = lineReader.next()) {
30
+ const json = JSON.parse(line.toString());
31
+ const contextId = contextIdMap.get(json[1]);
32
+ const value = valueInfoMap.get(json[0]);
33
+ // step the counter accordingly
34
+ value.set(contextId, value.get(contextId) + 1);
35
+ }
36
+ return {
37
+ filepath,
38
+ contextIdMap,
39
+ valueInfoMap
40
+ };
41
+ }
42
+ exports.clusterStatisticsOutput = clusterStatisticsOutput;
43
+ //# sourceMappingURL=clusterer.js.map
@@ -0,0 +1,17 @@
1
+ import type { ClusterReport } from './clusterer';
2
+ export interface FileBasedTable {
3
+ header: string[];
4
+ rows: string[][];
5
+ }
6
+ /**
7
+ * The purpose of this function is to reformat {@link ClusterReport} in way that lists file-based contributions.
8
+ * E.g., "the file with id 12 contained the assignment with `<-` 3 times".
9
+ * Feature Values are listed in the header.
10
+ *
11
+ * @param report - the report to reformat
12
+ */
13
+ export declare function fileBasedCount(report: ClusterReport): FileBasedTable;
14
+ /**
15
+ * The threshold will cap of values larger to the threshold.
16
+ */
17
+ export declare function writeFileBasedCountToFile(table: FileBasedTable, filepath: string): void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.writeFileBasedCountToFile = exports.fileBasedCount = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ /**
9
+ * The purpose of this function is to reformat {@link ClusterReport} in way that lists file-based contributions.
10
+ * E.g., "the file with id 12 contained the assignment with `<-` 3 times".
11
+ * Feature Values are listed in the header.
12
+ *
13
+ * @param report - the report to reformat
14
+ */
15
+ function fileBasedCount(report) {
16
+ const values = report.valueInfoMap;
17
+ const contexts = [...report.valueInfoMap.values()];
18
+ const header = [...values.keys()].map(k => `"${k}"`);
19
+ const rows = [];
20
+ for (const id of report.contextIdMap.values()) {
21
+ rows.push(contexts.map(c => `${c.get(id)}`));
22
+ }
23
+ return {
24
+ header: header,
25
+ rows: rows
26
+ };
27
+ }
28
+ exports.fileBasedCount = fileBasedCount;
29
+ /**
30
+ * The threshold will cap of values larger to the threshold.
31
+ */
32
+ function writeFileBasedCountToFile(table, filepath) {
33
+ const handle = fs_1.default.openSync(filepath, 'w');
34
+ const header = table.header.join('\t');
35
+ fs_1.default.writeSync(handle, `${header}\n`);
36
+ let max = 0;
37
+ function processEntry(r) {
38
+ const val = Number(r);
39
+ max = Math.max(val, max);
40
+ return r;
41
+ }
42
+ for (const row of table.rows) {
43
+ fs_1.default.writeSync(handle, row.map(processEntry).join('\t') + '\n');
44
+ }
45
+ fs_1.default.writeSync(handle, `%%% max: ${max}\n`);
46
+ fs_1.default.closeSync(handle);
47
+ }
48
+ exports.writeFileBasedCountToFile = writeFileBasedCountToFile;
49
+ //# sourceMappingURL=file-based-count.js.map
@@ -0,0 +1,59 @@
1
+ import type { ClusterReport } from './clusterer';
2
+ import type { Table } from '../../../util/files';
3
+ /**
4
+ * A conventional histogram (e.g., created by {@link histogramFromNumbers}).
5
+ * Can be converted to a {@link Table} by {@link histograms2table}.
6
+ * As described in {@link histogramFromNumbers}, there always will be a special bin for minimum.
7
+ */
8
+ export interface Histogram {
9
+ /** A name intended for humans to know what the histogram is about. */
10
+ readonly name: string;
11
+ /** Values located in each bin */
12
+ bins: number[];
13
+ /** The configured size of each bin (stored explicitly to avoid semantic confusion with floating point arithmetic/problems with different rounding schemes) */
14
+ binSize: number;
15
+ /** Minimum value encountered (inclusive minimum of the underlying value range) */
16
+ min: number;
17
+ /** Maximum value encountered (inclusive maximum of the underlying value range) */
18
+ max: number;
19
+ /** Average of the included numbers */
20
+ mean: number;
21
+ /** Standard deviation of the included numbers */
22
+ std: number;
23
+ /** Median of the included numbers */
24
+ median: number;
25
+ }
26
+ /**
27
+ * Produces column-wise histogram-information based on a {@link ClusterReport}.
28
+ *
29
+ * Let's suppose you want histograms for the Assignments feature.
30
+ * By default, for each clustered value, a histogram is produced (can be configured by `filter`).
31
+ *
32
+ * @param report - The report to collect histogram information from
33
+ * @param binSize - Size of each bin (see {@link histogramFromNumbers} for details on why we do not specify the bin-count)
34
+ * @param relateValuesToNumberOfLines - If true, each value (like `<-` appeared in file 'x' exactly `N` times) will be divided by the number of lines in the file 'x'.
35
+ * @param filter - If given, only produce histograms for the given values
36
+ */
37
+ export declare function histogramsFromClusters(report: ClusterReport, binSize: number, relateValuesToNumberOfLines: boolean, ...filter: string[]): Histogram[];
38
+ /**
39
+ * Produces a histogram from a list of numbers.
40
+ * Because we need to create several histograms of different datasets and want to compare them, we do not accept the
41
+ * number of bins desired and calculate the bin-size from the data (via `Math.ceil((max - min + 1) / bins)`).
42
+ * Instead, we require the bin-size to be given.
43
+ * There *always* will be an extra bin for the minimum value.
44
+ */
45
+ export declare function histogramFromNumbers(name: string, binSize: number, values: number[]): Histogram;
46
+ /**
47
+ * Takes an array of histograms created by {@link histogramFromNumbers} and produces a CSV table from it.
48
+ * They must have the same bin-size for this function to work.
49
+ *
50
+ * The table has the following columns:
51
+ * - `bin` - The corresponding bin number
52
+ * - `from` - The exclusive lower bound of the bin
53
+ * - `to` - The inclusive upper bound of the bin
54
+ * - a column with the name of each histogram, containing its count of values in the corresponding bin
55
+ *
56
+ * @param histograms - The histogram to convert (assumed to have the same ranges and bins)
57
+ * @param countAsDensity - If true, the count is divided by the total number of values (individually for each histogram, similar to pgfplots `hist/density` option)
58
+ */
59
+ export declare function histograms2table(histograms: Histogram[], countAsDensity?: boolean): Table;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.histograms2table = exports.histogramFromNumbers = exports.histogramsFromClusters = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const bimap_1 = require("../../../util/bimap");
9
+ const defaultmap_1 = require("../../../util/defaultmap");
10
+ const assert_1 = require("../../../util/assert");
11
+ const summarizer_1 = require("../../../util/summarizer");
12
+ /**
13
+ * Produces column-wise histogram-information based on a {@link ClusterReport}.
14
+ *
15
+ * Let's suppose you want histograms for the Assignments feature.
16
+ * By default, for each clustered value, a histogram is produced (can be configured by `filter`).
17
+ *
18
+ * @param report - The report to collect histogram information from
19
+ * @param binSize - Size of each bin (see {@link histogramFromNumbers} for details on why we do not specify the bin-count)
20
+ * @param relateValuesToNumberOfLines - If true, each value (like `<-` appeared in file 'x' exactly `N` times) will be divided by the number of lines in the file 'x'.
21
+ * @param filter - If given, only produce histograms for the given values
22
+ */
23
+ function histogramsFromClusters(report, binSize, relateValuesToNumberOfLines, ...filter) {
24
+ const contexts = [...report.valueInfoMap.entries()];
25
+ const filenameFromId = new bimap_1.BiMap(report.contextIdMap.entries());
26
+ // first, we collect the number of appearances for each value
27
+ const valueCounts = new defaultmap_1.DefaultMap(() => []);
28
+ for (const id of report.contextIdMap.values()) {
29
+ // calculate the number of lines within the file given by the id
30
+ const filename = filenameFromId.getKey(id);
31
+ (0, assert_1.guard)(filename !== undefined, `filename for id ${id} is undefined`);
32
+ const numberOfLines = relateValuesToNumberOfLines ? fs_1.default.readFileSync(filename, 'utf-8').split('\n').length : 1;
33
+ for (const [value, counts] of contexts) {
34
+ valueCounts.get(value).push(counts.get(id) / numberOfLines);
35
+ }
36
+ }
37
+ return [...valueCounts.entries()].map(([name, counts]) => filter.length === 0 || filter.includes(name) ? histogramFromNumbers(name, binSize, counts) : undefined).filter(assert_1.isNotUndefined);
38
+ }
39
+ exports.histogramsFromClusters = histogramsFromClusters;
40
+ /**
41
+ * Produces a histogram from a list of numbers.
42
+ * Because we need to create several histograms of different datasets and want to compare them, we do not accept the
43
+ * number of bins desired and calculate the bin-size from the data (via `Math.ceil((max - min + 1) / bins)`).
44
+ * Instead, we require the bin-size to be given.
45
+ * There *always* will be an extra bin for the minimum value.
46
+ */
47
+ function histogramFromNumbers(name, binSize, values) {
48
+ (0, assert_1.guard)(binSize > 0, `binSize must be greater than 0, but was ${binSize}`);
49
+ (0, assert_1.guard)(values.length > 0, 'values must not be empty');
50
+ const summarized = (0, summarizer_1.summarizeMeasurement)(values);
51
+ const numberOfBins = Math.ceil((summarized.max - summarized.min + 1) / binSize) + 1;
52
+ const histogram = new Array(numberOfBins).fill(0);
53
+ for (const v of values) {
54
+ const bin = v === summarized.min ? 0 : Math.floor((v - summarized.min) / binSize) + 1;
55
+ histogram[bin]++;
56
+ }
57
+ return {
58
+ name: name,
59
+ bins: histogram,
60
+ binSize,
61
+ ...summarized
62
+ };
63
+ }
64
+ exports.histogramFromNumbers = histogramFromNumbers;
65
+ /**
66
+ * Takes an array of histograms created by {@link histogramFromNumbers} and produces a CSV table from it.
67
+ * They must have the same bin-size for this function to work.
68
+ *
69
+ * The table has the following columns:
70
+ * - `bin` - The corresponding bin number
71
+ * - `from` - The exclusive lower bound of the bin
72
+ * - `to` - The inclusive upper bound of the bin
73
+ * - a column with the name of each histogram, containing its count of values in the corresponding bin
74
+ *
75
+ * @param histograms - The histogram to convert (assumed to have the same ranges and bins)
76
+ * @param countAsDensity - If true, the count is divided by the total number of values (individually for each histogram, similar to pgfplots `hist/density` option)
77
+ */
78
+ function histograms2table(histograms, countAsDensity = false) {
79
+ (0, assert_1.guard)(histograms.length > 0, 'there must be at least one histogram to convert to a table');
80
+ const mostBins = guardForLargestBinSize(histograms);
81
+ const header = ['bin', 'from', 'to', ...histograms.map(h => JSON.stringify(h.name))];
82
+ const sums = histograms.map(h => h.bins.reduce((a, b) => a + b, 0));
83
+ const rows = [];
84
+ for (let binIndex = 0; binIndex < mostBins; binIndex++) {
85
+ const row = new Array(histograms.length + 3);
86
+ row[0] = String(binIndex);
87
+ if (binIndex === 0) {
88
+ row[1] = histograms[0].min.toFixed(3);
89
+ row[2] = histograms[0].min.toFixed(3);
90
+ }
91
+ else {
92
+ row[1] = String((binIndex - 1) * histograms[0].binSize + histograms[0].min);
93
+ row[2] = String((binIndex) * histograms[0].binSize + histograms[0].min);
94
+ }
95
+ // fill remaining columns
96
+ writeRoResultsForHistograms(histograms, binIndex, row, countAsDensity, sums);
97
+ rows.push(row);
98
+ }
99
+ return {
100
+ header: header,
101
+ rows: rows
102
+ };
103
+ }
104
+ exports.histograms2table = histograms2table;
105
+ function guardForLargestBinSize(histograms) {
106
+ const first = histograms[0];
107
+ let mostBins = first.bins.length;
108
+ for (let i = 1; i < histograms.length; i++) {
109
+ (0, assert_1.guard)(histograms[i].binSize === first.binSize, `histograms must have the same bin-size, but ${histograms[i].name} has ${histograms[i].binSize} instead of ${first.binSize}`);
110
+ if (histograms[i].bins.length > mostBins) {
111
+ mostBins = histograms[i].bins.length;
112
+ }
113
+ }
114
+ return mostBins;
115
+ }
116
+ function writeRoResultsForHistograms(histograms, binIndex, row, countAsDensity, sums) {
117
+ for (let j = 0; j < histograms.length; j++) {
118
+ const bins = histograms[j].bins;
119
+ // does not have to be performant...
120
+ if (binIndex >= bins.length) {
121
+ row[j + 3] = '0'; /* in a histogram, 0 is the best default value for bins that are not present -- no value appeared in the corresponding bin */
122
+ }
123
+ else {
124
+ row[j + 3] = String(countAsDensity ? bins[binIndex] / sums[j] : bins[binIndex]);
125
+ }
126
+ }
127
+ }
128
+ //# sourceMappingURL=histogram.js.map