<commit_before>const { Vote } = require('lib/models')

/**
* Check for vote status of user
*
* @param {ObjectId} user
* @param {ObjectId} topic
* @api public
*/

exports.votedBy = function votedBy (user, topic) {
  if (!user || (topic.action.count === 0)) return Promise.resolve(false)
  return Vote.find({ topic: topic._id, author: user._id }).then((topicVote) => {
    return topicVote.length > 0 && topicVote[0].value
  })
}

/**
* Calculate votes results
*
* @param {ObjectId} topic
* @api public
*/

exports.calcResult = function calcResult (topic) {
  return Vote.find({ topic: topic._id }).then((votes) => {
    const options = topic.action.results.map((o) => o.value)

    const votesCounts = votes.reduce(function (counts, vote) {<commit_msg>Added removeOwnVote util function<commit_after>const { Vote } = require('lib/models')

/**
* Remove vote vote to change it.
*
* @param {ObjectId} user
* @param {ObjectId} topic
* @api public
*/

exports.removeOwnVote = function (user, topic) {
  return Vote.remove({ topic: topic._id, author: user._id })
    .then((writeOpResult) => writeOpResult.nMatched !== 0)
}

/**
* Check for vote status of user
*
* @param {ObjectId} user
* @param {ObjectId} topic
* @api public
*/

exports.votedBy = function votedBy (user, topic) {
  if (!user || (topic.action.count === 0)) return Promise.resolve(false)
  return Vote.find({ topic: topic._id, author: user._id }).then((topicVote) =>
    topicVote.length > 0 && topicVote[0].value
  )
}

/**
* Calculate votes results
*
* @param {ObjectId} topic
* @api public
*/

exports.calcResult = function calcResult (topic) {
  return Vote.find({ topic: topic._id }).then((votes) => {
    const options = topic.action.results.map((o) => o.value)

    const votesCounts = votes.reduce(function (counts, vote) {
{'fraction_non_alphanumeric': 0.16517857142857142, 'fraction_numerical': 0.00390625, 'mean_word_length': 4.079320113314448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1862737', 'n_tokens_mistral': 607, 'n_tokens_neox': 590, 'n_words': 159}