<commit_before>var async = require('async');
var api2HTML = require('./to_html');
var api2JSON = require('../origin/tools/json');
var utils = require('./utils');
var config = require('../config');
var db = config.mysql;


module.exports = function (app) {

  // 网站首页
  app.get('/', function (req, res, next) {
    req.url = '/public/index.html';
    app(req, res);
  });

  // 浏览指定API页面
  app.get('/api/:name.:type', function (req, res, next) {
    var name = req.params.name;
    var type = req.params.type;

    utils.readAPIFile(name, function (err, content, filename) {
      if (err) return next(err);
      if (type === 'html') {
        api2HTML(content, filename, utils.TEMPLATE_FILE, function (err, html) {
          if (err) return next(err);
          res.writeHead(200, {'content-type': 'text/html'});
          res.end(html);
        });
      } else {
        api2JSON(content, filename, function (err, data) {
          if (err) return next(err);
          res.json(data);
        })
      }
    });
  });

  // API首页
  app.get('/api', function (req, res, next) {
    req.url = '/api/index.html';
    app(req, res);
  });

  // 翻译进度
  app.get('/progress', function (req, res, next) {
    // 查询出所有的文件名
    db.select('origin_api', 'file', '`version`=' + db.escape(config.api.version), 'GROUP BY `file`', function (err, files) {
      if (err) return next(err);
      files = files.map(function (f) {
        return f.file;
      });

      // 分别获取每个文件的翻译进度
      var results = [];
      var userIds = {};
      async.eachSeries(files, function (f, next) {

        var sql = 'SELECT `A`.`hash`,`B`.`user_id`' +
                  ' FROM `origin_api` AS `A`' +
                  ' LEFT JOIN `translate_api` AS `B`' +
                  ' ON `A`.`hash`=`B`.`origin_hash`' +
                  ' WHERE `file`=' + db.escape(f) +
                  ' GROUP BY `A`.`hash`';
        db.query(sql, function (err, list) {
          if (err) return next(err);

          var lines = {};
          var users = {};
          list.forEach(function (line) {
            var uid = line.user_id;
            var hash = line.hash;
            if (uid > 0) {
              userIds[uid] = true;
              // 记录用户翻译的数量
              if (uid in users) {
                users[uid]++
              } else {
                users[uid] = 1;
              }
              // 记录已经完成的数量
              if (hash in lines) {
                lines[hash]++;
              } else {
                lines[hash] = 1;<commit_msg>修正完成进度页面<commit_after>var async = require('async');
var api2HTML = require('./to_html');
var api2JSON = require('../origin/tools/json');
var utils = require('./utils');
var config = require('../config');
var db = config.mysql;


module.exports = function (app) {

  // 网站首页
  app.get('/', function (req, res, next) {
    req.url = '/public/index.html';
    app(req, res);
  });

  // 浏览指定API页面
  app.get('/api/:name.:type', function (req, res, next) {
    var name = req.params.name;
    var type = req.params.type;

    utils.readAPIFile(name, function (err, content, filename) {
      if (err) return next(err);
      if (type === 'html') {
        api2HTML(content, filename, utils.TEMPLATE_FILE, function (err, html) {
          if (err) return next(err);
          res.writeHead(200, {'content-type': 'text/html'});
          res.end(html);
        });
      } else {
        api2JSON(content, filename, function (err, data) {
          if (err) return next(err);
          res.json(data);
        })
      }
    });
  });

  // API首页
  app.get('/api', function (req, res, next) {
    req.url = '/api/index.html';
    app(req, res);
  });

  // 翻译进度
  app.get('/progress', function (req, res, next) {
    // 查询出所有的文件名
    db.select('origin_api', 'file', '`version`=' + db.escape(config.api.version), 'GROUP BY `file`', function (err, files) {
      if (err) return next(err);
      files = files.map(function (f) {
        return f.file;
      });

      // 分别获取每个文件的翻译进度
      var results = [];
      var userIds = {};
      async.eachSeries(files, function (f, next) {

        var sql = 'SELECT `A`.`hash`,`B`.`user_id`' +
                  ' FROM `origin_api` AS `A`' +
                  ' LEFT JOIN `translate_api` AS `B`' +
                  ' ON `A`.`hash`=`B`.`origin_hash`' +
                  ' WHERE `file`=' + db.escape(f) +
                  ' AND `type`!="meta"' +
                  ' AND `version`=' + db.escape(config.api.version) +
                  ' GROUP BY `A`.`hash`';
        db.query(sql, function (err, list) {
          if (err) return next(err);

          var lines = {};
          var users = {};
          list.forEach(function (line) {
            var uid = line.user_id;
            var hash = line.hash;
            if (uid > 0) {
              userIds[uid] = true;
              // 记录用户翻译的数量
              if (uid in users) {
                users[uid]++
              } else {
                users[uid] = 1;
              }
              // 记录已经完成的数量
              if (hash in lines) {
                lines[hash]++;
              } else {
                lines[hash] = 1;
{'fraction_non_alphanumeric': 0.1705411213127564, 'fraction_numerical': 0.003907013088493847, 'mean_word_length': 1.6806282722513088, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3173458', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1748, 'n_words': 382}