<commit_before><?php
/* cow.php
 *  Functionized routines for IEM Cow
 *  This way we can call from other applications, like dailyb :)
 */
putenv("TZ=GMT");

class cow {

function cow($dbconn){
    /* Constructor */
    $this->dbconn = $dbconn;
    pg_query($dbconn, "SET TIME ZONE 'GMT'");

    $this->wfo = Array();        /* Array of WFOs to potentially limit */
    $this->warnings = Array();   /* Array of warnings */
    $this->sts = 0;              /* Verification window start UTC */
    $this->ets = 0;              /* Vertification window end UTC */
    $this->wtype = Array();      /* VTEC Phenomena types to verify */
    $this->ltype = Array();      /* LSR Types to verify with */
    $this->ugcCache = Array();   /* UGC information */
    $this->hailsize = 0.75;      /* Hail size limitation */
    $this->lsrbuffer = 15;       /* LSR report buffer in km */
}

/* Standard Workflow */
function milk(){ 
    $this->loadWarnings();
    $this->loadLSRs();
    $this->computeUGC();
    $this->computeSharedBorder();
    $this->sbwVerify();
    $this->areaVerify();
}

function callDB($sql){
    $rs = @pg_query($this->dbconn, $sql);
    //if (! $rs ){ echo $sql; }
    return $rs;
}

function setLSRBuffer($buffer){
    $this->lsrbuffer = $buffer;
}

function setLimitWFO($arWFO){
    $this->wfo = $arWFO;
}

function setLimitTime($sts, $ets){
    $this->sts = $sts;
    $this->ets = $ets;
}

function setLimitType($arType){
    $this->wtype = $arType;
}

function setLimitLSRType($arType){
    $this->ltype = $arType;
}

function setHailSize($val){
    $this->hailsize = $val;
}

function sqlWFOBuilder(){
    reset($this->wfo);
    if (sizeof($this->wfo) == 0){ return "1 = 1"; }

    $sql = "w.wfo IN ('". implode(",", $this->wfo) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function sqlLSRTypeBuilder(){
    reset($this->ltype);
    if (sizeof($this->ltype) == 0){ return "1 = 1"; }
    $l = Array();
    while( list($k,$v) = each($this->ltype)){
        if ($v == "TO"){ $l[] = "T"; }
        else if ($v == "SV"){ $l[] = "H"; $l[] = "G"; $l[] = "D"; }
        else if ($v == "MA"){ $l[] = "M"; $l[] = "W"; }
        else if ($v == "FF"){ $l[] = "F"; };
    }   
    $sql = "type IN ('". implode(",", $l) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function sqlTypeBuilder(){
    if (sizeof($this->wtype) == 0) return "1 = 1";

    $sql = "phenomena IN ('". implode(",", $this->wtype) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function computeAverageSize(){
    reset($this->warnings);
    $polysz = 0;
    while (list($k,$v) = each($this->warnings)){
        $polysz += $v["parea"];
    }
    return $polysz / floatval(sizeof($this->warnings));
}

function computeSizeReduction(){
    reset($this->warnings);
    $polysz = 0;
    $countysz = 0;
    while (list($k,$v) = each($this->warnings)){
        $polysz += $v["parea"];
        while (list($k2,$v2) = each($v["ugc"])){
            $countysz += $this->ugcCache[$v2]["area"];
        }
    }
    return ($countysz - $polysz) / $countysz * 100.0;
}

function computeUnwarnedEvents(){
    return sizeof($this->lsrs) - $this->computeWarnedEvents();
}


function computeWarnedEvents(){
    reset($this->lsrs);
    $counter = 0;
    while (list($k,$v) = each($this->lsrs)){
        if ($v["warned"]){ $counter += 1; }
    }
    return $counter;
}

function computeTDQEvents(){
    reset($this->lsrs);
    $counter = 0;
    while (list($k,$v) = each($this->lsrs)){
        if ($v["tdq"]){ $counter += 1; }
    }
    return $counter;
}

function computeMaxLeadTime(){
   $large = 0;
   reset($this->lsrs);
   while (list($k,$v) = each($this->lsrs)){
       if ($v["leadtime"] > $large){ $large = $v["leadtime"]; }
   }
   return $large;
}
function computeMinLeadTime(){
   $smallest = 99;
   reset($this->lsrs);
   while (list($k,$v) = each($this->lsrs)){
       if ($v["leadtime"] < $smallest){ $smallest = $v["leadtime"]; }
   }<commit_msg>get rid of some undefs<commit_after><?php
/* cow.php
 *  Functionized routines for IEM Cow
 *  This way we can call from other applications, like dailyb :)
 */
putenv("TZ=GMT");

class cow {

function cow($dbconn){
    /* Constructor */
    $this->dbconn = $dbconn;
    pg_query($dbconn, "SET TIME ZONE 'GMT'");

    $this->wfo = Array();        /* Array of WFOs to potentially limit */
    $this->warnings = Array();   /* Array of warnings */
    $this->sts = 0;              /* Verification window start UTC */
    $this->ets = 0;              /* Vertification window end UTC */
    $this->wtype = Array();      /* VTEC Phenomena types to verify */
    $this->ltype = Array();      /* LSR Types to verify with */
    $this->ugcCache = Array();   /* UGC information */
    $this->hailsize = 0.75;      /* Hail size limitation */
    $this->lsrbuffer = 15;       /* LSR report buffer in km */
}

/* Standard Workflow */
function milk(){ 
    $this->loadWarnings();
    $this->loadLSRs();
    $this->computeUGC();
    $this->computeSharedBorder();
    $this->sbwVerify();
    $this->areaVerify();
}

function callDB($sql){
    $rs = @pg_query($this->dbconn, $sql);
    //if (! $rs ){ echo $sql; }
    return $rs;
}

function setLSRBuffer($buffer){
    $this->lsrbuffer = $buffer;
}

function setLimitWFO($arWFO){
    $this->wfo = $arWFO;
}

function setLimitTime($sts, $ets){
    $this->sts = $sts;
    $this->ets = $ets;
}

function setLimitType($arType){
    $this->wtype = $arType;
}

function setLimitLSRType($arType){
    $this->ltype = $arType;
}

function setHailSize($val){
    $this->hailsize = $val;
}

function sqlWFOBuilder(){
    reset($this->wfo);
    if (sizeof($this->wfo) == 0){ return "1 = 1"; }

    $sql = "w.wfo IN ('". implode(",", $this->wfo) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function sqlLSRTypeBuilder(){
    reset($this->ltype);
    if (sizeof($this->ltype) == 0){ return "1 = 1"; }
    $l = Array();
    while( list($k,$v) = each($this->ltype)){
        if ($v == "TO"){ $l[] = "T"; }
        else if ($v == "SV"){ $l[] = "H"; $l[] = "G"; $l[] = "D"; }
        else if ($v == "MA"){ $l[] = "M"; $l[] = "W"; }
        else if ($v == "FF"){ $l[] = "F"; };
    }   
    $sql = "type IN ('". implode(",", $l) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function sqlTypeBuilder(){
    if (sizeof($this->wtype) == 0) return "1 = 1";

    $sql = "phenomena IN ('". implode(",", $this->wtype) ."')";
    $sql = str_replace(",", "','", $sql);
    return $sql;
}

function computeAverageSize(){
    reset($this->warnings);
    $polysz = 0;
    while (list($k,$v) = each($this->warnings)){
        $polysz += $v["parea"];
    }
    return $polysz / floatval(sizeof($this->warnings));
}

function computeSizeReduction(){
    reset($this->warnings);
    $polysz = 0;
    $countysz = 0;
    while (list($k,$v) = each($this->warnings)){
        $polysz += $v["parea"];
        while (list($k2,$v2) = each($v["ugc"])){
            $countysz += $this->ugcCache[$v2]["area"];
        }
    }
    if ($countysz == 0){ return 0; }
    return ($countysz - $polysz) / $countysz * 100.0;
}

function computeUnwarnedEvents(){
    return sizeof($this->lsrs) - $this->computeWarnedEvents();
}


function computeWarnedEvents(){
    reset($this->lsrs);
    $counter = 0;
    while (list($k,$v) = each($this->lsrs)){
        if ($v["warned"]){ $counter += 1; }
    }
    return $counter;
}

function computeTDQEvents(){
    reset($this->lsrs);
    $counter = 0;
    while (list($k,$v) = each($this->lsrs)){
        if ($v["tdq"]){ $counter += 1; }
    }
    return $counter;
}

function computeMaxLeadTime(){
   if (sizeof($this->lsrs) == 0){ return 0; }

   $large = 0;
   reset($this->lsrs);
   while (list($k,$v) = each($this->lsrs)){
       if ($v["leadtime"] > $large){ $large = $v["leadtime"]; }
   }
   return $large;
}
function computeMinLeadTime(){
   if (sizeof($this->lsrs) == 0){ return 0; }
   $smallest = 99;
   reset($this->lsrs);
   while (list($k,$v) = each($this->lsrs)){
       if ($v["leadtime"] < $smallest){ $smallest = $v["leadtime"]; }
   }
{'fraction_non_alphanumeric': 0.22633592496606195, 'fraction_numerical': 0.008885597926693817, 'mean_word_length': 2.8100611189468734, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 103, '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': '57909', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2962, 'n_words': 657}