Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.buildMetricsTableRow = exports.parseBucket = exports.parseTimeseriesResponse = void 0;
  4. const semver = require("semver");
  5. const clc = require("colorette");
  6. function parseTimeseriesResponse(series) {
  7. const ret = [];
  8. for (const s of series) {
  9. const ref = buildRef(s);
  10. if (ref === undefined) {
  11. continue;
  12. }
  13. let valueToday;
  14. let value7dAgo;
  15. let value28dAgo;
  16. if (s.points.length >= 28 && s.points[27].value.int64Value !== undefined) {
  17. value28dAgo = parseBucket(s.points[27].value.int64Value);
  18. }
  19. if (s.points.length >= 7 && s.points[6].value.int64Value !== undefined) {
  20. value7dAgo = parseBucket(s.points[6].value.int64Value);
  21. }
  22. if (s.points.length >= 1 && s.points[0].value.int64Value !== undefined) {
  23. valueToday = parseBucket(s.points[0].value.int64Value);
  24. }
  25. ret.push({
  26. ref,
  27. valueToday,
  28. value7dAgo,
  29. value28dAgo,
  30. });
  31. }
  32. ret.sort((a, b) => {
  33. if (a.ref.version === "all") {
  34. return 1;
  35. }
  36. if (b.ref.version === "all") {
  37. return -1;
  38. }
  39. return semver.lt(a.ref.version, b.ref.version) ? 1 : -1;
  40. });
  41. return ret;
  42. }
  43. exports.parseTimeseriesResponse = parseTimeseriesResponse;
  44. function parseBucket(value) {
  45. const v = Number(value);
  46. if (v >= 200) {
  47. return { low: v - 100, high: v };
  48. }
  49. if (v >= 10) {
  50. return { low: v - 10, high: v };
  51. }
  52. return { low: 0, high: 0 };
  53. }
  54. exports.parseBucket = parseBucket;
  55. function buildMetricsTableRow(metric) {
  56. const ret = [metric.ref.version];
  57. if (metric.valueToday) {
  58. ret.push(`${metric.valueToday.low} - ${metric.valueToday.high}`);
  59. }
  60. else {
  61. ret.push("Insufficient data");
  62. }
  63. ret.push(renderChangeCell(metric.value7dAgo, metric.valueToday));
  64. ret.push(renderChangeCell(metric.value28dAgo, metric.valueToday));
  65. return ret;
  66. }
  67. exports.buildMetricsTableRow = buildMetricsTableRow;
  68. function renderChangeCell(before, after) {
  69. if (!(before && after)) {
  70. return "Insufficient data";
  71. }
  72. if (before.high === after.high) {
  73. return "-";
  74. }
  75. if (before.high > after.high) {
  76. const diff = before.high - after.high;
  77. const tolerance = diff < 100 ? 10 : 100;
  78. return clc.red("▼ ") + `-${diff} (±${tolerance})`;
  79. }
  80. else {
  81. const diff = after.high - before.high;
  82. const tolerance = diff < 100 ? 10 : 100;
  83. return clc.green("▲ ") + `${diff} (±${tolerance})`;
  84. }
  85. }
  86. function buildRef(ts) {
  87. const publisherId = ts.resource.labels["publisher"];
  88. const extensionId = ts.resource.labels["extension"];
  89. const version = ts.resource.labels["version"];
  90. if (!(publisherId && extensionId && version)) {
  91. return undefined;
  92. }
  93. return {
  94. publisherId,
  95. extensionId,
  96. version,
  97. };
  98. }