Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package timeflow.data.analysis;
 
import timeflow.data.analysis.DBAnalysis.*;
import timeflow.data.db.*;
import timeflow.data.db.filter.*;
import java.text.*;
 
public class RangeNumberAnalysis implements FieldAnalysis {
 
   String[] description;
   static DecimalFormat intFormat=new DecimalFormat("###,###,###,###");
   static DecimalFormat df=new DecimalFormat("###,###,###,###.##");
   
   @Override
   public String getName() {
       return "Value Range";
   }
 
   @Override
   public String[] getResultDescription() {
       return description;
   }
 
   @Override
   public InterestLevel perform(ActList acts, Field field) {
       double low=0;
       double high=0;
       int numZero=0;
       double sum=0;
       int numDefined=0;
 
       boolean defined=false;
       for (Act a: acts)
       {
           if (a.get(field)==null)
               continue;
 
           double x=a.getValue(field);
           numDefined++;
           sum+=x;
           
           if (x==0)
               numZero++;
           if (defined)
           {
               low=Math.min(low,x);
               high=Math.max(high, x);
           } else
           {
               defined=true;
               low=x;
               high=low;
           }
       }
       if (defined)
           description= new String[]
             {
               "Average: "+df.format((sum/numDefined)),
                 "Lowest: "+df.format(low),
                 "Highest: "+df.format(high),
                 "Number of zero values: "+df.format(numZero)
             };
       else
           description=new String[] {"No values defined."};
       
       return InterestLevel.INTERESTING;
   }
   
   static String format(double x)
   {
       
       if (Math.abs(x)>.1)
       {
           if (Math.round(x)-x<.01)
               return intFormat.format(x);
           return df.format(x);
       }
       return ""+x;
   }
 
   @Override
   public boolean canHandleType(Class type) {
       return type==Double.class;
   }
}