<commit_before><?php
/**
 * Time for a standard library to access the IEMAccess DB for observations
 *  This could theoretically be distributed to others to access the DB!
 * $Id: $:
 */

include_once("$rootpath/include/database.inc.php");

class IEMAccess {
  var $dbconn;

  function IEMAccess($tzname="America/Chicago") {
    $this->dbconn = iemdb("access");
    $this->tzname = $tzname;
 
  } // End of IEMAccess Constructor

  function query($sql) {
    return pg_exec($this->dbconn, $sql);
  }

  function getSingleSite($sid) {
    $sid = strtoupper($sid);
    $rs = pg_exec($this->dbconn, sprintf("select *, 
    x(s.geom) as x, y(s.geom) as y, 
    valid at time zone '%s' as lvalid,
    max_gust_ts at time zone '%s' as lmax_gust_ts,
    max_sknt_ts at time zone '%s' as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s WHERE 
    c.station = '$sid' and c.station = s.id and c.network = s.network
    and c2.station = s.id and c2.network = s.network 
    and c.day = date(now() at time zone s.tzname)", 
    $this->tzname, $this->tzname,$this->tzname, date("Y")));
    return new IEMAccessOb(@pg_fetch_array($rs,0));
  }

  function getNetwork($network) {
    $ret = Array();
    $sql = sprintf("select *, c.pday as ob_pday, x(s.geom) as x, 
    y(s.geom) as y, valid at time zone '%s' as lvalid,
    max_gust_ts at time zone '%s' as lmax_gust_ts,
    max_sknt_ts at time zone '%s' as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s  
    WHERE c.network = '$network' and c.network = c2.network and
    c.network = s.network and c.station = s.id and 
    s.id = c2.station and 
    c.day = date(now() at time zone '%s')",
    $this->tzname, $this->tzname, $this->tzname, date("Y"), 
    $this->tzname);
    $rs = pg_exec($this->dbconn, $sql);
    for( $i=0; $row = @pg_fetch_assoc($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }

  function getIowa() {
    $ret = Array();
    $rs = pg_exec($this->dbconn, sprintf("select *, 
    x(s.geom) as x, y(s.geom) as y, valid at time zone '%s' as lvalid,
    max_gust_ts at time zone '%s' as lmax_gust_ts,
    max_sknt_ts at time zone '%s' as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s WHERE 
    c.network IN ('IA_RWIS', 'IA_ASOS', 'AWOS', 'KCCI', 'KIMT') 
    and c.day = 'TODAY' 
    and c2.valid > 'TODAY' and s.network = c.network and
    c.network = c2.network and s.id = c.station and 
    c.station = c2.station", $this->tzname, 
    $this->tzname, $this->tzname, date("Y")));
    for( $i=0; $row = @pg_fetch_array($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }

  function ge_max_tmpf($size) {
    $ret = Array();
    $rs = pg_exec($this->dbconn, "select * from current WHERE
      valid > (CURRENT_TIMESTAMP - '70 minutes'::interval) and tmpf < 140
      ORDER by tmpf DESC LIMIT $size");
    for( $i=0; $row = @pg_fetch_array($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }
<commit_msg>Use iemid instead of station,network<commit_after><?php
/**
 * Time for a standard library to access the IEMAccess DB for observations
 *  This could theoretically be distributed to others to access the DB!
 * $Id: $:
 */

include_once("$rootpath/include/database.inc.php");

class IEMAccess {
  var $dbconn;

  function IEMAccess($tzname="America/Chicago") {
    $this->dbconn = iemdb("access");
    $this->tzname = $tzname;
 
  } // End of IEMAccess Constructor

  function query($sql) {
    return pg_exec($this->dbconn, $sql);
  }

  function getSingleSite($sid) {
    $sid = strtoupper($sid);
    $rs = pg_exec($this->dbconn, sprintf("select *, 
    x(s.geom) as x, y(s.geom) as y, 
    valid at time zone s.tzname as lvalid,
    max_gust_ts at time zone s.tzname as lmax_gust_ts,
    max_sknt_ts at time zone s.tzname as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s WHERE 
    s.id = '$sid' and c.iemid = s.iemid and s.iemid = c2.iemid
    and c.day = date(now() at time zone s.tzname)",  date("Y")));
    return new IEMAccessOb(@pg_fetch_array($rs,0));
  }

  function getNetwork($network) {
    $ret = Array();
    $sql = sprintf("select *, c.pday as ob_pday, x(s.geom) as x, 
    y(s.geom) as y, valid at time zone '%s' as lvalid,
    max_gust_ts at time zone '%s' as lmax_gust_ts,
    max_sknt_ts at time zone '%s' as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s  
    WHERE s.network = '$network' and c.iemid = s.iemid and c2.iemid = c.iemid and
    c.day = date(now() at time zone '%s')",
    $this->tzname, $this->tzname, $this->tzname, date("Y"), 
    $this->tzname);
    $rs = pg_exec($this->dbconn, $sql);
    for( $i=0; $row = @pg_fetch_assoc($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }

  function getIowa() {
    $ret = Array();
    $rs = pg_exec($this->dbconn, sprintf("select *, 
    x(s.geom) as x, y(s.geom) as y, valid at time zone '%s' as lvalid,
    max_gust_ts at time zone '%s' as lmax_gust_ts,
    max_sknt_ts at time zone '%s' as lmax_sknt_ts,
    s.name as sname from 
    current c2, summary_%s c, stations s WHERE 
    s.network IN ('IA_RWIS', 'IA_ASOS', 'AWOS', 'KCCI', 'KIMT') 
    and c.day = 'TODAY' 
    and c2.valid > 'TODAY' and c2.iemid = c.iemid and c.iemid = s.iemid", 
    $this->tzname, $this->tzname, $this->tzname, date("Y")));
    for( $i=0; $row = @pg_fetch_array($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }

  function ge_max_tmpf($size) {
    $ret = Array();
    $rs = pg_exec($this->dbconn, "select * from current WHERE
      valid > (CURRENT_TIMESTAMP - '70 minutes'::interval) and tmpf < 140
      ORDER by tmpf DESC LIMIT $size");
    for( $i=0; $row = @pg_fetch_array($rs,$i); $i++) {
      $ret[$row["station"]] = new IEMAccessOb($row);
    }
    return $ret;
  }

{'fraction_non_alphanumeric': 0.1632210736912304, 'fraction_numerical': 0.005835278426142047, 'mean_word_length': 3.089297886843899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, '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': '1032342', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2302, 'n_words': 624}