Статистика в табличке

Varius

Пользователь
Автор: Wertos
Сложность: Легко
SQL
PHP:
ALTER TABLE bb_bt_users ADD `up_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `down_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `release_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `bonus_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_up_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_down_last` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `up_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `down_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `release_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `bonus_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_up_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_down_today` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `up_yesterday` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `down_yesterday` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `release_yesterday` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `bonus_yesterday` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_up_yesterday` bigint(20) unsigned NOT NULL default '0';
ALTER TABLE bb_bt_users ADD `speed_down_yesterday` bigint(20) unsigned NOT NULL default '0';
torrent_userprofile.php в самый конец файла
PHP:
// Advanced stat Wertos
$up_last = $down_last = $release_last = $bonus_last = $speed_up_last = $speed_down_last = $speed_up_today = $speed_down_today = $up_today = $down_today = $release_today = $bonus_today = $speed_up_yesterday = $speed_down_yesterday = $up_yesterday = $down_yesterday = $release_yesterday = $bonus_yesterday = 0;
$get_stat = DB()->sql_query("SELECT
                            up_last, down_last, release_last, bonus_last, speed_up_last, speed_down_last,
                            up_today, down_today, release_today, bonus_today, speed_up_today, speed_down_today,
                            up_yesterday, down_yesterday, release_yesterday, bonus_yesterday, speed_up_yesterday, speed_down_yesterday
        FROM ".BB_BT_USERS."
        WHERE user_id = $profile_user_id
      ");
while ($row = DB()->sql_fetchrow($get_stat))
{
  $up_last = humn_size($row['up_last']);
  $down_last = humn_size($row['down_last']);
  $release_last = humn_size($row['release_last']);
  $bonus_last =  humn_size($row['bonus_last']);
  $speed_up_last = ($row['speed_up_last']) ? humn_size($row['speed_up_last']).'/s' : '0B/s';
  $speed_down_last = ($row['speed_down_last']) ? humn_size($row['speed_down_last']).'/s' : '0B/s';

  $speed_up_today            = ($row['speed_up_today']) ? humn_size($row['speed_up_today']).'/s' : '0B/s';
  $speed_down_today          = ($row['speed_down_today']) ? humn_size($row['speed_down_today']).'/s' : '0B/s';
  $up_today                  = humn_size($row['up_today']);
  $down_today                = humn_size($row['down_today']);
  $release_today              = humn_size($row['release_today']);
  $bonus_today                = humn_size($row['bonus_today']);

  $speed_up_yesterday        = ($row['speed_up_yesterday']) ? humn_size($row['speed_up_yesterday']).'/s' : '0B/s';
  $speed_down_yesterday      = ($row['speed_down_yesterday']) ? humn_size($row['speed_down_yesterday']).'/s' : '0B/s';
  $up_yesterday              = humn_size($row['up_yesterday']);
  $down_yesterday            = humn_size($row['down_yesterday']);
  $release_yesterday          = humn_size($row['release_yesterday']);
  $bonus_yesterday            = humn_size($row['bonus_yesterday']);
}
  $template->assign_vars(array(
  'LAST_UP'                => $up_last,
  'LAST_DOWN'              => $down_last,
  'LAST_RELEASE'            => $release_last,
  'LAST_BONUS'              => $bonus_last,
  'LAST_SPEED_UP'          => $speed_up_last,
  'LAST_SPEED_DOWN'        => $speed_down_last,

  'SPEED_UP_TODAY'          => $speed_up_today,
  'SPEED_DOWN_TODAY'        => $speed_down_today,
  'UP_TODAY'                => $up_today,
  'DOWN_TODAY'              => $down_today,
  'RELEASE_TODAY'          => $release_today,
  'BONUS_TODAY'            => $bonus_today,

  'SPEED_UP_YESTERDAY'      => $speed_up_yesterday,
  'SPEED_DOWN_YESTERDAY'    => $speed_down_yesterday,
  'UP_YESTERDAY'            => $up_yesterday,
  'DOWN_YESTERDAY'          => $down_yesterday,
  'RELEASE_YESTERDAY'      => $release_yesterday,
  'BONUS_YESTERDAY'        => $bonus_yesterday
));
// Advanced stat Wertos end
Важно чтобы задача user_stats_today.php запускаласть примерно на 1 минуту раньше чем задача tr_cleanup_and_dlstat.php с такимже интервалом
Задача user_stats_yesterday.php раз в сутки... примерно в 00.01.00
user_stats_today.php
PHP:
<?php

if (!defined('BB_ROOT')) die(basename(__FILE__));
DB()->query("UPDATE ".BB_BT_USERS." u,
                  ".BB_BT_LAST_USERSTAT." lus
            SET
              u.up_last = lus.up_add,
              u.down_last = lus.down_add,
              u.release_last = lus.release_add,
              u.bonus_last =  lus.bonus_add,
              u.speed_up_last = lus.speed_up,
              u.speed_down_last = lus.speed_down,
              u.up_today = u.up_today + lus.up_add,
              u.down_today = u.down_today + lus.down_add,
              u.release_today = u.release_today + lus.release_add,
              u.bonus_today = u.bonus_today + lus.bonus_add,
              u.speed_up_today = u.speed_up_today + lus.speed_up,
              u.speed_down_today = u.speed_down_today + lus.speed_down
            WHERE u.user_id = lus.user_id
      ");

user_stats_yesterday.php
PHP:
<?php
if (!defined('BB_ROOT')) die(basename(__FILE__));
DB()->query("UPDATE ".BB_BT_USERS."
            SET
                up_yesterday = up_today,
                down_yesterday = down_today,
                release_yesterday = release_today,
                bonus_yesterday = bonus_today,
                speed_up_yesterday = speed_up_today,
                speed_down_yesterday = speed_down_today
        ");
DB()->query("UPDATE ".BB_BT_USERS."
            SET
                up_today = 0,
                down_today = 0,
                release_today = 0,
                bonus_today = 0,
                speed_up_today = 0,
                speed_down_today = 0
        ");
// GROUP BY user_id
В usercp_viewprofile.tpl в нужное для вас место добавить
Код:
            <!-- IF EDIT_PROF || SHOW_ADMIN_OPTIONS -->
            <tr>
                <td colspan="2">
                    <table class="ratio_cp bCenter borderless" cellspacing="1" align="center" width="468">
                        <tr class="row3">
                            <th width="16%"><a href="{U_RATIO_TOPIC}">{L_RATIO_FAQ}</a></th>
                            <th width="16%">{L_BT_LAST_UPDATE}</th>
                            <th width="16%">{L_BT_TODAY}</th>
                            <th width="16%">{L_BT_YESTERDAY}</th>
                            <th width="16%">{L_BT_COUNTED}</th>
                        </tr>
                        <tr class="row5 leech">
                            <th>{L_DOWNLOADED}</th>
                            <td>{LAST_DOWN}</td>
                            <td class="bold">{DOWN_TODAY}</td>
                            <td>{DOWN_YESTERDAY}</td>
                            <td id="u_down_total"  class="row1"><span class="editable bold">{DOWN_TOTAL}</span></td>
                        </tr>
                        <tr class="row1 seed">
                            <th>{L_UPLOADED}</p></th>
                            <td>{LAST_UP}</td>
                            <td class="bold">{UP_TODAY}</td>
                            <td>{UP_YESTERDAY}</td>
                            <td id="u_up_total"><span class="editable bold">{UP_TOTAL}</td>
                        </tr>
                        <tr class="row5 seed">
                            <th class="med">{L_RELEASED}</th>
                            <td>{LAST_RELEASE}</td>
                            <td class="bold">{RELEASE_TODAY}</td>
                            <td>{RELEASE_YESTERDAY}</td>
                            <td id="u_up_release"><i><span class="editable bold">{RELEASED}</span></i></td>
                        </tr>
                        <tr class="row1 seed">
                            <th class="med"><a href="{U_RATIO_TOPIC}">{L_BT_BONUS_UP}</th>
                            <td>{LAST_BONUS}</td>
                            <td class="bold">{BONUS_TODAY}</td>
                            <td>{BONUS_YESTERDAY}</td>
                            <td id="u_up_bonus"><span class="editable bold">{UP_BONUS}</span></td>
                        </tr>
                            <tr>
                              <th width="50%"><span class="med">Cид-Бонус:</span></th>
                              <td class="med" id="user_bonus">
                              <span style="{STYLE}" class="editable">{MY_BONUS}</span>
                            </td>
                            </tr>

                        <tr class="row5 seed">
                            <th class="med">{L_Bt_Show_Speed}</th>
                            <td><span class="seedsmall">{LAST_SPEED_UP}</span> | <span class="leechsmall">{LAST_SPEED_DOWN}</span></td>
                            <td><span class="seedsmall bold">{SPEED_UP_TODAY}</span> | <span class="leechsmall bold">{SPEED_DOWN_TODAY}</span></td>
                            <td><span class="seedsmall">{SPEED_UP_YESTERDAY}</span> | <span class="leechsmall">{SPEED_DOWN_YESTERDAY}</span></td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <!-- ENDIF -->
--- добавлено: Aug 22, 2011 10:41 AM ---
PS .Непонятные костыли со стороны
 

RomM1

Пользователь
Nikolaich, и где же он не адаптирован?
[22-Aug-2011 14:24:18] PHP Warning: mysql_fetch_assoc(): 33 is not a valid MySQL result resource in /usr/home/svn/public_html/includes/db/mysql.php on line 251 - решение:
из user_stats_yesterday.php удалить DB()->sql_freeresult($result);
 

DarkMod

Легенда
Я бы в ревизию вообще его закинул...;)
Зачем? смысла нет
--- добавлено: Aug 22, 2011 4:26 PM ---
Nikolaich, и где же он не адаптирован?
[22-Aug-2011 14:24:18] PHP Warning: mysql_fetch_assoc(): 33 is not a valid MySQL result resource in /usr/home/svn/public_html/includes/db/mysql.php on line 251 - решение:
из user_stats_yesterday.php удалить DB()->sql_freeresult($result);
:D
 
N

Nikolaich

Гость
Varius, ну-ну... А ты с хоботом его пробовал? А между тем, хобот включен в движок как один из стандартных анонсеров. А под него - точно не адаптировано.
 
Сверху