<commit_before><?php

  /*

  All Emoncms code is released under the GNU Affero General Public License.
  See COPYRIGHT.txt and LICENSE.txt.

  ---------------------------------------------------------------------
  Emoncms - open source energy visualisation
  Part of the OpenEnergyMonitor project:
  http://openenergymonitor.org

  Feeds table

  id | name | userid | tag | time | value | status | datatype

  status 0: active
  status 1: wastebin
  
  datatype 0: UNDEFINED
  datatype 1: REALTIME
  datatype 2: DAILY
  datatype 3: HISTOGRAM

  */

  function create_feed($userid,$name,$datatype)
  {
    // If feed of given name by the user already exists
    $feedid = get_feed_id($userid,$name);
    if ($feedid!=0) return $feedid;

    $result = db_query("INSERT INTO feeds (userid,name,status,datatype) VALUES ('$userid','$name','0','$datatype')");
    $feedid = db_insert_id();

    if ($feedid>0) 
    {
      $feedname = "feed_".$feedid;

      if ($datatype!=3) {										
        $result = db_query(
        "CREATE TABLE $feedname (
	  time INT UNSIGNED, data float,
        INDEX ( `time` ))");
      }

      if ($datatype==3) {										
        $result = db_query(										
        "CREATE TABLE $feedname (
	  time INT UNSIGNED, data float, data2 float,
        INDEX ( `time` ))");
      }

      return $feedid;											
    } else return 0;
  }

  function get_feed_id($userid,$name)
  {
    $result = db_query("SELECT id FROM feeds WHERE userid = '$userid' AND name = '$name'");
    $row = db_fetch_array($result);
    return $row['id'];
  }

  function feed_belongs_user($feedid,$userid)
  {
    $result = db_query("SELECT id FROM feeds WHERE `userid` = '$userid' AND `id` = '$feedid'");
    $row = db_fetch_array($result);
    if ($row) return 1;
    return 0;
  }

  /*

  User Feed lists

  Returns a specified user's feedlist in different forms:
  get_user_feeds: 	all the feeds table data
  get_user_feed_ids: 	only the id's
  get_user_feed_names: 	id's and names

  */

  function get_user_feeds($userid,$status)
  {
    $result = db_query("SELECT * FROM feeds WHERE userid = $userid AND status = '$status'");
    if (!$result) return 0;
    $feeds = array();
    while ($row = db_fetch_object($result)) { $row->size = get_feedtable_size($row->id); $feeds[] = $row; }
    return $feeds;
  }

  function get_user_feed_ids($userid)
  {
    $result = db_query("SELECT id FROM feeds WHERE userid = $userid");
    if (!$result) return 0;
    $feeds = array();
    while ($row = db_fetch_object($result)) { $feeds[] = $row->id; }
    return $feeds;
  }

  function get_user_feed_names($userid)
  {
    $result = db_query("SELECT id,name FROM feeds WHERE userid = $userid");
    if (!$result) return 0;<commit_msg>Feed update time now display's correctly on servers that are running on different timezones<commit_after><?php

  /*

  All Emoncms code is released under the GNU Affero General Public License.
  See COPYRIGHT.txt and LICENSE.txt.

  ---------------------------------------------------------------------
  Emoncms - open source energy visualisation
  Part of the OpenEnergyMonitor project:
  http://openenergymonitor.org

  Feeds table

  id | name | userid | tag | time | value | status | datatype

  status 0: active
  status 1: wastebin
  
  datatype 0: UNDEFINED
  datatype 1: REALTIME
  datatype 2: DAILY
  datatype 3: HISTOGRAM

  */

  function create_feed($userid,$name,$datatype)
  {
    // If feed of given name by the user already exists
    $feedid = get_feed_id($userid,$name);
    if ($feedid!=0) return $feedid;

    $result = db_query("INSERT INTO feeds (userid,name,status,datatype) VALUES ('$userid','$name','0','$datatype')");
    $feedid = db_insert_id();

    if ($feedid>0) 
    {
      $feedname = "feed_".$feedid;

      if ($datatype!=3) {										
        $result = db_query(
        "CREATE TABLE $feedname (
	  time INT UNSIGNED, data float,
        INDEX ( `time` ))");
      }

      if ($datatype==3) {										
        $result = db_query(										
        "CREATE TABLE $feedname (
	  time INT UNSIGNED, data float, data2 float,
        INDEX ( `time` ))");
      }

      return $feedid;											
    } else return 0;
  }

  function get_feed_id($userid,$name)
  {
    $result = db_query("SELECT id FROM feeds WHERE userid = '$userid' AND name = '$name'");
    $row = db_fetch_array($result);
    return $row['id'];
  }

  function feed_belongs_user($feedid,$userid)
  {
    $result = db_query("SELECT id FROM feeds WHERE `userid` = '$userid' AND `id` = '$feedid'");
    $row = db_fetch_array($result);
    if ($row) return 1;
    return 0;
  }

  /*

  User Feed lists

  Returns a specified user's feedlist in different forms:
  get_user_feeds: 	all the feeds table data
  get_user_feed_ids: 	only the id's
  get_user_feed_names: 	id's and names

  */

  function get_user_feeds($userid,$status)
  {
    $result = db_query("SELECT * FROM feeds WHERE userid = $userid AND status = '$status'");
    if (!$result) return 0;
    $feeds = array();
    while ($row = db_fetch_object($result)) 
    { 
      $row->size = get_feedtable_size($row->id);
      $row->time = strtotime($row->time)*1000;
      $feeds[] = $row; 
    }
    return $feeds;
  }

  function get_user_feed_ids($userid)
  {
    $result = db_query("SELECT id FROM feeds WHERE userid = $userid");
    if (!$result) return 0;
    $feeds = array();
    while ($row = db_fetch_object($result)) { $feeds[] = $row->id; }
    return $feeds;
  }

  function get_user_feed_names($userid)
  {
    $result = db_query("SELECT id,name FROM feeds WHERE userid = $userid");
    if (!$result) return 0;
{'fraction_non_alphanumeric': 0.15316275764036957, 'fraction_numerical': 0.007107320540156361, 'mean_word_length': 2.622265122265122, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '6244813', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1846, 'n_words': 512}