<commit_before>import React from 'react';
const afinn = require('./AFINN'), emotion = require('./emotion');

export function sentiMentator(sentimentObject, identifier) {
  let totalScore = 0, posWithVals = [], negsWithVals = [], orderedWordsRating = [];
  sentimentObject.words = sentimentObject.words.filter(word => word !== "");
  sentimentObject.words.forEach(word=>{
    let score = afinn[word];
    if(score>0){posWithVals.push([word, score])}
    else{ negsWithVals.push([word, score]) }
  });
  let sentimentArray = identifier === 'journal' ?  sentimentObject.words.reverse() :  sentimentObject.words;
  sentimentArray.forEach( (word, index) =>{
    totalScore += afinn[word];
    if(sentimentArray.length<100){
      orderedWordsRating.push( {word,totalScore} );
    } else {
      if(index===0 || index === sentimentArray.length-1 || index%20 === 0){
        orderedWordsRating.push( {word,totalScore} );
      }
    }
  });
  let totalPositive = posWithVals.reduce((a,b)=>a+b[1],0);
  let totalNegative = negsWithVals.reduce((a,b)=>a+b[1],0);
  return Object.assign({}, sentimentObject, {negsWithVals, posWithVals, orderedWordsRating, totalPositive, totalNegative});
}

export function emotinator(content) {
  let wordArray = content.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ").split(' ')
  let emotionObject = {}, preData = {}, emotionInstances = [];
  wordArray.forEach(word=>{
    if(emotion[word]){
      preData[word] =  preData[word] ? [preData[word][0], preData[word][1]+1] : [emotion[word],1]
      emotion[word].forEach(match=>{
        emotionObject[match] = emotionObject[match] ? emotionObject[match] + 1 : 1
      })
    }
  });

 for(let key in preData) {
    emotionInstances.push({value: key, count: preData[key][1]});
  };
  emotionInstances = emotionInstances.sort((a,b)=> b.count - a.count).slice(0,50);  //sort and return top 50
  return [emotionObject, emotionInstances];
};

export const customRenderer = (tag, size, color) => (
  <span key={tag.value}
    style={{
      fontSize: `${size+1}em`,
      margin: '3px',
      padding: '3px',
      display: 'inline-block',
      color: `${color}`
    }}>{tag.value}</span>
);

export function validateSong(values) {
  const error = {};
  if (!values.song_title) {
    error.song_title = 'A Song Title is Required';
  };
  if (!values.song_artist) {
    error.song_artist = 'Artist is  Required';
  };
  console.log('Errors======>', error);
  return error;
};

export function validateJournal(values) {
  const error = {};
  if (!values.title) {
    error.title = 'A Title is Required';
  };
  if (!values.content) {
    error.content = 'Content is Required';
  };
  console.log('Errors======>', error);
  return error;
};

export const tweetsToParagraph = (tweetsData) => {      //Twitter Util Functions tweetsToParagraph takes an array of twitter objects and returns the text of the tweets as one block of text

	let tweetsParagraph = '';
	tweetsData.forEach((tweetData) => {<commit_msg>delta variable, around 50 values<commit_after>import React from 'react';
const afinn = require('./AFINN'), emotion = require('./emotion');

export function sentiMentator(sentimentObject, identifier) {
  let totalScore = 0, posWithVals = [], negsWithVals = [], orderedWordsRating = [];
  sentimentObject.words = sentimentObject.words.filter(word => word !== "");
  sentimentObject.words.forEach(word=>{
    let score = afinn[word];
    if(score>0){posWithVals.push([word, score])}
    else{ negsWithVals.push([word, score]) }
  });
  let sentimentArray = identifier === 'journal' ?  sentimentObject.words.reverse() :  sentimentObject.words;
  sentimentArray.forEach( (word, index) =>{
    totalScore += afinn[word];
    if(sentimentArray.length<75){
      orderedWordsRating.push( {word,totalScore} );
    } else {
      let maximumNumberofValues = 50;
      let delta = Math.floor( sentimentArray.length / maximumNumberofValues );
      if(index===0 || index === sentimentArray.length-1 || index%delta === 0){
        orderedWordsRating.push( {word,totalScore} );
      }
    }
  });
  let totalPositive = posWithVals.reduce((a,b)=>a+b[1],0);
  let totalNegative = negsWithVals.reduce((a,b)=>a+b[1],0);
  return Object.assign({}, sentimentObject, {negsWithVals, posWithVals, orderedWordsRating, totalPositive, totalNegative});
}

export function emotinator(content) {
  let wordArray = content.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g," ").split(' ')
  let emotionObject = {}, preData = {}, emotionInstances = [];
  wordArray.forEach(word=>{
    if(emotion[word]){
      preData[word] =  preData[word] ? [preData[word][0], preData[word][1]+1] : [emotion[word],1]
      emotion[word].forEach(match=>{
        emotionObject[match] = emotionObject[match] ? emotionObject[match] + 1 : 1
      })
    }
  });

 for(let key in preData) {
    emotionInstances.push({value: key, count: preData[key][1]});
  };
  emotionInstances = emotionInstances.sort((a,b)=> b.count - a.count).slice(0,50);  //sort and return top 50
  return [emotionObject, emotionInstances];
};

export const customRenderer = (tag, size, color) => (
  <span key={tag.value}
    style={{
      fontSize: `${size+1}em`,
      margin: '3px',
      padding: '3px',
      display: 'inline-block',
      color: `${color}`
    }}>{tag.value}</span>
);

export function validateSong(values) {
  const error = {};
  if (!values.song_title) {
    error.song_title = 'A Song Title is Required';
  };
  if (!values.song_artist) {
    error.song_artist = 'Artist is  Required';
  };
  console.log('Errors======>', error)
  return error;
};

export function validateJournal(values) {
  const error = {};
  if (!values.title) {
    error.title = 'A Title is Required';
  };
  if (!values.content) {
    error.content = 'Content is Required';
  };
  console.log('Errors======>', error);
  return error;
};

export const tweetsToParagraph = (tweetsData) => {      //Twitter Util Functions tweetsToParagraph takes an array of twitter objects and returns the text of the tweets as one block of text

	let tweetsParagraph = '';
	tweetsData.forEach((tweetData) => {
{'fraction_non_alphanumeric': 0.1743783961798123, 'fraction_numerical': 0.00971513255392722, 'mean_word_length': 4.0281456953642385, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '1246407', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1976, 'n_words': 422}