<commit_before>
<?php 

function status_table($title, $rows, $config = null) {

?>
	<div class="panel panel-default">
	<div class="panel-heading"><?php echo $title?></div>
	<table class="table table-striped table-hover">
		<tr>
			<th class="col-sm-4">Agency</th>
			<th class="col-sm-2">/data.json</th>
			<th class="col-sm-2">records</th>						
			<th class="col-sm-2">valid schema</th>			
			<th class="col-sm-2">percent valid</th>										
		</tr>
		<?php foreach ($rows as $office):?>
		
		<?php 
		
		
		
			if(!empty($office->datajson_status)) {
				$office->datajson_status = json_decode($office->datajson_status);
			}
			
			if(!empty($office->datapage_status)) {
				$office->datapage_status = json_decode($office->datapage_status);
			}							
		
			$json_http_code = (!empty($office->datajson_status->http_code)) ? $office->datajson_status->http_code : 0;
			$html_http_code = (!empty($office->datapage_status->http_code)) ? $office->datapage_status->http_code : 0;

						
			$status_color = http_status_color($json_http_code);	
			
			$valid_json = (!empty($office->datajson_status->valid_json)) ? $office->datajson_status->valid_json : null;
			if ($valid_json !== true && $status_color == 'success') {
				$status_color = 'danger';
			}		
			
			$valid_schema = (!empty($office->datajson_status->valid_schema)) ? $office->datajson_status->valid_schema : false;
			if ($valid_schema !== true && $valid_json === true) {
				$status_color = 'warning';
			}

			
			$html_status = http_status_color($html_http_code);	
			
			
			$icon = null;
			
			if (isset($office->datajson_status->valid_json)) {
			    $json_status = ($office->datajson_status->valid_json == true) ? 'success' : 'danger';									    
			} else {
			    $json_status = 'danger';
			}

			if (isset($valid_schema)) {
			    $schema_status = ($valid_schema === true) ? 'success' : 'danger';									    
			} else {
			    $schema_status = 'danger';
			}				


			// var_dump($office->datajson_status); exit;


			if (!empty($config['max_size']) && !empty($office->datajson_status->download_content_length) && 				
				($office->datajson_status->download_content_length > $config['max_size'])) {
				$schema_status = 'warning';
			}

			//echo $office->datajson_status->download_content_length;


			$json_icon       = page_status($json_status);
			$schema_icon 	 = page_status($schema_status);
			
			$page_icon       = page_status($html_status);



			$error_count 		= (!empty($office->datajson_status->error_count)) ? $office->datajson_status->error_count : 0;
			$total_records	 	=	(!empty($office->datajson_status->total_records)) ? $office->datajson_status->total_records : '';

			$percent_valid 		= '';
			$percent_valid		=	(!empty($total_records)) ? ($total_records - $error_count)/$total_records : '';
			
			if($percent_valid) {

				if ($percent_valid == 1) {
					$percent_valid = "100%";
				} 
				else {
					$percent_valid = sprintf("%.1f%%", $percent_valid * 100);
				}

			}

			if ($percent_valid === 0) {
				$percent_valid = "0%";
			}			
			
				
		?>				
		
		<tr class="<?php echo $status_color ?>">
			<td><a href="/offices/detail/<?php echo $office->id;?>"><?php echo $office->name;?></a></td>
			<td><?php echo $json_icon; ?>	
			<td><?php echo $total_records; ?>			
			<td><?php echo $schema_icon; ?>	
			<td><?php echo $percent_valid?>
		</tr>
		<?php endforeach;?>
	</table>
	</div>

<?php 	
}

