<commit_before>(function() {
  'use strict';

  const settings = require('./settings.js');
  const express = require('express');
  const app = express();
  const server = require('http').Server(app);
  const io = require('socket.io')(server);
  const exphbs  = require('express-handlebars');
  const api = require('./api.js');
  const db = require('./database.js');
  const port = process.env.PORT || settings.SERVER_PORT;

  function init() {
    db.init();
    api.init();
    server.listen(port);
  }

  app.use('/api', api.router);
  app.engine('handlebars', exphbs({ defaultLayout: 'index' }));
  app.set('view engine', 'handlebars');

  // Static routes
  app.use('/css', express.static('static/css'));

  /**
  * Main route that gets the current/last entry
  * /
  */
  app.get('/', (req, res) => {
    db.getLastTemperatureEntry()
    .then((temperatureRow) => {
      db.getLastHumidityEntry()
      .then((humidityRow) => {
        res.render('index', {
          temperature: temperatureRow.temperature,
          humidity: humidityRow.humidity,
          scale: '˚'
        });
      });
    });
  });

  /**
  * Shows a chart of the last 24 hours
  * /chart
  */
  app.get('/chart', (req, res) => {
    let now = new Date();
    let query = {
      startDate: now.getTime() - settings.MILLISECONDS_IN_DAY,
      endDate: now.getTime()
    };
    
    db.getTemperature(query,
    (temperatureRows) => {
      db.getHumidity(query)
      .then((humidityRows) => {
        res.render('chart', {
          'temperature': temperatureRows,
          'humidity': humidityRows,
        });
      });
    });
  });

  /**
  * Public function to update all connected clients with a new readouts
  * @param {object} values Temperature and Humidity readout
  */
  function update(values) {
    io.emit('update', values);
  }

  // Make update publically available
  module.exports.update = update;
  module.exports.init = init;
})();
<commit_msg>Fixed promise workflow<commit_after>(function() {
  'use strict';

  const settings = require('./settings.js');
  const express = require('express');
  const app = express();
  const server = require('http').Server(app);
  const io = require('socket.io')(server);
  const exphbs  = require('express-handlebars');
  const api = require('./api.js');
  const db = require('./database.js');
  const port = process.env.PORT || settings.SERVER_PORT;

  function init() {
    db.init();
    api.init();
    server.listen(port);
  }

  app.use('/api', api.router);
  app.engine('handlebars', exphbs({ defaultLayout: 'index' }));
  app.set('view engine', 'handlebars');

  // Static routes
  app.use('/css', express.static('static/css'));

  /**
  * Main route that gets the current/last entry
  * /
  */
  app.get('/', (req, res) => {
    db.getLastTemperatureEntry()
    .then((temperatureRow) => {
      db.getLastHumidityEntry()
      .then((humidityRow) => {
        res.render('index', {
          temperature: temperatureRow.temperature,
          humidity: humidityRow.humidity,
          scale: '˚'
        });
      })
      .catch((error) => {
        res.status(500).send(error);
      });
    })
    .catch((error) => {
      res.status(500).send(error);
    });
  });

  /**
  * Shows a chart of the last 24 hours
  * /chart
  */
  app.get('/chart', (req, res) => {
    let now = new Date();
    let query = {
      startDate: now.getTime() - settings.MILLISECONDS_IN_DAY,
      endDate: now.getTime()
    };

    db.getTemperature(query)
    .then((temperatureRows) => {
      db.getHumidity(query)
      .then((humidityRows) => {
        res.render('chart', {
          'temperature': temperatureRows,
          'humidity': humidityRows,
        });
      })
      .catch((error) => {
        res.status(500).send(error);
      });
    })
    .catch((error) => {
      res.status(500).send(error);
    });
  });

  /**
  * Public function to update all connected clients with a new readouts
  * @param {object} values Temperature and Humidity readout
  */
  function update(values) {
    io.emit('update', values);
  }

  // Make update publically available
  module.exports.update = update;
  module.exports.init = init;
})();

{'fraction_non_alphanumeric': 0.17403777193401865, 'fraction_numerical': 0.0038250059765718384, 'mean_word_length': 2.613126079447323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2678061', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1306, 'n_words': 274}