<commit_before>const fs = require('fs');
const parse = require('csv-parse');
const stringify = require('csv-stringify');
const transform = require('stream-transform');
const PNG = require('node-png').PNG;

var input = fs.createReadStream('../workshop/long-cadence.csv');
var output = fs.createWriteStream('out.csv');
var parser = parse();
var stringifier = stringify();
var transformer = transform(function(data){
    return data;
});

var image_index = 0;
transformer.on('readable', function(){
    var row;
    while (row = transformer.read()) {
        var png = new PNG({
            width: 11,
            height: 11,
            filter: -1
        });

        var data = row.slice(1);
        var max = Math.max(...data);
        data.forEach(function(value, index){
            var gray = value/max * 255;
            png.data[4*index + 0] = gray;
            png.data[4*index + 1] = gray;
            png.data[4*index + 2] = gray;
            png.data[4*index + 3] = 0xff;
        });

        png.pack().pipe(fs.createWriteStream('resources/image-' + image_index + '.png'));
        image_index++;
    }
});

input
    .pipe(parser)
    .pipe(transformer)
    .pipe(stringifier)
    .pipe(output);<commit_msg>Pad image name with zeroes<commit_after>const fs = require('fs');
const parse = require('csv-parse');
const stringify = require('csv-stringify');
const transform = require('stream-transform');
const PNG = require('node-png').PNG;

var input = fs.createReadStream('../workshop/long-cadence.csv');
var output = fs.createWriteStream('out.csv');
var parser = parse();
var stringifier = stringify();
var transformer = transform(function(data){
    return data;
});

var image_index = 0;
transformer.on('readable', function(){
    var row;
    while (row = transformer.read()) {
        var png = new PNG({
            width: 11,
            height: 11,
            filter: -1
        });

        var data = row.slice(1);
        var max = Math.max(...data);
        data.forEach(function(value, index){
            var gray = value/max * 255;
            png.data[4*index + 0] = gray;
            png.data[4*index + 1] = gray;
            png.data[4*index + 2] = gray;
            png.data[4*index + 3] = 0xff;
        });

        png.pack().pipe(fs.createWriteStream('resources/image-' + pad(image_index, 4) + '.png'));
        image_index++;
    }
});

input
    .pipe(parser)
    .pipe(transformer)
    .pipe(stringifier)
    .pipe(output);

function pad(number, width, padding) {
    padding = padding || '0';
    number = number + '';
    return number.length >= width ? number : new Array(width - number.length + 1).join(padding) + number;
}
{'fraction_non_alphanumeric': 0.16259857303792716, 'fraction_numerical': 0.015396169733383402, 'mean_word_length': 2.5145118733509233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3691456', 'n_tokens_mistral': 868, 'n_tokens_neox': 809, 'n_words': 192}