resolve division by zero
This commit is contained in:
parent
f07ce97834
commit
c77fbcd473
4 changed files with 41 additions and 65 deletions
|
@ -1,30 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by geoff on 5/30/16.
|
|
||||||
* changed by Andy 10/20/18
|
|
||||||
*/
|
|
||||||
public class FrequencyScanResults {
|
|
||||||
|
|
||||||
public List<FrequencyTrial> trials = new ArrayList<>();
|
|
||||||
public double bestFrequencyMHz = 0.0;
|
|
||||||
public long dateTime;
|
|
||||||
|
|
||||||
|
|
||||||
public void sort() {
|
|
||||||
Collections.sort(trials, (trial1, trial2) -> {
|
|
||||||
int res = trial1.averageRSSI.compareTo(trial2.averageRSSI);
|
|
||||||
|
|
||||||
if (res == 0) {
|
|
||||||
return (int)(trial1.frequencyMHz - trial2.frequencyMHz);
|
|
||||||
} else
|
|
||||||
return res;
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data
|
||||||
|
|
||||||
|
class FrequencyScanResults {
|
||||||
|
|
||||||
|
@JvmField var trials: MutableList<FrequencyTrial> = ArrayList()
|
||||||
|
@JvmField var bestFrequencyMHz = 0.0
|
||||||
|
@JvmField var dateTime: Long = 0
|
||||||
|
fun sort() {
|
||||||
|
trials.sortWith { trial1: FrequencyTrial, trial2: FrequencyTrial ->
|
||||||
|
val res = trial1.averageRSSI.compareTo(trial2.averageRSSI)
|
||||||
|
if (res == 0) (trial1.frequencyMHz - trial2.frequencyMHz).toInt()
|
||||||
|
else res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,35 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by geoff on 5/30/16.
|
|
||||||
* changed by Andy 10/20/18
|
|
||||||
*/
|
|
||||||
public class FrequencyTrial {
|
|
||||||
|
|
||||||
public int tries = 0;
|
|
||||||
public int successes = 0;
|
|
||||||
public Double averageRSSI = 0.0;
|
|
||||||
public double frequencyMHz = 0.0;
|
|
||||||
public List<Integer> rssiList = new ArrayList<>();
|
|
||||||
public double averageRSSI2;
|
|
||||||
|
|
||||||
|
|
||||||
public void calculateAverage() {
|
|
||||||
int sum = 0;
|
|
||||||
int count = 0;
|
|
||||||
for (Integer rssi : rssiList) {
|
|
||||||
sum += Math.abs(rssi);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
double avg = (sum / (count * 1.0d));
|
|
||||||
|
|
||||||
if (count != 0)
|
|
||||||
this.averageRSSI = avg * (-1);
|
|
||||||
else
|
|
||||||
this.averageRSSI = -99.0d;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data
|
||||||
|
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
class FrequencyTrial {
|
||||||
|
|
||||||
|
@JvmField var tries = 0
|
||||||
|
@JvmField var successes = 0
|
||||||
|
@JvmField var averageRSSI = 0.0
|
||||||
|
@JvmField var frequencyMHz = 0.0
|
||||||
|
@JvmField var rssiList: List<Int> = ArrayList()
|
||||||
|
@JvmField var averageRSSI2 = 0.0
|
||||||
|
fun calculateAverage() {
|
||||||
|
var sum = 0
|
||||||
|
var count = 0
|
||||||
|
for (rssi in rssiList) {
|
||||||
|
sum += abs(rssi)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
averageRSSI =
|
||||||
|
if (count != 0) {
|
||||||
|
val avg = sum / (count * 1.0)
|
||||||
|
avg * -1
|
||||||
|
} else -99.0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue