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

// TODO pull out config.js
// TODO set up read-only db user!
var connections = mysql.createPool({
    connectionLimit : 10, //important
    host     : 'localhost',
    user     : 'root',
    password : '<PASSWORD>',
    database : 'olympics2016',
    debug    :  false
});


app.get('/teamstandings/', function (req, res, next) {
  connections.query('SELECT * from team_standings ORDER BY points DESC, golds DESC, silvers DESC', function(err, rows, fields) {
    if (err) {next(err); return;}

    res.send(rows);
  });
});

app.get('/countries/', function (req, res, next) {
  connections.query('SELECT * from countries ORDER BY pool ASC, last_olympics_score DESC', function(err, rows, fields) {
    if (err) {next(err); return;}

    var result = {"pools" : []};
    var pool = null;

    for(var i=0; i<rows.length; ++i) {
      var rawRow = rows[i];
      var row = {
        "name" : rawRow.name,
        "flagPath" : rawRow.flag_path,
        "isActive" : rawRow.is_active == 1,
        "lastOlympicsScore" : rawRow.last_olympics_score
      };

      if (pool == null || rawRow.pool != pool.index) {<commit_msg>Include positions in team standings summary<commit_after>var express = require('express');
var app = express();
var mysql = require('mysql');

// TODO pull out config.js
// TODO set up read-only db user!
var connections = mysql.createPool({
    connectionLimit : 10, //important
    host     : 'localhost',
    user     : 'root',
    password : '<PASSWORD>',
    database : 'olympics2016',
    debug    :  false
});


app.get('/teamstandings/summary', function (req, res, next) {
  connections.query('SELECT * from team_standings ORDER BY points DESC, golds DESC, silvers DESC', function(err, rows, fields) {
    if (err) {next(err); return;}

    var result = {standings: []}
    var previousRow = null;

    for (var i=0; i<rows.length; ++i) {
      var rawRow = rows[i];
      var position;

      if (previousRow != null &&
          rawRow.points == previousRow.points &&
          rawRow.golds == previousRow.golds &&
          rawRow.silvers == previousRow.silvers)
        position = previousRawRow.position;
      else
        position = i+1;

      var row = {
        "position" : position,
        "team" : rawRow.team,
        "username" : rawRow.username,
        "golds" : rawRow.golds,
        "silvers" : rawRow.silvers,
        "bronzes" : rawRow.bronzes,
        "points" : rawRow.points
      };

      result.standings.push(row);
      previousRow = row;
    }

    res.send(result);
  });
});

app.get('/countries/', function (req, res, next) {
  connections.query('SELECT * from countries ORDER BY pool ASC, last_olympics_score DESC', function(err, rows, fields) {
    if (err) {next(err); return;}

    var result = {"pools" : []};
    var pool = null;

    for(var i=0; i<rows.length; ++i) {
      var rawRow = rows[i];
      var row = {
        "name" : rawRow.name,
        "flagPath" : rawRow.flag_path,
        "isActive" : rawRow.is_active == 1,
        "lastOlympicsScore" : rawRow.last_olympics_score
      };

      if (pool == null || rawRow.pool != pool.index) {
{'fraction_non_alphanumeric': 0.14902204284383733, 'fraction_numerical': 0.005588326606643899, 'mean_word_length': 2.6738882554161916, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, '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': '4948297', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1032, 'n_words': 272}