<commit_before>const express = require('express');
const bodyParser= require('body-parser')
const MongoClient = require('mongodb').MongoClient
//var http = require('https');

//app var
const app = express();


// Generic error handler used by all endpoints.
function handleError(res, reason, message, code) {
  console.log("ERROR: " + reason);
  res.status(code || 500).json({"error": message});
}


app.use(bodyParser.urlencoded({extended: true}))

app.get('/', (req, res) => {
  //res.sendFile(__dirname + '/index.html')
  // Note: __dirname is directory that contains the JavaScript source code. Try logging it and see what you get!
  // Mine was '/Users/zellwk/Projects/demo-repos/crud-express-mongo' for this app.
})

/**
app.post('/quotes', (req, res) => {
  console.log(req.body)
})**/

//Get user data, verify by pin
//Test url to access
// http://localhost:3000/user/Alan%20Niemiec/2345
app.post('/user', getUserData);

app.get('/leaderboard');

app.get('/addRecord');
    //MONGO code
//Mongo instance
var db;

//User data objects
var currentUser;
var currentUserAccounts = new Map();

MongoClient.connect("mongodb://Test:<EMAIL>:39187/heroku_vh3f7203", (err, database) => {
  db = database;
  console.log("db connection ready");

  var server = app.listen(process.env.PORT || 3000, function () {
    var port = server.address().port;
    console.log("App now running on port", port);
  });
})<commit_msg>Get leaderboard ready for testing"<commit_after>const express = require('express');
const bodyParser= require('body-parser')
const MongoClient = require('mongodb').MongoClient
//var http = require('https');

//app var
const app = express();


// Generic error handler used by all endpoints.
function handleError(res, reason, message, code) {
  console.log("ERROR: " + reason);
  res.status(code || 500).json({"error": message});
}


app.use(bodyParser.urlencoded({extended: true}))

app.get('/', (req, res) => {
  //res.sendFile(__dirname + '/index.html')
  // Note: __dirname is directory that contains the JavaScript source code. Try logging it and see what you get!
  // Mine was '/Users/zellwk/Projects/demo-repos/crud-express-mongo' for this app.
})

/**
app.post('/quotes', (req, res) => {
  console.log(req.body)
})**/

//Get user data, verify by pin
//Test url to access
// http://localhost:3000/user/Alan%20Niemiec/2345
app.post('/user', getUserData);

app.get('/leaderboard' ,getLeaderboard);

app.get('/addRecord', addRecord);
    //MONGO code
//Mongo instance
var db;

//User data objects
var currentUser;
var currentUserAccounts = new Map();

MongoClient.connect("mongodb://testBasketball:<PASSWORD> <EMAIL>:45220/heroku_sjst9tqr", (err, database) => {
  db = database;
  console.log("db connection ready");

  var server = app.listen(process.env.PORT || 3000, function () {
    var port = server.address().port;
    console.log("App now running on port", port);
  });
})


function findOne(collectionName, query, callback){
   db.collection(collectionName).findOne(query, function (err, item){
     if (err){
       callback(err);
     }
     else{
       //Return the data with no errors
       callback(null, item);
    }
   });
 }

function getLeaderboard(req, res){
  //Constuct the query
  var query = {"users"};
  //Find one user only in the database
  findOne("leaderboard", query, function (err, item){
      //Log any errors
      if(err) {
       console.log(err);
        return;
     }

      //If result is not empty return the data
      if(item){
        console.log(item);
        console.log("Leaderboard has been found");
         res.type('json');
         res.json(item);

      }
      else{
        console.log("Leaderboard not found\n");
        res.status(500).send("Leaderboard has not been found");
    }
  });
}
{'fraction_non_alphanumeric': 0.16325988850544199, 'fraction_numerical': 0.014069551367135651, 'mean_word_length': 3.550724637681159, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 12, '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': '7672530', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1187, 'n_words': 321}