var mysql = require('mysql'),
    StatisticsService = require('../service/StatisticsService'),
    orm = require('orm');

//GLOBAL.DEBUG = true;

var mysql ="mysql://badjs:pass4badjs@10.198.30.62:4250/badjs";
//var mysql = "mysql://badjs:pass4badjs@10.134.5.103:3306/badjs";
//var mysql = "mysql://root:root@localhost:3306/badjs";


orm.connect( mysql, function(err , db) {
    if(err){
        throw err;
    }

    global.models = {
        userDao : require('../dao/UserDao')(db),
        applyDao : require('../dao/ApplyDao')(db),
        approveDao : require('../dao/ApproveDao')(db),
        statisticsDao : require('../dao/StatisticsDao')(db),
        db : db
    }


    var aa = new StatisticsService();


    var startDate = new Date('2014-12-23 00:00:00');
    var nowDate = new Date;

    var fetch = function (id , startDate){
        aa.fetchAndSave(id , startDate , function (){
            console.log(startDate.toLocaleDateString() + " ok ");
            if((startDate -0) > (nowDate - 0) ){
                console.log("out today");
                return ;
            }
            //fetch(id , new Date(startDate.getFullYear() + "-" + (startDate.getMonth()+1)+"-"+ (startDate.getDate()+1)+" 00:00:00"));

        })
    }

    var list = [47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,30,29,28,27,26,25,24,22,21,20,19,18,51];
    var i=0, len=list.length;
    //for(i= 0,s=0; s<5 && list[i];i++,s++){
    //    fetch(list[i] , startDate);
    //}

    fetch(24, startDate);
    //setTimeout(function () {
    //    var thisFn = arguments.callee;
    //    if (list.length) {
    //        fetch(list.pop(), startDate);
    //        setTimeout(thisFn, 1000);
    //    }
    //}, 1000);

    //var timer = setInterval(function(){
    //    if(i < len){
    //        fetch(list[i++], startDate);
    //    }else{
    //        clearInterval(timer);
    //    }
    //},1000);
});






@@ -325,17 +325,1155 @@
 adjs%22;%0A%0A
+GLOBAL.pjconfig = %7B%0A    %22mysql%22: %7B%0A        %22url%22: %22mysql://badjs:pass4badjs@10.198.30.62:4250/badjs%22%0A    %7D,%0A    %22storage%22: %7B%0A        %22errorMsgTopUrl%22: %22http://10.185.14.28:9000/errorMsgTop%22,%0A        %22errorMsgTopCacheUrl%22: %22http://10.185.14.28:9000/errorMsgTopCache%22,%0A        %22queryUrl%22: %22http://10.185.14.28:9000/query%22,%0A        %22queryCountUrl%22: %22http://10.185.14.28:9000/queryCount%22,%0A        %22querySvgUrl%22: %22http://10.185.14.28:9000/errorCountSvg%22%0A    %7D,%0A    %22acceptor%22: %7B%0A        %22pushProjectUrl%22: %22http://10.185.14.28:9001/getProjects%22%0A    %7D,%0A    %22zmq%22: %7B%0A        %22url%22: %22tcp://10.185.14.28:10000%22,%0A        %22subscribe%22: %22badjs%22%0A    %7D,%0A    %22email%22: %7B%0A        %22homepage%22: %22http://badjs.sng.local/user/index.html%22,%0A        %22from%22: %22badjs-vip@tencent.com%22,%0A        %22emailSuffix%22: %22@tencent.com%22,%0A        %22time%22: %2209:00:00%22,%0A        %22top%22: 20,%0A        %22module%22: %22email_tof%22%0A    %7D,%0A    %22postgreSql%22: %7B%0A        %22connString%22: %22postgres://tdw_v_zscai:234516038@pub-bi-tdw.oa.com:5432/sng_vas_speedtest_database%22%0A    %7D,%0A    %22fileStorage%22:%7B%0A        %22pageid%22:%22./fileStorage/pageid.json%22,%0A        %22threshold%22:%22./fileStorage/threshold.json%22%0A    %7D%0A%7D;
 %0A
-
 orm.conn
@@ -1883,15 +1883,15 @@
 '201
-4-12-23
+5-11-21
  00:

change test-statistics-services.js