Skip to content

Commit

Permalink
[Tech Debt] Reduce iterations in totalling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
levinmr committed Oct 31, 2024
1 parent 1343603 commit bc29e6b
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 142 deletions.
32 changes: 16 additions & 16 deletions reports/usa.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"name": "screen-resolution-30-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"screen_resolution"
],
"query": {
Expand Down Expand Up @@ -118,7 +118,7 @@
"name": "screen-resolution-90-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"screen_resolution"
],
"query": {
Expand Down Expand Up @@ -216,7 +216,7 @@
"name": "language",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"language",
"language_code"
],
Expand Down Expand Up @@ -362,7 +362,7 @@
"name": "devices",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"device"
],
"query": {
Expand Down Expand Up @@ -460,7 +460,7 @@
"name": "devices-90-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"device"
],
"query": {
Expand Down Expand Up @@ -558,7 +558,7 @@
"name": "device-model",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"mobile_device"
],
"query": {
Expand Down Expand Up @@ -656,7 +656,7 @@
"name": "os",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"os"
],
"query": {
Expand Down Expand Up @@ -754,7 +754,7 @@
"name": "os-90-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"os"
],
"query": {
Expand Down Expand Up @@ -852,7 +852,7 @@
"name": "windows",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"os_version"
],
"query": {
Expand Down Expand Up @@ -908,7 +908,7 @@
"name": "windows-90-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"os_version"
],
"query": {
Expand Down Expand Up @@ -1014,7 +1014,7 @@
"name": "browsers",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"browser"
],
"query": {
Expand Down Expand Up @@ -1112,7 +1112,7 @@
"name": "browsers-90-days",
"frequency": "daily",
"slim": true,
"sumUsersByColumns": [
"sumUsersByDimensions": [
"browser"
],
"query": {
Expand Down Expand Up @@ -2054,7 +2054,7 @@
"name": "top-session-channel-group-30-days",
"frequency": "daily",
"slim": true,
"sumVisitsByColumns": [
"sumVisitsByDimensions": [
"session_default_channel_group"
],
"query": {
Expand Down Expand Up @@ -2132,7 +2132,7 @@
"name": "top-session-source-medium-30-days",
"frequency": "daily",
"slim": true,
"sumVisitsByColumns": [
"sumVisitsByDimensions": [
"session_source_medium"
],
"query": {
Expand Down Expand Up @@ -2647,7 +2647,7 @@
{
"name": "top-download-file-extensions-30-days",
"frequency": "daily",
"sumTotalEventsByColumns": [
"sumTotalEventsByDimensions": [
"file_extension"
],
"query": {
Expand Down Expand Up @@ -3223,7 +3223,7 @@
{
"name": "top-user-engagement-events-30-days",
"frequency": "daily",
"sumTotalEventsByColumns": [
"sumTotalEventsByDimensions": [
"event_label"
],
"query": {
Expand Down
62 changes: 31 additions & 31 deletions src/process_results/analytics_data_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,18 @@ class AnalyticsDataProcessor {
};
}

#fieldNameForColumnIndex({ entryKey, index, data }) {
// data keys come back as values for the header keys
const targetKey = entryKey.replace("Values", "Headers");
const name = data[targetKey][index].name;
return this.#mapping[name] || name;
}
#removeColumnFromData({ column, data }) {
data = Object.assign(data);

#filterRowsBelowThreshold({ threshold, data }) {
data = Object.assign({}, data);
const columnToRemove = this.#findDimensionOrMetricIndex(column, data);

const column = this.#findDimensionOrMetricIndex(threshold.field, data);
if (column != null) {
data.rows = data.rows.filter((row) => {
return (
parseInt(row[column.rowKey][column.index].value) >=
parseInt(threshold.value)
);
if (columnToRemove != null) {
data[columnToRemove.rowKey.replace("Values", "Headers")].splice(
columnToRemove.index,
1,
);
data.rows.forEach((row) => {
row[columnToRemove.rowKey].splice(columnToRemove.index, 1);
});
}

Expand Down Expand Up @@ -151,6 +146,22 @@ class AnalyticsDataProcessor {
}
}

#filterRowsBelowThreshold({ threshold, data }) {
data = Object.assign({}, data);

const column = this.#findDimensionOrMetricIndex(threshold.field, data);
if (column != null) {
data.rows = data.rows.filter((row) => {
return (
parseInt(row[column.rowKey][column.index].value) >=
parseInt(threshold.value)
);
});
}

return data;
}

#formatDate(date) {
if (date == "(other)") {
return date;
Expand Down Expand Up @@ -195,22 +206,11 @@ class AnalyticsDataProcessor {
return point;
}

#removeColumnFromData({ column, data }) {
data = Object.assign(data);

const columnToRemove = this.#findDimensionOrMetricIndex(column, data);

if (columnToRemove != null) {
data[columnToRemove.rowKey.replace("Values", "Headers")].splice(
columnToRemove.index,
1,
);
data.rows.forEach((row) => {
row[columnToRemove.rowKey].splice(columnToRemove.index, 1);
});
}

return data;
#fieldNameForColumnIndex({ entryKey, index, data }) {
// data keys come back as values for the header keys
const targetKey = entryKey.replace("Values", "Headers");
const name = data[targetKey][index].name;
return this.#mapping[name] || name;
}
}

Expand Down
Loading

0 comments on commit bc29e6b

Please sign in to comment.