Skip to content

Commit

Permalink
Fix cumulative trend
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelef committed Mar 14, 2024
1 parent 59b1dea commit 2938571
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 6 deletions.
84 changes: 84 additions & 0 deletions test-grouped.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FusionChart - Temperature Readings</title>
<script
type="text/javascript"
src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"
></script>
<script
type="text/javascript"
src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"
></script>
<script
type="text/javascript"
src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.candy.js"
></script>
</head>
<body>
<h1>Sales performance</h1>
<div id="chart-container"></div>

<script>
const WEEKLY_BINNING = {
year: [],
month: [],
day: [],
week: [1],
hour: [],
minute: [],
second: [],
};

Promise.all([
loadData(
"https://s3.eu-central-1.amazonaws.com/fusion.store/ft/data/grouped-column_data.json"
),
loadData(
"https://s3.eu-central-1.amazonaws.com/fusion.store/ft/schema/grouped-column_schema.json"
),
]).then(function (res) {
const data = res[0];
const schema = res[1];

for (let i = 0; i < Math.min(100, data.length); i++) {
data[i] = data[i].slice(0, 2); // Select the first two elements using slicing
}

const dataStore = new FusionCharts.DataStore();
const dataSource = {
caption: {
text: "Sales Analysis",
},
subcaption: {
text: "Grocery & Footwear",
},
yaxis: {
plot: ["Grocery", "Footwear"],
plottype: "column",
title: "Sale Value",
format: {
prefix: "$",
},
},
};
dataSource.data = dataStore.createDataTable(data, schema);

new FusionCharts({
type: "timeseries",
renderAt: "chart-container",
width: "100%",
height: "500",
dataSource: dataSource,
}).render();
});

// Replace this with your actual loadData function
function loadData(url) {
return fetch(url).then((response) => response.json()); // Assuming JSON data
}
</script>
</body>
</html>
8 changes: 4 additions & 4 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"react18-json-view": "^0.2.7"
},
"devDependencies": {
"@types/react": "^18.2.65",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
Expand Down
37 changes: 37 additions & 0 deletions website/src/CompareChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,43 @@ function CompareChart() {
subarray.push(repoParsed2);
});

let currentRepo = repoParsed;
let currentIndex = 0;

do {
predictions[currentIndex][2] = combinedData[currentIndex][2];
currentIndex++;
currentRepo = combinedData[currentIndex][3];
} while (currentRepo == repoParsed);

currentIndex--;

let lastSum = combinedData[currentIndex][2];

for (let index = currentIndex; index < predictions.length; index++) {
predictions[index][2] = lastSum;
lastSum += predictions[index][1];
}

currentIndex++;

for (
let index = 0;
index < combinedData.length - currentIndex;
index++
) {
predictions2[index][2] = combinedData[currentIndex + index][2];
}

lastSum = combinedData[combinedData.length -1 ][2];

currentIndex = combinedData.length - currentIndex;

for (let index = currentIndex; index < predictions2.length; index++) {
predictions2[index][2] = lastSum;
lastSum += predictions2[index][1];
}

appliedAggregationResult = predictions.concat(predictions2);

options.dataSource.yAxis[0].plot.value =
Expand Down
17 changes: 16 additions & 1 deletion website/src/TimeSeriesChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,22 @@ function TimeSeriesChart() {
case "trend":
const repoParsed = parseGitHubRepoURL(selectedRepo);
const predictions = await fetchPredictions(repoParsed);
//console.log(predictions);

for (let index = 0; index < starHistory.length; index++) {
predictions[index][2] = starHistory[index][2];
}

let lastSum = starHistory[starHistory.length - 1][2];

for (
let index = starHistory.length;
index < predictions.length;
index++
) {
predictions[index][2] = lastSum;
lastSum += predictions[index][1];
}

appliedAggregationResult = predictions;
options.dataSource.yAxis[0].plot.value =
schema[1].name =
Expand Down

0 comments on commit 2938571

Please sign in to comment.