<commit_before>function setTitle(component,q) {
	var tpl = new Ext.Template([
		'<div class="question">{t}</div>',
	]);
	tpl.compile();
	html = tpl.apply( {t: q.get('text') } );
	component.getTitle().setHtml(html);
}

function setQuestion(c, q) {
	c.removeAll();
	var response = buildQuestion(q);
	c.add(Ext.decode(response).data);
}

function getNextQuestion(newO, direction) {
	// direction = 0 for direct, -1 for prev, 1 for next
	var s = Ext.getStore('Questions');
	// wrap around for now; go to welcome / summary
	if ( newO < 0 ) {
		// summary
		newO = s.getCount() - 1;
	} else if ( newO > s.getCount() - 1) {
		// start (clear/etc)
		newO = 0;
	}
	var q = s.getAt(newO);
	// skip?
	log(q.get('skip'));
	if ( q.get('skip') != null ) {
		q = skipQuestions(q, direction);
	}
	//
	return q;
}

function skipQuestions(q, direction) {
	log('skipQuestion direction: ' + direction + ' q: ' + q.get('skip').split(',')[0] );
	var skipItems = q.get('skip').split(',');
	skipItems.forEach(logArrayElements);
	newQ = q;
	skipItems.forEach(function(element) {
		newQ = skipQuestionsItem(newQ, element, direction);
		log('newQ ' + newQ.get('id'));
	});
	return newQ;
}

function skipQuestionsItem(q, element, direction) {
	var item = element.split('.');
	if ( isResponseEqualSkip(q,item[0], item[1]) ) { 
		log('skipped ' + q.get('id'));
		// fixme save empty response for skipped q
		q = getNextQuestion(q.get('ordinal') + direction, direction);
	}
	return q;
}

function isResponseEqualSkip(q,skipQ, skipR) {
	log('skipQ ' + skipQ + ',skipR ' + skipR + ', skip it? q ' + q.get('id') + ',skip it? o ' + q.get('ordinal') );
	// fixme lookup the actual response and check the values
	var s = Ext.getStore('Responses');
	s.load();
	var r = s.findRecord('q', skipQ);
	if ( r != null ) {
		log(r);
		var options = r.get('options');
		if (options instanceof Array) {
			return ( options != null && options.indexOf(skipR) > -1 );
		} else {
			return ( options != null && options == skipR );
		}
	}
	return false;
	// test multi skip on q 65 return ( skipQ == 62 && skipR == 1 ); 
	//return ( skipQ == 62 && skipR == 1 ); 
}<commit_msg>Skip rules working incl. empty responses<commit_after>function setTitle(component,q) {
	var tpl = new Ext.Template([
		'<div class="question">{t}</div>',
	]);
	tpl.compile();
	html = tpl.apply( {t: q.get('text') } );
	component.getTitle().setHtml(html);
}

function setQuestion(c, q) {
	c.removeAll();
	var response = buildQuestion(q);
	c.add(Ext.decode(response).data);
}

function getNextQuestion(newO, direction) {
	// direction = 0 for direct, -1 for prev, 1 for next
	var s = Ext.getStore('Questions');
	// wrap around for now; go to welcome / summary
	if ( newO < 0 ) {
		// summary
		newO = s.getCount() - 1;
	} else if ( newO > s.getCount() - 1) {
		// start (clear/etc)
		newO = 0;
	}
	var q = s.getAt(newO);
	if ( q.get('skip') != null ) {
		q = skipQuestions(q, direction);
	}
	return q;
}

function skipQuestions(q, direction) {
	log('skipQuestion direction: ' + direction + ' q: ' + q.get('skip').split(',')[0] );
	var skipItems = q.get('skip').split(',');
	skipItems.forEach(logArrayElements);
	newQ = q;
	skipItems.forEach(function(element) {
		newQ = skipQuestionsItem(newQ, element, direction);
		log('newQ ' + newQ.get('id'));
	});
	return newQ;
}

function skipQuestionsItem(q, element, direction) {
	var item = element.split('.');
	if ( isResponseEqualSkip(q,item[0], item[1]) ) { 
		log('skipped ' + q.get('id'));
		saveEmptyResponse(q);
		q = getNextQuestion(q.get('ordinal') + direction, direction);
	}
	return q;
}

function saveEmptyResponse(q) {
	r = Ext.create('adnat.model.Response', {
		q:q.get('id'),
		options: null,
		ordinal:q.get('ordinal'),
		other: null,
	});
	Ext.getStore('Responses').saveResponse(r);
}

function isResponseEqualSkip(q,skipQ, skipR) {
	log('skipQ ' + skipQ + ',skipR ' + skipR + ', skip it? q ' + q.get('id') + ',skip it? o ' + q.get('ordinal') );
	var s = Ext.getStore('Responses');
	s.load(); //fixme needed?
	var r = s.findRecord('q', skipQ);
	if ( r != null ) {
		log(r);
		var options = r.get('options');
		if (options instanceof Array) {
			// fixme test these
			return ( options != null && options.indexOf(skipR) > -1 );
		} else {
			return ( options != null && options == skipR );
		}
	}
	return false;
}
{'fraction_non_alphanumeric': 0.1945479962721342, 'fraction_numerical': 0.006989748369058714, 'mean_word_length': 3.7279735682819384, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4396975', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1591, 'n_words': 378}