Skip to content

Commit

Permalink
Adding interpolation calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
  • Loading branch information
gnanakeethan committed Sep 1, 2023
1 parent 3b3eef4 commit a6e49d1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib/teads-curve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class TeadsCurveModel implements IImpactModelInterface {
* @param {string} name name of the resource
* @param {Object} staticParams static parameters for the resource
* @param {number} staticParams.tdp Thermal Design Power in Watts
* @param {Interpolation} staticParams.interpolation Interpolation method
*/
async configure(
name: string,
Expand Down Expand Up @@ -133,7 +134,22 @@ export class TeadsCurveModel implements IImpactModelInterface {
tdp = observation['tdp'] as number;
}

const wattage = this.spline.at(cpu) * tdp;
let wattage = 0.0;
if (this.interpolation === Interpolation.SPLINE) {
wattage = this.spline.at(cpu) * tdp;
} else if (this.interpolation === Interpolation.LINEAR) {
let min = 0;
let max = 1;
const x = this.points;
const y = this.curve;
for (let i = 0; i < x.length; i++) {
if (cpu >= x[i] && cpu <= x[i + 1]) {
min = i;
max = i + 1;
}
}
wattage = (y[0] + ((y[max] - y[min]) / (x[max] - x[min])) * cpu) / 100.0;
}
// duration is in seconds
// wattage is in watts
// eg: 30W x 300s = 9000 J
Expand Down

0 comments on commit a6e49d1

Please sign in to comment.