-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null result handle in collections/misc/collstats.php #1453
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,83 +139,88 @@ | |
} | ||
elseif($action == "Run Statistics" && ($cPartentTaxon || $cCountry)){ | ||
$resultsTemp = $collManager->runStatisticsQuery($collId,$cPartentTaxon,$cCountry); | ||
$familyArr = $resultsTemp['families']; | ||
ksort($familyArr, SORT_STRING | SORT_FLAG_CASE); | ||
$countryArr = $resultsTemp['countries']; | ||
ksort($countryArr, SORT_STRING | SORT_FLAG_CASE); | ||
unset($resultsTemp['families']); | ||
unset($resultsTemp['countries']); | ||
ksort($resultsTemp, SORT_STRING | SORT_FLAG_CASE); | ||
$c = 0; | ||
foreach($resultsTemp as $k => $collArr){ | ||
if($c>0) $collStr .= ", "; | ||
$collStr .= $collArr['CollectionName']; | ||
if(array_key_exists("SpecimenCount",$results)){ | ||
$results['SpecimenCount'] = $results['SpecimenCount'] + $collArr['recordcnt']; | ||
} | ||
else{ | ||
$results['SpecimenCount'] = $collArr['recordcnt']; | ||
} | ||
|
||
if(array_key_exists("GeorefCount",$results)){ | ||
$results['GeorefCount'] = $results['GeorefCount'] + $collArr['georefcnt']; | ||
} | ||
else{ | ||
$results['GeorefCount'] = $collArr['georefcnt']; | ||
} | ||
if ($resultsTemp){ | ||
if (array_key_exists('families', $resultsTemp)){ | ||
$familyArr = $resultsTemp['families']; | ||
ksort($familyArr, SORT_STRING | SORT_FLAG_CASE); | ||
unset($resultsTemp['families']); | ||
} | ||
if (array_key_exists('countries', $resultsTemp)){ | ||
$countryArr = $resultsTemp['countries']; | ||
ksort($countryArr, SORT_STRING | SORT_FLAG_CASE); | ||
unset($resultsTemp['countries']); | ||
} | ||
ksort($resultsTemp, SORT_STRING | SORT_FLAG_CASE); | ||
$c = 0; | ||
foreach($resultsTemp as $k => $collArr){ | ||
if($c>0) $collStr .= ", "; | ||
$collStr .= $collArr['CollectionName']; | ||
if(array_key_exists("SpecimenCount",$results)){ | ||
$results['SpecimenCount'] = $results['SpecimenCount'] + $collArr['recordcnt']; | ||
} | ||
else{ | ||
$results['SpecimenCount'] = $collArr['recordcnt']; | ||
} | ||
|
||
if(array_key_exists("FamilyCount",$results)){ | ||
$results['FamilyCount'] = $results['FamilyCount'] + $collArr['familycnt']; | ||
} | ||
else{ | ||
$results['FamilyCount'] = $collArr['familycnt']; | ||
} | ||
if(array_key_exists("GeorefCount",$results)){ | ||
$results['GeorefCount'] = $results['GeorefCount'] + $collArr['georefcnt']; | ||
} | ||
else{ | ||
$results['GeorefCount'] = $collArr['georefcnt']; | ||
} | ||
|
||
if(array_key_exists("GeneraCount",$results)){ | ||
$results['GeneraCount'] = $results['GeneraCount'] + $collArr['genuscnt']; | ||
} | ||
else{ | ||
$results['GeneraCount'] = $collArr['genuscnt']; | ||
} | ||
if(array_key_exists("FamilyCount",$results)){ | ||
$results['FamilyCount'] = $results['FamilyCount'] + $collArr['familycnt']; | ||
} | ||
else{ | ||
$results['FamilyCount'] = $collArr['familycnt']; | ||
} | ||
|
||
if(array_key_exists("SpeciesCount",$results)){ | ||
$results['SpeciesCount'] = $results['SpeciesCount'] + $collArr['speciescnt']; | ||
} | ||
else{ | ||
$results['SpeciesCount'] = $collArr['speciescnt']; | ||
} | ||
if(array_key_exists("GeneraCount",$results)){ | ||
$results['GeneraCount'] = $results['GeneraCount'] + $collArr['genuscnt']; | ||
} | ||
else{ | ||
$results['GeneraCount'] = $collArr['genuscnt']; | ||
} | ||
|
||
if(array_key_exists("TotalTaxaCount",$results)){ | ||
$results['TotalTaxaCount'] = $results['TotalTaxaCount'] + $collArr['TotalTaxaCount']; | ||
} | ||
else{ | ||
$results['TotalTaxaCount'] = $collArr['TotalTaxaCount']; | ||
} | ||
if(array_key_exists("SpeciesCount",$results)){ | ||
$results['SpeciesCount'] = $results['SpeciesCount'] + $collArr['speciescnt']; | ||
} | ||
else{ | ||
$results['SpeciesCount'] = $collArr['speciescnt']; | ||
} | ||
|
||
if(array_key_exists("TotalImageCount",$results)){ | ||
$results['TotalImageCount'] = $results['TotalImageCount'] + $collArr['OccurrenceImageCount']; | ||
} | ||
else{ | ||
$results['TotalImageCount'] = $collArr['OccurrenceImageCount']; | ||
} | ||
if(array_key_exists("TotalTaxaCount",$results)){ | ||
$results['TotalTaxaCount'] = $results['TotalTaxaCount'] + $collArr['TotalTaxaCount']; | ||
} | ||
else{ | ||
$results['TotalTaxaCount'] = $collArr['TotalTaxaCount']; | ||
} | ||
|
||
if(array_key_exists("SpecimensCountID",$results)){ | ||
$results['SpecimensCountID'] = $results['SpecimensCountID'] + $collArr['speciesID']; | ||
} | ||
else{ | ||
$results['SpecimensCountID'] = $collArr['speciesID']; | ||
} | ||
if(array_key_exists("TotalImageCount",$results)){ | ||
$results['TotalImageCount'] = $results['TotalImageCount'] + $collArr['OccurrenceImageCount']; | ||
} | ||
else{ | ||
$results['TotalImageCount'] = $collArr['OccurrenceImageCount']; | ||
} | ||
|
||
if(array_key_exists("TypeCount",$results)){ | ||
$results['TypeCount'] = $results['TypeCount'] + $collArr['types']; | ||
} | ||
else{ | ||
$results['TypeCount'] = $collArr['types']; | ||
} | ||
if(array_key_exists("SpecimensCountID",$results)){ | ||
$results['SpecimensCountID'] = $results['SpecimensCountID'] + $collArr['speciesID']; | ||
} | ||
else{ | ||
$results['SpecimensCountID'] = $collArr['speciesID']; | ||
} | ||
|
||
$c++; | ||
} | ||
$results['SpecimensNullLatitude'] = $results['SpecimenCount'] - $results['GeorefCount']; | ||
if(array_key_exists("TypeCount",$results)){ | ||
$results['TypeCount'] = $results['TypeCount'] + $collArr['types']; | ||
} | ||
else{ | ||
$results['TypeCount'] = $collArr['types']; | ||
} | ||
$c++; | ||
} | ||
$results['SpecimensNullLatitude'] = $results['SpecimenCount'] - $results['GeorefCount']; | ||
} | ||
} | ||
if($action == "Update Statistics"){ | ||
$collManager->batchUpdateStatistics($collId); | ||
|
@@ -342,7 +347,7 @@ function toggleById(target){ | |
if(target != null){ | ||
var obj = document.getElementById(target); | ||
var style = window.getComputedStyle(obj); | ||
|
||
if(style.display=="none" || style.display==""){ | ||
obj.style.display="block"; | ||
} | ||
|
@@ -764,57 +769,59 @@ function changeCollForm(f){ | |
<legend><?php echo $LANG['GENERAL_STATISTICS']?></legend> | ||
<ul class="stats-display-ul"> | ||
<?php | ||
echo "<li>"; | ||
echo ($results['SpecimenCount'] ? number_format($results['SpecimenCount']) : 0) . " " . $LANG['OCC_RECORDS']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
$percGeo = ''; | ||
if($results['SpecimenCount'] && $results['GeorefCount'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percGeo = (100* ($results['GeorefCount'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
} | ||
} | ||
echo ($results['GeorefCount'] ? number_format($results['GeorefCount']) : 0) . ($percGeo ? " (" . ($percGeo>1 ? round($percGeo) : round($percGeo,2)) . "%)" : '') . " " . $LANG['GEOREFERENCED']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
$percImg = ''; | ||
if($results['SpecimenCount'] && $results['TotalImageCount'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percImg = (100* ($results['TotalImageCount'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
} | ||
} | ||
echo ($results['TotalImageCount'] ? number_format($results['TotalImageCount']) : 0) . ($percImg ? " (" . ($percImg>1 ? round($percImg) : round($percImg,2)) . "%)" : '') . " " . $LANG['OCCS_IMAGED']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
$percId = ''; | ||
if($results['SpecimenCount'] && $results['SpecimensCountID'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percId = (100* ($results['SpecimensCountID'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
if ($results){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe check for 'SpecimentCount' and 'GeorefCount' array key in $results? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dunno... it depends on whether it's possible to ever have at $results array without these keys, I suppose. I leave it up to you! |
||
echo "<li>"; | ||
echo ($results['SpecimenCount'] ? number_format($results['SpecimenCount']) : 0) . " " . $LANG['OCC_RECORDS']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
$percGeo = ''; | ||
if($results['SpecimenCount'] && $results['GeorefCount'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percGeo = (100* ($results['GeorefCount'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
} | ||
} | ||
echo ($results['GeorefCount'] ? number_format($results['GeorefCount']) : 0) . ($percGeo ? " (" . ($percGeo>1 ? round($percGeo) : round($percGeo,2)) . "%)" : '') . " " . $LANG['GEOREFERENCED']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
$percImg = ''; | ||
if($results['SpecimenCount'] && $results['TotalImageCount'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percImg = (100* ($results['TotalImageCount'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
} | ||
} | ||
echo ($results['TotalImageCount'] ? number_format($results['TotalImageCount']) : 0) . ($percImg ? " (" . ($percImg>1 ? round($percImg) : round($percImg,2)) . "%)" : '') . " " . $LANG['OCCS_IMAGED']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And 'TotalImageCount'. |
||
echo "</li>"; | ||
echo "<li>"; | ||
$percId = ''; | ||
if($results['SpecimenCount'] && $results['SpecimensCountID'] && $results['SpecimenCount'] !== 0){ | ||
try { | ||
$percId = (100* ($results['SpecimensCountID'] / $results['SpecimenCount'])); | ||
} catch (Exception $e) { | ||
error_log('Exception: ' . $e->getMessage()); | ||
} | ||
} | ||
echo ($results['SpecimensCountID'] ? number_format($results['SpecimensCountID']) : 0) . ($percId?" (" . ($percId>1 ? round($percId) : round($percId,2)) . "%)" : '') . " " . $LANG['IDED_TO_SP']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['FamilyCount'] ? number_format($results['FamilyCount']) : 0) . " " . $LANG['FAMILIES']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['GeneraCount'] ? number_format($results['GeneraCount']) : 0) . " " . $LANG['GENERA']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['SpeciesCount'] ? number_format($results['SpeciesCount']) : 0) . " " . $LANG['SPECIES']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['TotalTaxaCount'] ? number_format($results['TotalTaxaCount']) : 0) . " " . $LANG['TOTAL_TAXA']; | ||
echo "</li>"; | ||
/*echo "<li>"; | ||
echo ($results['TypeCount'] ? number_format($results['TypeCount']) : 0)." type specimens"; | ||
echo "</li>";*/ | ||
} | ||
} | ||
echo ($results['SpecimensCountID'] ? number_format($results['SpecimensCountID']) : 0) . ($percId?" (" . ($percId>1 ? round($percId) : round($percId,2)) . "%)" : '') . " " . $LANG['IDED_TO_SP']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['FamilyCount'] ? number_format($results['FamilyCount']) : 0) . " " . $LANG['FAMILIES']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['GeneraCount'] ? number_format($results['GeneraCount']) : 0) . " " . $LANG['GENERA']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['SpeciesCount'] ? number_format($results['SpeciesCount']) : 0) . " " . $LANG['SPECIES']; | ||
echo "</li>"; | ||
echo "<li>"; | ||
echo ($results['TotalTaxaCount'] ? number_format($results['TotalTaxaCount']) : 0) . " " . $LANG['TOTAL_TAXA']; | ||
echo "</li>"; | ||
/*echo "<li>"; | ||
echo ($results['TypeCount'] ? number_format($results['TypeCount']) : 0)." type specimens"; | ||
echo "</li>";*/ | ||
?> | ||
</ul> | ||
<form name="statscsv" id="statscsv" action="collstatscsv.php" method="post" onsubmit=""> | ||
|
@@ -998,7 +1005,10 @@ function changeCollForm(f){ | |
</section> | ||
<div class="top-marg"> | ||
<b><?php echo $LANG['SPEC_W_FAMILY']; ?>:</b> <?php echo number_format($total); ?><br /> | ||
<?php echo $LANG['SPEC_WO_FAMILY']; ?>: <?php echo number_format($results['SpecimenCount']-$total); ?><br /> | ||
<?php | ||
if ($results){ | ||
echo $LANG['SPEC_WO_FAMILY']; ?>: <?php echo number_format($results['SpecimenCount']-$total); | ||
}?><br /> | ||
</div> | ||
</fieldset> | ||
<fieldset id="geodistbox" class="geodistbox"> | ||
|
@@ -1053,7 +1063,11 @@ function changeCollForm(f){ | |
</section> | ||
<div class="top-marg"> | ||
<b><?php echo $LANG['SPEC_W_COUNTRY']; ?>:</b> <?php echo number_format($total); ?><br /> | ||
<?php echo $LANG['SPEC_WO_COUNTRY']; ?>: <?php echo number_format(($results['SpecimenCount']-$total)+$results['SpecimensNullLatitude']); ?><br /> | ||
<?php | ||
if ($results){ | ||
echo $LANG['SPEC_WO_COUNTRY']; ?>: <?php echo number_format(($results['SpecimenCount']-$total)+$results['SpecimensNullLatitude']); | ||
} | ||
?><br /> | ||
</div> | ||
</fieldset> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add
&& array_key_exists('families', $resultsTemp)
?