<commit_before>const express = require('express');
const request = require('request-promise-native');
const logger = require('winston');

const router = new express.Router();


router.get('/', (req, res) => {
  request(`http://localhost:${req.app.locals.settings.port}/server/details`).then((serverJson) => {
    const serverDetails = JSON.parse(serverJson);

    request(`http://localhost:${req.app.locals.settings.port}/user/details`).then((userJson) => {
      const users = JSON.parse(userJson);
      const achievementsPromises = [];

      users.forEach((user) => {
        achievementsPromises.push(
          request(`http://localhost:${req.app.locals.settings.port}/user/${user.uuid}/achievements`)
        );
      });

      Promise.all(achievementsPromises).then((achievementsJson) => {
        const playerDataArray = [];

        users.forEach((user, index) => {
          const achievements = JSON.parse(achievementsJson[index]);

          const playerData =
            {
              name: user.name,
              achievements: achievements.achievements.map(x => ({ class: x })),
              score: achievements.score
            };

          playerDataArray.push(Object.assign(playerData));
        });

        const pageData = {
          serverDetails: `${serverDetails.connecturl}`,
          players: playerDataArray
        };

        res.render('index', pageData);
      }).catch(e => logger.log('error', e));
    }).catch(e => logger.log('error', e));
  }).catch(e => logger.log('error', e));
});

module.exports = router;
<commit_msg>Change index-controller to use ServerHelper<commit_after>const express = require('express');
const request = require('request-promise-native');
const logger = require('winston');
const ServerHelper = require('../util/server-helper');

const router = new express.Router();


router.get('/', (req, res) => {
  const serverHelper = new ServerHelper(req.app.locals.mcServerPath);
  const serverDetails = serverHelper.getDetails();

  request(`http://localhost:${req.app.locals.settings.port}/user/details`).then((userJson) => {
    const users = JSON.parse(userJson);
    const achievementsPromises = [];

    users.forEach((user) => {
      achievementsPromises.push(
        request(`http://localhost:${req.app.locals.settings.port}/user/${user.uuid}/achievements`)
      );
    });

    Promise.all(achievementsPromises).then((achievementsJson) => {
      const playerDataArray = [];

      users.forEach((user, index) => {
        const achievements = JSON.parse(achievementsJson[index]);

        const playerData =
          {
            name: user.name,
            achievements: achievements.achievements.map(x => ({ class: x })),
            score: achievements.score
          };

        playerDataArray.push(Object.assign(playerData));
      });

      const pageData = {
        serverDetails: `${serverDetails.connecturl}`,
        players: playerDataArray
      };

      res.render('index', pageData);
    }).catch(e => logger.log('error', e));
  }).catch(e => logger.log('error', e));
});

module.exports = router;

{'fraction_non_alphanumeric': 0.1662899580238941, 'fraction_numerical': 0.0, 'mean_word_length': 2.966709346991037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5431410', 'n_tokens_mistral': 877, 'n_tokens_neox': 870, 'n_words': 141}