<commit_before>var fs=require('fs');
var constants= require('../../../constants.js')
var envVariables=require('../../../envVariables.js')

module.exports = function(socket){
  socket.on('connect',function(){
    fs.readFile(constants.MAIN_ID_PATH,'utf8',function(err,data){
      if(err){
        throw err;
      }
      constants.MAIN_ID=data;
      socket.emit('identification', {mainID: constants.MAIN_ID}, function(err,res){
        if(err){
          throw err;
        }
        if(res.status){
          if(res.new){
            fs.writeFile(constants.MAIN_ID_PATH, res.mainID, 'utf8', function(err){
              if(err){
                throw err;
              }
              constants.MAIN_ID=res.id;
              socket.disconnect();
            });
          }
          else{
            envVariables.serverConnectionStatus=true;
          }
        }
        else{
          if(res.error){
            console.log(res.error);
          }
          socket.disconnect();
        }
      });
    });
  }); 
  socket.on('disconnect',function(){
    envVariables.serverConnectionStatus=false;
  });
}
<commit_msg>Update connection.js<commit_after>var fs=require('fs');
var async=require('../../../async');
var constants= require('../../../constants.js')
var envVariables=require('../../../envVariables.js')
var Reading=require('../../../server/models/reading.js')


module.exports = function(socket){
  socket.on('connect',function(){
    fs.readFile(constants.MAIN_ID_PATH,'utf8',function(err,data){
      if(err){
        throw err;
      }
      constants.MAIN_ID=data;
      socket.emit('identification', {mainID: constants.MAIN_ID}, function(err,res){
        if(err){
          throw err;
        }
        if(res.status){
          if(res.new){
            fs.writeFile(constants.MAIN_ID_PATH, res.mainID, 'utf8', function(err){
              if(err){
                throw err;
              }
              constants.MAIN_ID=res.id;
              socket.disconnect();
            });
          }
          else{
            envVariables.serverConnectionStatus=true;
            Reading.find({},function(err,docs){
              if(err){
                throw err;
              }
              var i=0;
              var j=0;
              async.whilst(i<docs.length
                async.whilst(i==j,
                  socket.emit('rReading',docs[i],function(err,res){
                    if(err){
                      throw err;
                    }
                    if(res.status){
                      Reading.findById(docs[i]._id,function(err,doc){
                        if(err){
                          throw err;
                        }
                        doc.remove(function(err,res){
                          if(err){
                            throw err;
                          }
                        });
                      });
                    i++;
                    }
                  });                       
               );
               j++;
              ); 
            });
          }
        }
        else{
          if(res.error){
            console.log(res.error);
          }
          socket.disconnect();
        }
      });
    });
  }); 
  socket.on('disconnect',function(){
    envVariables.serverConnectionStatus=false;
  });
}

{'fraction_non_alphanumeric': 0.14337349397590363, 'fraction_numerical': 0.0018072289156626507, 'mean_word_length': 1.2378706199460916, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812207', 'n_tokens_mistral': 902, 'n_tokens_neox': 886, 'n_words': 112}