Skip to content

Conversation

MattG57
Copy link
Collaborator

@MattG57 MattG57 commented Jun 15, 2025

Also, fixed time savings chart to use configured targets & max values

…ng and resetting targets

Also, fixed time savings chart to use configured targets & max values
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

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;

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

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 of percentTimeSaved. 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:

  1. Replace the any type with string | number | null for percentTimeSaved.
  2. Add validation logic to ensure the value can be safely parsed as a float.
  3. Update the relevant lines in the calculateWeeklyTimeSavedHrs method.

Suggested changeset 1
backend/src/services/target-calculation-service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/backend/src/services/target-calculation-service.ts b/backend/src/services/target-calculation-service.ts
--- a/backend/src/services/target-calculation-service.ts
+++ b/backend/src/services/target-calculation-service.ts
@@ -705,3 +705,5 @@
         // Always parse percentTimeSaved as float
-        const percentTimeSaved = survey.percentTimeSaved != null ? parseFloat(survey.percentTimeSaved as any) : 0;
+        const percentTimeSaved = survey.percentTimeSaved != null && (typeof survey.percentTimeSaved === 'string' || typeof survey.percentTimeSaved === 'number')
+          ? parseFloat(survey.percentTimeSaved.toString())
+          : 0;
         return sum + percentTimeSaved;
EOF
@@ -705,3 +705,5 @@
// Always parse percentTimeSaved as float
const percentTimeSaved = survey.percentTimeSaved != null ? parseFloat(survey.percentTimeSaved as any) : 0;
const percentTimeSaved = survey.percentTimeSaved != null && (typeof survey.percentTimeSaved === 'string' || typeof survey.percentTimeSaved === 'number')
? parseFloat(survey.percentTimeSaved.toString())
: 0;
return sum + percentTimeSaved;
Copilot is powered by AI and may make mistakes. Always verify output.
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 failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

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 of settings.hoursPerYear. Based on the context, it seems that settings.hoursPerYear can be a string, null, or undefined. We can use a union type (string | null | undefined) to represent this. The same approach should be applied to other instances where any is used for type casting, such as settings.percentCoding and settings.percentTimeSaved.

Changes to make:

  1. Replace any with string | null | undefined for type casting.
  2. Ensure that the logic handles all possible values of the property (e.g., null, undefined, or non-numeric strings).
Suggested changeset 1
backend/src/services/target-calculation-service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/backend/src/services/target-calculation-service.ts b/backend/src/services/target-calculation-service.ts
--- a/backend/src/services/target-calculation-service.ts
+++ b/backend/src/services/target-calculation-service.ts
@@ -715,4 +715,4 @@
     // Convert settings values to numbers (parse from string if needed)
-    const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000;
-    const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as any) : 50;
+    const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as string | null | undefined) : 2000;
+    const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as string | null | undefined) : 50;
     
@@ -724,3 +724,3 @@
     // Calculate max based on settings
-    const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as any) : 20;
+    const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as string | null | undefined) : 20;
     const maxWeeklyTimeSaved = weeklyDevHours * (maxPercentTimeSaved / 100);
EOF
@@ -715,4 +715,4 @@
// Convert settings values to numbers (parse from string if needed)
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000;
const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as any) : 50;
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as string | null | undefined) : 2000;
const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as string | null | undefined) : 50;

@@ -724,3 +724,3 @@
// Calculate max based on settings
const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as any) : 20;
const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as string | null | undefined) : 20;
const maxWeeklyTimeSaved = weeklyDevHours * (maxPercentTimeSaved / 100);
Copilot is powered by AI and may make mistakes. Always verify output.
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;
const percentCoding = this.settings.percentCoding != null ? parseFloat(this.settings.percentCoding as any) : 50;

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

Copilot Autofix

AI 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 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 failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

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 of this.settings.percentTimeSaved. Based on the context, it seems that percentTimeSaved can be a string, a number, or null. We can use the union type string | number | null to represent this. This change ensures type safety while maintaining the flexibility to handle different input types.

The fix involves:

  1. Updating the type definition for this.settings.percentTimeSaved (if it exists) to string | number | null.
  2. Replacing the any type cast with a union type cast (as string | number | null).
  3. Ensuring that parseFloat is applied correctly to handle the union type.

Suggested changeset 1
backend/src/services/target-calculation-service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/backend/src/services/target-calculation-service.ts b/backend/src/services/target-calculation-service.ts
--- a/backend/src/services/target-calculation-service.ts
+++ b/backend/src/services/target-calculation-service.ts
@@ -724,3 +724,3 @@
     // Calculate max based on settings
-    const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as any) : 20;
+    const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as string | number | null) : 20;
     const maxWeeklyTimeSaved = weeklyDevHours * (maxPercentTimeSaved / 100);
EOF
@@ -724,3 +724,3 @@
// Calculate max based on settings
const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as any) : 20;
const maxPercentTimeSaved = this.settings.percentTimeSaved != null ? parseFloat(this.settings.percentTimeSaved as string | number | null) : 20;
const maxWeeklyTimeSaved = weeklyDevHours * (maxPercentTimeSaved / 100);
Copilot is powered by AI and may make mistakes. Always verify output.
// 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 failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

Copilot Autofix

AI 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 failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

Copilot Autofix

AI 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.

