testilo 30.0.0 → 30.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -755,12 +755,13 @@ The `track()` function returns an ID and an HTML tracking report that shows data
755
755
  A user can invoke `track()` in one of these ways:
756
756
 
757
757
  ```javaScript
758
+ node call track ttp99a
758
759
  node call track ttp99a 241016
759
760
  node call track ttp99a 241016 'ABC Foundation'
760
761
  ```
761
762
 
762
763
  When a user invokes `track()` in this example, the `call` module:
763
- - gets the summary report from the first file in the `summarized` subdirectory of the `REPORTDIR` directory whose name begins with `'241016'`.
764
+ - gets the summary report from the last file in the `summarized` subdirectory of the `REPORTDIR` directory, or if the third argument to `call()` exists the last one whose name begins with `'241016'`.
764
765
  - selects the summarized data for all results in the summary report, or if the fourth argument to `call()` exists from all results whose `target.what` property has the value `'ABC Foundation'`.
765
766
  - uses tracker `ttp99a` to create a tracking report.
766
767
  - assigns an ID to the tracking report.
package/call.js CHANGED
@@ -52,11 +52,17 @@ const fnArgs = process.argv.slice(3);
52
52
 
53
53
  // ########## FUNCTIONS
54
54
 
55
- // Gets a summary report.
55
+ // Gets the last matching summary report.
56
56
  const getSummaryReport = async selector => {
57
57
  const summaryDir = `${reportDir}/summarized`;
58
58
  const summaryReportNames = await fs.readdir(summaryDir);
59
- const summaryReportName = summaryReportNames.find(reportName => reportName.startsWith(selector));
59
+ let summaryReportName;
60
+ if (summaryReportNames && summaryReportNames.length) {
61
+ summaryReportName = summaryReportNames.findLast(reportName => reportName.startsWith(selector));
62
+ }
63
+ else {
64
+ summaryReportName = summaryReportNames.pop();
65
+ }
60
66
  if (summaryReportName) {
61
67
  const summaryReportJSON = await fs.readFile(`${summaryDir}/${summaryReportName}`, 'utf8');
62
68
  const summaryReport = JSON.parse(summaryReportJSON);
@@ -255,7 +261,7 @@ const callSummarize = async (what, selector = '') => {
255
261
  const summaryReport = {
256
262
  id: getFileID(2),
257
263
  what,
258
- data: []
264
+ summaries: []
259
265
  };
260
266
  // For each report to be summarized:
261
267
  for (const reportID of reportIDs) {
@@ -263,7 +269,7 @@ const callSummarize = async (what, selector = '') => {
263
269
  const report = await getReport('scored', reportID);
264
270
  // Add a summary of it to the summary report.
265
271
  const summary = summarize(report);
266
- summaryReport.data.push(summary);
272
+ summaryReport.summaries.push(summary);
267
273
  };
268
274
  // Save the summary report.
269
275
  const summaryDir = `${reportDir}/summarized`;
@@ -302,50 +308,21 @@ const callCompare = async (what, compareProcID, selector) => {
302
308
  }
303
309
  }
304
310
  };
305
- // Fulfills a credit request.
306
- const callCredit = async (what, selector = '') => {
307
- // Get the IDs of the scored reports to be credited.
308
- const reportIDs = await getReportIDs('scored', selector);
309
- // If any exist:
310
- if (reportIDs.length) {
311
- // Get an array of the score properties of the reports to be credited.
312
- const reportScores = [];
313
- for (const id of reportIDs) {
314
- const report = await getReport('scored', id);
315
- reportScores.push(report.score);
316
- }
317
- // Credit the reports.
318
- const tally = credit(what, reportScores);
319
- // Save the credit report.
320
- const creditDir = `${reportDir}/credit`;
321
- await fs.mkdir(creditDir, {recursive: true});
322
- const creditReportID = getFileID(2);
323
- tally.id = creditReportID;
324
- const reportPath = `${creditDir}/${creditReportID}.json`;
325
- await fs.writeFile(reportPath, `${JSON.stringify(tally, null, 2)}\n`);
326
- console.log(`Reports credited and credit report saved as ${reportPath}`);
327
- }
328
- // Otherwise, i.e. if no scored reports are to be credited:
329
- else {
330
- // Report this.
331
- console.log('ERROR: No scored reports to be credited');
332
- }
333
- };
334
311
  // Fulfills a tracking request.
335
312
  const callTrack = async (trackerID, selector, targetWhat) => {
336
313
  // Get the summary report.
337
314
  try {
338
315
  const summaryReport = await getSummaryReport(selector);
339
316
  // Remove unwanted results from it.
340
- summaryReport.data = summaryReport.data.filter(
317
+ summaryReport.summaries = summaryReport.summaries.filter(
341
318
  result => targetWhat
342
319
  ? result.sources
343
320
  && result.sources.target
344
- && result.sources.target.what !== targetWhat
321
+ && result.sources.target.what === targetWhat
345
322
  : true
346
323
  );
347
324
  // If any results remain:
348
- if (summaryReport.data.length) {
325
+ if (summaryReport.summaries.length) {
349
326
  // Get the tracker.
350
327
  const {tracker} = require(`${functionDir}/track/${trackerID}/index`);
351
328
  // Track the results.
@@ -365,6 +342,35 @@ const callTrack = async (trackerID, selector, targetWhat) => {
365
342
  console.log(`ERROR: Tracking request invalid (${error.message})`);
366
343
  }
367
344
  };
345
+ // Fulfills a credit request.
346
+ const callCredit = async (what, selector = '') => {
347
+ // Get the IDs of the scored reports to be credited.
348
+ const reportIDs = await getReportIDs('scored', selector);
349
+ // If any exist:
350
+ if (reportIDs.length) {
351
+ // Get an array of the score properties of the reports to be credited.
352
+ const reportScores = [];
353
+ for (const id of reportIDs) {
354
+ const report = await getReport('scored', id);
355
+ reportScores.push(report.score);
356
+ }
357
+ // Credit the reports.
358
+ const tally = credit(what, reportScores);
359
+ // Save the credit report.
360
+ const creditDir = `${reportDir}/credit`;
361
+ await fs.mkdir(creditDir, {recursive: true});
362
+ const creditReportID = getFileID(2);
363
+ tally.id = creditReportID;
364
+ const reportPath = `${creditDir}/${creditReportID}.json`;
365
+ await fs.writeFile(reportPath, `${JSON.stringify(tally, null, 2)}\n`);
366
+ console.log(`Reports credited and credit report saved as ${reportPath}`);
367
+ }
368
+ // Otherwise, i.e. if no scored reports are to be credited:
369
+ else {
370
+ // Report this.
371
+ console.log('ERROR: No scored reports to be credited');
372
+ }
373
+ };
368
374
 
369
375
  // ########## OPERATION
370
376
 
package/compare.js CHANGED
@@ -11,6 +11,6 @@
11
11
  // Compares the summarized reports and returns a comparison.
12
12
  exports.compare = async (id, what, comparer, summaryReport) => {
13
13
  // Return the comparison.
14
- console.log(`Comparison complete. Report count: ${summaryReport.data.length}`);
14
+ console.log(`Comparison complete. Report count: ${summaryReport.summaries.length}`);
15
15
  return comparer(id, what, summaryReport);
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "30.0.0",
3
+ "version": "30.1.0",
4
4
  "description": "Prepares and processes Testaro reports",
5
5
  "main": "call.js",
6
6
  "scripts": {
@@ -17,13 +17,13 @@ const innestJoiner = '\n ';
17
17
  // ########## FUNCTIONS
18
18
 
19
19
  // Returns the maximum score.
20
- const getMaxScore = summaryReport => summaryReport.data.reduce(
20
+ const getMaxScore = summaryReport => summaryReport.summaries.reduce(
21
21
  (max, result) => Math.max(max, result.score), 0
22
22
  );
23
23
  // Converts summary report data to a table body.
24
24
  const getTableBody = async summaryReport => {
25
25
  const maxScore = getMaxScore(summaryReport);
26
- const rows = summaryReport.data
26
+ const rows = summaryReport.summaries
27
27
  .sort((a, b) => a.score - b.score)
28
28
  .map(result => {
29
29
  const {id, sources, score} = result;
@@ -42,7 +42,7 @@ const getTableBody = async summaryReport => {
42
42
  const populateQuery = async (id, what, summaryReport, query) => {
43
43
  query.id = id;
44
44
  query.what = what;
45
- query.pageCount = summaryReport.data.length;
45
+ query.pageCount = summaryReport.summaries.length;
46
46
  query.tableBody = await getTableBody(summaryReport);
47
47
  query.dateISO = getNowDate();
48
48
  query.dateSlash = getNowDateSlash();
@@ -31,7 +31,7 @@
31
31
  const summaryReportJSON = '__summaryReportJSON__';
32
32
  const summaryReport = JSON.parse(summaryReportJSON);
33
33
  const graphData = [];
34
- summaryReport.data.forEach(result => {
34
+ summaryReport.summaries.forEach(result => {
35
35
  graphData.push({
36
36
  target: result.sources.target.what,
37
37
  time: new Date(`20${result.endTime}Z`),
@@ -28,15 +28,15 @@ const populateQuery = async (id, summaryReport, query) => {
28
28
  query.dateISO = getNowDate();
29
29
  query.dateSlash = getNowDateSlash();
30
30
  // JSON of pruned summary report.
31
- summaryReport.data.forEach(result => {
31
+ const {summaries} = summaryReport;
32
+ summaries.forEach(result => {
32
33
  delete result.sources.target.id;
33
34
  });
34
35
  query.summaryReportJSON = JSON.stringify(summaryReport);
35
36
  // For each score:
36
37
  const rows = [];
37
- const results = summaryReport.data;
38
- const targetWhats = Array.from(new Set(results.map(result => result.sources.target.what))).sort();
39
- summaryReport.data.forEach(result => {
38
+ const targetWhats = Array.from(new Set(summaries.map(result => result.sources.target.what))).sort();
39
+ summaries.forEach(result => {
40
40
  // Create an HTML table row for it.
41
41
  const timeCell = `<td>${result.endTime}</td>`;
42
42
  const digestLinkDestination = digestURL.replace('__id__', result.id);
package/track.js CHANGED
@@ -18,6 +18,5 @@ exports.track = async (tracker, summaryReport) => {
18
18
  // Use the tracker to create a tracking report.
19
19
  const id = getFileID(2);
20
20
  const trackingReport = await tracker(id, summaryReport);
21
- console.log(`Tracking report ${id} created`);
22
21
  return [id, trackingReport];
23
22
  };