Skip to content

Commit 3d5ee2f

Browse files
committed
variable naming convention refactor
1 parent 7c2a3e4 commit 3d5ee2f

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed

server/src/main/java/swim/tutorial/UnitAgent.java

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ public class UnitAgent extends AbstractAgent {
1616
// *********************** EXAMPLE SOLUTIONS FOR STATS LANE ***********************
1717

1818
// 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;
2121
private int index = 0;
22-
private long[] recent_data = new long[5];
22+
private long[] recentData = new long[5];
2323

2424

2525
// 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()
2828
.didSet((n, o) -> {
29-
logMessage("stats_1: mean updated to " + n + " from " + o);
29+
logMessage("avg: mean updated to " + n + " from " + o);
3030
});
3131

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()
3434
.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);
3636
});
3737

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()
4040
.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);
4242
});
4343

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()
4646
.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);
4848
});
4949

5050

@@ -62,41 +62,38 @@ public class UnitAgent extends AbstractAgent {
6262
.didUpdate((k, n, o) -> {
6363
logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o));
6464

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);
7070

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) {
7373
index = 0;
7474
}
75-
recent_data[index] = n.getItem(0).longValue();
75+
recentData[index] = n.getItem(0).longValue();
7676
index ++;
7777

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);
8383

8484
// 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);
8989

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);
9393

9494
// 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);
9896
stats.set(all_stats);
99-
// TODO: ask how to combine the Longs from each stats_# above into one Value in stats
10097

10198
dropOldData();
10299
})
@@ -105,8 +102,8 @@ public class UnitAgent extends AbstractAgent {
105102
// stats.put(stats.get()-o)
106103

107104
logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">");
108-
count_sum = 0;
109-
count_total = 0;
105+
countSum = 0;
106+
countTotal = 0;
110107
index = 0;
111108
});
112109

ui/gauge.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@
3333
.sweepAngle(swim.Angle.rad(3 * Math.PI / 2))
3434
.dialColor("#cccccc")
3535
.meterColor("#989898")
36-
.title(new swim.TextRunView("Mean, Local Mean, Local Variance, Local Standard Deviation").font("10px sans-serif"))
36+
.title(new swim.TextRunView("Mean, Local Mean, Local Variance, Local Standard Deviation").font("10px sans-serif")) // TextView Docs to find newline
3737
.font("10px sans-serif")
3838
.textColor("#4a4a4a");
3939
gaugeCanvas.append(gauge);
4040

4141
const avgDial = new swim.DialView()
4242
.label("AVG");
43-
gauge.setChildView("avg", avgDial);
43+
gauge.setChildView("AVG", avgDial);
4444

4545
const locAvgDial = new swim.DialView()
4646
.label("LOC_AVG");
47-
gauge.setChildView("loc_avg", locAvgDial);
47+
gauge.setChildView("LOC_AVG", locAvgDial);
4848

4949
const locVarDial = new swim.DialView()
5050
.label("LOC_VAR");
51-
gauge.setChildView("loc_var", locVarDial);
51+
gauge.setChildView("LOC_VAR", locVarDial);
5252

5353
const locStdDevDial = new swim.DialView()
5454
.label("LOC_STD_DEV");
55-
gauge.setChildView("loc_std_dev", locStdDevDial);
55+
gauge.setChildView("LOC_STD_DEV", locStdDevDial);
5656

5757
var colorLow = "#50e3c2";
5858
var colorMed = "#359680";
@@ -80,10 +80,10 @@
8080
.nodeUri(agent_URI)
8181
.laneUri("stats")
8282
.didSet(function (value) {
83-
updateDial(avgDial, 60, "avg", value);
84-
updateDial(locAvgDial, 60, "local_avg", value);
85-
updateDial(locVarDial, 1000, "local_variance", value);
86-
updateDial(locStdDevDial, 40, "local_std_dev", value)
83+
updateDial(avgDial, 60, "AVG", value);
84+
updateDial(locAvgDial, 60, "LOCAL_AVG", value);
85+
updateDial(locVarDial, 1000, "LOCAL_VAR", value);
86+
updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value)
8787
})
8888
.open();
8989

@@ -103,10 +103,10 @@
103103
.nodeUri(agent_URI)
104104
.laneUri("stats")
105105
.didSet(function (value) {
106-
updateDial(avgDial, 60, "avg", value);
107-
updateDial(locAvgDial, 60, "local_avg", value);
108-
updateDial(locVarDial, 1000, "local_variance", value);
109-
updateDial(locStdDevDial, 40, "local_std_dev", value)
106+
updateDial(avgDial, 60, "AVG", value);
107+
updateDial(locAvgDial, 60, "LOCAL_AVG", value);
108+
updateDial(locVarDial, 1000, "LOCAL_VAR", value);
109+
updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value)
110110
})
111111
.open();
112112

ui/pie.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
.nodeUri(agent_URI)
115115
.laneUri("latest")
116116
.didSet(function (value) {
117+
// TODO: change to stats
117118
updateSlice("foo", value);
118119
updateSlice("bar", value);
119120
updateSlice("baz", value);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy