Skip to content

Commit

Permalink
Added rating
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jun 19, 2024
1 parent 59627a6 commit 05c5745
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugin-server/src/cdp/hog-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,24 @@ export class HogWatcher {
})

this.observations[id] = update(observation)
this.observations[id].rating = this.calculateRating(this.observations[id])
console.log('Observation updated', id, this.observations[id])
}

private calculateRating(observation: HogWatcherObservation): number {
// Rating is from 0 to 1
// 1 - Function is working perfectly
// 0 - Function is not working at all

const totalInvocations = observation.successes + observation.failures
const totalAsyncInvocations = observation.asyncFunctionSuccesses + observation.asyncFunctionFailures

const successRate = totalInvocations ? observation.successes / totalInvocations : 1
const asyncSuccessRate = totalAsyncInvocations ? observation.asyncFunctionSuccesses / totalAsyncInvocations : 1

return Math.min(1, successRate, asyncSuccessRate)
}

observeResults(results: HogFunctionInvocationResult[]) {
// TODO: Actually measure something and store the result
results.forEach((result) => {
Expand Down

0 comments on commit 05c5745

Please sign in to comment.