<commit_before>import { React, View, Button } from 'reapp-kit';

import * as _ from 'ramda';

// const endSpeech = (start) => {
//     let end = Date.now()
//     return {start, end, total: end - start }
// }

//global variables yuck

// const setStarted(){
//         this.started = Date.now()
//     }

//<Button onTap={()=> alert('hello')}>Boom</Button>



// const Clocktick = React.createClass({



// 	getInitialState(){
// 		const date = new Date();
// 		const hours = date.getHours();
// 		const minutes = date.getMinutes();
// 		const seconds = date.getSeconds();
// 		return ({hours, minutes, seconds});
// 	},

// 	render() {
// 		return( <span>
// 			<p>{this.state.hours}:
// 			{this.state.minutes}:
// 			{this.state.seconds}</p>

// 			</span>
// 			)
// 	},

// 	componentDidMount(){
// 		setInterval(this.clock, 1000);
// 	}
// });




class Clock extends React.Component{

	render(){

		let elapsed = Math.round(this.props.elapsed / 100);

		let seconds = parseInt(elapsed /10);
		return <h1>{this.props.speaker} started {seconds} seconds ago</h1>
	}




}

//takes a match, a callback
//returns a function that will do the callback if the input matches match
const onlyIf = _.curry((match, callback) => {
	return _.cond([
		[match, callback],
		[_.T, _.identity]
	]);
});



const speakingLens = _.lensProp('speaking');

		const namelens = _.lensProp('name')
const newNames = _.over(namelens, _.add('hey'))



export default class TalkerApp extends React.Component {

    constructor(){
		super()
		this.state = {
			ticking: true,
			start: Date.now(),
			currentLog: [],
	  		speakers: [{name: 'Silence', speaking: true},{name: 'Conor', speaking: false},{name: 'Sanj', speaking: false}],
	  		elapsed: 0
		}
	}

	componentDidMount(){

		this.timer = setInterval(this.tick, 1000)
	}

	tick(){
		if (this.state.ticking){
			var sinceStart = new Date() - this.state.start;
			var timeonfloor = _.reduce(_.add, sinceStart, this.state.currentLog)

			this.setState({elapsed: timeonfloor});
		}
	}

	restartConvo(){
		this.setState({start: Date.now(), currentLog: [], ticking: true})
	}

	pause(){
		var thislog = new Date() - this.state.start;
		this.setState({currentLog: this.state.currentLog.concat(thislog), ticking: false});
		}
	
	resume(){
		this.setState({start: new Date(), ticking: true});
	}

	speak(speaker){
		const toggleSpeaking = _.over(speakingLens, _.not);

		
		var onlyspeaker = onlyIf(_.equals(speaker))

		var newspeakers = _.map(onlyspeaker(toggleSpeaking))(this.state.speakers);


		this.setState({speakers: newspeakers});
	}

	silence(){
		
		const silenceAll = _.map(_.set(speakingLens, false));

		var newspeakers = silenceAll(this.state.speakers)
		this.setState({speakers: newspeakers});
	}


    render() {

    	let alt = (this.state.ticking)? <Button onTap={this.pause}>Pause</Button> : <Button color="green" onTap={this.resume}>Resume</Button>



    	return (

        <View title="Talking Stick">
          {this.state.speakers.map(s => {

          	let ticker = (s.speaking)? <Clock speaker={s.name} elapsed={this.state.elapsed} /> : '';

            return(<div>
            <Button onTap={this.speak.bind(this, s)}>{s.name}</Button>
    		{ticker}
            </div>
          )})}

          <Button color="red" onTap={this.silence}>Silence</Button>
    	  {alt}
    	  <Button onTap={this.restartConvo}>Restart</Button>

        </View>
        );
    }
}



const get = _.curry((property, object) => object[property]);


