<commit_before>'use strict'

class DataLogger {

  initDb () {
    if (!this.Datastore && !this.db) {
      this.Datastore = require('nedb')

      this.db = new this.Datastore({
        filename: process.cwd() + '/caravel_log.db', autoload: true
      })
    }
  }

  insertLog (status, details) {
    this.initDb()
    let self = this
    let timestamp = +new Date()
    let date = new Date().toISOString()

    let data = {
      timestamp: timestamp,
      time: date,
      status: status
    }

    if (details) {
      data.details = details
    }

    self.db.count({}, (err, count) => {
      if (err) {
        console.log(err)
      }

      data.id = count

      self.db.insert(data, (err, newDoc) => {
        if (err) {
          console.log(err)
        }
      })
    })
  }

  updateLastLog (status, details) {
    this.initDb()
    let self = this
    let timestamp = +new Date()
    let date = new Date().toISOString()

    let data = {
      timestamp: timestamp,
      time: date,
      status: status
    }

    if (details) {
      data.details = details
    }

    self.db.find({}).sort({ id: -1 }).limit(1).exec((err, lastLogID) => {
      if (err) {
        console.log(err)
      }

      lastLogID = lastLogID[0].id

      console.log('Last log id: ' + lastLogID)

      self.db.update({id: lastLogID}, { $set: data }, {}, (err, numRowsAffected, newDoc) => {
        if (err) {
          console.log(err)
        }

        self.db.persistence.compactDatafile()
      })
    })
  }

  getLogs (cb) {
    this.initDb()
    let self = this
    self.db.persistence.compactDatafile()
    self.db.find({}).sort({ id: -1 }).exec((err, docs) => {
      if (err) {
        console.log(err)
      }
      cb(docs)
    })
  }

  getLastId (cb) {
    this.initDb()
    let self = this
    self.db.persistence.compactDatafile()
    self.db.find({}).sort({ id: -1 }).limit(1).exec((err, docs) => {
      if (err) {
        console.log(err)
      }
      cb(docs[0].id)
    })
  }
}

module.exports = new DataLogger()<commit_msg>Removing "self" redundant variable<commit_after>'use strict'

class DataLogger {

  initDb () {
    if (!this.Datastore && !this.db) {
      this.Datastore = require('nedb')

      this.db = new this.Datastore({
        filename: process.cwd() + '/caravel_log.db', autoload: true
      })
    }
  }

  insertLog (status, details) {
    this.initDb()
    let timestamp = +new Date()
    let date = new Date().toISOString()

    let data = {
      timestamp: timestamp,
      time: date,
      status: status
    }

    if (details) {
      data.details = details
    }

    this.db.count({}, (err, count) => {
      if (err) {
        console.log(err)
      }

      data.id = count

      this.db.insert(data, (err, newDoc) => {
        if (err) {
          console.log(err)
        }
      })
    })
  }

  updateLastLog (status, details) {
    this.initDb()
    let timestamp = +new Date()
    let date = new Date().toISOString()

    let data = {
      timestamp: timestamp,
      time: date,
      status: status
    }

    if (details) {
      data.details = details
    }

    this.db.find({}).sort({ id: -1 }).limit(1).exec((err, lastLogID) => {
      if (err) {
        console.log(err)
      }

      lastLogID = lastLogID[0].id

      console.log('Last log id: ' + lastLogID)

      this.db.update({id: lastLogID}, { $set: data }, {}, (err, numRowsAffected, newDoc) => {
        if (err) {
          console.log(err)
        }

        this.db.persistence.compactDatafile()
      })
    })
  }

  getLogs (cb) {
    this.initDb()
    this.db.persistence.compactDatafile()
    this.db.find({}).sort({ id: -1 }).exec((err, docs) => {
      if (err) {
        console.log(err)
      }
      cb(docs)
    })
  }

  getLastId (cb) {
    this.initDb()
    this.db.persistence.compactDatafile()
    this.db.find({}).sort({ id: -1 }).limit(1).exec((err, docs) => {
      if (err) {
        console.log(err)
      }
      cb(docs[0].id)
    })
  }
}

module.exports = new DataLogger()
{'fraction_non_alphanumeric': 0.16480516257135766, 'fraction_numerical': 0.003474807644576818, 'mean_word_length': 1.8622159090909092, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1255640', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1396, 'n_words': 282}