<commit_before>#!/usr/bin/env node

// Only run on the first of the year
const today = new Date();
if (process.env.NODE_ENV === 'production' && today.getDate() !== 1 && today.getMonth() !== 0) {
  console.log('NODE_ENV is production and today is not the first of year, script aborted!');
  process.exit();
}

process.env.PORT = 3066;

import models, { sequelize, Op } from '../../server/models';
import _ from 'lodash';
import Promise from 'bluebird';
import { formatCurrency, formatArrayToString, formatCurrencyObject } from '../../server/lib/utils';
import emailLib from '../../server/lib/email';
import queries from '../../server/lib/queries';

const d = new Date();
const startDate = new Date(`${d.getFullYear() - 1}`);
const endDate = new Date(`${d.getFullYear()}`);
const year = startDate.getFullYear();

console.log('startDate', startDate, 'endDate', endDate);

let platformStats,
  totalUsersProcessed = 0,
  totalUsersSkipped = 0;

const GetCollectiveTransactionsQuery = `
with "CollectiveTransactions" as (
  SELECT
    "CollectiveId",
    MAX("HostCollectiveId") as "HostCollectiveId",
    SUM("amountInHostCurrency") as "amountInHostCurrency",
    MAX("hostCurrency") as "hostCurrency",
    SUM("platformFeeInHostCurrency") as "platformFeeInHostCurrency",<commit_msg>test(email): allow to pass a custom START_DATE as env variable when running yearly email report<commit_after>#!/usr/bin/env node

// Only run on the first of the year
const today = new Date();
if (process.env.NODE_ENV === 'production' && today.getDate() !== 1 && today.getMonth() !== 0) {
  console.log('NODE_ENV is production and today is not the first of year, script aborted!');
  process.exit();
}

process.env.PORT = 3066;

import models, { sequelize, Op } from '../../server/models';
import _ from 'lodash';
import Promise from 'bluebird';
import { formatCurrency, formatArrayToString, formatCurrencyObject } from '../../server/lib/utils';
import emailLib from '../../server/lib/email';
import queries from '../../server/lib/queries';

const d = process.env.START_DATE ? new Date(process.env.START_DATE) : new Date();
const startDate = new Date(`${d.getFullYear() - 1}`);
const endDate = new Date(`${d.getFullYear()}`);
const year = startDate.getFullYear();

console.log('startDate', startDate, 'endDate', endDate);

let platformStats,
  totalUsersProcessed = 0,
  totalUsersSkipped = 0;

const GetCollectiveTransactionsQuery = `
with "CollectiveTransactions" as (
  SELECT
    "CollectiveId",
    MAX("HostCollectiveId") as "HostCollectiveId",
    SUM("amountInHostCurrency") as "amountInHostCurrency",
    MAX("hostCurrency") as "hostCurrency",
    SUM("platformFeeInHostCurrency") as "platformFeeInHostCurrency",
{'fraction_non_alphanumeric': 0.15222222222222223, 'fraction_numerical': 0.006666666666666667, 'mean_word_length': 4.846320346320346, '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': '6406968', 'n_tokens_mistral': 834, 'n_tokens_neox': 833, 'n_words': 234}