<commit_before>// tslint:disable-next-line: file-name-casing
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
import * as stream from 'stream';
import * as loadJsonFile from 'load-json-file';

import { IConfig } from '../../global';
import { getTeamId } from '../misc/teamUtils';

//https://medium.com/@wietsevenema/node-js-using-for-await-to-read-lines-from-a-file-ead1f4dd8c6f
const readLines = (input: any) => {
  const output = new stream.PassThrough({ objectMode: true });
  const rl = readline.createInterface({ input });
  rl.on('line', line => {
    output.write(line);
  });
  rl.on('close', () => {
    output.push(null);
  });
  return output;
};

const teamVelocityFromCache = async (userConfig: IConfig, cacheDir: string) => {
  const teamsVelocity = [];
  for (const team of userConfig.teams) {
    const teamCacheFile = path.join(
      cacheDir,
      'velocity-artifacts-' + getTeamId(team.name) + '.json'
    );
    if (fs.existsSync(teamCacheFile)) {
      const teamVelocity: any = loadJsonFile.sync(teamCacheFile);
      teamsVelocity.push({
        team: team.name,
        velocity: teamVelocity.health.weeks.velocity
      });
    }
  }
  return teamsVelocity;
};

export default teamVelocityFromCache;<commit_msg>For the forecast chart, taking the team order from the config file<commit_after>// tslint:disable-next-line: file-name-casing
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
import * as stream from 'stream';
import * as loadJsonFile from 'load-json-file';

import { IConfig } from '../../global';
import { getTeamId } from '../misc/teamUtils';

//https://medium.com/@wietsevenema/node-js-using-for-await-to-read-lines-from-a-file-ead1f4dd8c6f
const readLines = (input: any) => {
  const output = new stream.PassThrough({ objectMode: true });
  const rl = readline.createInterface({ input });
  rl.on('line', line => {
    output.write(line);
  });
  rl.on('close', () => {
    output.push(null);
  });
  return output;
};

const teamVelocityFromCache = async (userConfig: IConfig, cacheDir: string) => {
  const teamsVelocity = [];
  for (const team of userConfig.roadmap.teams) {
    const teamCacheFile = path.join(
      cacheDir,
      'velocity-artifacts-' + getTeamId(team) + '.json',
    );
    if (fs.existsSync(teamCacheFile)) {
      const teamVelocity: any = loadJsonFile.sync(teamCacheFile);
      teamsVelocity.push({
        team: team,
        velocity: teamVelocity.health.weeks.velocity,
      });
    }
  }
  return teamsVelocity;
};

export default teamVelocityFromCache;
{'fraction_non_alphanumeric': 0.15043909889270715, 'fraction_numerical': 0.0030546009927453228, 'mean_word_length': 3.5094664371772804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '925697', 'n_tokens_mistral': 865, 'n_tokens_neox': 853, 'n_words': 200}