-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add target recalculation functionality and UI controls for saving and resetting targets #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -702,7 +702,8 @@ | |||||||||||||||||||||||||||||||||||||
const userTimeSavings = distinctUsers.map(userId => { | ||||||||||||||||||||||||||||||||||||||
const userSurveys = this.surveysWeekly.filter(survey => survey.userId === userId); | ||||||||||||||||||||||||||||||||||||||
const totalPercent = userSurveys.reduce((sum, survey) => { | ||||||||||||||||||||||||||||||||||||||
const percentTimeSaved = typeof survey.percentTimeSaved === 'number' ? survey.percentTimeSaved : 0; | ||||||||||||||||||||||||||||||||||||||
// Always parse percentTimeSaved as float | ||||||||||||||||||||||||||||||||||||||
const percentTimeSaved = survey.percentTimeSaved != null ? parseFloat(survey.percentTimeSaved as any) : 0; | ||||||||||||||||||||||||||||||||||||||
return sum + percentTimeSaved; | ||||||||||||||||||||||||||||||||||||||
}, 0); | ||||||||||||||||||||||||||||||||||||||
return totalPercent / userSurveys.length; // Average percent time saved per user | ||||||||||||||||||||||||||||||||||||||
|
@@ -711,17 +712,17 @@ | |||||||||||||||||||||||||||||||||||||
// Average across all users | ||||||||||||||||||||||||||||||||||||||
const avgPercentTimeSaved = userTimeSavings.reduce((sum, percent) => sum + percent, 0) / userTimeSavings.length; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Convert settings values to numbers | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = typeof this.settings.hoursPerYear === 'number' ? this.settings.hoursPerYear : 2000; | ||||||||||||||||||||||||||||||||||||||
const percentCoding = typeof this.settings.percentCoding === 'number' ? this.settings.percentCoding : 50; | ||||||||||||||||||||||||||||||||||||||
// Convert settings values to numbers (parse from string if needed) | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago To fix the issue, we need to replace the Changes to make:
Suggested changeset
1
backend/src/services/target-calculation-service.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||
const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as any) : 50; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago Copilot could not generate an autofix suggestion Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support. |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Calculate weekly hours saved based on settings and average percent | ||||||||||||||||||||||||||||||||||||||
const weeklyHours = hoursPerYear / 50; // Assuming 50 working weeks | ||||||||||||||||||||||||||||||||||||||
const weeklyDevHours = weeklyHours * (percentCoding / 100); | ||||||||||||||||||||||||||||||||||||||
const avgWeeklyTimeSaved = weeklyDevHours * (avgPercentTimeSaved / 100); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Calculate max based on settings | ||||||||||||||||||||||||||||||||||||||
const maxPercentTimeSaved = typeof this.settings.percentTimeSaved === 'number' ? this.settings.percentTimeSaved : 20; | ||||||||||||||||||||||||||||||||||||||
const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as any) : 20; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago To fix the issue, we need to replace the The fix involves:
Suggested changeset
1
backend/src/services/target-calculation-service.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||
const maxWeeklyTimeSaved = weeklyDevHours * (maxPercentTimeSaved / 100); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const result = { | ||||||||||||||||||||||||||||||||||||||
|
@@ -785,11 +786,11 @@ | |||||||||||||||||||||||||||||||||||||
const adoptedDevs = this.calculateAdoptedDevs().current; | ||||||||||||||||||||||||||||||||||||||
const weeklyTimeSavedHrs = this.calculateWeeklyTimeSavedHrs().current; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Ensure all values are properly typed as numbers | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = typeof this.settings.hoursPerYear === 'number' ? this.settings.hoursPerYear : 2000; | ||||||||||||||||||||||||||||||||||||||
// Always parse settings values as numbers (from string if needed) | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago Copilot could not generate an autofix suggestion Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support. |
||||||||||||||||||||||||||||||||||||||
const weeksInYear = Math.round(hoursPerYear / 40) || 50; // Calculate weeks and ensure it's a number | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const devCostPerYear = typeof this.settings.devCostPerYear === 'number' ? this.settings.devCostPerYear : 0; | ||||||||||||||||||||||||||||||||||||||
const devCostPerYear = this.settings.devCostPerYear != null ? parseFloat(this.settings.devCostPerYear as any) : 0; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago Copilot could not generate an autofix suggestion Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support. |
||||||||||||||||||||||||||||||||||||||
const hourlyRate = devCostPerYear > 0 ? (devCostPerYear / hoursPerYear) : 50; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const annualSavings = weeklyTimeSavedHrs * weeksInYear * hourlyRate * adoptedDevs; | ||||||||||||||||||||||||||||||||||||||
|
@@ -824,8 +825,8 @@ | |||||||||||||||||||||||||||||||||||||
const adoptedDevs = this.calculateAdoptedDevs().current; | ||||||||||||||||||||||||||||||||||||||
const weeklyTimeSavedHrs = this.calculateWeeklyTimeSavedHrs().current; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Convert hours per year to number | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = typeof this.settings.hoursPerYear === 'number' ? this.settings.hoursPerYear : 2000; | ||||||||||||||||||||||||||||||||||||||
// Always parse hours per year as number | ||||||||||||||||||||||||||||||||||||||
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000; | ||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago To fix the issue, we need to replace the The fix involves:
Suggested changeset
1
backend/src/services/target-calculation-service.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||
const hoursPerWeek = hoursPerYear / 50 || 40; // Default to 40 if undefined | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Calculate productivity boost factor (not percentage) | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ export class TimeSavedChartComponent implements OnInit, OnChanges { | |
text: 'Time Saved (Hrs per Week)' | ||
}, | ||
min: 0, | ||
max: 10, | ||
max: 10, // Will be updated dynamically | ||
labels: { | ||
format: '{value}hrs' | ||
}, | ||
|
@@ -45,7 +45,7 @@ export class TimeSavedChartComponent implements OnInit, OnChanges { | |
} | ||
}], | ||
plotLines: [{ | ||
value: 5, | ||
value: 5, // Will be updated dynamically | ||
color: 'var(--sys-primary)', | ||
dashStyle: 'Dash', | ||
width: 2, | ||
|
@@ -91,6 +91,7 @@ export class TimeSavedChartComponent implements OnInit, OnChanges { | |
this._chartOptions.yAxis = Object.assign({}, this.chartOptions?.yAxis, this._chartOptions.yAxis); | ||
this._chartOptions.tooltip = Object.assign({}, this.chartOptions?.tooltip, this._chartOptions.tooltip); | ||
this._chartOptions = Object.assign({}, this.chartOptions, this._chartOptions); | ||
this.updateYAxisFromTargets(); | ||
} | ||
|
||
ngOnChanges() { | ||
|
@@ -101,6 +102,41 @@ export class TimeSavedChartComponent implements OnInit, OnChanges { | |
}; | ||
this.updateFlag = true; | ||
} | ||
this.updateYAxisFromTargets(); | ||
} | ||
|
||
private updateYAxisFromTargets() { | ||
if (this.targets?.user?.weeklyTimeSavedHrs) { | ||
const targetValue = this.targets.user.weeklyTimeSavedHrs.target; | ||
const maxValue = Math.max( | ||
targetValue * 1.5, | ||
this.targets.user.weeklyTimeSavedHrs.max || 10, | ||
10 | ||
); | ||
const yAxis = { | ||
...this._chartOptions.yAxis, | ||
max: maxValue, | ||
plotLines: [{ | ||
value: targetValue, | ||
color: 'var(--sys-primary)', | ||
dashStyle: 'Dash' as Highcharts.DashStyleValue, | ||
width: 2, | ||
label: { | ||
text: 'Target Level', | ||
align: 'left' as Highcharts.AlignValue, | ||
style: { | ||
color: 'var(--sys-primary)' | ||
} | ||
}, | ||
zIndex: 2 | ||
}] | ||
}; | ||
this._chartOptions = { | ||
...this._chartOptions, | ||
yAxis | ||
}; | ||
this.updateFlag = true; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -77,5 +77,10 @@ | |||||||||||||||||||||||||||||||||||||||||||
saveTargets(targets: Targets) { | ||||||||||||||||||||||||||||||||||||||||||||
return this.http.post<Targets>(`${this.apiUrl}`, targets); | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
recalculateTargets() { | ||||||||||||||||||||||||||||||||||||||||||||
// Calls the backend endpoint to recalculate targets | ||||||||||||||||||||||||||||||||||||||||||||
return this.http.get<any>(`${this.apiUrl}/calculate`); | ||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / ESLint Disallow the `any` type Error
Unexpected any. Specify a different type.
Copilot AutofixAI 4 months ago To fix the issue, we need to replace the Steps to fix:
Suggested changeset
1
frontend/src/app/services/api/targets.service.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
Check failure
Code scanning / ESLint
Disallow the `any` type Error
Copilot Autofix
AI 4 months ago
To fix the issue, we need to replace the
any
type with a more specific type that accurately represents the possible values ofpercentTimeSaved
. Based on the context,percentTimeSaved
appears to be a property that can be a string, number, or null. We can use a union type (string | number | null
) to represent this. Additionally, we should validate the value before parsing it as a float to ensure it is a valid number or numeric string.Changes to make:
any
type withstring | number | null
forpercentTimeSaved
.calculateWeeklyTimeSavedHrs
method.