<commit_before>'use strict';

/**
 * External dependencies
 */
var React = require( 'react' ),
	isInteger = require( 'is-integer' ),
	_ = require( 'lodash' ),
	url = require( 'url' );

/**
 * Internal dependencies
 */
var canvasUtils = require( './utils/canvas-utils' ),
	config = require( './config' ),
	ConversionDataForm = require( './form/conversion-data-form' ),
	CopyURLButton = require( './copy-url-button' ),
	ExecutiveSummary = require( './executive-summary' ),
	SampleProportionsGraph = require( './graphs/sample-proportions-graph' ),
	ImprovementGraph = require( './graphs/improvement-graph' ),
	Variation = require( './stats/variation' ),
	utils = require( './utils' );

module.exports = React.createClass( {
	getInitialState: function() {
		var params = url.parse( document.URL, true ).query,
			queryNameA, queryNameB, queryParticipantsA, queryConversionsA, queryParticipantsB, queryConversionsB,
			nameA = config.variations.a.defaultName,
			nameB = config.variations.b.defaultName,
			participantsA = config.variations.a.defaultParticipants,
			conversionsA = config.variations.a.defaultConversions,
			participantsB = config.variations.b.defaultParticipants,
			conversionsB = config.variations.b.defaultConversions;

		if ( ! _.isEmpty( params ) ) {
			queryNameA = params.an;
			queryNameB = params.bn;

			if ( queryNameA && queryNameB ) {
				nameA = queryNameA;
				nameB = queryNameB;
			}

			queryParticipantsA = params.ap;
			queryConversionsA = params.ac;
			queryParticipantsB = params.bp;
			queryConversionsB = params.bc;

			if ( utils.isIntegerString( queryParticipantsA ) && utils.isIntegerString( queryConversionsA ) && utils.isIntegerString( queryParticipantsB ) && utils.isIntegerString( queryConversionsB ) ) {
				participantsA = +queryParticipantsA;
				conversionsA = +queryConversionsA;
				participantsB = +queryParticipantsB;
				conversionsB = +queryConversionsB;
			} else {
				// Rather than show an error message about not being able to parse the params
				// we'll simply not include any defaults in the fields
				participantsA = conversionsA = participantsB = conversionsB = '';
			}
		}

		return {
			nameA: nameA,
			nameB: nameB,
			participantsA: participantsA,
			conversionsA: conversionsA,
			participantsB: participantsB,
			conversionsB: conversionsB
		};
	},

	updateConversionData: function( updatedData ) {
		this.setState( updatedData );
	},

	getVariations: function() {
		return {
			a: new Variation( this.state.nameA, '#F1C40F', this.state.participantsA, this.state.conversionsA ),
			b: new Variation( this.state.nameB, '#B6E2FF', this.state.participantsB, this.state.conversionsB )
		};
	},

	hasIntegerInputs: function() {
		return isInteger( this.state.participantsA ) &&
			isInteger( this.state.conversionsA ) &&
			isInteger( this.state.participantsB ) &&
			isInteger( this.state.conversionsB );
	},

	hasMoreParticipantsThanConversions: function() {
		return this.state.conversionsA <= this.state.participantsA &&
			this.state.conversionsB <= this.state.participantsB;
	},

	hasGaussianDistributions: function() {<commit_msg>Refactor logic to set the initial app state<commit_after>'use strict';

/**
 * External dependencies
 */
var React = require( 'react' ),
	isInteger = require( 'is-integer' ),
	_ = require( 'lodash' ),
	url = require( 'url' );

/**
 * Internal dependencies
 */
var canvasUtils = require( './utils/canvas-utils' ),
	config = require( './config' ),
	ConversionDataForm = require( './form/conversion-data-form' ),
	CopyURLButton = require( './copy-url-button' ),
	ExecutiveSummary = require( './executive-summary' ),
	SampleProportionsGraph = require( './graphs/sample-proportions-graph' ),
	ImprovementGraph = require( './graphs/improvement-graph' ),
	Variation = require( './stats/variation' ),
	utils = require( './utils' );

module.exports = React.createClass( {
	getInitialState: function() {
		var params = this.getURLParams(), initialState;

		initialState = {
			nameA: config.variations.a.defaultName,
			nameB: config.variations.b.defaultName,
			participantsA: config.variations.a.defaultParticipants,
			conversionsA: config.variations.a.defaultConversions,
			participantsB: config.variations.b.defaultParticipants,
			conversionsB: config.variations.b.defaultConversions
		};

		if ( ! _.isEmpty( params ) ) {
			if ( params.an && params.bn ) {
				initialState.nameA = params.an;
				initialState.nameB = params.bn;
			}

			if ( this.hasValidDataParams() ) {
				initialState.participantsA = parseInt( params.ap, 10 );
				initialState.conversionsA = parseInt( params.ac, 10 );
				initialState.participantsB = parseInt( params.bp, 10 );
				initialState.conversionsB = parseInt( params.bc, 10 );
			} else {
				// Rather than show an error message about not being able to parse
				// the params we'll simply not include any defaults in the fields
				initialState.participantsA = initialState.conversionsA = initialState.participantsB = initialState.conversionsB = '';
			}
		}

		return initialState;
	},

	getURLParams: function() {
		return url.parse( document.URL, true ).query;
	},

	hasValidDataParams: function() {
		var params = this.getURLParams();

		return utils.isIntegerString( params.ap ) &&
			utils.isIntegerString( params.ac ) &&
			utils.isIntegerString( params.bp ) &&
			utils.isIntegerString( params.bc );
	},

	updateConversionData: function( updatedData ) {
		this.setState( updatedData );
	},

	getVariations: function() {
		return {
			a: new Variation( this.state.nameA, '#F1C40F', this.state.participantsA, this.state.conversionsA ),
			b: new Variation( this.state.nameB, '#B6E2FF', this.state.participantsB, this.state.conversionsB )
		};
	},

	hasIntegerInputs: function() {
		return isInteger( this.state.participantsA ) &&
			isInteger( this.state.conversionsA ) &&
			isInteger( this.state.participantsB ) &&
			isInteger( this.state.conversionsB );
	},

	hasMoreParticipantsThanConversions: function() {
		return this.state.conversionsA <= this.state.participantsA &&
			this.state.conversionsB <= this.state.participantsB;
	},

	hasGaussianDistributions: function() {
{'fraction_non_alphanumeric': 0.12967499591703413, 'fraction_numerical': 0.002939735423811857, 'mean_word_length': 4.116123642439432, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '590023', 'n_tokens_mistral': 2157, 'n_tokens_neox': 1886, 'n_words': 391}