Skip to content

Commit

Permalink
Update length and unique empty charts message
Browse files Browse the repository at this point in the history
  • Loading branch information
ElsonOtake committed Dec 10, 2023
1 parent 6939199 commit 257c0ed
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions app/javascript/controllers/chart_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,38 @@ export default class extends Controller {

lengthData = (success) => {
let averageLength = {};
let data = this.createDateRange();
this.lengthAnalyticTargets.forEach(target => {
if (!averageLength[target.dataset.created]) {
averageLength[target.dataset.created] = { totalLength: 0, count: 0 };
};
averageLength[target.dataset.created].totalLength += parseInt(target.dataset.length);
averageLength[target.dataset.created].count++;
});
for (const created in averageLength) {
if (data[created] != null) {
data[created] = averageLength[created].totalLength / averageLength[created].count;
if (this.lengthAnalyticTargets.length > 0) {
let data = this.createDateRange();
this.lengthAnalyticTargets.forEach(target => {
if (!averageLength[target.dataset.created]) {
averageLength[target.dataset.created] = { totalLength: 0, count: 0 };
};
averageLength[target.dataset.created].totalLength += parseInt(target.dataset.length);
averageLength[target.dataset.created].count++;
});
for (const created in averageLength) {
if (data[created] != null) {
data[created] = averageLength[created].totalLength / averageLength[created].count;
};
};
};
success(data);
success(data);
} else {
success([]);
}
}

uniqueData = (success) => {
let data = this.createDateRange();
this.uniqueAnalyticTargets.forEach(target => {
if (data[target.dataset.created] != null) {
data[target.dataset.created]++;
};
});
success(data);
if (this.uniqueAnalyticTargets.length > 0) {
let data = this.createDateRange();
this.uniqueAnalyticTargets.forEach(target => {
if (data[target.dataset.created] != null) {
data[target.dataset.created]++;
};
});
success(data);
} else {
success([]);
}
}

devicesData = (success) => {
Expand Down

0 comments on commit 257c0ed

Please sign in to comment.