<commit_before><?php

$STATUS_SEPERATOR = ":";
$SNIPPET_TIMEOUT = "SNIPPET_TIMEOUT";
$SNIPPET_EOA = "SNIPPET_EOA";
$SNIPPET_NOT_ONLINE ="SNIPPET_NOT_ONLINE";
$RALLYE_DONE = "RALLEY_DONE";
$SOLUTION_OK = "SOLUTION_OK";
$SOLUTION_FALSE = "SOLUTION_FALSE";

include 'db/db.php';

// Get parameters
$aFunction = -1;
if( isset($_GET['f'])  ){
	$aFunction = $_GET['f'];
}

$aRallyeID = null;
if( isset($_GET['rID']) ){
	$aRallyeID = $_GET['rID'];
}

$aGroupHash = null;
if( isset($_GET['gHash']) ){
	$aGroupHash = $_GET['gHash'];
}

$aGroupName = null;
if( isset($_GET['gName']) ){
	$aGroupName = $_GET['gName'];
}

$aSnippetNumber = null;
if( isset($_GET['n']) ){
	$aSnippetNumber = $_GET['n'];
}

$aSolution = null;
if( isset($_GET['S']) ){
	$aSolution = $_GET['S'];
}

/**
 * 	Select function
 * 	1	Get Rallye information		(rID)
 * 	2	Get next snippet from		(rID, gHash, gName, snippetNr)
 * 		unsolved item 		
 * 	3	Get number of items 		(rID)
 * 	4	Get number of solved items	(rID, gHash, gName)
 * 	5	Submit solution				(rID, gHash, gName, itemSolution)
 */
switch( $aFunction ){
	
	case 1:
		// Get Rallye information
		$vData = qr_getRallye($aRallyeID);
		if( $vData ) {
			unset( $vData[0]['rPassword'], $vData[0]['rMail'] );
			print json_encode( $vData[0] );
		}		
		break;
		
	case 2:
		print getPendingSnipped($aRallyeID, $aGroupHash, $aGroupName, $aSnippetNumber);		
		break;
		
	case 3:
		print sizeof(qr_getRallyeItems($aRallyeID));
		break;
	
	case 4:
		print sizeof(qr_getSolvedItems($aRallyeID, $aGroupHash));
		break;
		
	case 5:
		$vItem = qr_getPendingItem($aRallyeID, $aGroupHash);
		if( !$vItem || qr_submitSolution($aRallyeID, $aGroupHash, $vItem, $aSolution) )
			status($SOLUTION_OK);
		else status($SOLUTION_FALSE);
		break;
	
}

function getPendingSnipped($rID, $gHash, $gName, $snippedNr){
	global $SNIPPET_EOA, $SNIPPET_TIMEOUT, $RALLYE_DONE, $SNIPPET_NOT_ONLINE;
	<commit_msg>Update groupname on solution submit.<commit_after><?php

$STATUS_SEPERATOR = ":";
$SNIPPET_TIMEOUT = "SNIPPET_TIMEOUT";
$SNIPPET_EOA = "SNIPPET_EOA";
$SNIPPET_NOT_ONLINE ="SNIPPET_NOT_ONLINE";
$RALLYE_DONE = "RALLEY_DONE";
$SOLUTION_OK = "SOLUTION_OK";
$SOLUTION_FALSE = "SOLUTION_FALSE";

include 'db/db.php';

// Get parameters
$aFunction = -1;
if( isset($_GET['f'])  ){
	$aFunction = $_GET['f'];
}

$aRallyeID = null;
if( isset($_GET['rID']) ){
	$aRallyeID = $_GET['rID'];
}

$aGroupHash = null;
if( isset($_GET['gHash']) ){
	$aGroupHash = $_GET['gHash'];
}

$aGroupName = null;
if( isset($_GET['gName']) ){
	$aGroupName = $_GET['gName'];
}

$aSnippetNumber = null;
if( isset($_GET['n']) ){
	$aSnippetNumber = $_GET['n'];
}

$aSolution = null;
if( isset($_GET['S']) ){
	$aSolution = $_GET['S'];
}

/**
 * 	Select function
 * 	1	Get Rallye information		(rID)
 * 	2	Get next snippet from		(rID, gHash, gName, snippetNr)
 * 		unsolved item 		
 * 	3	Get number of items 		(rID)
 * 	4	Get number of solved items	(rID, gHash, gName)
 * 	5	Submit solution				(rID, gHash, gName, itemSolution)
 */
switch( $aFunction ){
	
	case 1:
		// Get Rallye information
		$vData = qr_getRallye($aRallyeID);
		if( $vData ) {
			unset( $vData[0]['rPassword'], $vData[0]['rMail'] );
			print json_encode( $vData[0] );
		}		
		break;
		
	case 2:
		print getPendingSnipped($aRallyeID, $aGroupHash, $aGroupName, $aSnippetNumber);		
		break;
		
	case 3:
		print sizeof(qr_getRallyeItems($aRallyeID));
		break;
	
	case 4:
		print sizeof(qr_getSolvedItems($aRallyeID, $aGroupHash));
		break;
		
	case 5:
		$vItem = qr_getPendingItem($aRallyeID, $aGroupHash);
		if( $aGroupName && $aGroupHash ){
			qr_updateGroup($gHash, $gName);
		}
		if( !$vItem || qr_submitSolution($aRallyeID, $aGroupHash, $vItem, $aSolution) )
			status($SOLUTION_OK);
		else status($SOLUTION_FALSE);
		break;
	
}

function getPendingSnipped($rID, $gHash, $gName, $snippedNr){
	global $SNIPPET_EOA, $SNIPPET_TIMEOUT, $RALLYE_DONE, $SNIPPET_NOT_ONLINE;
	
{'fraction_non_alphanumeric': 0.1760635571501794, 'fraction_numerical': 0.007175807278318811, 'mean_word_length': 4.799405646359584, 'pattern_counts': {'":': 2, '<': 5, '<?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': '5569853', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1680, 'n_words': 321}