function http_status_color($status_code) {
    
    switch ($status_code) {
        case 404:
            $status_color = 'danger';
            break;
        case 200:
            $status_color = 'success';
            break;
        case 0:
            $status_color = 'danger';
            break;					<commit_msg>Highlight agencies with no valid records<commit_after>
<?php 

function status_table($title, $rows, $config = null) {

?>
	<div class="panel panel-default">
	<div class="panel-heading"><?php echo $title?></div>
	<table class="table table-striped table-hover">
		<tr>
			<th class="col-sm-4">Agency</th>
			<th class="col-sm-2">/data.json</th>
			<th class="col-sm-2">records</th>						
			<th class="col-sm-2">valid schema</th>			
			<th class="col-sm-2">percent valid</th>										
		</tr>
		<?php foreach ($rows as $office):?>
		
		<?php 
		
		
		
			if(!empty($office->datajson_status)) {
				$office->datajson_status = json_decode($office->datajson_status);
			}
			
			if(!empty($office->datapage_status)) {
				$office->datapage_status = json_decode($office->datapage_status);
			}							
		
			$json_http_code = (!empty($office->datajson_status->http_code)) ? $office->datajson_status->http_code : 0;
			$html_http_code = (!empty($office->datapage_status->http_code)) ? $office->datapage_status->http_code : 0;

						
			$status_color = http_status_color($json_http_code);	
			
			$valid_json = (!empty($office->datajson_status->valid_json)) ? $office->datajson_status->valid_json : null;
			if ($valid_json !== true && $status_color == 'success') {
				$status_color = 'danger';
			}		
			
			$valid_schema = (!empty($office->datajson_status->valid_schema)) ? $office->datajson_status->valid_schema : false;
			if ($valid_schema !== true && $valid_json === true) {
				$status_color = 'warning';
			}

			
			$html_status = http_status_color($html_http_code);	
			
			
			$icon = null;
			
			if (isset($office->datajson_status->valid_json)) {
			    $json_status = ($office->datajson_status->valid_json == true) ? 'success' : 'danger';									    
			} else {
			    $json_status = 'danger';
			}

			if (isset($valid_schema)) {
			    $schema_status = ($valid_schema === true) ? 'success' : 'danger';									    
			} else {
			    $schema_status = 'danger';
			}				


			// var_dump($office->datajson_status); exit;


			if (!empty($config['max_size']) && !empty($office->datajson_status->download_content_length) && 				
				($office->datajson_status->download_content_length > $config['max_size'])) {
				$schema_status = 'warning';
			}

			//echo $office->datajson_status->download_content_length;


			$json_icon       = page_status($json_status);
			$schema_icon 	 = page_status($schema_status);
			
			$page_icon       = page_status($html_status);



			$error_count 		= (!empty($office->datajson_status->error_count)) ? $office->datajson_status->error_count : 0;
			$total_records	 	=	(!empty($office->datajson_status->total_records)) ? $office->datajson_status->total_records : '';

			$percent_valid 		= '';
			$percent_valid		=	(!empty($total_records)) ? ($total_records - $error_count)/$total_records : '';
			
			if($percent_valid) {

				if ($percent_valid == 1) {
					$percent_valid = "100%";
				} 
				else {
					$percent_valid = sprintf("%.1f%%", $percent_valid * 100);
				}

			}

			if ($percent_valid === 0) {
				$percent_valid = "0%";
				$status_color = 'danger';
			}			
			
				
		?>				
		
		<tr class="<?php echo $status_color ?>">
			<td><a href="/offices/detail/<?php echo $office->id;?>"><?php echo $office->name;?></a></td>
			<td><?php echo $json_icon; ?>	
			<td><?php echo $total_records; ?>			
			<td><?php echo $schema_icon; ?>	
			<td><?php echo $percent_valid?>
		</tr>
		<?php endforeach;?>
	</table>
	</div>

<?php 	
}

function http_status_color($status_code) {
    
    switch ($status_code) {
        case 404:
            $status_color = 'danger';
            break;
        case 200:
            $status_color = 'success';
            break;
        case 0:
            $status_color = 'danger';
            break;					
{'fraction_non_alphanumeric': 0.17720676341365996, 'fraction_numerical': 0.006656903208627347, 'mean_word_length': 3.0539665407447383, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 171, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6191175', 'n_tokens_mistral': 3203, 'n_tokens_neox': 2560, 'n_words': 391}