$max_other_currencies_time = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT max(`time`)\n\t\tFROM `" . DB_PREFIX . "max_other_currencies_time`\n\t\t", 'fetch_one');
if ($time - $max_other_currencies_time > $variables['new_max_other_currencies']) {
    // берем все голоса
    $res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t  `count`,\n\t\t\t\t\t\t    count(`user_id`) as `votes`\n\t\t\tFROM `" . DB_PREFIX . "votes_max_other_currencies`\n\t\t\tGROUP BY  `currency_id`, `count`\n\t\t\t");
    while ($row = $db->fetchArray($res)) {
        $max_other_currencies_votes[$row['currency_id']][$row['count']] = $row['votes'];
    }
    if (!isset($max_other_currencies_votes)) {
        debug_print('!isset($max_other_currencies_votes)', __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
        main_unlock();
        exit;
    }
    debug_print($max_other_currencies_votes, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    $total_count_currencies = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT count(`id`)\n\t\t\tFROM `" . DB_PREFIX . "currency`\n\t\t\t", 'fetch_one');
    foreach ($max_other_currencies_votes as $currency_id => $count_and_votes) {
        $new_max_other_currencies[$currency_id] = get_max_vote($count_and_votes, 0, $total_count_currencies, 10);
    }
    if (get_community_users($db)) {
        $my_prefix = $testBlock->user_id . '_';
    } else {
        $my_prefix = '';
    }
    $node_private_key = get_node_private_key($db, $my_prefix);
    $json_data = json_encode($new_max_other_currencies);
    // подписываем нашим нод-ключем данные транзакции
    $data_for_sign = ParseData::findType('new_max_other_currencies') . ",{$time},{$my_user_id},{$json_data}";
    $rsa = new Crypt_RSA();
    $rsa->loadKey($node_private_key);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $signature = $rsa->sign($data_for_sign);
    debug_print('$data_for_sign=' . $data_for_sign . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 $res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT `currency_id`,\n\t\t\t\t\t\t  `amount`,\n\t\t\t\t\t\t    count(`user_id`) as `votes`\n\t\t\tFROM `" . DB_PREFIX . "votes_max_promised_amount`\n\t\t\tGROUP BY  `currency_id`, `amount`\n\t\t\t");
 while ($row = $db->fetchArray($res)) {
     $max_promised_amount_votes[$row['currency_id']][$row['amount']] = $row['votes'];
 }
 if (!isset($max_promised_amount_votes)) {
     debug_print('!isset($max_promised_amount_votes)', __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
     main_unlock();
     exit;
 }
 debug_print($max_promised_amount_votes, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
 $new_max_promised_amounts = array();
 foreach ($max_promised_amount_votes as $currency_id => $amounts_and_votes) {
     //$valid_amounts_and_votes = ParseData::makeMaxPromisedAmount($amounts_and_votes);
     //$key = get_max_vote($valid_amounts_and_votes, 0, 1000, 100);
     //$new_max_promised_amounts[$currency_id] =  ParseData::getPctValue($key);
     $new_max_promised_amounts[$currency_id] = get_max_vote($amounts_and_votes, 0, 165, 10);
 }
 if (get_community_users($db)) {
     $my_prefix = $testBlock->user_id . '_';
 } else {
     $my_prefix = '';
 }
 $node_private_key = get_node_private_key($db, $my_prefix);
 $json_data = json_encode($new_max_promised_amounts);
 // подписываем нашим нод-ключем данные транзакции
 $data_for_sign = ParseData::findType('new_max_promised_amounts') . ",{$time},{$my_user_id},{$json_data}";
 $rsa = new Crypt_RSA();
 $rsa->loadKey($node_private_key);
 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
 $signature = $rsa->sign($data_for_sign);
 debug_print('$data_for_sign=' . $data_for_sign . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
Example #3
0
$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);
    $new_pct['currency'][$currency_id]['user_pct'] = ParseData::getPctValue($key);
    $tpl['new_pct'][$currency_id]['user_pct'] = round((pow(1 + ParseData::getPctValue($key), 3600 * 24 * 365) - 1) * 100, 2);
}
/*
 * %/год
 * */
$res = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\tSELECT *\n\t\tFROM `" . DB_PREFIX . "currency`\n\t\t");
while ($row = $db->fetchArray($res)) {
    $pct = $db->query(__FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, "\n\t\t\tSELECT *\n\t\t\tFROM `" . DB_PREFIX . "pct`\n\t\t\tWHERE `currency_id` = {$row['id']}\n\t\t\tORDER BY `block_id` DESC\n\t\t\tLIMIT 1\n\t\t\t", 'fetch_array');
    $tpl['currency_pct'][$row['id']]['name'] = $row['name'];
    $tpl['currency_pct'][$row['id']]['miner'] = round((pow(1 + $pct['miner'], 120) - 1) * 100, 6);
    $tpl['currency_pct'][$row['id']]['user'] = round((pow(1 + $pct['user'], 120) - 1) * 100, 6);
}
$tpl['currency_list'] = get_currency_list($db, 'full');
require_once ABSPATH . 'templates/statistic_voting.tpl';
Example #4
0
function get_max_vote($array, $min, $max, $step)
{
    debug_print('$array=' . print_r_hex($array) . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$min=' . $min . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$max=' . $max . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$step=' . $step . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    // если <=10 то тупо берем максимальное кол-во голосов
    if (sizeof($array) <= 10) {
        if (sizeof($array) > 0) {
            $max_votes = max($array);
            $max_pct = array_search($max_votes, $array);
        } else {
            $max_pct = 0;
        }
        return $max_pct;
    }
    // делим набор данных от $min до $max на секции кратные $step
    // таких секций будет 100 при $max=1000
    // цель такого деления - найти ту секцию, где больше всего голосов
    for ($i = $min; $i < $max; $i = $i + $step / 10) {
        $min_0 = $i;
        $max_0 = $i + $step;
        // берем из массива те данные, которые попадают в данную секцию
        foreach ($array as $number => $votes) {
            if ($number >= $min_0 && $number < $max_0) {
                $data_bank[$i][$number] = $votes;
                //debug_print( '$min_0='.$min_0."\n", __FILE__, __LINE__,  __FUNCTION__,  __CLASS__, __METHOD__);
                //debug_print( '$max_0='.$max_0."\n", __FILE__, __LINE__,  __FUNCTION__,  __CLASS__, __METHOD__);
            }
        }
        if (isset($data_bank[$i])) {
            $sums[$i] = array_sum($data_bank[$i]);
        }
    }
    debug_print('$data_bank=' . print_r_hex($data_bank) . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$sums=' . print_r_hex($sums) . "\n", __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    // ищем id секции, где больше всего голосов
    $max_sum = max($sums);
    $max_i = array_search($max_sum, $sums);
    debug_print('$max_sum:' . $max_sum, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$max_i:' . $max_i, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    debug_print('$data_bank[$max_i]:' . print_r_hex($data_bank[$max_i]), __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
    // если в этой секции <= 10-и элементов, то просто выбираем максимальное кол-во голосов
    if (sizeof($data_bank[$max_i]) <= 10) {
        debug_print('sizeof($data_bank[$max_i])<=10', __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__);
        $max_votes = max($data_bank[$max_i]);
        $max_pct = array_search($max_votes, $data_bank[$max_i]);
        return $max_pct;
    } else {
        // без рекурсии, просто один раз вызываем свою функцию
        return get_max_vote($data_bank[$max_i], $max_i, $max_i + $step, $step / 10);
    }
}
Example #5
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;
     }
 }