Beispiel #1
0
function find_user_pct($max_user_pct_y)
{
    $PctArray = ParseData::getPctArray();
    //debug_print( '$PctArray='.print_r_hex($PctArray), __FILE__, __LINE__,  __FUNCTION__,  __CLASS__, __METHOD__);
    $i = 0;
    foreach ($PctArray as $pct_y => $pct_ssc) {
        if ($pct_y >= $max_user_pct_y) {
            debug_print('$pct_y<$max_user_pct_y = ' . $pct_y . ' < ' . $max_user_pct_y, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
            if ($i > 0) {
                return $i - 1;
            } else {
                return 0;
            }
        }
        $i++;
    }
}
Beispiel #2
0
/*
 * Голосоваие за майнеркие и юзерские %
 * */
// берем все голоса miner_pct
$res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_miner_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
while ($row = $db->fetchArray($res)) {
    $pct_votes[$row['currency_id']]['miner_pct'][$row['pct']] = $row['votes'];
    $tpl['pct_votes'][$row['currency_id']]['miner_pct'][round((pow(1 + $row['pct'], 3600 * 24 * 365) - 1) * 100, 2)] = $row['votes'];
}
// берем все голоса user_pct
$res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_user_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
while ($row = $db->fetchArray($res)) {
    $pct_votes[$row['currency_id']]['user_pct'][$row['pct']] = $row['votes'];
    $tpl['pct_votes'][$row['currency_id']]['user_pct'][round((pow(1 + $row['pct'], 3600 * 24 * 365) - 1) * 100, 2)] = $row['votes'];
}
$PctArray = ParseData::getPctArray();
$new_pct = array();
foreach ($pct_votes as $currency_id => $data) {
    // определяем % для майнеров
    $pct_arr = ParseData::makePctArray($data['miner_pct']);
    $key = get_max_vote($pct_arr, 0, 390, 100);
    $new_pct['currency'][$currency_id]['miner_pct'] = ParseData::getPctValue($key);
    $tpl['new_pct'][$currency_id]['miner_pct'] = round((pow(1 + ParseData::getPctValue($key), 3600 * 24 * 365) - 1) * 100, 2);
    // определяем % для юзеров
    $pct_arr = ParseData::makePctArray($data['user_pct']);
    $pct_y = array_search($new_pct['currency'][$currency_id]['miner_pct'], $PctArray);
    $max_user_pct_y = round($pct_y / 2, 2);
    $user_max_key = find_user_pct($max_user_pct_y);
    // отрезаем лишнее, т.к. поиск идет ровно до макимального возможного, т.е. до miner_pct/2
    $pct_arr = del_user_pct($pct_arr, $user_max_key);
    $key = get_max_vote($pct_arr, 0, $user_max_key, 100);
Beispiel #3
0
        $votes_max_other_currencies = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `count`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_max_other_currencies`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one');
        $votes_max_promised_amount = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `amount`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_max_promised_amount`\n\t\t\t\tWHERE `user_id` = {$user_id} AND\n\t\t\t\t\t\t\t `currency_id` = {$row['currency_id']}\n\t\t\t\tLIMIT 1\n\t\t\t\t", 'fetch_one');
        $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_user_pct'] = $votes_user_pct;
        $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_miner_pct'] = $votes_miner_pct;
        $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_max_other_currencies'] = $votes_max_other_currencies;
        $tpl['promised_amount_currency_list'][$row['currency_id']]['votes_max_promised_amount'] = $votes_max_promised_amount;
        $tpl['promised_amount_currency_list'][$row['currency_id']]['name'] = $row['name'];
    }
}
$tpl['referral'] = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT `first`, `second`, `third`\n\t\tFROM `" . DB_PREFIX . "votes_referral`\n\t\tWHERE `user_id` = {$user_id}\n\t\tLIMIT 1\n\t\t", 'fetch_array');
if (!$tpl['referral']) {
    $tpl['referral']['first'] = rand(0, 30);
    $tpl['referral']['second'] = rand(0, 30);
    $tpl['referral']['third'] = rand(0, 30);
}
$tpl['max_currency_id'] = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT max(`id`)\n\t\tFROM `" . DB_PREFIX . "currency`\n\t\t", 'fetch_one');
/*$tpl['AllMaxPromisedAmount'] = ParseData::getAllMaxPromisedAmount();*/
$tpl['AllMaxPromisedAmount'] = array("1", "2", "5", "10", "20", "50", "100", "200", "500", "1000", "2000", "5000", "10000", "20000", "50000", "100000", "200000", "500000", "1000000", "2000000", "5000000", "10000000", "20000000", "50000000", "100000000", "200000000", "500000000", "1000000000");
$tpl['AllPct'] = ParseData::getPctArray();
$pct_array = ParseData::getPctArray();
$tpl['js_pct'] = '{';
foreach ($pct_array as $year_pct => $sec_pct) {
    $tpl['js_pct'] .= "{$year_pct}: '{$sec_pct}',";
}
$tpl['js_pct'] = substr($tpl['js_pct'], 0, -1);
$tpl['js_pct'] .= '}';
$tpl['last_tx'] = get_last_tx($user_id, types_to_ids(array('votes_complex')));
if (!empty($tpl['last_tx'])) {
    $tpl['last_tx_formatted'] = make_last_tx($tpl['last_tx']);
}
require_once ABSPATH . 'templates/voting.tpl';
Beispiel #4
0
 function new_pct_front()
 {
     $error = $this->general_check();
     if ($error) {
         return $error;
     }
     // является ли данный юзер майнером
     if (!$this->check_miner($this->tx_data['user_id'])) {
         return 'error miner id';
     }
     // получим public_key
     $this->node_public_key = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `node_public_key`\n\t\t\t\tFROM `" . DB_PREFIX . "miners_data`\n\t\t\t\tWHERE `user_id` = {$this->tx_data['user_id']}\n\t\t\t\t", 'fetch_one');
     ////print $this->db->printsql();
     if (!$this->node_public_key) {
         return 'error user_id';
     }
     $new_pct_tx = json_decode($this->tx_data['new_pct'], true);
     if (!$new_pct_tx) {
         return 'error $new_pct_tx';
     }
     // раньше не было рефских
     if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 77951) {
         $new_pct_tx['currency'] = $new_pct_tx;
     } else {
         if (!isset($new_pct_tx['currency'], $new_pct_tx['referral'])) {
             return 'error currency referral';
         }
     }
     if (!is_array($new_pct_tx['currency'])) {
         return 'error $new_pct_tx[currency])';
     }
     // проверим, верно ли указаны ID валют
     $currency_ids_sql = '';
     $count_currency = 0;
     foreach ($new_pct_tx['currency'] as $id => $_data) {
         $currency_ids_sql .= $id . ',';
         $count_currency++;
     }
     $currency_ids_sql = substr($currency_ids_sql, 0, -1);
     $count = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT count(`id`)\n\t\t\t\tFROM `" . DB_PREFIX . "currency`\n\t\t\t\tWHERE `id` IN ({$currency_ids_sql})\n\t\t\t\t", 'fetch_one');
     if ($count != $count_currency) {
         return 'error count_currency';
     }
     // проверяем подпись
     $for_sign = "{$this->tx_data['type']},{$this->tx_data['time']},{$this->tx_data['user_id']},{$this->tx_data['new_pct']}";
     $error = self::checkSign($this->node_public_key, $for_sign, $this->tx_data['sign'], true);
     if ($error) {
         return $error;
     }
     // проверим, прошло ли 2 недели с момента последнего обновления pct
     $pct_time = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT max(`time`)\n\t\t\t\tFROM `" . DB_PREFIX . "pct`", 'fetch_one');
     if ($this->tx_data['time'] - $pct_time <= $this->variables['new_pct_period']) {
         return '14 day error';
     }
     // берем все голоса miner_pct
     $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_miner_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
     while ($row = $this->db->fetchArray($res)) {
         $pct_votes[$row['currency_id']]['miner_pct'][$row['pct']] = $row['votes'];
     }
     // берем все голоса user_pct
     $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t\t `pct`,\n\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\tFROM `" . DB_PREFIX . "votes_user_pct`\n\t\t\t\tGROUP BY  `currency_id`, `pct`\n\t\t\t\t");
     while ($row = $this->db->fetchArray($res)) {
         $pct_votes[$row['currency_id']]['user_pct'][$row['pct']] = $row['votes'];
     }
     debug_print($pct_votes, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     $PctArray = ParseData::getPctArray();
     $new_pct = array();
     foreach ($pct_votes as $currency_id => $data) {
         // определяем % для майнеров
         $pct_arr = ParseData::makePctArray($data['miner_pct']);
         $key = get_max_vote($pct_arr, 0, 390, 100);
         $new_pct['currency'][$currency_id]['miner_pct'] = ParseData::getPctValue($key);
         debug_print('$key miner_pct=' . $key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         // определяем % для юзеров
         $pct_arr = ParseData::makePctArray($data['user_pct']);
         // раньше не было завимости юзерского % от майнерского
         if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 95263) {
             $user_max_key = 390;
         } else {
             $pct_y = array_search($new_pct['currency'][$currency_id]['miner_pct'], $PctArray);
             debug_print('miner_pct $pct_y=' . $pct_y, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             $max_user_pct_y = round($pct_y / 2, 2);
             debug_print('$max_user_pct=' . $max_user_pct_y, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             $user_max_key = find_user_pct($max_user_pct_y);
             debug_print('$user_max_key=' . $user_max_key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
             // отрезаем лишнее, т.к. поиск идет ровно до макимального возможного, т.е. до miner_pct/2
             $pct_arr = del_user_pct($pct_arr, $user_max_key);
             debug_print('$user_$pct_arr=' . print_r_hex($pct_arr), __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         }
         $key = get_max_vote($pct_arr, 0, $user_max_key, 100);
         debug_print('$key user_pct=' . $key, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         $new_pct['currency'][$currency_id]['user_pct'] = ParseData::getPctValue($key);
         debug_print('user_pct=' . $new_pct['currency'][$currency_id]['user_pct'], __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
         debug_print('user pct y=' . array_search($new_pct['currency'][$currency_id]['user_pct'], $PctArray), __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     }
     // раньше не было рефских
     if (isset($this->block_data['block_id']) && $this->block_data['block_id'] <= 77951) {
         $new_pct = $new_pct['currency'];
     } else {
         $ref_levels = array('first', 'second', 'third');
         for ($i = 0; $i < sizeof($ref_levels); $i++) {
             $level = $ref_levels[$i];
             $votes_referral = array();
             // берем все голоса
             $res = $this->db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\t\t\t\tSELECT `{$level}`,\n\t\t\t\t\t\t\t\t\t  count(`user_id`) as `votes`\n\t\t\t\t\t\tFROM `" . DB_PREFIX . "votes_referral`\n\t\t\t\t\t\tGROUP BY  `{$level}`\n\t\t\t\t\t\t");
             while ($row = $this->db->fetchArray($res)) {
                 $votes_referral[$row[$level]] = $row['votes'];
             }
             $new_pct['referral'][$level] = get_max_vote($votes_referral, 0, 30, 10);
         }
     }
     debug_print($new_pct, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     $json_data = json_encode($new_pct);
     debug_print($json_data, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     debug_print($this->tx_data['new_pct'], __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     if ($this->tx_data['new_pct'] != $json_data) {
         return 'new_pct error ' . $json_data;
     }
 }