<commit_before>var Visualizer = (function(viz) {
    var canvas, 
        ctx,
        freqByteData,
        timeByteData,
        animate = false,
        analyser
    ;
    
    function update() {
        analyser.smoothingTimeConstant = 0.1;
		analyser.getByteFrequencyData(freqByteData);
		analyser.getByteTimeDomainData(timeByteData);
    }
    
    function render() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);

        ctx.fillStyle = "red";
        for (var i = 0; i < timeByteData.length; i++) {
           ctx.fillRect(450 + i, 200 - timeByteData[i] / 2, 1, timeByteData[i]);
        }
        
        ctx.fillStyle = "orange";
        for (var i = 0; i < freqByteData.length; i++) {
           ctx.fillRect(450 + i, 700 - freqByteData[i], 1, freqByteData[i]);
        }
    }
    
    function doAnimate() {
        if(animate) {
            requestAnimationFrame(doAnimate);
            render();
            update();
        }
    }
        
    viz.init = function(canvas_id) {
        canvas = document.getElementById(canvas_id);
        ctx = canvas.getContext('2d');
    };
    
    viz.reset = function(node) {
        analyser = node;
        animate = false;
        freqByteData = new Uint8Array(analyser.frequencyBinCount);
		timeByteData = new Uint8Array(analyser.frequencyBinCount);
    };
    
    viz.animate = function() {
        animate = true;
        doAnimate();
    };
    
    viz.stop = function() {
        animate = false;<commit_msg>Implemented some quick and dirty animation for beats<commit_after>function Ball(x, y, r, speed, fr, fg, fb) {
    this.x = x;
    this.y = y;
    this.r = r;
    
    this.vx = Math.sin(Math.random() * 2 * Math.PI) * 400;
    this.vy = speed - 10 * this.r;
    
    //Random colors
	var r = fr * 255 >> 0;
	var g = fg * 255 >> 0;
	var b = fb * 255 >> 0;
	
	this.gradient = [
	    [0, "white"], 
	    [0.4, "rgba(255, 255, 255, 0.5)"], 
	    [0.4, "rgba(" + r + ", " + g + ", " + b + ", 0.5)"],
	    [1, "rgba(0, 0, 0, 0.3)"]
	];
}

Ball.prototype = {
    constructor: Ball,
    update: function(delta) {
        this.x += (this.vx * delta);
        this.y -= (this.vy * delta);
    },
    draw: function(ctx) {		
		//Time for some colors
		var gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.r);
		this.gradient.forEach(function(g) {
		    gradient.addColorStop(g[0], g[1]);
		});
		
		ctx.beginPath();
		ctx.fillStyle = gradient;
		ctx.arc(this.x, this.y, this.r, Math.PI * 2, false);
		ctx.fill();
    }
};

var Visualizer = (function(viz) {
    var canvas, 
        ctx,
        freqByteData,
        timeByteData,
        animate = false,
        analyser,
        beatDetect = [],
        balls = [],
        last_time = Date.now()
    ;
    
    function update() {
        analyser.smoothingTimeConstant = 0.1;
		analyser.getByteFrequencyData(freqByteData);
		analyser.getByteTimeDomainData(timeByteData);
    }
    
    function render() {
        var fqavg = 0, pastavg = 0;
        ctx.clearRect(0, 0, canvas.width, canvas.height);

        ctx.fillStyle = "red";
        for (var i = 0; i < timeByteData.length; i++) {
           ctx.fillRect(450 + i, 200 - timeByteData[i] / 2, 1, timeByteData[i]);
        }
        
        ctx.fillStyle = "orange";
        for (var i = 0; i < freqByteData.length; i++) {
            fqavg += freqByteData[i];
            ctx.fillRect(450 + i, 700 - freqByteData[i], 1, freqByteData[i]);
        }
        
        fqavg /= freqByteData.length;
        beatDetect.push(fqavg);
        if(beatDetect.length > 10) {
            beatDetect.shift();
        }
        
        for (var i = 0; i  < beatDetect.length - 1; i++) {
            pastavg += beatDetect[i];
        };
        pastavg /= beatDetect.length - 1;
        
        if (pastavg - fqavg > 10) {
            fire();
        };
        
        ctx.fillStyle = "blue";
        ctx.fillRect(450, 700 - fqavg, freqByteData.length, 2);
        
        draw();
    }
    
    function doAnimate() {
        if(animate) {
            requestAnimationFrame(doAnimate);
            render();
            update();
        }
    }
    
    function draw() {
        var now = Date.now();
        var delta = (now - last_time) / 1000;
        
        // Draw background
        ctx.globalCompositeOperation = "source-over";
        ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
    	ctx.fillRect(0, 0, canvas.width, canvas.height);
        
        balls = balls.filter(function(b) {
            return b.x - b.r > 0 && b.x + b.r < canvas.width && b.y + b.r > 0 && b.y - b.r < canvas.height;
        });
        
        last_time = now;
        balls.forEach(function(b) {
           b.update(delta);
           b.draw(ctx); 
        });
    };
    
    function fire() {
        var r = Math.random(),
            g = Math.random(),
            b = Math.random(),
            speed = Math.random() * 200 + 600;
        for (var i = Math.random() * 10 + 10; i > 0; i--){
            balls.push(new Ball(
                canvas.width / 2, 
                canvas.height - 30, 
                Math.random() * 20 + 20,
                speed,
                r, g, b
            ));
        };
    };
        
    viz.init = function(canvas_id) {
        canvas = document.getElementById(canvas_id);
        ctx = canvas.getContext('2d');
    };
    
    viz.reset = function(node) {
        analyser = node;
        animate = false;
        freqByteData = new Uint8Array(analyser.frequencyBinCount);
		timeByteData = new Uint8Array(analyser.frequencyBinCount);
    };
    
    viz.animate = function() {
        animate = true;
        last_time = Date.now();
        doAnimate();
    };
    
    viz.stop = function() {
        animate = false;
{'fraction_non_alphanumeric': 0.14258423063563738, 'fraction_numerical': 0.024487669329628342, 'mean_word_length': 1.642955484167049, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, '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': '7010231', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1901, 'n_words': 400}