Skip to content

Commit

Permalink
Refactor HighchartsService to improve code readability by adjusting f…
Browse files Browse the repository at this point in the history
…ormatting and commenting out unused scatter series code
  • Loading branch information
austenstone committed Dec 6, 2024
1 parent 82d2a26 commit 088c914
Showing 1 changed file with 55 additions and 54 deletions.
109 changes: 55 additions & 54 deletions frontend/src/app/services/highcharts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,22 @@ export class HighchartsService {
const surveyAverages = Object.keys(activity).reduce((acc, activityDate) => {
const dateKey = activityDate.split('T')[0];
acc[dateKey] = {
sum: 0,
count: 0
sum: 0,
count: 0
};
const dateSurveys = surveys.filter(survey =>
new Date(survey.createdAt!).toISOString().split('T')[0] === dateKey

const dateSurveys = surveys.filter(survey =>
new Date(survey.createdAt!).toISOString().split('T')[0] === dateKey
);

if (dateSurveys.length > 0) {
const avgPercentTimeSaved = dateSurveys.reduce((sum, survey) => sum + survey.percentTimeSaved, 0)
acc[dateKey].sum = avgPercentTimeSaved * 0.01 * 0.3 * 40; // TODO pull settings
acc[dateKey].count = dateSurveys.length;
const avgPercentTimeSaved = dateSurveys.reduce((sum, survey) => sum + survey.percentTimeSaved, 0)
acc[dateKey].sum = avgPercentTimeSaved * 0.01 * 0.3 * 40; // TODO pull settings
acc[dateKey].count = dateSurveys.length;
}

return acc;
}, {} as Record<string, { sum: number; count: number }>);
}, {} as Record<string, { sum: number; count: number }>);


// Generate series with 7-day rolling average
Expand Down Expand Up @@ -524,50 +524,51 @@ export class HighchartsService {
.sort((a, b) => a.x - b.x);

return {
series: [{
name: 'Time Saved',
type: 'spline' as const,
data: seriesData,
lineWidth: 2,
marker: {
enabled: true,
radius: 4,
symbol: 'circle'
},
states: {
hover: {
lineWidth: 3
series: [
{
name: 'Time Saved',
type: 'spline' as const,
data: seriesData,
lineWidth: 2,
marker: {
enabled: true,
radius: 4,
symbol: 'circle'
},
states: {
hover: {
lineWidth: 3
}
}
}
},
// {
// type: 'scatter' as const,
// name: 'Survey',
// data: surveys.map(survey => ({
// x: new Date(survey.createdAt!).getTime(),
// y: survey.percentTimeSaved,
// raw: survey
// })),
// marker: {
// enabled: true,
// radius: 4,
// symbol: 'triangle',
// },
// tooltip: {
// headerFormat: '<b>{point.x:%b %d, %Y}</b><br/>',
// pointFormatter: function () {
// return [
// `User: `,
// '<b>' + this.raw?.userId + '</b>',
// `</br>Time saved: `,
// '<b>' + Math.round(this.y || 0) + '%</b>',
// `</br>PR: `,
// '<b>#' + this.raw?.prNumber + '</b>',
// ].join('');
// } as Highcharts.FormatterCallbackFunction<CustomHighchartsPoint>
// }
// }
]
},
// {
// type: 'scatter' as const,
// name: 'Survey',
// data: surveys.map(survey => ({
// x: new Date(survey.createdAt!).getTime(),
// y: survey.percentTimeSaved,
// raw: survey
// })),
// marker: {
// enabled: true,
// radius: 4,
// symbol: 'triangle',
// },
// tooltip: {
// headerFormat: '<b>{point.x:%b %d, %Y}</b><br/>',
// pointFormatter: function () {
// return [
// `User: `,
// '<b>' + this.raw?.userId + '</b>',
// `</br>Time saved: `,
// '<b>' + Math.round(this.y || 0) + '%</b>',
// `</br>PR: `,
// '<b>#' + this.raw?.prNumber + '</b>',
// ].join('');
// } as Highcharts.FormatterCallbackFunction<CustomHighchartsPoint>
// }
// }
]
};
}

Expand Down

0 comments on commit 088c914

Please sign in to comment.