{"size": 1372, "ext": "js", "max_stars_repo_path": "scripts/collect-type-counts-for-small-examples.js", "max_stars_repo_name": "sehilyi/ivy", "max_stars_repo_stars_event_min_datetime": "2021-03-30T23:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T03:53:29.000Z", "max_issues_repo_path": "scripts/collect-type-counts-for-small-examples.js", "max_issues_repo_name": "sehilyi/ivy", "max_issues_repo_issues_event_min_datetime": "2021-04-16T21:39:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T12:54:23.000Z", "max_forks_repo_path": "scripts/collect-type-counts-for-small-examples.js", "max_forks_repo_name": "sehilyi/ivy", "max_forks_repo_forks_event_min_datetime": "2021-04-16T21:35:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-05T16:24:32.000Z"}
{"max_stars_count": 12, "max_issues_count": 5, "max_forks_count": 2, "avg_line_length": 31.1818181818, "max_line_length": 107, "alphanum_fraction": 0.5138483965}
const {getFile, writeFile, executeCommandLineCmd} = require('hoopoe');
const {Analyzer} = require('type-analyzer');
const {computeColMeta} = Analyzer;

const jsonReader = data => JSON.parse(data);
const getReader = fileName => {
  if (fileName.includes('.json')) {
    return jsonReader;
  }
  return () => [];
};
executeCommandLineCmd('ls example-datasets')
  .then(({stdout}) => stdout.split('\n').filter(d => d))
  .then(datasets => {
    Promise.all(
      datasets.map(key => {
        return getFile(`./example-datasets/${key}`)
          .then(d => getReader(key)(d))
          .then(file => [computeColMeta(file), file])
          .then(([colMeta, file]) =>
            colMeta.reduce(
              (acc, row) => {
                acc[row.category] = (acc[row.category] || 0) + 1;
                acc.columns.push(row.key);
                return acc;
              },
              {file: key, length: file.length, columns: []},
            ),
          )
          .catch(e => {
            console.log(`FAILED TO COUNT ${key}`, e);
          });
      }),
    ).then(results => {
      const fullCounts = results
        .filter(d => d)
        .reduce((acc, row) => {
          acc[row.file] = row;
          return acc;
        }, {});
      writeFile('./src/constants/small-example-datasets-counts.json', JSON.stringify(fullCounts, null, 2));
    });
  });
