'use strict';

var SETS = 'dataType';
var LABELS = 'bindingsCount';
var VALUES = 'scriptTime';
var FILTERS = [{
  key: 'dataSize',
  value: function (val) {
    return val === 5;
  }
}];
var DIR_NAME = './log/';
var CHART_DIR = './charts/';
var RenderData = require('./lib/RenderData');
var Filter = require('./lib/Filter');
var FilterRule = require('./lib/FilterRule');
var ChartRenderer = require('./lib/ChartRenderer');

var dataFilter = new Filter(FILTERS.map(function (f) {
  return new FilterRule(f.key, f.value);
}));

var fs = require('fs');
var path = require('path');
var files = fs.readdirSync(DIR_NAME);

files = files.filter(function (f) {
  return fs.statSync(path.join(DIR_NAME, f)).isFile();
});

// Elegant but not efficient, requires memory...
var logs = files.map(function (file) {
  return require('./' + path.join(DIR_NAME, file));
}).filter(function (data) {
  return dataFilter.filter(data.description.description);
});

var renderData = new RenderData(SETS, LABELS, VALUES);
renderData.process(logs);
var data = renderData.aggregate();
var labels = data[0].labels;

var chart = ChartRenderer.generate(labels, data);
var filters = FILTERS.map(function (f) {
  return f.key;
}).join('-');

ChartRenderer.save(chart, path.join(CHART_DIR) + filters + '.png');

@@ -12,234 +12,43 @@
 ';%0A%0A
-var SETS = 'dataType';%0Avar LABELS = 'bindingsCount';%0Avar VALUES = 'scriptTime';%0Avar FILTERS = %5B%7B%0A  key: 'dataSize',%0A  value: function (val) %7B%0A    return val === 5;%0A  %7D%0A%7D%5D;%0Avar DIR_NAME = './log/';%0Avar CHART_DIR = './charts/';%0A
+function formatResults(config) %7B%0A  
 var 
@@ -85,24 +85,26 @@
 nderData');%0A
+  
 var Filter =
@@ -125,24 +125,26 @@
 b/Filter');%0A
+  
 var FilterRu
@@ -173,24 +173,26 @@
 lterRule');%0A
+  
 var ChartRen
@@ -228,24 +228,26 @@
 enderer');%0A%0A
+  
 var dataFilt
@@ -262,23 +262,30 @@
  Filter(
-FILTERS
+config.filters
 .map(fun
@@ -288,32 +288,34 @@
 (function (f) %7B%0A
+  
   return new Fil
@@ -343,14 +343,18 @@
 e);%0A
+  
 %7D));%0A%0A
+  
 var 
@@ -369,24 +369,26 @@
 uire('fs');%0A
+  
 var path = r
@@ -403,16 +403,18 @@
 path');%0A
+  
 var file
@@ -432,16 +432,23 @@
 dirSync(
+config.
 DIR_NAME
@@ -451,16 +451,18 @@
 NAME);%0A%0A
+  
 files = 
@@ -481,32 +481,34 @@
 (function (f) %7B%0A
+  
   return fs.stat
@@ -514,32 +514,39 @@
 tSync(path.join(
+config.
 DIR_NAME, f)).is
@@ -553,21 +553,25 @@
 File();%0A
+  
 %7D);%0A%0A
+  
 // Elega
@@ -611,16 +611,18 @@
 mory...%0A
+  
 var logs
@@ -650,24 +650,26 @@
  (file) %7B%0A  
+ 
+ 
 return requi
@@ -688,16 +688,23 @@
 th.join(
+config.
 DIR_NAME
@@ -713,16 +713,18 @@
 file));%0A
+  
 %7D).filte
@@ -741,24 +741,26 @@
  (data) %7B%0A  
+ 
+ 
 return dataF
@@ -803,21 +803,25 @@
 ption);%0A
+  
 %7D);%0A%0A
+  
 var rend
@@ -848,31 +848,54 @@
 ata(
-SETS, LABELS, VALUES
+config.sets, config.labels, config.values
 );%0A
+  
 rend
@@ -916,16 +916,18 @@
 (logs);%0A
+  
 var data
@@ -953,16 +953,18 @@
 gate();%0A
+  
 var labe
@@ -985,16 +985,18 @@
 abels;%0A%0A
+  
 var char
@@ -1041,33 +1041,296 @@
 a);%0A
-var filters = FILTERS.map
+  ChartRenderer.save(chart, path.join(config.CHART_DIR) + config.name + '.png');%0A%7D%0A%0Avar SETS = 'dataType';%0Avar LABELS = 'bindingsCount';%0Avar VALUES = 'scriptTime';%0Avar DIR_NAME = './log/';%0Avar CHART_DIR = './charts/';%0A%0A%5B5, 10, 20, 50, 100, 500, 1000, 2000, 5000, 10000, 100000%5D%0A  .forEach
 (fun
@@ -1340,108 +1340,281 @@
 on (
-f
+s
 ) %7B%0A  
-return f.key;%0A%7D).join('-');%0A%0AChartRenderer.save(chart, path.join(CHART_DIR) + filters + '.png'
+  formatResults(%7B%0A      sets: SETS,%0A      labels: LABELS,%0A      values: VALUES,%0A      filters: %5B%7B%0A        key: 'dataSize',%0A        value: function (val) %7B%0A          return val === s;%0A        %7D%0A      %7D%5D,%0A      DIR_NAME: DIR_NAME,%0A      CHART_DIR: CHART_DIR%0A    %7D);%0A  %7D
 );%0A

Update log parser