You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check for extreme growth - for Old Trees form Flags stems where absolute annual growth > $annualGrowth mm Check for shrinkage in recensuses - only for Old Trees form Flags records with annual relative growth <= -0.05 in stems with previous dbh>=50mm and no current stem lost code
Local
To calculate growth rates, need DBH and date of previous census.
$tempTableName = 'TempOldTrees';
//Check for extreme growth - for Old Trees form//Tags stems where absolute annual growth > 65 mm$annualGrowth = '65';
//Check for shrinkage in recensuses - only for Old Trees form//Tags records with annual relative growth <= -0.05 in stems with previous dbh>=50mm and no current stem lost code$dbhCheck2 = '50';
$annualShrink = '-0.05';
////Helper to above////publicfunction_getCodes($description)
{
$this->screeningdb->select('TSMCode');
$this->screeningdb->like('Description',$description);
$query = $this->screeningdb->get('TSMAttributes');
$codesarr = array();
if($query->num_rows() > 0)
{
$j = 0;
foreach($query->result() as$row)
$codesarr[$j++] = $row->TSMCode;
}
else
{
$codesarr[0] = 'none';
}
return$codesarr;
}
//////Old Trees screening/////////publicfunctioncheckGrowth ($filen,$minDBH,$annualGrowth,$dbhCheck2,$annualShrink)
{
//Check for extreme growth - for Old Trees form//Tags stems where absolute annual growth > $annualGrowth mm$q1 = 'UPDATE '.$filen.' AS a,TempQuadratDates AS b SET Errors = CONCAT(TRIM(Errors),";DBH too large?") WHERE a.QuadratName=b.QuadratName AND HOM=OldHOM AND Errors <> "" AND Errors IS NOT NULL AND Errors<>"NONE" AND DBH>='.$minDBH.' AND OldDBH>='.$minDBH.' AND (DBH-OldDBH)/((to_days(ExactDate)-to_days(b.PrevDate))/365.25) > '.$annualGrowth;
$q2 = 'UPDATE '.$filen.' AS a,TempQuadratDates AS b SET Errors = "DBH too large?" WHERE a.QuadratName=b.QuadratName AND HOM=OldHOM AND (Errors = "" OR ISNULL(Errors)) AND Errors<>"NONE"AND DBH>='.$minDBH.' AND OldDBH>='.$minDBH.' AND (DBH-OldDBH)/((to_days(ExactDate)-to_days(b.PrevDate))/365.25) > '.$annualGrowth;
$runQ1 = $this->screeningdb->query($q1);
$runQ2 = $this->screeningdb->query($q2);
//Check for shrinkage in recensuses - only for Old Trees form//Tags records with annual relative growth <= -0.05 in stems with previous dbh>=50mm and no current stem lost code$resprcodes = $this->_getCodes('stem lost'); //The helper public function above//$q1 = "SELECT TSMCode FROM TSMAttributes WHERE LOWER(DESCRIPTION) like '%resprout%' or LOWER(DESCRIPTION) like '%broken%'";//$q1 = "SELECT TSMCode FROM TSMAttributes WHERE LOWER(DESCRIPTION)='stem lost'";//$r1 = mysql_query($q1, $connect) or die('Selecting stem lost codes failed: ' . mysql_error());//$resprcodes=array();//if (mysql_num_rows($r1)> 0) {// $j=0;// while ($row = mysql_fetch_assoc($r1)) {// $resprcodes[$j++] = $row["TSMCode"]; }// }$q2 = "Select TempID FROM ".$filen;
$queryQ2 = $this->screeningdb->query($q2);
// Go through entire fileforeach($queryQ2->result() as$rowQ2)
{
//Check whether tree has resprout or broken code, in which case do not run shrinkage test$tempID = $rowQ2->TempID;
$q3 = "SELECT Codes FROM ".$filen." WHERE TempID = ".$tempID;
$queryQ3 = $this->screeningdb->query($q3);
$rowQ3 = $queryQ3->row();
$codes = $rowQ3->Codes;
$continue = 0;
if (!is_null($codes) AND $codes<>'*' AND $codes<>'')
{
$nocodes = SUBSTR_COUNT($codes,';');
$arrcodes = explode(";", $codes);
for ($i = 0; $i <= $nocodes; $i++)
{
if (in_array($arrcodes[$i], $resprcodes))
{
$continue=1;
}
}
}
if($continue==0)
{
$q4 = 'UPDATE '.$filen.' AS a,TempQuadratDates AS b SET Errors = CONCAT(TRIM(Errors),";DBH shrank too much") WHERE a.QuadratName=b.QuadratName AND HOM=OldHom AND Errors <> "" AND Errors IS NOT NULL AND Errors<>"NONE" AND DBH>='.$minDBH.' AND olddbh>='.$dbhCheck2.' AND ((DBH-OldDBH)/OldDBH)/((to_days(ExactDate)-to_days(b.PrevDate))/365.25) <='.$annualShrink.' AND TempID = '.$tempID;
$q5 = 'UPDATE '.$filen.' AS a, TempQuadratDates AS b SET Errors = "DBH shrank too much?" WHERE a.QuadratName=b.QuadratName AND HOM=OldHOM AND (Errors = "" OR ISNULL(Errors)) AND Errors<>"NONE" AND DBH>='.$minDBH.' AND olddbh>='.$dbhCheck2.' AND ((DBH-OldDBH)/OldDBH)/((to_days(ExactDate)-to_days(b.PrevDate))/365.25) <='.$annualShrink.' AND tempID = '.$tempID;
$runQ4 = $this->screeningdb->query($q4);
$runQ5 = $this->screeningdb->query($q5);
}
}
}
Here is an updated procedure to run this and mark its errors in the CMVErrors table! Function's been reviewed with GPT so it should work as intended, but full testing is still pending:
See "instructions for writing a validation function". Below are notes from the spec, the original validation function (in the PHP language), and the SQL table structure.
The text was updated successfully, but these errors were encountered: