Skip to content

Commit 22d4c5b

Browse files
[Stats] Add percentage columns
Calculate the amount of templates that are externally managed and have unit tests Add them to new columns in the output csv file Include percentange in the overview displayed on the terminal
1 parent c8493f6 commit 22d4c5b

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

lib/cli/stats.js

+73-14
Original file line numberDiff line numberDiff line change
@@ -159,48 +159,67 @@ async function setMainPath(templateType, templateName) {
159159
return filePath;
160160
}
161161

162+
function percentageRoundTwo(num, den) {
163+
return den > 0 ? Number(((num / den) * 100).toFixed(2)) : 0;
164+
}
165+
162166
async function getTemplatesSummary() {
163167
const summary = {
164168
reconciliations: {
165169
total: 0,
166170
externallyManaged: 0,
171+
externallyManagedPerc: 0,
167172
yamlFiles: 0,
173+
yamlFilesPerc: 0,
168174
unitTests: 0,
169175
},
170176
sharedParts: {
171177
total: 0,
172178
externallyManaged: 0,
179+
externallyManagedPerc: 0,
173180
},
174181
exportFiles: {
175182
total: 0,
176183
externallyManaged: 0,
184+
externallyManagedPerc: 0,
177185
},
178186
accountTemplates: {
179187
total: 0,
180188
externallyManaged: 0,
189+
externallyManagedPerc: 0,
181190
yamlFiles: 0,
191+
yamlFilesPerc: 0,
182192
unitTests: 0,
183193
},
184194
all: {
185195
total: 0,
186196
externallyManaged: 0,
197+
externallyManagedPerc: 0,
187198
yamlFiles: 0,
199+
yamlFilesPerc: 0,
188200
unitTests: 0,
189201
},
190202
};
191203

192204
// Reconciliations
193-
const reconciliationsNonEmpty = await listNonEmptyTemplates(
194-
"reconciliationText"
195-
);
205+
const reconciliationsNonEmpty =
206+
await listNonEmptyTemplates("reconciliationText");
196207
const reconciliationsExtMan = await listExternallyManagedTemplates(
197208
"reconciliationText",
198209
reconciliationsNonEmpty
199210
);
200211
const reconciliationsTests = await countYamlFiles("reconciliationText");
201212
summary.reconciliations.total = reconciliationsNonEmpty.length;
202213
summary.reconciliations.externallyManaged = reconciliationsExtMan.length;
214+
summary.reconciliations.externallyManagedPerc = percentageRoundTwo(
215+
summary.reconciliations.externallyManaged,
216+
summary.reconciliations.total
217+
);
203218
summary.reconciliations.yamlFiles = reconciliationsTests.files;
219+
summary.reconciliations.yamlFilesPerc = percentageRoundTwo(
220+
summary.reconciliations.yamlFiles,
221+
summary.reconciliations.total
222+
);
204223
summary.reconciliations.unitTests = reconciliationsTests.tests;
205224

206225
// Shared Parts
@@ -211,6 +230,10 @@ async function getTemplatesSummary() {
211230
);
212231
summary.sharedParts.total = sharedPartsNonEmpty.length;
213232
summary.sharedParts.externallyManaged = sharedPartsExtMan.length;
233+
summary.sharedParts.externallyManagedPerc = percentageRoundTwo(
234+
summary.sharedParts.externallyManaged,
235+
summary.sharedParts.total
236+
);
214237

215238
// Export Files
216239
const exportFilesNonEmpty = await listNonEmptyTemplates("exportFile");
@@ -220,19 +243,30 @@ async function getTemplatesSummary() {
220243
);
221244
summary.exportFiles.total = exportFilesNonEmpty.length;
222245
summary.exportFiles.externallyManaged = exportFilesExtMan.length;
246+
summary.exportFiles.externallyManagedPerc = percentageRoundTwo(
247+
summary.exportFiles.externallyManaged,
248+
summary.exportFiles.total
249+
);
223250

224251
// Account Templates
225-
const accountTemplatesNonEmpty = await listNonEmptyTemplates(
226-
"accountTemplate"
227-
);
252+
const accountTemplatesNonEmpty =
253+
await listNonEmptyTemplates("accountTemplate");
228254
const accountTemplatesExtMan = await listExternallyManagedTemplates(
229255
"accountTemplate",
230256
accountTemplatesNonEmpty
231257
);
232258
const accountTemplatesTests = await countYamlFiles("accountTemplate");
233259
summary.accountTemplates.total = accountTemplatesNonEmpty.length;
234260
summary.accountTemplates.externallyManaged = accountTemplatesExtMan.length;
261+
summary.accountTemplates.externallyManagedPerc = percentageRoundTwo(
262+
summary.accountTemplates.externallyManaged,
263+
summary.accountTemplates.total
264+
);
235265
summary.accountTemplates.yamlFiles = accountTemplatesTests.files;
266+
summary.accountTemplates.yamlFilesPerc = percentageRoundTwo(
267+
summary.accountTemplates.yamlFiles,
268+
summary.accountTemplates.total
269+
);
236270
summary.accountTemplates.unitTests = accountTemplatesTests.tests;
237271

238272
// All
@@ -246,8 +280,16 @@ async function getTemplatesSummary() {
246280
summary.sharedParts.externallyManaged +
247281
summary.exportFiles.externallyManaged +
248282
summary.accountTemplates.externallyManaged;
283+
summary.all.externallyManagedPerc = percentageRoundTwo(
284+
summary.all.externallyManaged,
285+
summary.all.total
286+
)
249287
summary.all.yamlFiles =
250288
summary.reconciliations.yamlFiles + summary.accountTemplates.yamlFiles;
289+
summary.all.yamlFilesPerc = percentageRoundTwo(
290+
summary.all.yamlFiles,
291+
summary.all.total
292+
);
251293
summary.all.unitTests =
252294
summary.reconciliations.unitTests + summary.accountTemplates.unitTests;
253295

@@ -277,35 +319,35 @@ function displayOverview(sinceDate, today, templateSummary, yamlSummary) {
277319
consola.log(`${chalk.bold("Reconciliations:")}`);
278320
consola.log(`Templates: ${templateSummary.reconciliations.total}`);
279321
consola.log(
280-
`Externally Managed: ${templateSummary.reconciliations.externallyManaged}`
322+
`Externally Managed: ${templateSummary.reconciliations.externallyManaged} (${templateSummary.reconciliations.externallyManagedPerc}%)`
281323
);
282-
consola.log(`YAML files: ${templateSummary.reconciliations.yamlFiles}`);
324+
consola.log(`YAML files: ${templateSummary.reconciliations.yamlFiles} (${templateSummary.reconciliations.yamlFilesPerc}%)`);
283325
consola.log(`Unit Tests: ${templateSummary.reconciliations.unitTests}`);
284326
consola.log("");
285327
consola.log(`${chalk.bold("Account Templates:")}`);
286328
consola.log(`Templates: ${templateSummary.accountTemplates.total}`);
287329
consola.log(
288-
`Externally Managed: ${templateSummary.accountTemplates.externallyManaged}`
330+
`Externally Managed: ${templateSummary.accountTemplates.externallyManaged} (${templateSummary.accountTemplates.externallyManagedPerc}%)`
289331
);
290-
consola.log(`YAML files: ${templateSummary.accountTemplates.yamlFiles}`);
332+
consola.log(`YAML files: ${templateSummary.accountTemplates.yamlFiles} (${templateSummary.accountTemplates.yamlFilesPerc}%)`);
291333
consola.log(`Unit Tests: ${templateSummary.accountTemplates.unitTests}`);
292334
consola.log("");
293335
consola.log(`${chalk.bold("Shared Parts:")}`);
294336
consola.log(`Templates: ${templateSummary.sharedParts.total}`);
295337
consola.log(
296-
`Externally Managed: ${templateSummary.sharedParts.externallyManaged}`
338+
`Externally Managed: ${templateSummary.sharedParts.externallyManaged} (${templateSummary.sharedParts.externallyManagedPerc}%)`
297339
);
298340
consola.log("");
299341
consola.log(`${chalk.bold("Export Files:")}`);
300342
consola.log(`Templates: ${templateSummary.exportFiles.total}`);
301343
consola.log(
302-
`Externally Managed: ${templateSummary.exportFiles.externallyManaged}`
344+
`Externally Managed: ${templateSummary.exportFiles.externallyManaged} (${templateSummary.exportFiles.externallyManagedPerc}%)`
303345
);
304346
consola.log("");
305347
consola.log(`${chalk.bold("All:")}`);
306348
consola.log(`Templates: ${templateSummary.all.total}`);
307-
consola.log(`Externally Managed: ${templateSummary.all.externallyManaged}`);
308-
consola.log(`YAML files: ${templateSummary.all.yamlFiles}`);
349+
consola.log(`Externally Managed: ${templateSummary.all.externallyManaged} (${templateSummary.all.externallyManagedPerc}%)`);
350+
consola.log(`YAML files: ${templateSummary.all.yamlFiles} (${templateSummary.all.yamlFilesPerc}%)`);
309351
consola.log(`Unit Tests: ${templateSummary.all.unitTests}`);
310352
consola.log("");
311353
consola.log("------------------------------------");
@@ -334,6 +376,15 @@ function createRow(sinceDate, today, templateSummary, yamlSummary) {
334376
templateSummary.sharedParts.externallyManaged,
335377
templateSummary.exportFiles.total,
336378
templateSummary.exportFiles.externallyManaged,
379+
templateSummary.all.externallyManagedPerc,
380+
templateSummary.reconciliations.externallyManagedPerc,
381+
templateSummary.accountTemplates.externallyManagedPerc,
382+
templateSummary.sharedParts.externallyManagedPerc,
383+
templateSummary.exportFiles.externallyManagedPerc,
384+
templateSummary.all.yamlFilesPerc,
385+
templateSummary.reconciliations.yamlFilesPerc,
386+
templateSummary.accountTemplates.yamlFilesPerc,
387+
337388
];
338389
const row = `\r\n${rowContent.join(";")}`;
339390
return row;
@@ -362,6 +413,14 @@ function saveOverviewToFile(row) {
362413
"Shared Parts - externally managed",
363414
"Export Files - templates",
364415
"Export Files - externally managed",
416+
"All - externally managed (%)",
417+
"Reconciliations - externally managed (%)",
418+
"Account Templates - externally managed (%)",
419+
"Shared Parts - externally managed (%)",
420+
"Export Files - externally managed (%)",
421+
"All - yaml files (%)",
422+
"Reconciliations - yaml files (%)",
423+
"Account Templates - yaml files (%)",
365424
];
366425
const ROW_HEADER = `${COLUMNS.join(";")}`;
367426
const CSV_PATH = `./stats/overview.csv`;

0 commit comments

Comments
 (0)