// 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 failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

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 of this.settings.hoursPerYear. Based on the context, hoursPerYear is likely a numeric value or a string that can be parsed into a number. Therefore, the type should be string | number | null | undefined to account for all possible cases. This change ensures that TypeScript can enforce type safety while still allowing flexibility in the input.

The fix involves:

  1. Updating the type assertion on line 829 to use string | number | null | undefined instead of any.
  2. Ensuring that parseFloat is only called on valid inputs (e.g., strings or numbers).
  3. No additional imports or dependencies are required.
Suggested changeset 1
backend/src/services/target-calculation-service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/backend/src/services/target-calculation-service.ts b/backend/src/services/target-calculation-service.ts
--- a/backend/src/services/target-calculation-service.ts
+++ b/backend/src/services/target-calculation-service.ts
@@ -828,3 +828,3 @@
     // Always parse hours per year as number
-    const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000;
+    const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as string | number | null | undefined) : 2000;
     const hoursPerWeek = hoursPerYear / 50 || 40; // Default to 40 if undefined
EOF
@@ -828,3 +828,3 @@
// Always parse hours per year as number
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as any) : 2000;
const hoursPerYear = this.settings.hoursPerYear != null ? parseFloat(this.settings.hoursPerYear as string | number | null | undefined) : 2000;
const hoursPerWeek = hoursPerYear / 50 || 40; // Default to 40 if undefined
Copilot is powered by AI and may make mistakes. Always verify output.

resetTargets() {
// Call the backend endpoint to recalculate targets
this.targetsService.recalculateTargets().subscribe((result: any) => {

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

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 structure of the result object returned by the recalculateTargets method. Based on the code, result appears to have a targets property containing org, user, and impact objects, or it might directly be the targets object. We can define a new interface to represent this structure and use it as the type for result.

The changes will involve:

  1. Defining a new interface, RecalculateTargetsResponse, to represent the structure of the result object.
  2. Updating the type of result in the resetTargets method to use this new interface.
Suggested changeset 1
frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts b/frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts
--- a/frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts
+++ b/frontend/src/app/main/copilot/copilot-value-modeling/copilot-value-modeling.component.ts
@@ -23,2 +23,11 @@
 
+interface RecalculateTargetsResponse {
+  targets?: {
+    org: Record<string, Target>;
+    user: Record<string, Target>;
+    impact: Record<string, Target>;
+  };
+  logs?: any; // Optional, if logs are part of the response
+}
+
 @Component({
@@ -152,3 +161,3 @@
     // Call the backend endpoint to recalculate targets
-    this.targetsService.recalculateTargets().subscribe((result: any) => {
+    this.targetsService.recalculateTargets().subscribe((result: RecalculateTargetsResponse) => {
       const targets = result.targets || result; // handle both {targets, logs} and just targets
EOF
@@ -23,2 +23,11 @@

interface RecalculateTargetsResponse {
targets?: {
org: Record<string, Target>;
user: Record<string, Target>;
impact: Record<string, Target>;
};
logs?: any; // Optional, if logs are part of the response
}

@Component({
@@ -152,3 +161,3 @@
// Call the backend endpoint to recalculate targets
this.targetsService.recalculateTargets().subscribe((result: any) => {
this.targetsService.recalculateTargets().subscribe((result: RecalculateTargetsResponse) => {
const targets = result.targets || result; // handle both {targets, logs} and just targets
Copilot is powered by AI and may make mistakes. Always verify output.

recalculateTargets() {
// Calls the backend endpoint to recalculate targets
return this.http.get<any>(`${this.apiUrl}/calculate`);

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.

Copilot Autofix

AI 4 months ago

To fix the issue, we need to replace the any type in the recalculateTargets method with a more specific type that matches the expected structure of the API response. If the response structure is known, we should define a new interface or reuse an existing one that accurately represents the data. If the structure is not well-defined, we can use a more generic type like unknown or a union type to provide some level of type safety.

Steps to fix:

  1. Define a new interface (e.g., RecalculateTargetsResponse) that matches the expected structure of the API response, or reuse an existing interface if applicable.
  2. Update the recalculateTargets method to use the new type instead of any.
  3. Ensure the method's implementation and any downstream code handle the response according to the defined type.
Suggested changeset 1
frontend/src/app/services/api/targets.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/app/services/api/targets.service.ts b/frontend/src/app/services/api/targets.service.ts
--- a/frontend/src/app/services/api/targets.service.ts
+++ b/frontend/src/app/services/api/targets.service.ts
@@ -12,2 +12,8 @@
 
+export interface RecalculateTargetsResponse {
+  success: boolean;
+  message?: string;
+  updatedTargets?: Targets;
+}
+
 export interface Targets {
@@ -82,3 +88,3 @@
     // Calls the backend endpoint to recalculate targets
-    return this.http.get<any>(`${this.apiUrl}/calculate`);
+    return this.http.get<RecalculateTargetsResponse>(`${this.apiUrl}/calculate`);
   }
EOF
@@ -12,2 +12,8 @@

export interface RecalculateTargetsResponse {
success: boolean;
message?: string;
updatedTargets?: Targets;
}

export interface Targets {
@@ -82,3 +88,3 @@
// Calls the backend endpoint to recalculate targets
return this.http.get<any>(`${this.apiUrl}/calculate`);
return this.http.get<RecalculateTargetsResponse>(`${this.apiUrl}/calculate`);
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant