Skip to content
Browse files

Attempt to generate random metrics from the service. THIS IS BROKEN.

  • Loading branch information...
1 parent a208b97 commit c2a8b7fa84e7b8ea7dfc062a39e693bd15857f46 @therealadam committed Feb 10, 2013
Showing with 48 additions and 5 deletions.
  1. +21 −3 src/main/scala/stella/StellaServlet.scala
  2. +27 −2 src/main/webapp/js/stella.js
View
24 src/main/scala/stella/StellaServlet.scala
@@ -20,7 +20,10 @@ class StellaServlet extends StellaByStarlightStack with JacksonJsonSupport {
}
get("/api/metrics") {
- MetricData.generate
+ // Rewrite this to take the start, stop, step parameters and pass
+ // them to the Scala version of the random number generator?
+ MetricData.generate(params("start").toDouble, params("stop").toDouble,
+ params("step").toDouble)
}
}
@@ -36,8 +39,23 @@ object MetricData {
Metric("456", DateTime.now.toString())
)
- def generate = {
- 1 to 1000 map { i => Metric(i.toString(), DateTime.now.toString()) }
+ def generate(start: Double, stop: Double, step: Double) = {
+ var last: Double = start
+ var value: Double = 0.0
+ var values: List[Double] = List()
+ var i: Int = 0
+
+ while (last < stop) {
+ last += step
+ i += 2
+ value = Math.max(-10.0,
+ Math.min(10.0, value + 0.8 * Math.random - 0.4 + 0.2 * Math.cos(i)))
+ value :: values
+ }
+
+ values.slice(((start - stop) / step).toInt, values.length).map { v: Double =>
+ Metric(v.toString(), DateTime.now.toString())
+ }
}
}
View
29 src/main/webapp/js/stella.js
@@ -1,5 +1,28 @@
jQuery(function() {
+
var stellaMetric = function(name) {
+ host = "http://localhost:8080"
+ return context.metric(function(start, stop, step, callback) {
+ path = "/api/metrics"
+ + "?start=" + d3.time.format.iso(start)
+ + "&stop=" + d3.time.format.iso(stop)
+ + "&step" + step;
+ d3.json(host + path,
+ function(data) {
+ if (!data) {
+ return callback(new Error("whups!"));
+ }
+
+ console.log(data);
+ values = data.map(function(d) { return d.value; });
+ // values = data.map(function(d) { return d.value }).slice((start - stop) / step);
+ callback(null, values);
+ console.log("stella", values);
+ });
+ }, name += "");
+ };
+
+ var randomMetric = function(name) {
var value = 0,
values = [],
i = 0,
@@ -24,8 +47,10 @@ jQuery(function() {
.step(1e3)
.size(700);
- var foo = stellaMetric("foo"),
- bar = stellaMetric("bar");
+ // var foo = randomMetric("foo"),
+ // bar = randomMetric("bar");
+ var foo = randomMetric("random"),
+ bar = stellaMetric("stella");
d3.select("#graph").call(function(div) {
div.append("div")

0 comments on commit c2a8b7f

Please sign in to comment.
Something went wrong with that request. Please try again.