<commit_before>/**
 * Created by sunado on 12/13/2016.
 */
var fs = require("fs");
var Docxtemplater = require('docxtemplater');
var JSZip = require('jszip');
var _ = require("underscore");

var root = require('../setting').root;
const genStudentAndTutorListPath = root + "/templates/genStudentAndTutor.docx";
const tmp = root + "/tmp";

exports.genStudentAndTutorList = function (theses, next) {
    fs.readFile(genStudentAndTutorListPath, "binary", function (error, content) {
        if (error) {
            return next(error);
        }
        var zip = new JSZip(content);
        var doc = new Docxtemplater().loadZip(zip);
        // normalize data
        var students = [];
        _.forEach(theses, function (thesis, index) {
            var tmp = {};
            tmp.tt = index + 1;
            tmp.id = thesis.student.user.officerNumber;
            tmp.name = thesis.student.user.fullName;
            tmp.birthday = thesis.student.user.dateOfBirth;
            tmp.unit = thesis.student.user.unit.name;
            tmp.thesis = thesis.title;
            tmp.tutor = thesis.lecturer.user.fullName;
            students.push(tmp);
        });

        var data = {
            student: students,
            sum: students.length
        };
        doc.setData(data);
        doc.render();
        var buf = doc.getZip()
            .generate({type: "nodebuffer"});

        return next(null, buf);
    });
};<commit_msg>fix tools export doc<commit_after>/**
 * Created by sunado on 12/13/2016.
 */
var fs = require("fs");
var Docxtemplater = require('docxtemplater');
var JSZip = require('jszip');
var _ = require("underscore");
var getModel = require('express-waterline').getModels;
var root = require('../setting').root;
const genStudentAndTutorListPath = root + "/templates/genStudentAndTutor.docx";
const tmp = root + "/tmp";

exports.genStudentAndTutorList = function (theses, next) {


    getModel('unit').then(function (Unit) {
        Unit.find().exec(function (error, units) {

            if (error) {
                return next(error);
            }

            fs.readFile(genStudentAndTutorListPath, "binary", function (error, content) {
                if (error) {
                    return next(error);
                }
                var zip = new JSZip(content);
                var doc = new Docxtemplater().loadZip(zip);
                // normalize data
                var students = [];
                _.forEach(theses, function (thesis, index) {
                    var tmp = {};
                    tmp.tt = index + 1;
                    tmp.id = thesis.student.user.officerNumber;
                    tmp.name = thesis.student.user.fullName;
                    tmp.birthday = thesis.student.user.dateOfBirth;
                    tmp.unit = _.find(units, function (item) {
                        return item.id == thesis.student.user.unit;
                    }).name;
                    tmp.thesis = thesis.title;
                    tmp.tutor = thesis.lecturer.user.fullName;
                    students.push(tmp);
                });

                var data = {
                    student: students,
                    sum: students.length
                };
                doc.setData(data);
                doc.render();
                var buf = doc.getZip()
                    .generate({type: "nodebuffer"});

                return next(null, buf);
            });
        })
    });


};
{'fraction_non_alphanumeric': 0.12738853503184713, 'fraction_numerical': 0.0052113491603937466, 'mean_word_length': 1.6475095785440612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5477572', 'n_tokens_mistral': 1004, 'n_tokens_neox': 926, 'n_words': 203}