Skip to content

Commit

Permalink
Adjusting formula
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmenon committed Dec 27, 2023
1 parent 79d3bcb commit c1da0ca
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app/listening-trends/listening-trends.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,29 @@ export class ListeningTrendsComponent implements OnInit {
const maxSumOfLengths = 100000;
let sumOfLengths = data.reduce((accumulator, currentValue) => accumulator + currentValue.series.length, 0);
console.log(`Total data points to show in chart is: ${sumOfLengths} of max ${maxSumOfLengths} allowed`)

if (sumOfLengths < maxSumOfLengths)
return data

if (sumOfLengths >= 2 * maxSumOfLengths) {
while (sumOfLengths >= 2 * maxSumOfLengths) {
data.forEach((item) => {
item.series = item.series.filter((_, index) => (index + 1) % 2 !== 0);
});
sumOfLengths = data.reduce((accumulator, currentValue) => accumulator + currentValue.series.length, 0)
console.log(`Reduced data points to ${sumOfLengths}`)
}
}

// Calculate the optimal value of n
let n = 50;
while (sumOfLengths >= maxSumOfLengths) {
n--;
sumOfLengths = data.reduce((accumulator, currentValue) => accumulator + (currentValue.series.length - Math.floor(currentValue.series.length / n)), 0);
sumOfLengths = sumOfLengths - Math.floor(sumOfLengths / n);
}

// Remove every nth element from each series array
if (n > 1) {
if (n > 1 && n < 50) {
console.log(`Removing each nth item from series arrays (n = ${n})`)
data.forEach((item) => {
item.series = item.series.filter((_, index) => (index + 1) % n !== 0);
Expand Down

0 comments on commit c1da0ca

Please sign in to comment.