Navigation Menu

Skip to content

Commit

Permalink
Attempt to generate random metrics from the service. THIS IS BROKEN.
Browse files Browse the repository at this point in the history
  • Loading branch information
therealadam committed Feb 11, 2013
1 parent a208b97 commit c2a8b7f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/main/scala/stella/StellaServlet.scala
Expand Up @@ -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)
}

}
Expand All @@ -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())
}
}

}
Expand Down
29 changes: 27 additions & 2 deletions 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,
Expand All @@ -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")
Expand Down

0 comments on commit c2a8b7f

Please sign in to comment.