const ifSpeaking = (callback) => {
	return _.cond([
  		[get('speaking'), (speaker) => {return callback(speaker)}]
	]);<commit_msg>Only Those Currently Speaking are Having their name changed<commit_after>import { React, View, Button } from 'reapp-kit';

import * as _ from 'ramda';

// const endSpeech = (start) => {
//     let end = Date.now()
//     return {start, end, total: end - start }
// }

//global variables yuck

// const setStarted(){
//         this.started = Date.now()
//     }

//<Button onTap={()=> alert('hello')}>Boom</Button>



// const Clocktick = React.createClass({



// 	getInitialState(){
// 		const date = new Date();
// 		const hours = date.getHours();
// 		const minutes = date.getMinutes();
// 		const seconds = date.getSeconds();
// 		return ({hours, minutes, seconds});
// 	},

// 	render() {
// 		return( <span>
// 			<p>{this.state.hours}:
// 			{this.state.minutes}:
// 			{this.state.seconds}</p>

// 			</span>
// 			)
// 	},

// 	componentDidMount(){
// 		setInterval(this.clock, 1000);
// 	}
// });




class Clock extends React.Component{

	render(){

		let elapsed = Math.round(this.props.elapsed / 100);
		let time = parseInt(elapsed /10);
		let minutes = () => {
			let m = parseInt(time /60)
			return (m > 0)? `${m} minutes and `: '';
		}

		let seconds = time % 60 ;

		return <h1>{this.props.speaker} has held the floor for {minutes()}{seconds} seconds</h1>
	}




}

//takes a match, a callback
//returns a function that will do the callback if the input matches match
const onlyIf = _.curry((match, callback) => {
	return _.cond([
		[match, callback],
		[_.T, _.identity]
	]);
});



const speakingLens = _.lensProp('speaking');

const namelens = _.lensProp('name')
const newNames = _.over(namelens, _.add('h'))



var timeonfloor = function(speaker){
	var sinceStart = new Date() - speaker.start;
	_.reduce(_.add, sinceStart, speaker.currentLog);
}

export default class TalkerApp extends React.Component {

    constructor(){
		super()
		this.state = {
			ticking: true,
			start: Date.now(),
			currentLog: [],
	  		speakers: [{name: 'Silence', started: null, currentSpeech: 0, currentLog: [], speaking: true},
	  		{name: 'Conor', started: null, currentSpeech: 0, currentLog: [], speaking: false},
	  		{name: 'Sanj', started: null, currentSpeech: 0, currentLog: [], speaking: false}],
	  		elapsed: 0
		}
	}

	componentDidMount(){

		this.timer = setInterval(this.tick, 1000)
	}

	tick(){
		//maps over all the speakers and ticks the ones who are ticking
		let changespeakers = _.map(onlyIf(get('speaking'), newNames), this.state.speakers);

		let speechtime = (s) => {
			_.set(_.lensProp('currentSpeech'), timeonfloor(s))
		};

		if (this.state.ticking){

			this.setState({elapsed: timeonfloor(this.state)});
			this.setState({speakers: changespeakers});
		}
	}

	restartConvo(){
		this.setState({start: Date.now(), currentLog: [], ticking: true})
	}

	pause(){
		var thislog = new Date() - this.state.start;
		this.setState({currentLog: this.state.currentLog.concat(thislog), ticking: false});
		}
	
	resume(){
		this.setState({start: new Date(), ticking: true});
	}

	speak(speaker){
		const toggleSpeaking = _.over(speakingLens, _.not);

		
		var onlyspeaker = onlyIf(_.equals(speaker))

		var newspeakers = _.map(onlyspeaker(toggleSpeaking))(this.state.speakers);


		this.setState({speakers: newspeakers});
	}




	silence(){
		
		const silenceAll = _.map(_.set(speakingLens, false));

		var newspeakers = silenceAll(this.state.speakers)
		this.setState({speakers: newspeakers});
	}


    render() {

    	let alt = (this.state.ticking)? <Button onTap={this.pause}>Pause</Button> : <Button color="green" onTap={this.resume}>Resume</Button>



    	return (

        <View title="Talking Stick">
          {this.state.speakers.map(s => {

          	let ticker = (s.speaking)? <Clock speaker={s.name} elapsed={s.currentSpeech} /> : '';

            return(<div>
            <Button onTap={this.speak.bind(this, s)}>{s.name}</Button>
    		{ticker}
            </div>
          )})}

          <Button color="red" onTap={this.silence}>Silence</Button>
    	  {alt}
    	  <Button onTap={this.restartConvo}>Restart</Button>

        </View>
        );
    }
}



const get = _.curry((property, object) => object[property]);


const ifSpeaking = (callback) => {
	return _.cond([
  		[get('speaking'), (speaker) => {return callback(speaker)}]
	]);
{'fraction_non_alphanumeric': 0.1792010145846544, 'fraction_numerical': 0.0050729232720355105, 'mean_word_length': 3.083894355256344, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 66, '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': '2108130', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2698, 'n_words': 585}