Skip to content
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

Implement Target Values API and frontend component for predictive modeling #62

Merged
3 commits merged into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backend/src/controllers/target-values.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Request, Response } from 'express';
import TargetValuesService from '../services/target-values.service.js';

class TargetValuesController {
async getTargetValues(req: Request, res: Response): Promise<void> {
try {
const targetValues = await TargetValuesService.getTargetValues();
res.status(200).json(targetValues);
} catch (error) {
res.status(500).json(error);
}
}

async updateTargetValues(req: Request, res: Response): Promise<void> {
try {
const updatedTargetValues = await TargetValuesService.updateTargetValues(req.body);
res.status(200).json(updatedTargetValues);
} catch (error) {
res.status(500).json(error);
}
}
}

export default new TargetValuesController();
29 changes: 29 additions & 0 deletions backend/src/models/target-values.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../database.js';

class TargetValues extends Model {
public targetedRoomForImprovement!: number;
public targetedNumberOfDevelopers!: number;
public targetedPercentOfTimeSaved!: number;
}

TargetValues.init({
targetedRoomForImprovement: {
type: DataTypes.FLOAT,
allowNull: false,
},
targetedNumberOfDevelopers: {
type: DataTypes.INTEGER,
allowNull: false,
},
targetedPercentOfTimeSaved: {
type: DataTypes.FLOAT,
allowNull: false,
}
}, {
sequelize,
modelName: 'TargetValues',
timestamps: false,
});

export { TargetValues };
9 changes: 9 additions & 0 deletions backend/src/routes/target-values.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from 'express';
import TargetValuesController from '../controllers/target-values.controller.js';

const router = Router();

router.get('/', TargetValuesController.getTargetValues);
router.put('/', TargetValuesController.updateTargetValues);

export default router;
22 changes: 22 additions & 0 deletions backend/src/services/target-values.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TargetValues } from '../models/target-values.model.js';

class TargetValuesService {
async getTargetValues() {
return await TargetValues.findAll();
}

async updateTargetValues(data: { targetedRoomForImprovement: number, targetedNumberOfDevelopers: number, targetedPercentOfTimeSaved: number }) {
const [targetValues] = await TargetValues.findOrCreate({
where: {},
defaults: data
});

if (!targetValues.isNewRecord) {
await targetValues.update(data);
}

return targetValues;
}
}

export default new TargetValuesService();
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="page-container">
<div class="page-header">
<h1>Predictive Modeling</h1>
</div>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="developerTotal">Total Developers</label>
<input type="number" id="developerTotal" formControlName="developerTotal">
</div>
<div class="form-group">
<label for="adopterCount">Adopter Count</label>
<input type="number" id="adopterCount" formControlName="adopterCount">
</div>
<div class="form-group">
<label for="perLicenseCost">Per License Cost</label>
<input type="number" id="perLicenseCost" formControlName="perLicenseCost">
</div>
<div class="form-group">
<label for="perDevCostPerYear">Per Developer Cost Per Year</label>
<input type="number" id="perDevCostPerYear" formControlName="perDevCostPerYear">
</div>
<div class="form-group">
<label for="perDevHoursPerYear">Per Developer Hours Per Year</label>
<input type="number" id="perDevHoursPerYear" formControlName="perDevHoursPerYear">
</div>
<div class="form-group">
<label for="percentofHoursCoding">Percent of Hours Coding</label>
<input type="number" id="percentofHoursCoding" formControlName="percentofHoursCoding">
</div>
<div class="form-group">
<label for="targetedNumberOfDevelopers">Targeted Number of Developers</label>
<input type="number" id="targetedNumberOfDevelopers" formControlName="targetedNumberOfDevelopers">
</div>
<div class="form-group">
<label for="targetedPercentOfTimeSaved">Targeted Percent of Time Saved</label>
<input type="number" id="targetedPercentOfTimeSaved" formControlName="targetedPercentOfTimeSaved">
</div>
<div class="form-group">
<label for="targetedRoomForImprovement">Targeted Room for Improvement</label>
<input type="number" id="targetedRoomForImprovement" formControlName="targetedRoomForImprovement" readonly>
</div>
<div class="form-group">
<label for="roomForImprovement">Room for Improvement</label>
<input type="number" id="roomForImprovement" formControlName="roomForImprovement" readonly>
</div>
<button type="submit">Save</button>
</form>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { PredictiveModelingComponent } from './predictive-modeling.component';

describe('PredictiveModelingComponent', () => {
let component: PredictiveModelingComponent;
let fixture: ComponentFixture<PredictiveModelingComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PredictiveModelingComponent]
})
.compileComponents();

fixture = TestBed.createComponent(PredictiveModelingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-predictive-modeling',
standalone: true,
imports: [],
templateUrl: './predictive-modeling.component.html',
styleUrl: './predictive-modeling.component.scss'
})
export class PredictiveModelingComponent {

}
Loading