From 18c997dd1bbc7f642b030805220e1848a804042d Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 16:22:07 -0700 Subject: [PATCH 01/34] multiple agents --- server/src/main/java/swim/tutorial/DataSource.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index 1f23965..bcb0b87 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -39,7 +39,14 @@ void sendCommands() throws InterruptedException { // *CommandLane* addressable by "publish" OF the // *Web Agent* addressable by "/unit/master" RUNNING ON the // *(Swim) server* addressable by hostUri - this.ref.command(this.hostUri, "/unit/master", "publish", msg); + this.ref.command(this.hostUri, "/unit/master1", "publish", msg); + + // add agents by following the format of the hostURI specified in TutorialPlane + // line 12: @SwimRoute("/unit/:id") + + // this.ref.command(this.hostUri, "/unit/master2", "publish", msg); + // this.ref.command(this.hostUri, "/unit/master3", "publish", msg); + indicator = (indicator + 1) % 1000; // Throttle events to four every three seconds From 6be26515695424adea4e6c0fe73ae1229963ff37 Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 16:27:22 -0700 Subject: [PATCH 02/34] clarify instructions to add agents --- server/src/main/java/swim/tutorial/DataSource.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index bcb0b87..c4a14ca 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -39,13 +39,14 @@ void sendCommands() throws InterruptedException { // *CommandLane* addressable by "publish" OF the // *Web Agent* addressable by "/unit/master" RUNNING ON the // *(Swim) server* addressable by hostUri - this.ref.command(this.hostUri, "/unit/master1", "publish", msg); + this.ref.command(this.hostUri, "/unit/master", "publish", msg); - // add agents by following the format of the hostURI specified in TutorialPlane - // line 12: @SwimRoute("/unit/:id") + // To instantiate more agents, follow the format of the URI pattern specified in TutorialPlane + // see line 12: @SwimRoute("/unit/:id") - // this.ref.command(this.hostUri, "/unit/master2", "publish", msg); - // this.ref.command(this.hostUri, "/unit/master3", "publish", msg); + // EXAMPLES: + // this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); + // this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); indicator = (indicator + 1) % 1000; From a588c8cea878697bb87bd0a8f254a7b332317b82 Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 16:45:09 -0700 Subject: [PATCH 03/34] add exercise instructions to read.me --- server/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/README.md b/server/README.md index 8a81b54..95cd9db 100644 --- a/server/README.md +++ b/server/README.md @@ -10,6 +10,11 @@ Swim implements a general purpose distributed object model. The "objects" in thi [Creating a class](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L13) that extends `swim.api.agent.AbstractAgent` defines a *template* for Web Agents (though not a useful one until we add some [lanes](#lanes)). +#### *Try it yourself:* +- [ ] *Navigate to [swim.tutorial.DataSource.java](https://github.com/swimos/tutorial/blob/master/server/src/main/java/swim/tutorial/DataSource.java)* +- [ ] *Create additional web agents using the instructions in the code* +- [ ] *Compare your answer with those in the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch* + Visit the [documentation](https://developer.swim.ai/concepts/agents/) for further details about Web Agents. ## Lanes From 8ffe6c380f722ac097a080a6e1b3186453279488 Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 17:12:10 -0700 Subject: [PATCH 04/34] make exercise into actionable with TODO --- server/src/main/java/swim/tutorial/DataSource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index c4a14ca..f7f1154 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -44,6 +44,8 @@ void sendCommands() throws InterruptedException { // To instantiate more agents, follow the format of the URI pattern specified in TutorialPlane // see line 12: @SwimRoute("/unit/:id") + // TODO: create two new web agents using the above format + // EXAMPLES: // this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); // this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); From 1a268a139238acc6df840049052959fedee22772 Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 17:15:43 -0700 Subject: [PATCH 05/34] add second try it yourself about stats lane --- server/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/README.md b/server/README.md index 95cd9db..4dd9b71 100644 --- a/server/README.md +++ b/server/README.md @@ -25,6 +25,12 @@ Continuing our analogy, *lane callback* functions serve as the "methods" of Web Each lane type defines a set of overridable (default no-op) lifecycle callbacks. For example, [sending a command message](#sending-data-do-swim) to any command lane will trigger its [`onCommand` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L51-L54). On the other hand, [setting a value lane](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L53) will trigger its `willSet` callback, then update its value, then trigger its [`didSet` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L40-L47). +#### *Try it yourself:* +- [ ] *Navigate to [swim.tutorial.UnitAgent.java](https://github.com/swimos/tutorial/blob/master/server/src/main/java/swim/tutorial/UnitAgent.java)* +- [ ] *Fill in the remaining code to create a new value lane called `stats` which gets populated by changes to the `histogram` map lane* +- [ ] *Experiment with ways to transform the data entries in histogram. Ideas: mean, median, range, standard deviation, variance, etc!* +- [ ] *Compare your answer with those in the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch* + Visit the [documentation](https://developer.swim.ai/concepts/lanes/) for further details about lanes. ## Standing a Swim Server From 237a080a99de6863bd276c5e6246386b95fcad4d Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 17:33:39 -0700 Subject: [PATCH 06/34] revise comment wording so I know what to separate out in the solutions branch --- server/src/main/java/swim/tutorial/DataSource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index f7f1154..0020601 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -44,9 +44,9 @@ void sendCommands() throws InterruptedException { // To instantiate more agents, follow the format of the URI pattern specified in TutorialPlane // see line 12: @SwimRoute("/unit/:id") - // TODO: create two new web agents using the above format + // TODO: Create two new web agents using the above format - // EXAMPLES: + // EXAMPLE SOLUTION: // this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); // this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); From 41748f26788514849ae99e71bc93ae0ce337e47d Mon Sep 17 00:00:00 2001 From: Crista Falk Date: Tue, 7 Jul 2020 17:34:38 -0700 Subject: [PATCH 07/34] empty template with TODOs and hints (w/o solutions) --- .../main/java/swim/tutorial/UnitAgent.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index faed0a5..eb7c03e 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -12,14 +12,27 @@ import java.util.Iterator; public class UnitAgent extends AbstractAgent { + + // TODO: complete the stats Value Lane + // @SwimLane("stats") + + // HINT: Use the valueLane() method to instantiate the lane + // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats + + @SwimLane("histogram") + private final MapLane histogram = this.mapLane() + .didUpdate((k, n, o) -> { + logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); + // TODO: update stats with update logic + + dropOldData(); - @SwimLane("histogram") - private final MapLane histogram = this.mapLane() - .didUpdate((k, n, o) -> { - logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); - dropOldData(); - }); + }) + .didRemove((k,o) -> { + // TODO: update stats with remove logic + }); + @SwimLane("history") private final ListLane history = this.listLane() .didUpdate((idx, newValue, oldValue) -> { From 93730e4c01603932370e05bf3cf377392d4d4dae Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 13:50:17 -0700 Subject: [PATCH 08/34] calculate basic average with stats value lane --- .../main/java/swim/tutorial/UnitAgent.java | 76 ++++++++++++++----- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index eb7c03e..6f4b29b 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -12,26 +12,66 @@ import java.util.Iterator; public class UnitAgent extends AbstractAgent { - - // TODO: complete the stats Value Lane - // @SwimLane("stats") + // instance variables to track metrics going into stats + private long count_sum = 0; + private int count_total = 0; + + @SwimLane("stats") + private final ValueLane stats = this.valueLane() + .didSet((n, o) -> { + logMessage("stats: mean updated to " + n + " from " + o); + }); - // HINT: Use the valueLane() method to instantiate the lane - // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats - @SwimLane("histogram") - private final MapLane histogram = this.mapLane() - .didUpdate((k, n, o) -> { - logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); - // TODO: update stats with update logic - - dropOldData(); - - }) - .didRemove((k,o) -> { - // TODO: update stats with remove logic - - }); + @SwimLane("histogram") + private final MapLane histogram = this.mapLane() + .didUpdate((k, n, o) -> { + logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); + + // calculating mean to send to stats + count_sum += n.getItem(0).longValue(); + // logMessage(count_sum); + + count_total ++; + // logMessage(count_total); + + final long avg = count_sum / count_total; + // logMessage(avg); + + stats.set(avg); + + dropOldData(); + }) + .didRemove((k,o) -> { + // update stats with remove logic + logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); + count_sum = 0; + count_total = 0; + }); + + + + // tutorial outline + +// // TODO: complete the stats Value Lane +// // @SwimLane("stats") +// +// // HINT: Use the valueLane() method to instantiate the lane +// // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats +// +// @SwimLane("histogram") +// private final MapLane histogram = this.mapLane() +// .didUpdate((k, n, o) -> { +// logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); +// // TODO: update stats with update logic +// +// dropOldData(); +// +// }) +// .didRemove((k,o) -> { +// // TODO: update stats with remove logic +// +// }); @SwimLane("history") private final ListLane history = this.listLane() From d6bd22c48f070b39bb4267618049dccdd3549a94 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 14:45:17 -0700 Subject: [PATCH 09/34] added second stats metric (local mean) --- .../main/java/swim/tutorial/UnitAgent.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 6f4b29b..355463e 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -15,12 +15,28 @@ public class UnitAgent extends AbstractAgent { // instance variables to track metrics going into stats private long count_sum = 0; private int count_total = 0; + private int index = 0; + private long local_sum = 0; + private long[] recent_data = new long[5]; - @SwimLane("stats") - private final ValueLane stats = this.valueLane() + + @SwimLane("stats_1") + private final ValueLane stats_1 = this.valueLane() + .didSet((n, o) -> { + logMessage("stats_1: mean updated to " + n + " from " + o); + }); + + @SwimLane("stats_2") + private final ValueLane stats_2 = this.valueLane() .didSet((n, o) -> { - logMessage("stats: mean updated to " + n + " from " + o); + logMessage("stats_2: local median (last 5 entries) updated to " + n + " from " + o); }); + +// @SwimLane("stats_3") +// private final ValueLane stats_3 = this.valueLane() +// .didSet((n, o) -> { +// logMessage("stats_3: local ___ (last 5 entries) updated to " + n + " from " + o); +// }); @SwimLane("histogram") @@ -28,17 +44,24 @@ public class UnitAgent extends AbstractAgent { .didUpdate((k, n, o) -> { logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); - // calculating mean to send to stats + // calculating overall mean to send to stats1 count_sum += n.getItem(0).longValue(); - // logMessage(count_sum); - count_total ++; - // logMessage(count_total); - final long avg = count_sum / count_total; - // logMessage(avg); + stats_1.set(avg); + + // appending new data too the recent_data array + if (index >= recent_data.length-1) { + index = 0; + } + recent_data[index] = n.getItem(0).longValue(); + index ++; - stats.set(avg); + // calculating local mean to send to stats2 + local_sum = 0; + for (long d : recent_data) local_sum += d; + final long local_avg = local_sum / (long) recent_data.length; + stats_2.set(local_avg); dropOldData(); }) @@ -47,6 +70,7 @@ public class UnitAgent extends AbstractAgent { logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); count_sum = 0; count_total = 0; + index = 0; }); From 96a3716e0730b89844802073fe7e944549fcac48 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 15:00:34 -0700 Subject: [PATCH 10/34] add variance and std deviation calculations --- .../main/java/swim/tutorial/UnitAgent.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 355463e..5424823 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -16,7 +16,6 @@ public class UnitAgent extends AbstractAgent { private long count_sum = 0; private int count_total = 0; private int index = 0; - private long local_sum = 0; private long[] recent_data = new long[5]; @@ -32,11 +31,17 @@ public class UnitAgent extends AbstractAgent { logMessage("stats_2: local median (last 5 entries) updated to " + n + " from " + o); }); -// @SwimLane("stats_3") -// private final ValueLane stats_3 = this.valueLane() -// .didSet((n, o) -> { -// logMessage("stats_3: local ___ (last 5 entries) updated to " + n + " from " + o); -// }); + @SwimLane("stats_3") + private final ValueLane stats_3 = this.valueLane() + .didSet((n, o) -> { + logMessage("stats_3: local variance (last 5 entries) updated to " + n + " from " + o); + }); + + @SwimLane("stats_4") + private final ValueLane stats_4 = this.valueLane() + .didSet((n, o) -> { + logMessage("stats_4: local std deviation (last 5 entries) updated to " + n + " from " + o); + }); @SwimLane("histogram") @@ -50,7 +55,7 @@ public class UnitAgent extends AbstractAgent { final long avg = count_sum / count_total; stats_1.set(avg); - // appending new data too the recent_data array + // appending new data to the recent_data array if (index >= recent_data.length-1) { index = 0; } @@ -58,11 +63,21 @@ public class UnitAgent extends AbstractAgent { index ++; // calculating local mean to send to stats2 - local_sum = 0; + long local_sum = 0; for (long d : recent_data) local_sum += d; final long local_avg = local_sum / (long) recent_data.length; stats_2.set(local_avg); + // calculating local variance to send to stats3 + long squared_dif_sum = 0; // (sum of local mean - each value)^2 + for (long d : recent_data) squared_dif_sum += (d - local_avg)*(d - local_avg); + long local_variance = squared_dif_sum/recent_data.length; + stats_3.set(local_variance); + + // calculating local standard deviation to send to stats4 + double local_std_dev = Math.sqrt(local_variance); + stats_4.set((long)local_std_dev); + dropOldData(); }) .didRemove((k,o) -> { From 15a584b4e3c6bd4be02c27e4cbf280933979bda4 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 15:11:36 -0700 Subject: [PATCH 11/34] include more descriptive hints for logic to update stats --- .../main/java/swim/tutorial/UnitAgent.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 5424823..0db298a 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -92,25 +92,31 @@ public class UnitAgent extends AbstractAgent { // tutorial outline -// // TODO: complete the stats Value Lane -// // @SwimLane("stats") -// -// // HINT: Use the valueLane() method to instantiate the lane -// // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats -// -// @SwimLane("histogram") -// private final MapLane histogram = this.mapLane() -// .didUpdate((k, n, o) -> { -// logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); -// // TODO: update stats with update logic -// -// dropOldData(); -// -// }) -// .didRemove((k,o) -> { -// // TODO: update stats with remove logic -// -// }); + // TODO: complete the stats Value Lane + // @SwimLane("stats") + + // HINT: Use the valueLane() method to instantiate the lane + // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats + + @SwimLane("histogram") + private final MapLane histogram = this.mapLane() + .didUpdate((k, n, o) -> { + logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); + // TODO: update stats with update logic + + // HINT: access new data sent to histogram with + // n.getItem(0).longValue() + // HINT: use this data to calculate stats such as mean, variance, std dev, etc + // HINT: send new data to stats lane by calling + // stats.set($TRANSFORMED_DATA) + + dropOldData(); + + }) + .didRemove((k,o) -> { + // TODO: update stats with remove logic + + }); @SwimLane("history") private final ListLane history = this.listLane() From 2515c3d96f553c691bc3557c48c6f65f734b5760 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 15:14:41 -0700 Subject: [PATCH 12/34] made tutorial vs solutions code clearer --- .../main/java/swim/tutorial/DataSource.java | 2 +- .../main/java/swim/tutorial/UnitAgent.java | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index 0020601..c281b26 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -46,7 +46,7 @@ void sendCommands() throws InterruptedException { // TODO: Create two new web agents using the above format - // EXAMPLE SOLUTION: + // ***** EXAMPLE SOLUTION ****** // this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); // this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 0db298a..b643702 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -12,6 +12,8 @@ import java.util.Iterator; public class UnitAgent extends AbstractAgent { + + // ***** EXAMPLE SOLUTION ****** // instance variables to track metrics going into stats private long count_sum = 0; private int count_total = 0; @@ -90,33 +92,33 @@ public class UnitAgent extends AbstractAgent { - // tutorial outline - - // TODO: complete the stats Value Lane - // @SwimLane("stats") - - // HINT: Use the valueLane() method to instantiate the lane - // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats + // ***** TUTORIAL TEMPLATE ****** - @SwimLane("histogram") - private final MapLane histogram = this.mapLane() - .didUpdate((k, n, o) -> { - logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); - // TODO: update stats with update logic - - // HINT: access new data sent to histogram with - // n.getItem(0).longValue() - // HINT: use this data to calculate stats such as mean, variance, std dev, etc - // HINT: send new data to stats lane by calling - // stats.set($TRANSFORMED_DATA) - - dropOldData(); - - }) - .didRemove((k,o) -> { - // TODO: update stats with remove logic - - }); +// // TODO: complete the stats Value Lane +// // @SwimLane("stats") +// +// // HINT: Use the valueLane() method to instantiate the lane +// // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats +// +// @SwimLane("histogram") +// private final MapLane histogram = this.mapLane() +// .didUpdate((k, n, o) -> { +// logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); +// // TODO: update stats with update logic +// +// // HINT: access new data sent to histogram with +// // n.getItem(0).longValue() +// // HINT: use this data to calculate stats such as mean, variance, std dev, etc +// // HINT: send new data to stats lane by calling +// // stats.set($TRANSFORMED_DATA) +// +// dropOldData(); +// +// }) +// .didRemove((k,o) -> { +// // TODO: update stats with remove logic +// +// }); @SwimLane("history") private final ListLane history = this.listLane() From 85fb3aba4db7e15ed5e67556350a5b8f0feb01ca Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 16:19:08 -0700 Subject: [PATCH 13/34] remove TODOs/instructions --- .../main/java/swim/tutorial/DataSource.java | 12 +++---- .../main/java/swim/tutorial/UnitAgent.java | 36 +++---------------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index c281b26..cef9242 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -40,15 +40,13 @@ void sendCommands() throws InterruptedException { // *Web Agent* addressable by "/unit/master" RUNNING ON the // *(Swim) server* addressable by hostUri this.ref.command(this.hostUri, "/unit/master", "publish", msg); + + // *********************** EXAMPLE SOLUTION *********************** - // To instantiate more agents, follow the format of the URI pattern specified in TutorialPlane - // see line 12: @SwimRoute("/unit/:id") + this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); + this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); - // TODO: Create two new web agents using the above format - - // ***** EXAMPLE SOLUTION ****** - // this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); - // this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); + // **************************************************************** indicator = (indicator + 1) % 1000; diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index b643702..13c6a36 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -13,7 +13,8 @@ public class UnitAgent extends AbstractAgent { - // ***** EXAMPLE SOLUTION ****** + // *********************** EXAMPLE SOLUTIONS FOR STATS LANE *********************** + // instance variables to track metrics going into stats private long count_sum = 0; private int count_total = 0; @@ -45,7 +46,7 @@ public class UnitAgent extends AbstractAgent { logMessage("stats_4: local std deviation (last 5 entries) updated to " + n + " from " + o); }); - + // *********************** EXAMPLE SOLUTION FOR HISTOGRAM *********************** @SwimLane("histogram") private final MapLane histogram = this.mapLane() .didUpdate((k, n, o) -> { @@ -83,42 +84,13 @@ public class UnitAgent extends AbstractAgent { dropOldData(); }) .didRemove((k,o) -> { - // update stats with remove logic logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); count_sum = 0; count_total = 0; index = 0; }); - - - // ***** TUTORIAL TEMPLATE ****** - -// // TODO: complete the stats Value Lane -// // @SwimLane("stats") -// -// // HINT: Use the valueLane() method to instantiate the lane -// // HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats -// -// @SwimLane("histogram") -// private final MapLane histogram = this.mapLane() -// .didUpdate((k, n, o) -> { -// logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); -// // TODO: update stats with update logic -// -// // HINT: access new data sent to histogram with -// // n.getItem(0).longValue() -// // HINT: use this data to calculate stats such as mean, variance, std dev, etc -// // HINT: send new data to stats lane by calling -// // stats.set($TRANSFORMED_DATA) -// -// dropOldData(); -// -// }) -// .didRemove((k,o) -> { -// // TODO: update stats with remove logic -// -// }); + // **************************************************************************** @SwimLane("history") private final ListLane history = this.listLane() From a94cc0eb54ca2adf3674016321b31a6f36d48f0b Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 17:26:18 -0700 Subject: [PATCH 14/34] add suggestions to change UI after server exercises --- server/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/README.md b/server/README.md index 4dd9b71..9492f62 100644 --- a/server/README.md +++ b/server/README.md @@ -54,3 +54,10 @@ Visit the [documentation](https://developer.swim.ai/concepts) for further detail Swim client instances use Swim **links** to pull data from a Swim lanes. Like their corresponding lanes, links have overridable callback functions that can be used to [populate UIs](http://github.com/swimos/tutorial/tree/master/ui/index.html#L116-L141). Visit the [documentation](https://developer.swim.ai/concepts/links/) for further details about links. + +## *Visualizing Your Changes in the UI* + +- [ ] *Consider how the above changes to the server code may change the way you'd want to visualize your data* +- [ ] *Navigate to the [ui folder](https://github.com/swimos/tutorial/tree/master/ui)* +- [ ] *Experiment with the UI code to accommodate for your server-side changes* +- [ ] *See the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch for an example of this* From dad986ed31265e95d9d65d8489139c02bf1d726c Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 8 Jul 2020 17:27:22 -0700 Subject: [PATCH 15/34] add suggestions to change UI after server exercises --- ui/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/README.md b/ui/README.md index 6821f30..049348c 100644 --- a/ui/README.md +++ b/ui/README.md @@ -4,6 +4,11 @@ The minimum you need to visualize Swim data is a Swim client. That said, Swim comes with additional tools that let you see your data right away with no extra work. +#### *Try it yourself:* + +- [ ] *Based on changes suggested in* [*the server README*](https://github.com/swimos/tutorial/blob/tutorial_solutions/server/README.md) *, update the UI code to accommodate your new server-side* +- [ ] *See the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch for an example of this* + Read [chart.html](http://github.com/swimos/tutorial/tree/master/ui/chart.html) to build your own line chart. Read [gauge.html](http://github.com/swimos/tutorial/tree/master/ui/gauge.html) to build your own gauge. From 789da1dc36a70a44fa0f479a43572d50fbf5f251 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 14:06:53 -0700 Subject: [PATCH 16/34] select web agent by dropdown with color changes --- ui/chart.html | 146 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 43 deletions(-) diff --git a/ui/chart.html b/ui/chart.html index 0ae92c6..3f8a2dc 100644 --- a/ui/chart.html +++ b/ui/chart.html @@ -5,54 +5,114 @@ +
+ +
+ + + +
+ From aece681469a6b29147435843c7e675729645aac5 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 15:27:01 -0700 Subject: [PATCH 17/34] change color gradients for web agents, dropdown select --- ui/gauge.html | 70 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/ui/gauge.html b/ui/gauge.html index a4d18bd..ffff11b 100644 --- a/ui/gauge.html +++ b/ui/gauge.html @@ -7,6 +7,17 @@
+ +
+ + + +
+ From a2f852d7b74c858c027e3747d9e13b7122a2dfae Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 16:03:43 -0700 Subject: [PATCH 18/34] drop down to select web agent, color scheme change updates per agent --- ui/pie.html | 80 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/ui/pie.html b/ui/pie.html index 479a235..54f77e2 100644 --- a/ui/pie.html +++ b/ui/pie.html @@ -7,6 +7,17 @@
+ +
+ + + +
+ From 65290c20b034e19969aaea0b2e2a623d1d234232 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 16:05:15 -0700 Subject: [PATCH 19/34] differentiate data generated and sent to each web agent --- .../src/main/java/swim/tutorial/DataSource.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/swim/tutorial/DataSource.java b/server/src/main/java/swim/tutorial/DataSource.java index cef9242..f4d639c 100644 --- a/server/src/main/java/swim/tutorial/DataSource.java +++ b/server/src/main/java/swim/tutorial/DataSource.java @@ -43,8 +43,20 @@ void sendCommands() throws InterruptedException { // *********************** EXAMPLE SOLUTION *********************** - this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg); - this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg); + + // change and round scale of foo, bar, baz to make data sent to different agents more distinct and recognizable from each other + final Record msg2 = Record.create(3) + .slot("foo", (double)Math.round((foo + 20) * .5)) + .slot("bar", (double)Math.round((bar - 25) * 1.05)) + .slot("baz", (double)Math.round(baz * .5)); + + final Record msg3 = Record.create(3) + .slot("foo", (double)Math.round((foo + 5) * .5)) + .slot("bar", (double)Math.round((bar + 5) * .75)) + .slot("baz", (double)Math.round((baz + 10) * .15)); + + this.ref.command(this.hostUri, "/unit/secondAgent", "publish", msg2); + this.ref.command(this.hostUri, "/unit/thirdAgent", "publish", msg3); // **************************************************************** From d8901e3d6ad1ad146d499c389338968286a5e010 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 16:35:00 -0700 Subject: [PATCH 20/34] send all stats data to one value lane of type Value --- .../main/java/swim/tutorial/UnitAgent.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 13c6a36..4a191f6 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -22,6 +22,7 @@ public class UnitAgent extends AbstractAgent { private long[] recent_data = new long[5]; + // intermediary lanes that represent individual metrics @SwimLane("stats_1") private final ValueLane stats_1 = this.valueLane() .didSet((n, o) -> { @@ -45,6 +46,15 @@ public class UnitAgent extends AbstractAgent { .didSet((n, o) -> { logMessage("stats_4: local std deviation (last 5 entries) updated to " + n + " from " + o); }); + + + // TODO: combine all calculations into one swimlane of type Value + + @SwimLane("stats") + private final ValueLane stats = this.valueLane() + .didSet((n, o) -> { + logMessage("stats: set to " + Recon.toString(n) + " from " + Recon.toString(o)); + }); // *********************** EXAMPLE SOLUTION FOR HISTOGRAM *********************** @SwimLane("histogram") @@ -78,12 +88,20 @@ public class UnitAgent extends AbstractAgent { stats_3.set(local_variance); // calculating local standard deviation to send to stats4 - double local_std_dev = Math.sqrt(local_variance); - stats_4.set((long)local_std_dev); + long local_std_dev = (long)Math.sqrt(local_variance); + stats_4.set(local_std_dev); + + // Consolidating all data to the valuelane stats of type value + + 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); + // build new Record.create(4).slot("") etc + stats.set(all_stats); + // TODO: ask how to combine the Longs from each stats_# above into one Value in stats dropOldData(); }) .didRemove((k,o) -> { + // TODO: stats.put(stats.get()-o) logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); count_sum = 0; count_total = 0; From ea806bb09b55f644aa8ee94ecd8787e094377718 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 17:59:19 -0700 Subject: [PATCH 21/34] model the stats lane vals in the gauge UI --- ui/gauge.html | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/ui/gauge.html b/ui/gauge.html index ffff11b..db4dffc 100644 --- a/ui/gauge.html +++ b/ui/gauge.html @@ -33,22 +33,26 @@ .sweepAngle(swim.Angle.rad(3 * Math.PI / 2)) .dialColor("#cccccc") .meterColor("#989898") - .title(new swim.TextRunView("Foo, Bar, Baz").font("20px sans-serif")) - .font("14px sans-serif") + .title(new swim.TextRunView("Mean, Local Mean, Local Variance, Local Standard Deviation").font("10px sans-serif")) + .font("10px sans-serif") .textColor("#4a4a4a"); gaugeCanvas.append(gauge); -const fooDial = new swim.DialView() - .label("FOO"); -gauge.setChildView("foo", fooDial); +const avgDial = new swim.DialView() + .label("AVG"); +gauge.setChildView("avg", avgDial); -const barDial = new swim.DialView() - .label("BAR"); -gauge.setChildView("bar", barDial); +const locAvgDial = new swim.DialView() + .label("LOC_AVG"); +gauge.setChildView("loc_avg", locAvgDial); -const bazDial = new swim.DialView() - .label("BAZ"); -gauge.setChildView("baz", bazDial); +const locVarDial = new swim.DialView() + .label("LOC_VAR"); +gauge.setChildView("loc_var", locVarDial); + +const locStdDevDial = new swim.DialView() + .label("LOC_STD_DEV"); +gauge.setChildView("loc_std_dev", locStdDevDial); var colorLow = "#50e3c2"; var colorMed = "#359680"; @@ -74,11 +78,12 @@ var valueLink = swim.downlinkValue() .hostUri("warp://localhost:9001") .nodeUri(agent_URI) - .laneUri("latest") + .laneUri("stats") .didSet(function (value) { - updateDial(fooDial, 70, "foo", value); - updateDial(barDial, 140, "bar", value); - updateDial(bazDial, 210, "baz", value); + updateDial(avgDial, 60, "avg", value); + updateDial(locAvgDial, 60, "local_avg", value); + updateDial(locVarDial, 1000, "local_variance", value); + updateDial(locStdDevDial, 40, "local_std_dev", value) }) .open(); @@ -96,11 +101,12 @@ valueLink = swim.downlinkValue() .hostUri("warp://localhost:9001") .nodeUri(agent_URI) - .laneUri("latest") + .laneUri("stats") .didSet(function (value) { - updateDial(fooDial, 70, "foo", value); - updateDial(barDial, 140, "bar", value); - updateDial(bazDial, 210, "baz", value); + updateDial(avgDial, 60, "avg", value); + updateDial(locAvgDial, 60, "local_avg", value); + updateDial(locVarDial, 1000, "local_variance", value); + updateDial(locStdDevDial, 40, "local_std_dev", value) }) .open(); From 7c2a3e4cecef6c49c26a03a73b1be7aae4b1742e Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Fri, 10 Jul 2020 18:10:57 -0700 Subject: [PATCH 22/34] made TODO comment to add remove logic for histogram --- server/src/main/java/swim/tutorial/UnitAgent.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 4a191f6..ef583e9 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -101,7 +101,9 @@ public class UnitAgent extends AbstractAgent { dropOldData(); }) .didRemove((k,o) -> { - // TODO: stats.put(stats.get()-o) + // TODO: Finish here by adding remove logic + // stats.put(stats.get()-o) + logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); count_sum = 0; count_total = 0; From 3d5ee2fde358f9d08d10b291cb78455821aa907e Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Mon, 13 Jul 2020 12:13:02 -0700 Subject: [PATCH 23/34] variable naming convention refactor --- .../main/java/swim/tutorial/UnitAgent.java | 79 +++++++++---------- ui/gauge.html | 26 +++--- ui/pie.html | 1 + 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index ef583e9..13bda8e 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -16,35 +16,35 @@ public class UnitAgent extends AbstractAgent { // *********************** EXAMPLE SOLUTIONS FOR STATS LANE *********************** // instance variables to track metrics going into stats - private long count_sum = 0; - private int count_total = 0; + private long countSum = 0; + private int countTotal = 0; private int index = 0; - private long[] recent_data = new long[5]; + private long[] recentData = new long[5]; // intermediary lanes that represent individual metrics - @SwimLane("stats_1") - private final ValueLane stats_1 = this.valueLane() + @SwimLane("avg") + private final ValueLane avg = this.valueLane() .didSet((n, o) -> { - logMessage("stats_1: mean updated to " + n + " from " + o); + logMessage("avg: mean updated to " + n + " from " + o); }); - @SwimLane("stats_2") - private final ValueLane stats_2 = this.valueLane() + @SwimLane("localAvg") + private final ValueLane localAvg = this.valueLane() .didSet((n, o) -> { - logMessage("stats_2: local median (last 5 entries) updated to " + n + " from " + o); + logMessage("localAvg: local average (last 5 entries) updated to " + n + " from " + o); }); - @SwimLane("stats_3") - private final ValueLane stats_3 = this.valueLane() + @SwimLane("localVar") + private final ValueLane localVar = this.valueLane() .didSet((n, o) -> { - logMessage("stats_3: local variance (last 5 entries) updated to " + n + " from " + o); + logMessage("localVar: local variance (last 5 entries) updated to " + n + " from " + o); }); - @SwimLane("stats_4") - private final ValueLane stats_4 = this.valueLane() + @SwimLane("localStdDev") + private final ValueLane localStdDev = this.valueLane() .didSet((n, o) -> { - logMessage("stats_4: local std deviation (last 5 entries) updated to " + n + " from " + o); + logMessage("localStdDev: local std deviation (last 5 entries) updated to " + n + " from " + o); }); @@ -62,41 +62,38 @@ public class UnitAgent extends AbstractAgent { .didUpdate((k, n, o) -> { logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); - // calculating overall mean to send to stats1 - count_sum += n.getItem(0).longValue(); - count_total ++; - final long avg = count_sum / count_total; - stats_1.set(avg); + // calculating overall mean to send to average lane + countSum += n.getItem(0).longValue(); + countTotal ++; + final long AVG = countSum / countTotal; + avg.set(AVG); - // appending new data to the recent_data array - if (index >= recent_data.length-1) { + // appending new data to the recentData array + if (index >= recentData.length-1) { index = 0; } - recent_data[index] = n.getItem(0).longValue(); + recentData[index] = n.getItem(0).longValue(); index ++; - // calculating local mean to send to stats2 - long local_sum = 0; - for (long d : recent_data) local_sum += d; - final long local_avg = local_sum / (long) recent_data.length; - stats_2.set(local_avg); + // calculating local mean to send to local average lane + long localSum = 0; + for (long d : recentData) localSum += d; + final long LOCAL_AVG = localSum / (long) recentData.length; + localAvg.set(LOCAL_AVG); // calculating local variance to send to stats3 - long squared_dif_sum = 0; // (sum of local mean - each value)^2 - for (long d : recent_data) squared_dif_sum += (d - local_avg)*(d - local_avg); - long local_variance = squared_dif_sum/recent_data.length; - stats_3.set(local_variance); + long squaredDifSum = 0; // (sum of local mean - each value)^2 + for (long d : recentData) squaredDifSum += (d - LOCAL_AVG)*(d - LOCAL_AVG); + final long LOCAL_VAR = squaredDifSum/recentData.length; + localVar.set(LOCAL_VAR); - // calculating local standard deviation to send to stats4 - long local_std_dev = (long)Math.sqrt(local_variance); - stats_4.set(local_std_dev); + // calculating local standard deviation to send to local standard deviation lane + final long LOCAL_STD_DEV = (long)Math.sqrt(LOCAL_VAR); + localStdDev.set(LOCAL_STD_DEV); // Consolidating all data to the valuelane stats of type value - - 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); - // build new Record.create(4).slot("") etc + 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); stats.set(all_stats); - // TODO: ask how to combine the Longs from each stats_# above into one Value in stats dropOldData(); }) @@ -105,8 +102,8 @@ public class UnitAgent extends AbstractAgent { // stats.put(stats.get()-o) logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); - count_sum = 0; - count_total = 0; + countSum = 0; + countTotal = 0; index = 0; }); diff --git a/ui/gauge.html b/ui/gauge.html index db4dffc..89c591e 100644 --- a/ui/gauge.html +++ b/ui/gauge.html @@ -33,26 +33,26 @@ .sweepAngle(swim.Angle.rad(3 * Math.PI / 2)) .dialColor("#cccccc") .meterColor("#989898") - .title(new swim.TextRunView("Mean, Local Mean, Local Variance, Local Standard Deviation").font("10px sans-serif")) + .title(new swim.TextRunView("Mean, Local Mean, Local Variance, Local Standard Deviation").font("10px sans-serif")) // TextView Docs to find newline .font("10px sans-serif") .textColor("#4a4a4a"); gaugeCanvas.append(gauge); const avgDial = new swim.DialView() .label("AVG"); -gauge.setChildView("avg", avgDial); +gauge.setChildView("AVG", avgDial); const locAvgDial = new swim.DialView() .label("LOC_AVG"); -gauge.setChildView("loc_avg", locAvgDial); +gauge.setChildView("LOC_AVG", locAvgDial); const locVarDial = new swim.DialView() .label("LOC_VAR"); -gauge.setChildView("loc_var", locVarDial); +gauge.setChildView("LOC_VAR", locVarDial); const locStdDevDial = new swim.DialView() .label("LOC_STD_DEV"); -gauge.setChildView("loc_std_dev", locStdDevDial); +gauge.setChildView("LOC_STD_DEV", locStdDevDial); var colorLow = "#50e3c2"; var colorMed = "#359680"; @@ -80,10 +80,10 @@ .nodeUri(agent_URI) .laneUri("stats") .didSet(function (value) { - updateDial(avgDial, 60, "avg", value); - updateDial(locAvgDial, 60, "local_avg", value); - updateDial(locVarDial, 1000, "local_variance", value); - updateDial(locStdDevDial, 40, "local_std_dev", value) + updateDial(avgDial, 60, "AVG", value); + updateDial(locAvgDial, 60, "LOCAL_AVG", value); + updateDial(locVarDial, 1000, "LOCAL_VAR", value); + updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value) }) .open(); @@ -103,10 +103,10 @@ .nodeUri(agent_URI) .laneUri("stats") .didSet(function (value) { - updateDial(avgDial, 60, "avg", value); - updateDial(locAvgDial, 60, "local_avg", value); - updateDial(locVarDial, 1000, "local_variance", value); - updateDial(locStdDevDial, 40, "local_std_dev", value) + updateDial(avgDial, 60, "AVG", value); + updateDial(locAvgDial, 60, "LOCAL_AVG", value); + updateDial(locVarDial, 1000, "LOCAL_VAR", value); + updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value) }) .open(); diff --git a/ui/pie.html b/ui/pie.html index 54f77e2..0ef27cf 100644 --- a/ui/pie.html +++ b/ui/pie.html @@ -114,6 +114,7 @@ .nodeUri(agent_URI) .laneUri("latest") .didSet(function (value) { + // TODO: change to stats updateSlice("foo", value); updateSlice("bar", value); updateSlice("baz", value); From 3a639ddbbfbce55efda6b0228164880665b01380 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Mon, 13 Jul 2020 17:43:08 -0700 Subject: [PATCH 24/34] commit with didRemove logic stopping point, before realizing that upating local stats might not require that --- .../main/java/swim/tutorial/UnitAgent.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 13bda8e..c3174eb 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -81,7 +81,7 @@ public class UnitAgent extends AbstractAgent { final long LOCAL_AVG = localSum / (long) recentData.length; localAvg.set(LOCAL_AVG); - // calculating local variance to send to stats3 + // calculating local variance to send to local var lane long squaredDifSum = 0; // (sum of local mean - each value)^2 for (long d : recentData) squaredDifSum += (d - LOCAL_AVG)*(d - LOCAL_AVG); final long LOCAL_VAR = squaredDifSum/recentData.length; @@ -98,13 +98,41 @@ public class UnitAgent extends AbstractAgent { dropOldData(); }) .didRemove((k,o) -> { - // TODO: Finish here by adding remove logic // stats.put(stats.get()-o) logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); - countSum = 0; - countTotal = 0; - index = 0; + + // remove logic for avg lane + countSum -= o.getItem(0).longValue(); + countTotal --; + avg.put(countSum / countTotal) + + // remove logic for local avg lane + localSum -= o.getItem(0).longValue() + newLocAvg = localSum/(long) (recentData.length-1); + localAvg.put(newLocAvg) + + // remove logic for local var lane + + long squaredDifSum = 0; // (sum of local mean - each value)^2 + for (long d : recentData) squaredDifSum += (d - LOCAL_AVG)*(d - LOCAL_AVG); + final long LOCAL_VAR = squaredDifSum/recentData.length; + localVar.set(LOCAL_VAR); + + for (long d : recentData) { + if (d.equals()) + } + + final long LOCAL_AVG = localSum / (long) recentData.length; + localAvg.set(LOCAL_AVG); + + squaredDifSum-()*()/ + recentData.length-1 + + // remove logic for avg lane + + // remove logic for stats + }); // **************************************************************************** From 4a2ed0286daf5fc86998ed31b6df9cbac7afd1cb Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Mon, 13 Jul 2020 17:48:00 -0700 Subject: [PATCH 25/34] add didRemove for avg and stats (local_* lanes may not require this logic) --- .../main/java/swim/tutorial/UnitAgent.java | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index c3174eb..ed3f67e 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -98,6 +98,7 @@ public class UnitAgent extends AbstractAgent { dropOldData(); }) .didRemove((k,o) -> { + // remove logic typically follows this format: // stats.put(stats.get()-o) logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); @@ -105,33 +106,14 @@ public class UnitAgent extends AbstractAgent { // remove logic for avg lane countSum -= o.getItem(0).longValue(); countTotal --; - avg.put(countSum / countTotal) + AVG = countSum / countTotal; + avg.set(AVG) - // remove logic for local avg lane - localSum -= o.getItem(0).longValue() - newLocAvg = localSum/(long) (recentData.length-1); - localAvg.put(newLocAvg) - - // remove logic for local var lane - - long squaredDifSum = 0; // (sum of local mean - each value)^2 - for (long d : recentData) squaredDifSum += (d - LOCAL_AVG)*(d - LOCAL_AVG); - final long LOCAL_VAR = squaredDifSum/recentData.length; - localVar.set(LOCAL_VAR); - - for (long d : recentData) { - if (d.equals()) - } - - final long LOCAL_AVG = localSum / (long) recentData.length; - localAvg.set(LOCAL_AVG); - - squaredDifSum-()*()/ - recentData.length-1 - - // remove logic for avg lane + // stats based only on the most recent inputs (i.e. localAvg, et al) will constantly update already // remove logic for stats + 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); + stats.set(all_stats); }); From cfd7a9e8b9928b7c2df3568f49b07d95f2e903d3 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Mon, 13 Jul 2020 18:33:55 -0700 Subject: [PATCH 26/34] fixing scope/syntax errors in didRemove --- server/src/main/java/swim/tutorial/UnitAgent.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index ed3f67e..271662b 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -48,8 +48,7 @@ public class UnitAgent extends AbstractAgent { }); - // TODO: combine all calculations into one swimlane of type Value - + // combination all calculations into one swim lane of type Value @SwimLane("stats") private final ValueLane stats = this.valueLane() .didSet((n, o) -> { @@ -106,14 +105,17 @@ public class UnitAgent extends AbstractAgent { // remove logic for avg lane countSum -= o.getItem(0).longValue(); countTotal --; - AVG = countSum / countTotal; - avg.set(AVG) + final long UPDATED_AVG = countSum / countTotal; + avg.set(UPDATED_AVG); // stats based only on the most recent inputs (i.e. localAvg, et al) will constantly update already + final long LOCAL_AVG = localAvg.get(); + final long LOCAL_VAR = localVar.get(); + final long LOCAL_STD_DEV = localStdDev.get(); // remove logic for stats - 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); - stats.set(all_stats); + Value updated_stats = Record.create(4).slot("AVG", UPDATED_AVG).slot("LOCAL_AVG", LOCAL_AVG).slot("LOCAL_VAR", LOCAL_VAR).slot("LOCAL_STD_DEV", LOCAL_STD_DEV); + stats.set(updated_stats); }); From 698515b1804751df1edf11b1e239a4008a9f4cf2 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 11:48:22 -0700 Subject: [PATCH 27/34] fix casing for local final variables (from UPPER to camelCase) --- .../main/java/swim/tutorial/UnitAgent.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 271662b..a7a1771 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -64,8 +64,8 @@ public class UnitAgent extends AbstractAgent { // calculating overall mean to send to average lane countSum += n.getItem(0).longValue(); countTotal ++; - final long AVG = countSum / countTotal; - avg.set(AVG); + final long setAvg = countSum / countTotal; + avg.set(setAvg); // appending new data to the recentData array if (index >= recentData.length-1) { @@ -77,21 +77,21 @@ public class UnitAgent extends AbstractAgent { // calculating local mean to send to local average lane long localSum = 0; for (long d : recentData) localSum += d; - final long LOCAL_AVG = localSum / (long) recentData.length; - localAvg.set(LOCAL_AVG); + final long setLocalAvg = localSum / (long) recentData.length; + localAvg.set(setLocalAvg); // calculating local variance to send to local var lane long squaredDifSum = 0; // (sum of local mean - each value)^2 - for (long d : recentData) squaredDifSum += (d - LOCAL_AVG)*(d - LOCAL_AVG); - final long LOCAL_VAR = squaredDifSum/recentData.length; - localVar.set(LOCAL_VAR); + for (long d : recentData) squaredDifSum += (d - setLocalAvg)*(d - setLocalAvg); + final long setLocalVar = squaredDifSum/recentData.length; + localVar.set(setLocalVar); // calculating local standard deviation to send to local standard deviation lane - final long LOCAL_STD_DEV = (long)Math.sqrt(LOCAL_VAR); - localStdDev.set(LOCAL_STD_DEV); + final long setLocalStdDev = (long)Math.sqrt(setLocalVar); + localStdDev.set(setLocalStdDev); // Consolidating all data to the valuelane stats of type value - 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); + Value all_stats = Record.create(4).slot("avg", setAvg).slot("localAvg", setLocalAvg).slot("localVar", setLocalVar).slot("localStdDev", setLocalStdDev); stats.set(all_stats); dropOldData(); @@ -105,16 +105,16 @@ public class UnitAgent extends AbstractAgent { // remove logic for avg lane countSum -= o.getItem(0).longValue(); countTotal --; - final long UPDATED_AVG = countSum / countTotal; - avg.set(UPDATED_AVG); + final long setUpdatedAvg = countSum / countTotal; + avg.set(setUpdatedAvg); // stats based only on the most recent inputs (i.e. localAvg, et al) will constantly update already - final long LOCAL_AVG = localAvg.get(); - final long LOCAL_VAR = localVar.get(); - final long LOCAL_STD_DEV = localStdDev.get(); + final long setLocalAvg = localAvg.get(); + final long setLocalVar = localVar.get(); + final long setLocalStdDev = localStdDev.get(); // remove logic for stats - Value updated_stats = Record.create(4).slot("AVG", UPDATED_AVG).slot("LOCAL_AVG", LOCAL_AVG).slot("LOCAL_VAR", LOCAL_VAR).slot("LOCAL_STD_DEV", LOCAL_STD_DEV); + Value updated_stats = Record.create(4).slot("avg", setUpdatedAvg).slot("localAvg", setLocalAvg).slot("localVar", setLocalVar).slot("localStdDev", setLocalStdDev); stats.set(updated_stats); }); From f61a70e0e994dada13ffd14b76355dfa982315e6 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 11:58:20 -0700 Subject: [PATCH 28/34] update case of value labels to reflect last commit --- ui/gauge.html | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ui/gauge.html b/ui/gauge.html index 89c591e..5d4c57c 100644 --- a/ui/gauge.html +++ b/ui/gauge.html @@ -39,20 +39,20 @@ gaugeCanvas.append(gauge); const avgDial = new swim.DialView() - .label("AVG"); -gauge.setChildView("AVG", avgDial); + .label("avg"); +gauge.setChildView("avg", avgDial); const locAvgDial = new swim.DialView() - .label("LOC_AVG"); -gauge.setChildView("LOC_AVG", locAvgDial); + .label("localAvg"); +gauge.setChildView("localAvg", locAvgDial); const locVarDial = new swim.DialView() - .label("LOC_VAR"); -gauge.setChildView("LOC_VAR", locVarDial); + .label("localVar"); +gauge.setChildView("localVar", locVarDial); const locStdDevDial = new swim.DialView() - .label("LOC_STD_DEV"); -gauge.setChildView("LOC_STD_DEV", locStdDevDial); + .label("localStdDev"); +gauge.setChildView("localStdDev", locStdDevDial); var colorLow = "#50e3c2"; var colorMed = "#359680"; @@ -80,10 +80,10 @@ .nodeUri(agent_URI) .laneUri("stats") .didSet(function (value) { - updateDial(avgDial, 60, "AVG", value); - updateDial(locAvgDial, 60, "LOCAL_AVG", value); - updateDial(locVarDial, 1000, "LOCAL_VAR", value); - updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value) + updateDial(avgDial, 60, "avg", value); + updateDial(locAvgDial, 60, "localAvg", value); + updateDial(locVarDial, 1000, "localVar", value); + updateDial(locStdDevDial, 40, "localStdDev", value) }) .open(); @@ -103,10 +103,10 @@ .nodeUri(agent_URI) .laneUri("stats") .didSet(function (value) { - updateDial(avgDial, 60, "AVG", value); - updateDial(locAvgDial, 60, "LOCAL_AVG", value); - updateDial(locVarDial, 1000, "LOCAL_VAR", value); - updateDial(locStdDevDial, 40, "LOCAL_STD_DEV", value) + updateDial(avgDial, 60, "avg", value); + updateDial(locAvgDial, 60, "localAvg", value); + updateDial(locVarDial, 1000, "localVar", value); + updateDial(locStdDevDial, 40, "localStdDev", value) }) .open(); From 794d58c188c59384aac65a67ac2a0e4528c49388 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 12:02:21 -0700 Subject: [PATCH 29/34] get item slot in histogram using 'count' key instead of index --- server/src/main/java/swim/tutorial/UnitAgent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index a7a1771..34950a3 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -62,7 +62,7 @@ public class UnitAgent extends AbstractAgent { logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); // calculating overall mean to send to average lane - countSum += n.getItem(0).longValue(); + countSum += n.get("count").longValue(); countTotal ++; final long setAvg = countSum / countTotal; avg.set(setAvg); @@ -71,7 +71,7 @@ public class UnitAgent extends AbstractAgent { if (index >= recentData.length-1) { index = 0; } - recentData[index] = n.getItem(0).longValue(); + recentData[index] = n.get("count").longValue(); index ++; // calculating local mean to send to local average lane @@ -103,7 +103,7 @@ public class UnitAgent extends AbstractAgent { logMessage("histogram: removed <" + k + "," + Recon.toString(o) + ">"); // remove logic for avg lane - countSum -= o.getItem(0).longValue(); + countSum -= o.get("count").longValue() ; countTotal --; final long setUpdatedAvg = countSum / countTotal; avg.set(setUpdatedAvg); From f071c997fac3d94c25bea6b9757eea6c44ffdce4 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 16:25:37 -0700 Subject: [PATCH 30/34] explain code solutions in the readmes --- server/README.md | 22 +++++++++------------- ui/README.md | 7 ++++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/server/README.md b/server/README.md index 9492f62..55baa6b 100644 --- a/server/README.md +++ b/server/README.md @@ -10,10 +10,9 @@ Swim implements a general purpose distributed object model. The "objects" in thi [Creating a class](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L13) that extends `swim.api.agent.AbstractAgent` defines a *template* for Web Agents (though not a useful one until we add some [lanes](#lanes)). -#### *Try it yourself:* -- [ ] *Navigate to [swim.tutorial.DataSource.java](https://github.com/swimos/tutorial/blob/master/server/src/main/java/swim/tutorial/DataSource.java)* -- [ ] *Create additional web agents using the instructions in the code* -- [ ] *Compare your answer with those in the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch* +#### *Example Solutions* +- *Created two additional web agents in (DataSource)[https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/DataSource.java]* +- *Created unique Records (msg2 and msg3) to vary the data sent to different agents* Visit the [documentation](https://developer.swim.ai/concepts/agents/) for further details about Web Agents. @@ -25,11 +24,11 @@ Continuing our analogy, *lane callback* functions serve as the "methods" of Web Each lane type defines a set of overridable (default no-op) lifecycle callbacks. For example, [sending a command message](#sending-data-do-swim) to any command lane will trigger its [`onCommand` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L51-L54). On the other hand, [setting a value lane](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L53) will trigger its `willSet` callback, then update its value, then trigger its [`didSet` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L40-L47). -#### *Try it yourself:* -- [ ] *Navigate to [swim.tutorial.UnitAgent.java](https://github.com/swimos/tutorial/blob/master/server/src/main/java/swim/tutorial/UnitAgent.java)* -- [ ] *Fill in the remaining code to create a new value lane called `stats` which gets populated by changes to the `histogram` map lane* -- [ ] *Experiment with ways to transform the data entries in histogram. Ideas: mean, median, range, standard deviation, variance, etc!* -- [ ] *Compare your answer with those in the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch* +#### *Example Solutions* +- *Added 5 new SwimLanes in (UnitAgent)[https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/UnitAgent.java]* + - *the 'avg' ValueLane keeps track of changes to the mean cumulatively* + - *the 'localAvg', 'localVar', and 'localStdDev' ValueLanes run calculations on the 5 most recent data points sent from histogram* + - *the 'stats' ValueLane is an alternative design choice which tracks each of the above metrics using one lane of type Value (rather than 4 individual lanes of type Long)* Visit the [documentation](https://developer.swim.ai/concepts/lanes/) for further details about lanes. @@ -57,7 +56,4 @@ Visit the [documentation](https://developer.swim.ai/concepts/links/) for further ## *Visualizing Your Changes in the UI* -- [ ] *Consider how the above changes to the server code may change the way you'd want to visualize your data* -- [ ] *Navigate to the [ui folder](https://github.com/swimos/tutorial/tree/master/ui)* -- [ ] *Experiment with the UI code to accommodate for your server-side changes* -- [ ] *See the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch for an example of this* +- *See the [**solutions**](https://github.com/swimos/tutorial/tree/solutions/ui) branch for an example of changes you could make to the UI to reflect these possible solutions* diff --git a/ui/README.md b/ui/README.md index 049348c..70f5bb0 100644 --- a/ui/README.md +++ b/ui/README.md @@ -4,10 +4,11 @@ The minimum you need to visualize Swim data is a Swim client. That said, Swim comes with additional tools that let you see your data right away with no extra work. -#### *Try it yourself:* +#### *Example Solutions* -- [ ] *Based on changes suggested in* [*the server README*](https://github.com/swimos/tutorial/blob/tutorial_solutions/server/README.md) *, update the UI code to accommodate your new server-side* -- [ ] *See the [**tutorial_solutions**](https://github.com/swimos/tutorial/tree/tutorial_solutions) branch for an example of this* +- [ ] *Use the dropdown menu to toggle between three different web agents for each UI demo* +- [ ] *See how each UI demo updates its downlinks when new web agents are selected* +- [ ] *Explore how to include simple visual changes (e.g. color changes for different agents) using the* [*swim UI framework*](https://docs.swimos.org/js/latest/index.html) Read [chart.html](http://github.com/swimos/tutorial/tree/master/ui/chart.html) to build your own line chart. From eea3c4f83b43e18eec3cac45c22e29abd22c3d50 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 16:49:36 -0700 Subject: [PATCH 31/34] flipping the () and [] markdown for links --- server/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/README.md b/server/README.md index 55baa6b..1eea4a6 100644 --- a/server/README.md +++ b/server/README.md @@ -11,7 +11,7 @@ Swim implements a general purpose distributed object model. The "objects" in thi [Creating a class](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L13) that extends `swim.api.agent.AbstractAgent` defines a *template* for Web Agents (though not a useful one until we add some [lanes](#lanes)). #### *Example Solutions* -- *Created two additional web agents in (DataSource)[https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/DataSource.java]* +- *Created two additional web agents in [DataSource](https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/DataSource.java)* - *Created unique Records (msg2 and msg3) to vary the data sent to different agents* Visit the [documentation](https://developer.swim.ai/concepts/agents/) for further details about Web Agents. @@ -25,7 +25,7 @@ Continuing our analogy, *lane callback* functions serve as the "methods" of Web Each lane type defines a set of overridable (default no-op) lifecycle callbacks. For example, [sending a command message](#sending-data-do-swim) to any command lane will trigger its [`onCommand` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L51-L54). On the other hand, [setting a value lane](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L53) will trigger its `willSet` callback, then update its value, then trigger its [`didSet` callback](http://github.com/swimos/tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L40-L47). #### *Example Solutions* -- *Added 5 new SwimLanes in (UnitAgent)[https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/UnitAgent.java]* +- *Added 5 new SwimLanes in [UnitAgent](https://github.com/swimos/tutorial/blob/solutions/server/src/main/java/swim/tutorial/UnitAgent.java)* - *the 'avg' ValueLane keeps track of changes to the mean cumulatively* - *the 'localAvg', 'localVar', and 'localStdDev' ValueLanes run calculations on the 5 most recent data points sent from histogram* - *the 'stats' ValueLane is an alternative design choice which tracks each of the above metrics using one lane of type Value (rather than 4 individual lanes of type Long)* From fb541c1415bd3c1725bcc688cd4a89004fcf10b7 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 16:52:52 -0700 Subject: [PATCH 32/34] fix variable name -> updatedStats --- server/src/main/java/swim/tutorial/UnitAgent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 34950a3..5a7c37f 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -115,7 +115,7 @@ public class UnitAgent extends AbstractAgent { // remove logic for stats Value updated_stats = Record.create(4).slot("avg", setUpdatedAvg).slot("localAvg", setLocalAvg).slot("localVar", setLocalVar).slot("localStdDev", setLocalStdDev); - stats.set(updated_stats); + stats.set(updatedStats); }); From a89facfe8262ab356ed1f414a1888489c1599bc8 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Tue, 14 Jul 2020 16:54:50 -0700 Subject: [PATCH 33/34] remove gratuitous TODO --- ui/pie.html | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/pie.html b/ui/pie.html index 0ef27cf..54f77e2 100644 --- a/ui/pie.html +++ b/ui/pie.html @@ -114,7 +114,6 @@ .nodeUri(agent_URI) .laneUri("latest") .didSet(function (value) { - // TODO: change to stats updateSlice("foo", value); updateSlice("bar", value); updateSlice("baz", value); From 95a5f3c5f03a8348982fca4a90ab2e52d8907b85 Mon Sep 17 00:00:00 2001 From: Crista2019 Date: Wed, 15 Jul 2020 10:20:40 -0700 Subject: [PATCH 34/34] make ++ and -- uniform without spaces before --- server/src/main/java/swim/tutorial/UnitAgent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/swim/tutorial/UnitAgent.java b/server/src/main/java/swim/tutorial/UnitAgent.java index 5a7c37f..d2e9a07 100644 --- a/server/src/main/java/swim/tutorial/UnitAgent.java +++ b/server/src/main/java/swim/tutorial/UnitAgent.java @@ -63,7 +63,7 @@ public class UnitAgent extends AbstractAgent { // calculating overall mean to send to average lane countSum += n.get("count").longValue(); - countTotal ++; + countTotal++; final long setAvg = countSum / countTotal; avg.set(setAvg); @@ -72,7 +72,7 @@ public class UnitAgent extends AbstractAgent { index = 0; } recentData[index] = n.get("count").longValue(); - index ++; + index++; // calculating local mean to send to local average lane long localSum = 0; @@ -104,7 +104,7 @@ public class UnitAgent extends AbstractAgent { // remove logic for avg lane countSum -= o.get("count").longValue() ; - countTotal --; + countTotal--; final long setUpdatedAvg = countSum / countTotal; avg.set(setUpdatedAvg);