<commit_before>var express = require('express');

var app = express();
var http = require('http');
app.set('views', './views');
app.set('view engine', 'jade');
app.use(express.static(__dirname + '/build'));

// Middleware
var bodyParser = require('body-parser');
app.use(bodyParser());

// Store
if (process.env.REDISTOGO_URL) {
  var rtg   = require("url").parse(process.env.REDISTOGO_URL);
  var redis = require("redis").createClient(rtg.port, rtg.hostname);

  redis.auth(rtg.auth.split(":")[1]);
} else {
   var redis = require("redis").createClient();
}

app.route('/')
.get(function (req, res, next){
  console.log('Rendered')
  return res.render('index', { title: 'MockingWatt energy app', message: 'Hello there!'});
})

app.route('/meters')
.get(function (req, res, next){
  return res.json([
    {
      "id": 1,
      "name": "Mystery Building Meter",
      "descr": "A meter you might have in your building.",
      "type": "Electricity",
      "units": "kW",
    }
  ]);
});

// Readings endpoint returns reading values waiting to be sent to BOS. They are rendered meter readings from 
// the values stored in the usage slots. 
// 
// == GET requests return reading objects that have not been processed
// == params: 
// ==   `processed`: [true, false] are allowed; false is the default. 
// ==   `limit`: Number of records to return, default 100

app.route('/readings')
.get(function (req, res, next){
  var readings = [];
  var readingCount = 100;
  if (!isNaN(req.params.limit)){
    readingCount = parseInt(req.params.limit);
  } 
  // faken baken
  var date = new Date();
  
  for (var i=0; i < readingCount; i++){
    date.setMinutes(date.getMinutes() - i);
    var reading = {"timestamp": date.toJSON(), "meterId": 1, "value": 10, "buildingLocalTime": false};
    readings.push(reading);
  }
  return res.json(readings);
});


// Usage endpoint returns/updates energy usage values (faked) for 1 minute resolution for a 24 hour period. 
// The time "slots" are allocated starting at the first minute after midnight (slot 0) all the
// way up to midnight (slot 1440). The usage `values` are set external to the API and reflect the 
// baseline usage for this ficticious meter. The `bias` numbers are set by the client. The
// change when the client posts to the endpoint with an increase, decrease, or reset action.
// 
// == GET requests to this end point will return usage data
// == The default request will return 100 time slots based on the current server time going forward.
// -- 
// == POST will allow the adjustment of usage data
// == params: 
// ==   `action`:['increase', 'decrease', 'reset'] are allowed values
// --  
app.route('/usage')
.get(function (req, res, next){
  var usage = [];
  var slotCount = 100;
  
  // Faked for now
  var date = new Date();
  var currentHour = date.getHours();
  var currentMinute = date.getMinutes(); 
  for (var i=0; i < slotCount; i++){
    var slotNow = (currentHour * currentMinute) + i;
    var fakeBias = Math.ceil(Math.cos(slotNow) * 10);
    usage.push({"slot": slotNow, "value": 10, "bias": fakeBias});
  }
  return res.json(usage);
})
.post(function (req, res, next){
  return res.json({"status":"okay", "message": "Usage adjusted!"})
});

http.createServer(app).listen(process.env.PORT || 3001);
<commit_msg>sligtly better looking fake bias<commit_after>var express = require('express');

var app = express();
var http = require('http');
app.set('views', './views');
app.set('view engine', 'jade');
app.use(express.static(__dirname + '/build'));

// Middleware
var bodyParser = require('body-parser');
app.use(bodyParser());

// Store
if (process.env.REDISTOGO_URL) {
  var rtg   = require("url").parse(process.env.REDISTOGO_URL);
  var redis = require("redis").createClient(rtg.port, rtg.hostname);

  redis.auth(rtg.auth.split(":")[1]);
} else {
   var redis = require("redis").createClient();
}

app.route('/')
.get(function (req, res, next){
  console.log('Rendered')
  return res.render('index', { title: 'MockingWatt energy app', message: 'Hello there!'});
})

app.route('/meters')
.get(function (req, res, next){
  return res.json([
    {
      "id": 1,
      "name": "<NAME>",
      "descr": "A meter you might have in your building.",
      "type": "Electricity",
      "units": "kW",
    }
  ]);
});

// Readings endpoint returns reading values waiting to be sent to BOS. They are rendered meter readings from 
// the values stored in the usage slots. 
// 
// == GET requests return reading objects that have not been processed
// == params: 
// ==   `processed`: [true, false] are allowed; false is the default. 
// ==   `limit`: Number of records to return, default 100

app.route('/readings')
.get(function (req, res, next){
  var readings = [];
  var readingCount = 100;
  if (!isNaN(req.params.limit)){
    readingCount = parseInt(req.params.limit);
  } 
  // faken baken
  var date = new Date();
  
  for (var i=0; i < readingCount; i++){
    date.setMinutes(date.getMinutes() - i);
    var reading = {"timestamp": date.toJSON(), "meterId": 1, "value": 10, "buildingLocalTime": false};
    readings.push(reading);
  }
  return res.json(readings);
});


// Usage endpoint returns/updates energy usage values (faked) for 1 minute resolution for a 24 hour period. 
// The time "slots" are allocated starting at the first minute after midnight (slot 0) all the
// way up to midnight (slot 1440). The usage `values` are set external to the API and reflect the 
// baseline usage for this ficticious meter. The `bias` numbers are set by the client. The
// change when the client posts to the endpoint with an increase, decrease, or reset action.
// 
// == GET requests to this end point will return usage data
// == The default request will return 100 time slots based on the current server time going forward.
// -- 
// == POST will allow the adjustment of usage data
// == params: 
// ==   `action`:['increase', 'decrease', 'reset'] are allowed values
// --  
app.route('/usage')
.get(function (req, res, next){
  var usage = [];
  var slotCount = 100;
  
  // Faked for now
  var date = new Date();
  var currentHour = date.getHours();
  var currentMinute = date.getMinutes(); 
  for (var i=0; i < slotCount; i++){
    var slotNow = (currentHour * currentMinute) + i;
    var fakeBias = Math.ceil(Math.cos(slotNow/10)*10);
    usage.push({"slot": slotNow, "value": 10, "bias": fakeBias});
  }
  return res.json(usage);
})
.post(function (req, res, next){
  return res.json({"status":"okay", "message": "Usage adjusted!"})
});

http.createServer(app).listen(process.env.PORT || 3001);

{'fraction_non_alphanumeric': 0.16291451171280802, 'fraction_numerical': 0.010952236081533314, 'mean_word_length': 3.630281690140845, 'pattern_counts': {'":': 30, '<': 8, '<?xml version=': 0, '>': 4, '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': '38956', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2073, 'n_words': 697}