<commit_before>Router.route('/contacts/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
      user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    log.info(user);
    var data = [];
    var stateSupport;
    var contact;
    // Prepare date criteria
    var toDate = new Date();
    var fromDate = new Date();
    log.info(toDate);
    fromDate.setFullYear(toDate.getFullYear() - 2);
    log.info(fromDate);
    var orderLastYEar = Orders.find({ 'createdAt' : { $lte : fromDate , $lt: toDate}});
    orderLastYEar.forEach(function(order) {
      contact = order.getContact();
      if (contact) {
        stateSupport = contact.stateSupport.toString();
      } else {
        stateSupport = '';
      }
      data.push({
        name: order.name,
        phone: order.phone,
        course: order.courseName,
        stateSupport: stateSupport,
        createdAt: order.createdAt.toISOString()
      });
    });
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=contacts.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});

Router.route('/orders/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
      user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    var startYear = moment().startOf('year').toDate();
    var startLastYear = moment().subtract(1, 'year').startOf('year').toDate();
    var pipeline = [
      { $match: { createdAt: { $lt: startYear, $gt: startLastYear } } },
      { $group: { _id: "$courseName", count:{ $sum:1 } } }
    ];
    var data = Orders.aggregate(pipeline);
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=orders.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});

// Download name and phone from order list
Router.route('/phoneList/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
    user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    var data = [];
    _.each(Meteor.call('phonesNameToContact'), function(m) {
      data.push({phone: m.phone, name: m.name});
    });
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=phoneList.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});

<commit_msg>Remove date criteria on Contact export button<commit_after>Router.route('/contacts/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
      user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    log.info(user);
    var data = [];
    var stateSupport;
    var contact;
    // Prepare date criteria
    var toDate = new Date();
    var fromDate = new Date();
    log.info(toDate);
    fromDate.setFullYear(toDate.getFullYear() - 2);
    log.info(fromDate);
    // var orderLastYEar = Orders.find({ 'createdAt' : { $lte : fromDate , $lt: toDate}});
    var orderLastYEar = Orders.find();
    orderLastYEar.forEach(function(order) {
      contact = order.getContact();
      if (contact) {
        stateSupport = contact.stateSupport.toString();
      } else {
        stateSupport = '';
      }
      data.push({
        name: order.name,
        phone: order.phone,
        course: order.courseName,
        stateSupport: stateSupport,
        createdAt: order.createdAt.toISOString()
      });
    });
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=contacts.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});

Router.route('/orders/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
      user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    var startYear = moment().startOf('year').toDate();
    var startLastYear = moment().subtract(1, 'year').startOf('year').toDate();
    var pipeline = [
      { $match: { createdAt: { $lt: startYear, $gt: startLastYear } } },
      { $group: { _id: "$courseName", count:{ $sum:1 } } }
    ];
    var data = Orders.aggregate(pipeline);
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=orders.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});

// Download name and phone from order list
Router.route('/phoneList/download', function() {
  var user = '';
  log.info(this.request.cookies.meteor_login_token);
  if(this.request.cookies.meteor_login_token)
    user = Meteor.users.findOne({"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(this.request.cookies.meteor_login_token)});
  if (user && Houston._user_is_admin(user._id)) {
    var data = [];
    _.each(Meteor.call('phonesNameToContact'), function(m) {
      data.push({phone: m.phone, name: m.name});
    });
    this.response.writeHead(200, {
      'Content-type': 'text/csv',
      'Content-Disposition': "attachment; filename=phoneList.csv"
    });
    this.response.end(CSV.unparse(data));
  }
}, {where: 'server'});


{'fraction_non_alphanumeric': 0.16492659053833605, 'fraction_numerical': 0.003915171288743882, 'mean_word_length': 3.565152643335815, 'pattern_counts': {'":': 6, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1152375', 'n_tokens_mistral': 2060, 'n_tokens_neox': 2022, 'n_words': 311}