<commit_before><?php

  require_once dirname(__FILE__) . "/../include/jsonRPCClient.php";
  require_once dirname(__FILE__) . "/../include/config.php";
  
  function diffTime ($time) {
    $now = date("U");
    $diff = $now - $time;
    
    $days = $diff / 86400;
    $hours = ($diff % 86400) / 3600;
    $minutes = ($diff % 3600) / 60;
    
    return sprintf ("%dd %02d:%02d", $days, $hours, $minutes);
  }
  
  function walletLogic ($wallet, $minbalance) {

    $output = array("found_time" => "n/a",
                    "since_time" => "n/a",
                    "immature" => 0,
                    "balance" => 0);
    $found_block = False;
    $last_tx_checked = array("txid" => "n/a",
                             "addr" => "n/a");
    $count = 25;
    
    do {
      $transactions = $wallet->listtransactions("", $count);
      $output['immature'] = 0;
      
      if ( count($transactions) > 0 ) { // check if there are transactions
        $value = end($transactions);
          
        do { // searching for immature or generated blocks
          if ( (array_search('immature', $value) !== False)  || (array_search('generate', $value) !== False) ) {
            if ( $output['found_time'] == 'n/a' ) {
              $output['found_time'] = date("Y-m-d H:i:s", $value['time']);
              $output['since_time'] = diffTime($value['time']);
            }
            if ( $value['category'] == 'generate' ) {
              $found_block = True;
              break;
            }
            if ( $value['category'] == 'immature' ) {
              $output['immature'] += $value['amount'];
            }
          }
          if ( prev($transactions) === False ) {
            break;
          } else {
            $value = current($transactions);
          }
        } while ( True );
      }
      
      if ( $last_tx_checked['txid'] == $value['txid'] && $last_tx_checked['addr'] == $value['address'] ) {
        break;
      } else {
        $last_tx_checked['txid'] = $value['txid'];
        $last_tx_checked['addr'] = $value['address'];
      }
      
      $count += $count;
    } while ( !$found_block );

    $output['balance'] = $wallet->getbalance("") - $output['immature'] - $minbalance;

    return $output;
  }

  if ( !isset($minbalance) ) $minbalance = 1.0;
  
  $vertcoin_rpc = "http://" . $vtc_wallet_user . ":" . $vtc_wallet_password . "@" . $vtc_wallet_address . "/";<commit_msg>Balance could go to negative<commit_after><?php

  require_once dirname(__FILE__) . "/../include/jsonRPCClient.php";
  require_once dirname(__FILE__) . "/../include/config.php";
  
  function diffTime ($time) {
    $now = date("U");
    $diff = $now - $time;
    
    $days = $diff / 86400;
    $hours = ($diff % 86400) / 3600;
    $minutes = ($diff % 3600) / 60;
    
    return sprintf ("%dd %02d:%02d", $days, $hours, $minutes);
  }
  
  function walletLogic ($wallet, $minbalance) {

    $output = array("found_time" => "n/a",
                    "since_time" => "n/a",
                    "immature" => 0,
                    "balance" => 0);
    $found_block = False;
    $last_tx_checked = array("txid" => "n/a",
                             "addr" => "n/a");
    $count = 25;
    
    do {
      $transactions = $wallet->listtransactions("", $count);
      $output['immature'] = 0;
      
      if ( count($transactions) > 0 ) { // check if there are transactions
        $value = end($transactions);
          
        do { // searching for immature or generated blocks
          if ( (array_search('immature', $value) !== False)  || (array_search('generate', $value) !== False) ) {
            if ( $output['found_time'] == 'n/a' ) {
              $output['found_time'] = date("Y-m-d H:i:s", $value['time']);
              $output['since_time'] = diffTime($value['time']);
            }
            if ( $value['category'] == 'generate' ) {
              $found_block = True;
              break;
            }
            if ( $value['category'] == 'immature' ) {
              $output['immature'] += $value['amount'];
            }
          }
          if ( prev($transactions) === False ) {
            break;
          } else {
            $value = current($transactions);
          }
        } while ( True );
      }
      
      if ( $last_tx_checked['txid'] == $value['txid'] && $last_tx_checked['addr'] == $value['address'] ) {
        break;
      } else {
        $last_tx_checked['txid'] = $value['txid'];
        $last_tx_checked['addr'] = $value['address'];
      }
      
      $count += $count;
    } while ( !$found_block );

    $output['balance'] = $wallet->getbalance("") - $output['immature'] - $minbalance;
    if ( $output['balance'] < 0 ) $output['balance'] = 0;

    return $output;
  }

  if ( !isset($minbalance) ) $minbalance = 1.0;
  
  $vertcoin_rpc = "http://" . $vtc_wallet_user . ":" . $vtc_wallet_password . "@" . $vtc_wallet_address . "/";
{'fraction_non_alphanumeric': 0.18929957116602, 'fraction_numerical': 0.013477639371043496, 'mean_word_length': 1.9259259259259258, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 21, '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': '175804', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1575, 'n_words': 297}