<commit_before>  var moment = require("moment");
  var rsvp = require("rsvp");
  
  var _createGuid = function(){
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
    });
  };
  
  var _createUndefinedError = function(functionName, identifier){
    return new Error(functionName + "(): " + identifier + " must be defined");
  }
  
  var _timedEvents = [];
  var _events = [];
  var _submitEventsImmediately = true;
  var _regardURL = "";
  var _sessionId = _createGuid();
  var _userId = _createGuid(); 

  var _timedEvent = function(eventName, funcToTime){
    var begin = moment();
    funcToTime();
    var end = moment();
    
    _timedEvents.push({
      name : eventName,
      startTime : begin.valueOf(),
      endTime : end.valueOf(),
      duration: end.diff(begin)
    });
  };
  
  var _postEvent = function(event){
    return new rsvp.Promise(function(resolve, reject){
      if(!event){
        reject(_createUndefinedError("_postEvent", "event"));
      }
          
      var postEventRequest = new XMLHttpRequest();
      postEventRequest.onreadystatechange = function(){
        if(postEventRequest.readyState === 4){
          if(postEventRequest.status === 200){
            resolve(event);
          }
          else{
            reject(new Error(postEventRequest.statusText));
          }
        }
      };
      
      postEventRequest.open("POST", _regardURL, true);
      postEventRequest.send(JSON.stringify(event));
    });
  };
   
  var _trackEvent = function(eventType, props){
    return new rsvp.Promise(function(resolve, reject){
      if(!eventType){
        reject(_createUndefinedError("_trackEvent", "eventType"));
      }
      if(!_sessionId){
        reject(_createUndefinedError("_postEvent", "A session Id"));
      }
      if(!_userId){
        reject(_createUndefinedError("_postEvent", "A user Id"));
      }
       
       var event = {
        "event-type" : eventType,
        "session-id" : _sessionId,
        "user-id" : _userId,
        "time" : moment().valueOf()
      };           
      
      if(props){
        event["data"] = props;
      } 
      
      if(_submitEventsImmediately){
        _postEvent(event).then(resolve, reject);
      }
      else{
        _events.push(event);
        resolve(event);
      }
    });   
  }
    
  module.exports.trackTimedEvent = _timedEvent;
  module.exports.timedEvents = _timedEvents;
  module.exports.events = _events;
  module.exports.trackEvent = _trackEvent;
  module.exports.startNewSession = function() { 
    _sessionId = _createGuid();
    return _sessionId;
  };
  module.exports.createNewUser = function() {
    _userId = _createGuid();
    return _userId;
  }
  module.exports.setRegardURL = function(url){ _regardURL = url; };
  module.exports.setUserId = function(userId) { _userId = userId; };
  module.exports.getUserId = function(){ return _userId };
  module.exports.getSessionId = function(){ return _sessionId; };<commit_msg>added setSessionId to the interface<commit_after>  var moment = require("moment");
  var rsvp = require("rsvp");

  var _createGuid = function () {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          var r = Math.random() * 16 | 0,
              v = c === 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
      });
  };

  var _createUndefinedError = function (functionName, identifier) {
      return new Error(functionName + "(): " + identifier + " must be defined");
  }

  var _timedEvents = [];
  var _events = [];
  var _submitEventsImmediately = true;
  var _regardURL = "";
  var _sessionId = _createGuid();
  var _userId = _createGuid();

  var _timedEvent = function (eventName, funcToTime) {
      var begin = moment();
      funcToTime();
      var end = moment();

      _timedEvents.push({
          name: eventName,
          startTime: begin.valueOf(),
          endTime: end.valueOf(),
          duration: end.diff(begin)
      });
  };

  var _postEvent = function (event) {
      return new rsvp.Promise(function (resolve, reject) {
          if (!event) {
              reject(_createUndefinedError("_postEvent", "event"));
          }

          var postEventRequest = new XMLHttpRequest();
          postEventRequest.onreadystatechange = function () {
              if (postEventRequest.readyState === 4) {
                  if (postEventRequest.status === 200) {
                      resolve(event);
                  } else {
                      reject(new Error(postEventRequest.statusText));
                  }
              }
          };

          postEventRequest.open("POST", _regardURL, true);
          postEventRequest.send(JSON.stringify(event));
      });
  };

  var _trackEvent = function (eventType, props) {
      return new rsvp.Promise(function (resolve, reject) {
          if (!eventType) {
              reject(_createUndefinedError("_trackEvent", "eventType"));
          }
          if (!_sessionId) {
              reject(_createUndefinedError("_postEvent", "A session Id"));
          }
          if (!_userId) {
              reject(_createUndefinedError("_postEvent", "A user Id"));
          }

          var event = {
              "event-type": eventType,
              "session-id": _sessionId,
              "user-id": _userId,
              "time": moment().valueOf()
          };

          if (props) {
              event["data"] = props;
          }

          if (_submitEventsImmediately) {
              _postEvent(event).then(resolve, reject);
          } else {
              _events.push(event);
              resolve(event);
          }
      });
  }

  module.exports.trackTimedEvent = _timedEvent;
  module.exports.timedEvents = _timedEvents;
  module.exports.events = _events;
  module.exports.trackEvent = _trackEvent;
  module.exports.startNewSession = function () {
      _sessionId = _createGuid();
      return _sessionId;
  };
  module.exports.createNewUser = function () {
      _userId = _createGuid();
      return _userId;
  }
  module.exports.setRegardURL = function (url) {
      _regardURL = url;
  };
  module.exports.setUserId = function (userId) {
      _userId = userId;
  };
  module.exports.setSessionId = function (sessionId) {
      _sessionId = sessionId;
  };
  module.exports.getUserId = function () {
      return _userId
  };
  module.exports.getSessionId = function () {
      return _sessionId;
  };
{'fraction_non_alphanumeric': 0.13098699311400153, 'fraction_numerical': 0.004284621270084162, 'mean_word_length': 2.259850374064838, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '1125604', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1927, 'n_words': 376}