Skip to content

Commit

Permalink
Generate gradient array on startup instead of every cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Conroman16 committed Jan 20, 2020
1 parent 81f9346 commit ffd1b6e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ICMPPing extends q.DesktopApp {
constructor() {
super();
this.pollingInterval = 1000 * this.getPollingIntervalSeconds();
this.gradientArray = this.generateGradientArray();
logger.info("ICMP Ping applet initialized");
}

async run() {
this.generateGradientArray();
return this.getPingAddress()
.then(address => this.ping(address))
.then(avgResponseTime => ICMPPing.buildSignal(this.config.pingAddress, this.getColor(avgResponseTime), avgResponseTime))
Expand Down Expand Up @@ -79,11 +79,10 @@ class ICMPPing extends q.DesktopApp {
}

getColor(avgResponseTime) {
const colors = this.generateGradientArray();
const minPing = this.getMinPing();
const scalingInterval = this.getColorScalingInterval();
let arrIndx = Math.floor(Math.abs(((avgResponseTime - minPing) / scalingInterval) + 1))
return colors[arrIndx < colors.length ? arrIndx : colors.length - 1];
return this.gradientArray[arrIndx < this.gradientArray.length ? arrIndx : this.gradientArray.length - 1];
}

generateGradientArray(){
Expand Down

0 comments on commit ffd1b6e

Please sign in to comment.