<commit_before>//importing our Reading model, which has a predefined schema you can see in Readings.js
var mongoose       = require('mongoose');
var Reading        = require('./models/Readings.js');
var Usage          = require('./models/Usage.js');
var data           = require('./data.json');
var bodyParser     = require('body-parser');

module.exports = function(app) {

	// server routes ===========================================================
	// handle things like api calls
	// authentication routes	
	// sample api route

var new_load = new Array();

//this should be how we add to the database from now on
/*
app.use(bodyParser.json());
app.use(bodyParser.urlEncoded({extended: true}));
*/
app.post('/load/WaterQuality', function(req, res) {
  var new_load = req.body.data;
  var return_string = "";
  for(i = 0; i < new_load.length; i++) {
    new_load[i].timestamp = new Date(new_load[i].timestamp);
  }
  Reading.create(new_load, function(err, added) {
    if(err)
      res.send(err);
    for(i = 1; i < arguments.length; i++) {
      return_string = return_string + "" + arguments[i] + "\n";
    }
  });
  res.send(return_string);
});

app.post('/load/Usage', function(req, res) {
  var new_load = req.body.data;
  var return_string = "";
  for(i = 0; i < new_load.length; i++) {
    new_load[i].timestamp = new Date(new_load[i].timestamp);
  }
  Usage.create(new_load, function(err, added) {
    if(err)
      res.send(err);
    for(i = 1; i < arguments.length; i++) {
      return_string = return_string + "" + arguments[i] + "\n";
    }
  });
  res.send(return_string);
});
/**
 * Handles the server request to retrieve n records from the database
 * Returns n records from the database... i hope these are most recent
 */
app.post('/api/data/WaterQuality', function(req, res) {
  var n = parseInt(req.body.data);

  Reading.find().sort({timestamp : -1}).limit(n).exec(function(err, readingDetails) {
   // if there is an error retrieving, send the error. 
   // nothing after res.send(err) will execute
    if (err) 
    res.send(err);
      res.json(readingDetails); // return all nerds in JSON format
  });
});<commit_msg>update post request to dynamically load data<commit_after>//importing our Reading model, which has a predefined schema you can see in Readings.js
var mongoose       = require('mongoose');
var Reading        = require('./models/Readings.js');
var Usage          = require('./models/Usage.js');
var data           = require('./data.json');
var bodyParser     = require('body-parser');

module.exports = function(app) {

	// server routes ===========================================================
	// handle things like api calls
	// authentication routes	
	// sample api route

var new_load = new Array();

//this should be how we add to the database from now on
/*
app.use(bodyParser.json());
app.use(bodyParser.urlEncoded({extended: true}));
*/
app.post('/load/WaterQuality', function(req, res) {
  var new_load = req.body;
  var return_string = "success";
  for(i = 0; i < new_load.length; i++) {
    new_load[i].timestamp = new Date(new_load[i].timestamp);
  }
  Reading.create(new_load, function(err, added) {
    if(err)
      res.send(err);
    res.json(added);
  });
});

app.post('/load/Usage', function(req, res) {
  var new_load = req.body;
  var return_string = "success\n";
  for(i = 0; i < new_load.length; i++) {
    new_load[i].timestamp = new Date(new_load[i].timestamp);
  }
  Usage.create(new_load, function(err, added) {
    if(err)
      res.send(err);
    res.json(added);
  });
});
/**
 * Handles the server request to retrieve n records from the database
 * Returns n records from the database... i hope these are most recent
 */
app.post('/api/data/WaterQuality', function(req, res) {
  var n = parseInt(req.body.data);

  Reading.find().sort({timestamp : -1}).limit(n).exec(function(err, readingDetails) {
   // if there is an error retrieving, send the error. 
   // nothing after res.send(err) will execute
    if (err) 
    res.send(err);
      res.json(readingDetails); // return all nerds in JSON format
  });
});
{'fraction_non_alphanumeric': 0.1811293082375947, 'fraction_numerical': 0.001955512099731117, 'mean_word_length': 3.390557939914163, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1011227', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1276, 'n_words': 350}