@@ -16,35 +16,35 @@ public class UnitAgent extends AbstractAgent {
16
16
// *********************** EXAMPLE SOLUTIONS FOR STATS LANE ***********************
17
17
18
18
// instance variables to track metrics going into stats
19
- private long count_sum = 0 ;
20
- private int count_total = 0 ;
19
+ private long countSum = 0 ;
20
+ private int countTotal = 0 ;
21
21
private int index = 0 ;
22
- private long [] recent_data = new long [5 ];
22
+ private long [] recentData = new long [5 ];
23
23
24
24
25
25
// intermediary lanes that represent individual metrics
26
- @ SwimLane ("stats_1 " )
27
- private final ValueLane <Long > stats_1 = this .<Long >valueLane ()
26
+ @ SwimLane ("avg " )
27
+ private final ValueLane <Long > avg = this .<Long >valueLane ()
28
28
.didSet ((n , o ) -> {
29
- logMessage ("stats_1 : mean updated to " + n + " from " + o );
29
+ logMessage ("avg : mean updated to " + n + " from " + o );
30
30
});
31
31
32
- @ SwimLane ("stats_2 " )
33
- private final ValueLane <Long > stats_2 = this .<Long >valueLane ()
32
+ @ SwimLane ("localAvg " )
33
+ private final ValueLane <Long > localAvg = this .<Long >valueLane ()
34
34
.didSet ((n , o ) -> {
35
- logMessage ("stats_2 : local median (last 5 entries) updated to " + n + " from " + o );
35
+ logMessage ("localAvg : local average (last 5 entries) updated to " + n + " from " + o );
36
36
});
37
37
38
- @ SwimLane ("stats_3 " )
39
- private final ValueLane <Long > stats_3 = this .<Long >valueLane ()
38
+ @ SwimLane ("localVar " )
39
+ private final ValueLane <Long > localVar = this .<Long >valueLane ()
40
40
.didSet ((n , o ) -> {
41
- logMessage ("stats_3 : local variance (last 5 entries) updated to " + n + " from " + o );
41
+ logMessage ("localVar : local variance (last 5 entries) updated to " + n + " from " + o );
42
42
});
43
43
44
- @ SwimLane ("stats_4 " )
45
- private final ValueLane <Long > stats_4 = this .<Long >valueLane ()
44
+ @ SwimLane ("localStdDev " )
45
+ private final ValueLane <Long > localStdDev = this .<Long >valueLane ()
46
46
.didSet ((n , o ) -> {
47
- logMessage ("stats_4 : local std deviation (last 5 entries) updated to " + n + " from " + o );
47
+ logMessage ("localStdDev : local std deviation (last 5 entries) updated to " + n + " from " + o );
48
48
});
49
49
50
50
@@ -62,41 +62,38 @@ public class UnitAgent extends AbstractAgent {
62
62
.didUpdate ((k , n , o ) -> {
63
63
logMessage ("histogram: replaced " + k + "'s value to " + Recon .toString (n ) + " from " + Recon .toString (o ));
64
64
65
- // calculating overall mean to send to stats1
66
- count_sum += n .getItem (0 ).longValue ();
67
- count_total ++;
68
- final long avg = count_sum / count_total ;
69
- stats_1 .set (avg );
65
+ // calculating overall mean to send to average lane
66
+ countSum += n .getItem (0 ).longValue ();
67
+ countTotal ++;
68
+ final long AVG = countSum / countTotal ;
69
+ avg .set (AVG );
70
70
71
- // appending new data to the recent_data array
72
- if (index >= recent_data .length -1 ) {
71
+ // appending new data to the recentData array
72
+ if (index >= recentData .length -1 ) {
73
73
index = 0 ;
74
74
}
75
- recent_data [index ] = n .getItem (0 ).longValue ();
75
+ recentData [index ] = n .getItem (0 ).longValue ();
76
76
index ++;
77
77
78
- // calculating local mean to send to stats2
79
- long local_sum = 0 ;
80
- for (long d : recent_data ) local_sum += d ;
81
- final long local_avg = local_sum / (long ) recent_data .length ;
82
- stats_2 .set (local_avg );
78
+ // calculating local mean to send to local average lane
79
+ long localSum = 0 ;
80
+ for (long d : recentData ) localSum += d ;
81
+ final long LOCAL_AVG = localSum / (long ) recentData .length ;
82
+ localAvg .set (LOCAL_AVG );
83
83
84
84
// calculating local variance to send to stats3
85
- long squared_dif_sum = 0 ; // (sum of local mean - each value)^2
86
- for (long d : recent_data ) squared_dif_sum += (d - local_avg )*(d - local_avg );
87
- long local_variance = squared_dif_sum / recent_data .length ;
88
- stats_3 .set (local_variance );
85
+ long squaredDifSum = 0 ; // (sum of local mean - each value)^2
86
+ for (long d : recentData ) squaredDifSum += (d - LOCAL_AVG )*(d - LOCAL_AVG );
87
+ final long LOCAL_VAR = squaredDifSum / recentData .length ;
88
+ localVar .set (LOCAL_VAR );
89
89
90
- // calculating local standard deviation to send to stats4
91
- long local_std_dev = (long )Math .sqrt (local_variance );
92
- stats_4 .set (local_std_dev );
90
+ // calculating local standard deviation to send to local standard deviation lane
91
+ final long LOCAL_STD_DEV = (long )Math .sqrt (LOCAL_VAR );
92
+ localStdDev .set (LOCAL_STD_DEV );
93
93
94
94
// Consolidating all data to the valuelane stats of type value
95
-
96
- Value all_stats = Record .create (4 ).slot ("avg" , avg ).slot ("local_avg" , local_avg ).slot ("local_variance" , local_variance ).slot ("local_std_dev" , local_std_dev );
97
- // build new Record.create(4).slot("") etc
95
+ Value all_stats = Record .create (4 ).slot ("AVG" , AVG ).slot ("LOCAL_AVG" , LOCAL_AVG ).slot ("LOCAL_VAR" , LOCAL_VAR ).slot ("LOCAL_STD_DEV" , LOCAL_STD_DEV );
98
96
stats .set (all_stats );
99
- // TODO: ask how to combine the Longs from each stats_# above into one Value in stats
100
97
101
98
dropOldData ();
102
99
})
@@ -105,8 +102,8 @@ public class UnitAgent extends AbstractAgent {
105
102
// stats.put(stats.get()-o)
106
103
107
104
logMessage ("histogram: removed <" + k + "," + Recon .toString (o ) + ">" );
108
- count_sum = 0 ;
109
- count_total = 0 ;
105
+ countSum = 0 ;
106
+ countTotal = 0 ;
110
107
index = 0 ;
111
108
});
112
109
0 commit comments