From 77042e8c74f25024b2b69988250a3e900a329dc3 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 8 Oct 2024 15:49:46 +0300 Subject: [PATCH 1/4] Print attributes histogram from ets --- arkoala/ets-plugin/src/StructTransformer.ts | 7 +- .../test/scripts/attributes-histogram.mjs | 65 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 arkoala/ets-plugin/test/scripts/attributes-histogram.mjs diff --git a/arkoala/ets-plugin/src/StructTransformer.ts b/arkoala/ets-plugin/src/StructTransformer.ts index 986a01b3e..e14463b8d 100644 --- a/arkoala/ets-plugin/src/StructTransformer.ts +++ b/arkoala/ets-plugin/src/StructTransformer.ts @@ -911,6 +911,9 @@ export class StructTransformer extends AbstractVisitor { translateBuiltinEtsComponent(node: ts.EtsComponentExpression): ts.CallExpression { const newName = this.findEtsAdaptorName(node.expression) + if (ts.isIdentifier(node.expression)) { + console.log(">>> " + ts.idText(node.expression)) + } return this.translateEtsComponent(node, newName) } @@ -975,7 +978,9 @@ export class StructTransformer extends AbstractVisitor { const parentName = parent.name if (!parentName || !ts.isIdentifier(parentName)) return false const parentNameString = ts.idText(parentName) - + if (parentNameString.endsWith("Attribute") || parentNameString.endsWith("Method")) { + console.log(">>> ." + name.getText() + " of " + parentNameString) + } const ohosDeclaredClass = parentNameString.endsWith("Attribute") || parentNameString == "CommonMethod" diff --git a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs new file mode 100644 index 000000000..0cd0bbd59 --- /dev/null +++ b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs @@ -0,0 +1,65 @@ +// Handles output of the ets transformer with component attributes printing enabled and prints histogram + +import fs from "fs" + +const INPUT_FILE = process.argv[2] + +const COMPONENT_PATTERN = /^[^a-zA-Z0-9]*([a-zA-Z0-9]+)$/ +const ATTRIBUTE_PATTERN = /^[^a-zA-Z0-9]*\.(.+)\sof\s(.*)$/ + +const ATTRIBUTE_TYPES_MAP = new Map() + +function mergeByComponent() { + let currentComponent = "unknown" + parseInput(token => { + if (!parseAttribute(token, currentComponent)) { + const match = token.match(COMPONENT_PATTERN) + if (match) { + currentComponent = match.splice(1)[0] + } + } + }) +} + +function mergeByAttributeType() { + parseInput(token => { + parseAttribute(token) + }) +} + +function parseInput(callback) { + const content = fs.readFileSync(INPUT_FILE) + "" + content.split(/\r?\n/).forEach(token => callback(token)) +} + +function parseAttribute(token, component = undefined) { + const match = token.match(ATTRIBUTE_PATTERN) + if (!match) { + return false + } + const groups = match.splice(1) + const attribute = groups[0] + const attributeType = component ?? groups[1] + + const attributesMap = ATTRIBUTE_TYPES_MAP.get(attributeType) ?? new Map() + let freq = attributesMap.get(attribute) ?? 0 + attributesMap.set(attribute, ++freq) + ATTRIBUTE_TYPES_MAP.set(attributeType, attributesMap) + + return true +} + +function printHistogram() { + console.log(".attribute : frequency") + ATTRIBUTE_TYPES_MAP.forEach((attributesMap, attributeType) => { + console.log("----------------------") + console.log(attributeType) + attributesMap.forEach((freq, attribute) => { + console.log(`.${attribute} : ${freq}`) + }) + }) +} + +// mergeByComponent() +mergeByAttributeType() +printHistogram() -- Gitee From be997b849a0d495d442be138b3ec2cce740a1350 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Thu, 10 Oct 2024 18:44:00 +0300 Subject: [PATCH 2/4] Fix attributes-histogram.mjs by components stats Signed-off-by: Anton Tarasov --- arkoala/ets-plugin/src/StructTransformer.ts | 6 ++-- .../test/scripts/attributes-histogram.mjs | 30 ++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arkoala/ets-plugin/src/StructTransformer.ts b/arkoala/ets-plugin/src/StructTransformer.ts index e14463b8d..bdf610362 100644 --- a/arkoala/ets-plugin/src/StructTransformer.ts +++ b/arkoala/ets-plugin/src/StructTransformer.ts @@ -911,9 +911,6 @@ export class StructTransformer extends AbstractVisitor { translateBuiltinEtsComponent(node: ts.EtsComponentExpression): ts.CallExpression { const newName = this.findEtsAdaptorName(node.expression) - if (ts.isIdentifier(node.expression)) { - console.log(">>> " + ts.idText(node.expression)) - } return this.translateEtsComponent(node, newName) } @@ -1092,6 +1089,9 @@ export class StructTransformer extends AbstractVisitor { } visitor(beforeChildren: ts.Node): ts.Node { + if (ts.isEtsComponentExpression(beforeChildren) && ts.isIdentifier(beforeChildren.expression)) { + console.log(">>> " + ts.idText(beforeChildren.expression)) + } const node = this.visitEachChild(beforeChildren) if (ts.isStructDeclaration(node)) { return this.translateStructToClass(node) diff --git a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs index 0cd0bbd59..2cd081597 100644 --- a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs +++ b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs @@ -1,8 +1,10 @@ -// Handles output of the ets transformer with component attributes printing enabled and prints histogram - import fs from "fs" +const MERGE_BY_COMPONENT = "--by-component" +const MERGE_BY_ATTRIBUTE_TYPE = "--by-attribute-type" + const INPUT_FILE = process.argv[2] +const MERGE_BY = process.argv[3] ?? MERGE_BY_COMPONENT const COMPONENT_PATTERN = /^[^a-zA-Z0-9]*([a-zA-Z0-9]+)$/ const ATTRIBUTE_PATTERN = /^[^a-zA-Z0-9]*\.(.+)\sof\s(.*)$/ @@ -38,8 +40,12 @@ function parseAttribute(token, component = undefined) { return false } const groups = match.splice(1) - const attribute = groups[0] - const attributeType = component ?? groups[1] + let attribute = groups[0] + let attributeType = groups[1] + if (component) { + attribute += ` (${attributeType})` + attributeType = component + } const attributesMap = ATTRIBUTE_TYPES_MAP.get(attributeType) ?? new Map() let freq = attributesMap.get(attribute) ?? 0 @@ -50,7 +56,11 @@ function parseAttribute(token, component = undefined) { } function printHistogram() { - console.log(".attribute : frequency") + if (MERGE_BY === MERGE_BY_COMPONENT) { + console.log(".attribute (type): frequency") + } else if (MERGE_BY === MERGE_BY_ATTRIBUTE_TYPE) { + console.log(".attribute : frequency") + } ATTRIBUTE_TYPES_MAP.forEach((attributesMap, attributeType) => { console.log("----------------------") console.log(attributeType) @@ -60,6 +70,12 @@ function printHistogram() { }) } -// mergeByComponent() -mergeByAttributeType() +if (MERGE_BY === MERGE_BY_COMPONENT) { + mergeByComponent() +} else if (MERGE_BY === MERGE_BY_ATTRIBUTE_TYPE) { + mergeByAttributeType() +} else { + console.log(`error: wrong option "${MERGE_BY}"`) + process.exit(1) +} printHistogram() -- Gitee From 21876ec90fb14d3d28060bbe65e50b09077b850d Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Fri, 11 Oct 2024 20:20:34 +0300 Subject: [PATCH 3/4] Parse options (in ctor) as well Signed-off-by: Anton Tarasov --- arkoala/ets-plugin/src/StructTransformer.ts | 11 +- .../test/scripts/attributes-histogram.mjs | 115 ++++++++++++++---- 2 files changed, 97 insertions(+), 29 deletions(-) diff --git a/arkoala/ets-plugin/src/StructTransformer.ts b/arkoala/ets-plugin/src/StructTransformer.ts index bdf610362..2a9f72940 100644 --- a/arkoala/ets-plugin/src/StructTransformer.ts +++ b/arkoala/ets-plugin/src/StructTransformer.ts @@ -976,7 +976,7 @@ export class StructTransformer extends AbstractVisitor { if (!parentName || !ts.isIdentifier(parentName)) return false const parentNameString = ts.idText(parentName) if (parentNameString.endsWith("Attribute") || parentNameString.endsWith("Method")) { - console.log(">>> ." + name.getText() + " of " + parentNameString) + console.log(">>>\t\t[M] " + name.getText() + " of " + parentNameString) } const ohosDeclaredClass = parentNameString.endsWith("Attribute") || @@ -1090,7 +1090,14 @@ export class StructTransformer extends AbstractVisitor { visitor(beforeChildren: ts.Node): ts.Node { if (ts.isEtsComponentExpression(beforeChildren) && ts.isIdentifier(beforeChildren.expression)) { - console.log(">>> " + ts.idText(beforeChildren.expression)) + console.log(">>>\t[C] " + ts.idText(beforeChildren.expression)) + } + if (ts.isPropertyAssignment(beforeChildren)) { + const parent = beforeChildren.parent?.parent + if (ts.isEtsComponentExpression(parent) && ts.isIdentifier(parent.expression)) { + // const parentName = ts.idText(parent.expression) + console.log(">>>\t\t[O] " + beforeChildren.name.getText()) + } } const node = this.visitEachChild(beforeChildren) if (ts.isStructDeclaration(node)) { diff --git a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs index 2cd081597..67c4a594d 100644 --- a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs +++ b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs @@ -6,21 +6,38 @@ const MERGE_BY_ATTRIBUTE_TYPE = "--by-attribute-type" const INPUT_FILE = process.argv[2] const MERGE_BY = process.argv[3] ?? MERGE_BY_COMPONENT -const COMPONENT_PATTERN = /^[^a-zA-Z0-9]*([a-zA-Z0-9]+)$/ -const ATTRIBUTE_PATTERN = /^[^a-zA-Z0-9]*\.(.+)\sof\s(.*)$/ +const COMPONENT_PATTERN = /^.*\[C]\s([a-zA-Z0-9]+)$/ +const MODIFIER_PATTERN = /^.*\[M]\s(.+)\sof\s(.*)$/ +const OPTION_PATTERN = /^.*\[O]\s(.+)$/ +// 'attribute' is a 'modifier' (method) or an 'option' (ctor arg) const ATTRIBUTE_TYPES_MAP = new Map() +const KEY_UNCOMPLETED_OPTIONS_VARIANT = "KEY_UNCOMPLETED_OPTIONS_VARIANT" // a sorted list of 'option's variant being parsed +const KEY_OPTIONS_VARIANTS = "KEY_OPTIONS_VARIANTS" // a list of 'option's variants (an 'option's variant is a certain ctor call) + +const LOG_ENABLED = false + +function log(msg) { + if (LOG_ENABLED) console.log("> " + msg) +} + +function specialKey(key) { + return key === KEY_UNCOMPLETED_OPTIONS_VARIANT || key === KEY_OPTIONS_VARIANTS +} + function mergeByComponent() { - let currentComponent = "unknown" + let currentComponent = undefined parseInput(token => { - if (!parseAttribute(token, currentComponent)) { - const match = token.match(COMPONENT_PATTERN) - if (match) { - currentComponent = match.splice(1)[0] - } + const match = token.match(COMPONENT_PATTERN) + if (match) { + completeForComponent(currentComponent) // complete for prev component + currentComponent = match.splice(1)[0] + } else { + parseAttribute(token, currentComponent) } }) + completeForComponent(currentComponent) // complete for prev component } function mergeByAttributeType() { @@ -35,37 +52,81 @@ function parseInput(callback) { } function parseAttribute(token, component = undefined) { - const match = token.match(ATTRIBUTE_PATTERN) - if (!match) { - return false - } - const groups = match.splice(1) - let attribute = groups[0] - let attributeType = groups[1] - if (component) { - attribute += ` (${attributeType})` - attributeType = component + log("token: " + token + (component ? ", component: " + component : "")) + const match = token.match(MODIFIER_PATTERN) + if (match) { + const groups = match.splice(1) + let modifier = groups[0] + let modifierType = groups[1] // a super 'component' type where 'modifier' is originally defined + if (component) { + modifier += ` (${modifierType})` + modifierType = component + } + const attributesMap = ATTRIBUTE_TYPES_MAP.get(modifierType) ?? new Map() + let freq = attributesMap.get(modifier) ?? 0 + attributesMap.set(modifier, ++freq) + ATTRIBUTE_TYPES_MAP.set(modifierType, attributesMap) + + // parse 'option' only when 'component' is provided + } else if (component) { + const match = token.match(OPTION_PATTERN) + if (match) { + const groups = match.splice(1) + const option = groups[0] + const attributesMap = ATTRIBUTE_TYPES_MAP.get(component) ?? new Map() + const uncompleted = attributesMap.get(KEY_UNCOMPLETED_OPTIONS_VARIANT) ?? [] + let i = 0 + for (; i < uncompleted.length; i++) { + if (option < uncompleted[i]) break + } + uncompleted.splice(i, 0, option) + attributesMap.set(KEY_UNCOMPLETED_OPTIONS_VARIANT, uncompleted) + ATTRIBUTE_TYPES_MAP.set(component, attributesMap) + } } +} - const attributesMap = ATTRIBUTE_TYPES_MAP.get(attributeType) ?? new Map() - let freq = attributesMap.get(attribute) ?? 0 - attributesMap.set(attribute, ++freq) - ATTRIBUTE_TYPES_MAP.set(attributeType, attributesMap) +function completeForComponent(component) { + if (!component) { + return + } + const attributesMap = ATTRIBUTE_TYPES_MAP.get(component) + if (!attributesMap) { + // just add 'component' + ATTRIBUTE_TYPES_MAP.set(component, new Map()) + return + } + const uncompleted = attributesMap.get(KEY_UNCOMPLETED_OPTIONS_VARIANT) + if (uncompleted) { + attributesMap.set(KEY_UNCOMPLETED_OPTIONS_VARIANT, undefined) + const variant = uncompleted.join(", ") - return true + const allVariants = attributesMap.get(KEY_OPTIONS_VARIANTS) ?? new Map() + let freq = allVariants.get(variant) ?? 0 + allVariants.set(variant, ++freq) + attributesMap.set(KEY_OPTIONS_VARIANTS, allVariants) + } } function printHistogram() { + console.log("COMPONENT") if (MERGE_BY === MERGE_BY_COMPONENT) { - console.log(".attribute (type): frequency") + console.log("{OPTIONS}") + console.log(".ATTRIBUTE (SUPER_TYPE) : FREQUENCY") } else if (MERGE_BY === MERGE_BY_ATTRIBUTE_TYPE) { - console.log(".attribute : frequency") + console.log(".ATTRIBUTE : FREQUENCY") } ATTRIBUTE_TYPES_MAP.forEach((attributesMap, attributeType) => { console.log("----------------------") console.log(attributeType) - attributesMap.forEach((freq, attribute) => { - console.log(`.${attribute} : ${freq}`) + const allVariants = attributesMap.get(KEY_OPTIONS_VARIANTS) ?? [] + allVariants.forEach((valueFreq, keyVariant) => { + console.log(`{${keyVariant}} : ${valueFreq}`) + }) + attributesMap.forEach((valueFreq, keyAttribute) => { + if (!specialKey(keyAttribute)) { + console.log(`.${keyAttribute} : ${valueFreq}`) + } }) }) } -- Gitee From 57bd3014b8a6d2dc9309ec2b2f8b9ca4983c73bd Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Mon, 14 Oct 2024 12:28:34 +0300 Subject: [PATCH 4/4] Refactor --- .../test/scripts/attributes-histogram.mjs | 202 +++++++++++------- 1 file changed, 124 insertions(+), 78 deletions(-) diff --git a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs index 67c4a594d..074867f15 100644 --- a/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs +++ b/arkoala/ets-plugin/test/scripts/attributes-histogram.mjs @@ -1,99 +1,151 @@ +// Parses an output of ets-plugin with component modifiers/options calls. +// Merges it by component or by super type and prints histogram with call frequency. + import fs from "fs" const MERGE_BY_COMPONENT = "--by-component" -const MERGE_BY_ATTRIBUTE_TYPE = "--by-attribute-type" +const MERGE_BY_SUPER_TYPE = "--by-super-type" + +const LOG_ENABLED = false + +function log(msg) { + if (LOG_ENABLED) console.log("> " + msg) +} const INPUT_FILE = process.argv[2] const MERGE_BY = process.argv[3] ?? MERGE_BY_COMPONENT -const COMPONENT_PATTERN = /^.*\[C]\s([a-zA-Z0-9]+)$/ -const MODIFIER_PATTERN = /^.*\[M]\s(.+)\sof\s(.*)$/ -const OPTION_PATTERN = /^.*\[O]\s(.+)$/ +// 'modifier' - A property setter method called on a component. +// E.g.: Button().width(30) +// 'modifier type' - A component or a super component a modifier is called/defined on. +// E.g.: Button().width(30) - the type of 'width' is Button or Common. +// 'option' - A property of a component set via an object literal passed to the component's ctor. +// 'options variant' - A sorted list of options in a certain component ctor call. +// E.g.: Rect({height: 100, radius: 10, width: 200}) +// 'attribute' - A 'modifier' or 'options variant'. + +class TokenKind { + name + pattern + constructor(name, pattern) { + this.name = name + this.pattern = pattern + } + toString() { + return this.name + } +} -// 'attribute' is a 'modifier' (method) or an 'option' (ctor arg) -const ATTRIBUTE_TYPES_MAP = new Map() +class Token { + kind + value + constructor(kind, value) { + this.kind = kind + this.value = value + log(`token: ${this.toString()}`) + } + toString() { + return `${this.kind.name} [${this.value.join(", ")}]` + } +} -const KEY_UNCOMPLETED_OPTIONS_VARIANT = "KEY_UNCOMPLETED_OPTIONS_VARIANT" // a sorted list of 'option's variant being parsed -const KEY_OPTIONS_VARIANTS = "KEY_OPTIONS_VARIANTS" // a list of 'option's variants (an 'option's variant is a certain ctor call) +const TK_COMPONENT = new TokenKind("Component", /^.*\[C]\s([a-zA-Z0-9]+)$/) +const TK_MODIFIER = new TokenKind("Modifier", /^.*\[M]\s(.+)\sof\s(.*)$/) +const TK_OPTION = new TokenKind("Option", /^.*\[O]\s(.+)$/) -const LOG_ENABLED = false +const COMPONENTS_MAP = new Map() -function log(msg) { - if (LOG_ENABLED) console.log("> " + msg) -} +// a variant being parsed +const KEY_UNCOMPLETED_OPTIONS_VARIANT = "KEY_UNCOMPLETED_OPTIONS_VARIANT" +const KEY_ALL_OPTIONS_VARIANTS = "KEY_ALL_OPTIONS_VARIANTS" function specialKey(key) { - return key === KEY_UNCOMPLETED_OPTIONS_VARIANT || key === KEY_OPTIONS_VARIANTS + return key === KEY_UNCOMPLETED_OPTIONS_VARIANT || key === KEY_ALL_OPTIONS_VARIANTS } -function mergeByComponent() { +function main() { let currentComponent = undefined parseInput(token => { - const match = token.match(COMPONENT_PATTERN) - if (match) { - completeForComponent(currentComponent) // complete for prev component - currentComponent = match.splice(1)[0] - } else { - parseAttribute(token, currentComponent) + switch (token.kind) { + case TK_COMPONENT: + componentExprCompleted(currentComponent) + currentComponent = token.value[0] + break + + case TK_MODIFIER: + let modifier = token.value[0] + let modifierType = token.value[1] + if (MERGE_BY === MERGE_BY_COMPONENT) { + modifier += ` (${modifierType})` + modifierType = currentComponent + } + addModifier(modifier, modifierType) + break + + case TK_OPTION: + if (MERGE_BY === MERGE_BY_COMPONENT) { + const option = token.value[0] + addOption(option, currentComponent) + } + break } }) - completeForComponent(currentComponent) // complete for prev component + componentExprCompleted(currentComponent) + printHistogram() } -function mergeByAttributeType() { - parseInput(token => { - parseAttribute(token) - }) -} - -function parseInput(callback) { +function parseInput(acceptToken) { const content = fs.readFileSync(INPUT_FILE) + "" - content.split(/\r?\n/).forEach(token => callback(token)) -} - -function parseAttribute(token, component = undefined) { - log("token: " + token + (component ? ", component: " + component : "")) - const match = token.match(MODIFIER_PATTERN) - if (match) { - const groups = match.splice(1) - let modifier = groups[0] - let modifierType = groups[1] // a super 'component' type where 'modifier' is originally defined - if (component) { - modifier += ` (${modifierType})` - modifierType = component + content.split(/\r?\n/).forEach(token => { + let match = token.match(TK_COMPONENT.pattern) + if (match) { + const component = match.splice(1)[0] + acceptToken(new Token(TK_COMPONENT, [component])) + return } - const attributesMap = ATTRIBUTE_TYPES_MAP.get(modifierType) ?? new Map() - let freq = attributesMap.get(modifier) ?? 0 - attributesMap.set(modifier, ++freq) - ATTRIBUTE_TYPES_MAP.set(modifierType, attributesMap) - - // parse 'option' only when 'component' is provided - } else if (component) { - const match = token.match(OPTION_PATTERN) + match = token.match(TK_MODIFIER.pattern) if (match) { const groups = match.splice(1) - const option = groups[0] - const attributesMap = ATTRIBUTE_TYPES_MAP.get(component) ?? new Map() - const uncompleted = attributesMap.get(KEY_UNCOMPLETED_OPTIONS_VARIANT) ?? [] - let i = 0 - for (; i < uncompleted.length; i++) { - if (option < uncompleted[i]) break - } - uncompleted.splice(i, 0, option) - attributesMap.set(KEY_UNCOMPLETED_OPTIONS_VARIANT, uncompleted) - ATTRIBUTE_TYPES_MAP.set(component, attributesMap) + const modifier = groups[0] + const modifierType = groups[1] + acceptToken(new Token(TK_MODIFIER, [modifier, modifierType])) + return } + match = token.match(TK_OPTION.pattern) + if (match) { + const option = match.splice(1)[0] + acceptToken(new Token(TK_OPTION, [option])) + } + }) +} + +function addModifier(modifier, modifierType) { + const modifiersMap = COMPONENTS_MAP.get(modifierType) ?? new Map() + let freq = modifiersMap.get(modifier) ?? 0 + modifiersMap.set(modifier, ++freq) + COMPONENTS_MAP.set(modifierType, modifiersMap) +} + +function addOption(option, component) { + const optionsMap = COMPONENTS_MAP.get(component) ?? new Map() + const uncompleted = optionsMap.get(KEY_UNCOMPLETED_OPTIONS_VARIANT) ?? [] + let i = 0 + for (; i < uncompleted.length; i++) { + if (option < uncompleted[i]) break } + uncompleted.splice(i, 0, option) + optionsMap.set(KEY_UNCOMPLETED_OPTIONS_VARIANT, uncompleted) + COMPONENTS_MAP.set(component, optionsMap) } -function completeForComponent(component) { +function componentExprCompleted(component) { if (!component) { return } - const attributesMap = ATTRIBUTE_TYPES_MAP.get(component) + const attributesMap = COMPONENTS_MAP.get(component) if (!attributesMap) { // just add 'component' - ATTRIBUTE_TYPES_MAP.set(component, new Map()) + COMPONENTS_MAP.set(component, new Map()) return } const uncompleted = attributesMap.get(KEY_UNCOMPLETED_OPTIONS_VARIANT) @@ -101,25 +153,27 @@ function completeForComponent(component) { attributesMap.set(KEY_UNCOMPLETED_OPTIONS_VARIANT, undefined) const variant = uncompleted.join(", ") - const allVariants = attributesMap.get(KEY_OPTIONS_VARIANTS) ?? new Map() + const allVariants = attributesMap.get(KEY_ALL_OPTIONS_VARIANTS) ?? new Map() let freq = allVariants.get(variant) ?? 0 allVariants.set(variant, ++freq) - attributesMap.set(KEY_OPTIONS_VARIANTS, allVariants) + attributesMap.set(KEY_ALL_OPTIONS_VARIANTS, allVariants) } } function printHistogram() { - console.log("COMPONENT") if (MERGE_BY === MERGE_BY_COMPONENT) { + console.log("COMPONENT") console.log("{OPTIONS}") - console.log(".ATTRIBUTE (SUPER_TYPE) : FREQUENCY") - } else if (MERGE_BY === MERGE_BY_ATTRIBUTE_TYPE) { + console.log(".ATTRIBUTE (SUPER TYPE) : FREQUENCY") + + } else if (MERGE_BY === MERGE_BY_SUPER_TYPE) { + console.log("COMPONENT (SUPER TYPE)") console.log(".ATTRIBUTE : FREQUENCY") } - ATTRIBUTE_TYPES_MAP.forEach((attributesMap, attributeType) => { + COMPONENTS_MAP.forEach((attributesMap, attributeType) => { console.log("----------------------") console.log(attributeType) - const allVariants = attributesMap.get(KEY_OPTIONS_VARIANTS) ?? [] + const allVariants = attributesMap.get(KEY_ALL_OPTIONS_VARIANTS) ?? [] allVariants.forEach((valueFreq, keyVariant) => { console.log(`{${keyVariant}} : ${valueFreq}`) }) @@ -131,12 +185,4 @@ function printHistogram() { }) } -if (MERGE_BY === MERGE_BY_COMPONENT) { - mergeByComponent() -} else if (MERGE_BY === MERGE_BY_ATTRIBUTE_TYPE) { - mergeByAttributeType() -} else { - console.log(`error: wrong option "${MERGE_BY}"`) - process.exit(1) -} -printHistogram() +main() -- Gitee