fix error ratio calc

This commit is contained in:
Wolfgang Hottgenroth 2020-09-07 20:01:01 +02:00
parent 744f1b2108
commit d861fe19f2
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
3 changed files with 5 additions and 3 deletions

View File

@ -66,7 +66,7 @@ abstract public class MbusDevice {
}
public double getErrorRatio() {
return this.errorCnt / (this.successCnt + this.errorCnt);
return (double)this.errorCnt / (double)(this.successCnt + this.errorCnt);
}
public void parse(byte[] frame) throws MbusException {

View File

@ -69,7 +69,7 @@ public class MbusScheduledQuerier extends Thread {
}
}
logger.info("CycleCnt: " + cnt + ", SuccessCnt: " + successCnt + ", ErrCnt: " + errCnt);
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt));
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt, ((double)errCnt / (double)(errCnt+successCnt))));
try {
Thread.sleep(5*1000);
} catch (InterruptedException e) {

View File

@ -6,14 +6,16 @@ public class MbusStatisticsDataObject extends ADataObject {
private static final long serialVersionUID = 1L;
static final String ERROR_CNT_KEY = "error";
static final String SUCCESS_CNT_KEY = "success";
static final String ERROR_RATIO_KEY = "errorRatio";
static final String TABLE_NAME = "Statistics";
static final String KIND_NAME = "Statistics";
public MbusStatisticsDataObject(String name, int error, int success) {
public MbusStatisticsDataObject(String name, int error, int success, double errorRatio) {
super(name, KIND_NAME);
HashMap<String, Object> values = new HashMap<String, Object>();
values.put(ERROR_CNT_KEY, error);
values.put(SUCCESS_CNT_KEY, success);
values.put(ERROR_RATIO_KEY, errorRatio);
setValues(values);
}