Skip to content

Commit

Permalink
REST params
Browse files Browse the repository at this point in the history
  • Loading branch information
nickholub committed Apr 18, 2014
1 parent 69c5298 commit 0d1bb07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/scripts/services/datamodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ angular.module('app.service')
};

RestTimeSeriesDataModel.prototype.load = function () {
var params = this.mode ? { bucket: this.mode } : {};
var params = {
bucket: this.mode,
metric: this.dataModelOptions.metric
};

$http.get('/data', {
params: params
Expand Down
20 changes: 13 additions & 7 deletions routes/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var MongoClient = require('mongodb').MongoClient;
var etlDb;

function query(callback, bucket) {
var collection = etlDb.collection('apacheAggregates');
var collection = etlDb.collection('aggregations');

var dimBucket = bucket ? bucket : 'MINUTES';

Expand All @@ -15,7 +15,7 @@ function query(callback, bucket) {
'dimensions.logType': 'apache'
})
.sort({'dimensions.timestamp': -1 })
.limit(2000)
//.limit(2000)
.toArray(callback);
}

Expand All @@ -26,7 +26,7 @@ MongoClient.connect('mongodb://localhost:27017/etl_sample2', function (err, db)
}


var collection = db.collection('apacheAggregates');
var collection = db.collection('aggregations');

collection.stats(function (err, stats) {
console.log(stats);
Expand All @@ -38,20 +38,26 @@ MongoClient.connect('mongodb://localhost:27017/etl_sample2', function (err, db)
});

function data(req, res) {
var metric = req.query.metric;
query(function (err, items) {
var response = _.map(items, function (item) {
return {
timestamp: item.dimensions.timestamp.getTime(),
value: item.metrics.count
value: item.metrics[metric]
};
});

//TODO filter in query with $exists instead
response = _.reject(response, function (item) {
return _.isUndefined(item.value);
});

res.json(response);
}, req.query.bucket);
}

function countries(req, res) {
var collection = etlDb.collection('apacheAggregates');
var collection = etlDb.collection('aggregations');

var limit = req.query.limit ? parseInt(req.query.limit, 10) : 100;

Expand All @@ -76,9 +82,9 @@ function countries(req, res) {
}

function all(req, res) {
var collection = etlDb.collection('apacheAggregates');
var collection = etlDb.collection('aggregations');
collection.find({})
.limit(2000)
//.limit(2000)
.toArray(function (err, data) {
res.json(data);
});
Expand Down

0 comments on commit 0d1bb07

Please sign in to comment.