<commit_before>var express = require('express');
var fs = require('fs');
var router = express.Router();
var User = require('../model/schema');

router.get('/:charttype=?/:packagetype=?/:datename=?',function(req,res,next){
  var charttype = req.params.charttype;
  var packagetype = req.params.packagetype;
  var datename = req.params.datename;
  if(charttype==="rate")
  {
      if(packagetype==="all")
      {
          sp = datename.split('_');
          if(sp[0]==="monthwise")
          {
            var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            data = new Array();
            for(var i=0; i<12; i++)
            {
                tempObj = new Object();
                tempObj["period"] = month[i];
                tempObj["Input"] = 0;
                tempObj["Output"] = 0;
                data.push(tempObj);
            }
            User.aggregate([{$group:{_id: {"period":"$month","Type":"$mode"},count:{$sum:1}}}],function(err,result){

                  for(var i=0; i<result.length; i++)
                  {
                      if(result[i]["_id"]["Type"]==="I")
                      {
                          data[month.indexOf(result[i]["_id"]["period"])]["Input"]+=result[i]["count"];
                      }

                      else
                      {
                          data[month.indexOf(result[i]["_id"]["period"])]["Output"]+=result[i]["count"];
                      }
                  }
                  //console.log(data);

                  res.send(JSON.stringify(data));
              });

          }
          else
          {
              var odd = ["Jan","Mar","May","Jul","Aug","Oct","Dec"];
              var even = ["Apr","Jun","Sep","Nov"];
              data = new Array();
              if(odd.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<32; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              else if(even.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<31; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              else
              {
                  for(var i=0; i<30; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              User.aggregate([{$match:{"year":2015,"month":sp[0]}},{$group:{_id: {"period":"$date","Type":"$mode"},count:{$sum:1}}}],function(err,result){
                for(var i=0; i<result.length; i++)
                {
                    if(result[i]["_id"]["Type"]==="I")
                    {
                        data[result[i]["_id"]["period"]-1]["Input"]+=result[i]["count"];
                    }

                    else
                    {
                        data[result[i]["_id"]["period"]-1]["Output"]+=result[i]["count"];
                    }
                }
                res.send(JSON.stringify(data));
              });
          }
      }

      else if(packagetype === "metadata")
      {
          sp = datename.split('_');
          if(sp[0]==="monthwise")
          {
            var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            data = new Array();
            for(var i=0; i<12; i++)
            {
                tempObj = new Object();
                tempObj["period"] = month[i];
                tempObj["Input"] = 0;
                tempObj["Output"] = 0;
                data.push(tempObj);
            }
            User.aggregate([{$match:{"year":2015,"download":{$not:/.deb/}}},{$group:{_id: {"period":"$month","Type":"$mode"},count:{$sum:1}}}],function(err,result){
              for(var i=0; i<result.length; i++)
              {
                  if(result[i]["_id"]["Type"]==="I")
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Input"]+=result[i]["count"];
                  }

                  else
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Output"]+=result[i]["count"];
                  }
              }
              //console.log(data);

              res.send(JSON.stringify(data));
            });
          }
          else
          {
              var odd = ["Jan","Mar","May","Jul","Aug","Oct","Dec"];
              var even = ["Apr","Jun","Sep","Nov"];
              data = new Array();
              if(odd.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<32; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else if(even.indexOf(sp[0]) > -1)
                {
                  for(var i=1; i<31; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else
                {
                  for(var i=1; i<30; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                User.aggregate([{$match:{"year":2015,"month":sp[0],"download":{$not:/.deb/}}},{$group:{_id: {"period":"$date","Type":"$mode"},count:{$sum:1}}}],function(err,result){
                  for(var i=0; i<result.length; i++)
                  {
                      if(result[i]["_id"]["Type"]==="I")
                      {
                          data[result[i]["_id"]["period"]-1]["Input"]+=result[i]["count"];
                      }

                      else
                      {
                          data[result[i]["_id"]["period"]-1]["Output"]+=result[i]["count"];
                      }
                  }
                  res.send(JSON.stringify(data));
                });

          }
      }

  }
//  res.send(data.toString());
});

module.exports = router;
<commit_msg>package filter implemented using mongo<commit_after>var express = require('express');
var fs = require('fs');
var router = express.Router();
var User = require('../model/schema');

router.get('/:charttype=?/:packagetype=?/:datename=?',function(req,res,next){
  var charttype = req.params.charttype;
  var packagetype = req.params.packagetype;
  var datename = req.params.datename;
  if(charttype==="rate")
  {
      if(packagetype==="all")
      {
          sp = datename.split('_');
          if(sp[0]==="monthwise")
          {
            var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            data = new Array();
            for(var i=0; i<12; i++)
            {
                tempObj = new Object();
                tempObj["period"] = month[i];
                tempObj["Input"] = 0;
                tempObj["Output"] = 0;
                data.push(tempObj);
            }
            User.aggregate([{$group:{_id: {"period":"$month","Type":"$mode"},count:{$sum:1}}}],function(err,result){

                  for(var i=0; i<result.length; i++)
                  {
                      if(result[i]["_id"]["Type"]==="I")
                      {
                          data[month.indexOf(result[i]["_id"]["period"])]["Input"]+=result[i]["count"];
                      }

                      else
                      {
                          data[month.indexOf(result[i]["_id"]["period"])]["Output"]+=result[i]["count"];
                      }
                  }
                  //console.log(data);

                  res.send(JSON.stringify(data));
              });

          }
          else
          {
              var odd = ["Jan","Mar","May","Jul","Aug","Oct","Dec"];
              var even = ["Apr","Jun","Sep","Nov"];
              data = new Array();
              if(odd.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<32; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              else if(even.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<31; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              else
              {
                  for(var i=0; i<30; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
              }
              User.aggregate([{$match:{"year":2015,"month":sp[0]}},{$group:{_id: {"period":"$date","Type":"$mode"},count:{$sum:1}}}],function(err,result){
                for(var i=0; i<result.length; i++)
                {
                    if(result[i]["_id"]["Type"]==="I")
                    {
                        data[result[i]["_id"]["period"]-1]["Input"]+=result[i]["count"];
                    }

                    else
                    {
                        data[result[i]["_id"]["period"]-1]["Output"]+=result[i]["count"];
                    }
                }
                res.send(JSON.stringify(data));
              });
          }
      }

      else if(packagetype === "metadata")
      {
          sp = datename.split('_');
          if(sp[0]==="monthwise")
          {
            var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            data = new Array();
            for(var i=0; i<12; i++)
            {
                tempObj = new Object();
                tempObj["period"] = month[i];
                tempObj["Input"] = 0;
                tempObj["Output"] = 0;
                data.push(tempObj);
            }
            User.aggregate([{$match:{"year":2015,"download":{$not:/.deb/}}},{$group:{_id: {"period":"$month","Type":"$mode"},count:{$sum:1}}}],function(err,result){
              for(var i=0; i<result.length; i++)
              {
                  if(result[i]["_id"]["Type"]==="I")
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Input"]+=result[i]["count"];
                  }

                  else
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Output"]+=result[i]["count"];
                  }
              }
              //console.log(data);

              res.send(JSON.stringify(data));
            });
          }
          else
          {
              var odd = ["Jan","Mar","May","Jul","Aug","Oct","Dec"];
              var even = ["Apr","Jun","Sep","Nov"];
              data = new Array();
              if(odd.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<32; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else if(even.indexOf(sp[0]) > -1)
                {
                  for(var i=1; i<31; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else
                {
                  for(var i=1; i<30; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                User.aggregate([{$match:{"year":2015,"month":sp[0],"download":{$not:/.deb/}}},{$group:{_id: {"period":"$date","Type":"$mode"},count:{$sum:1}}}],function(err,result){
                  for(var i=0; i<result.length; i++)
                  {
                      if(result[i]["_id"]["Type"]==="I")
                      {
                          data[result[i]["_id"]["period"]-1]["Input"]+=result[i]["count"];
                      }

                      else
                      {
                          data[result[i]["_id"]["period"]-1]["Output"]+=result[i]["count"];
                      }
                  }
                  res.send(JSON.stringify(data));
                });

          }
      }
      else if(packagetype === "package")
      {
          sp = datename.split('_');
          if(sp[0]==="monthwise")
          {
            var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            data = new Array();
            for(var i=0; i<12; i++)
            {
                tempObj = new Object();
                tempObj["period"] = month[i];
                tempObj["Input"] = 0;
                tempObj["Output"] = 0;
                data.push(tempObj);
            }
            User.aggregate([{$match:{"year":2015,"download":/.deb/}},{$group:{_id: {"period":"$month","Type":"$mode"},count:{$sum:1}}}],function(err,result){
              for(var i=0; i<result.length; i++)
              {
                  if(result[i]["_id"]["Type"]==="I")
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Input"]+=result[i]["count"];
                  }

                  else
                  {
                      data[month.indexOf(result[i]["_id"]["period"])]["Output"]+=result[i]["count"];
                  }
              }
              //console.log(data);

              res.send(JSON.stringify(data));
            });
          }
          else
          {
              var odd = ["Jan","Mar","May","Jul","Aug","Oct","Dec"];
              var even = ["Apr","Jun","Sep","Nov"];
              data = new Array();
              if(odd.indexOf(sp[0]) > -1)
              {
                  for(var i=1; i<32; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else if(even.indexOf(sp[0]) > -1)
                {
                  for(var i=1; i<31; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                else
                {
                  for(var i=1; i<30; i++)
                  {
                      tempObj = new Object();
                      tempObj["period"] = i;
                      tempObj["Input"] = 0;
                      tempObj["Output"] = 0;
                      data.push(tempObj);
                  }
                }
                User.aggregate([{$match:{"year":2015,"month":sp[0],"download":/.deb/}},{$group:{_id: {"period":"$date","Type":"$mode"},count:{$sum:1}}}],function(err,result){
                  for(var i=0; i<result.length; i++)
                  {
                      if(result[i]["_id"]["Type"]==="I")
                      {
                          data[result[i]["_id"]["period"]-1]["Input"]+=result[i]["count"];
                      }

                      else
                      {
                          data[result[i]["_id"]["period"]-1]["Output"]+=result[i]["count"];
                      }
                  }
                  res.send(JSON.stringify(data));
                });

          }
      }

  }
//  res.send(data.toString());
});

module.exports = router;

{'fraction_non_alphanumeric': 0.18207739307535642, 'fraction_numerical': 0.011172534186790806, 'mean_word_length': 1.0599304806424548, 'pattern_counts': {'":': 39, '<': 33, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2589929', 'n_tokens_mistral': 4943, 'n_tokens_neox': 4528, 'n_words': 587}