<commit_before>var express = require('express');
var router = express.Router();

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('/home/pi/homeauto/backend/temp.db');

/* GET home page. */
router.get('/v1/temperature', function(req, res, next) {
  var filter = "WHERE sensor_fk = 1";
  if(req.query.starttime && req.query.endtime) {
    filter += " AND time >= " + req.query.starttime + " AND time <= " + req.query.endtime;
  } else if(req.query.starttime) {
    filter += " AND time >= " + req.query.starttime;
  } else if(req.query.endtime) {
    filter += " AND time <= " + req.query.endtime;
  }

  var stmt = "SELECT * FROM sensorstream " + filter + " ORDER BY time";
  console.log(stmt)
  db.all(stmt, function(err, rows) {
    res.send(rows);
  });
});

router.get('/v1/temperature/current', function(req, res, next) {
  db.all("SELECT * FROM sensorstream WHERE sensor_fk = 1 ORDER BY time DESC LIMIT 1", function(err, rows) {
    res.send(rows);
  });
});

router.get('/v1/sensorstream/:sid', function(req, res, next) {
  var sensor_id = req.params.sid;
  console.log("sensor id: " + sensor_id)
  res.send({})
});

module.exports = router;<commit_msg>unify sensor stream API and temperature API<commit_after>var express = require('express');
var router = express.Router();

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('/home/pi/homeauto/backend/temp.db');

var getSensorStream = function(sensor_id, starttime, endtime, callback) {
  var filter = "WHERE sensor_fk = " + sensor_id;
  if(starttime && endtime) {
    filter += " AND time >= " + starttime + " AND time <= " + endtime;
  } else if(starttime) {
    filter += " AND time >= " + starttime;
  } else if(endtime) {
    filter += " AND time <= " + endtime;
  }

  var stmt = "SELECT * FROM sensorstream " + filter + " ORDER BY time";
  console.log(stmt)
  db.all(stmt, callbak);
}

/* GET home page. */
router.get('/v1/temperature', function(req, res, next) {
  getSensorStream(1, req.query.starttime, req.query.endtime, function(err, rows) {
    res.send(rows);
  });
});

router.get('/v1/temperature/current', function(req, res, next) {
  db.all("SELECT * FROM sensorstream WHERE sensor_fk = 1 ORDER BY time DESC LIMIT 1", function(err, rows) {
    res.send(rows);
  });
});

router.get('/v1/sensorstream/:sid', function(req, res, next) {
  var sensor_id = req.params.sid;
  getSensorStream(sensor_id, req.query.starttime, req.query.endtime, function(err, rows) {
    res.send(rows);
  });
});

module.exports = router;
{'fraction_non_alphanumeric': 0.17480314960629922, 'fraction_numerical': 0.007086614173228346, 'mean_word_length': 3.849236641221374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2799894', 'n_tokens_mistral': 887, 'n_tokens_neox': 871, 'n_words': 201}