00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package sensix.sensing;
00036
00037 import sensix.*;
00038
00039
00040 public class Sigma extends Aggregate
00041 {
00042 public Sigma(byte l, Collection[] c) {
00043 super("Sigma", l, c);
00044 }
00045
00046 public Sigma(Collection[] c) {
00047 super("Sigma", c);
00048 }
00049
00050 public Sigma(byte l, Collection[] c, int seq) {
00051 super("Sigma", l, c, seq);
00052 }
00053
00054
00055 public byte identifier() {
00056 return Sensix.SIGMA;
00057 }
00058
00059 protected Data getResult(int idx) {
00060 double avg = 0;
00061 double value = 0;
00062 Data[] res = collectors()[idx].results();
00063 for (int i = 0; i < res.length; i++) {
00064 Data d = res[i];
00065 if (SenseUtil.isIntegerData(d.discriminator()))
00066 avg += res[i].iresult();
00067 else if (SenseUtil.isFloatingPointData(d.discriminator()))
00068 avg += res[i].fresult();
00069 }
00070 avg /= res.length;
00071 for (int i = 0; i < res.length; i++) {
00072 Data d = res[i];
00073 double dev = 0.0;
00074 if (SenseUtil.isIntegerData(d.discriminator()))
00075 dev = d.iresult() - avg;
00076 else if (SenseUtil.isFloatingPointData(d.discriminator()))
00077 dev = d.fresult() - avg;
00078 value += (dev * dev);
00079 }
00080 value /= (res.length - 1);
00081 value = Math.sqrt(value);
00082
00083 Data ret = new Data();
00084 ret.fresult(value);
00085 return ret;
00086 }
00087
00088 public Data result() {
00089 return getResult(0);
00090 }
00091
00092 public Data[] results() {
00093 int num = collectors().length;
00094 Data[] array = new Data[num];
00095 for (int i = 0; i < num; i++)
00096 array[i] = getResult(i);
00097 return array;
00098 }
00099
00100 public void results(Data[] data) {}
00101 }