PHP-02-筛选4k异常数据所占比率

setSsdbName( SSDB_COLD );
foreach($user as $uid => $kvs)
{
    $kvs = $db_cold ->hGet('reg_'.$uid,'regTime');
    if($kvs >= $start_time_uid)
    {
        $reg_uid[$uid] = 0;
    }
    else
    {
        $login_uid[$uid] = 0;
    }
}

$reg_num = count($reg_uid);
$log_num = count($login_uid);

$reg_uid_filter = array();
$login_uid_filter = array();
//需要统计的筹码变动原因
$reason_list = [
    'fishH_Bet'                             => 'fish百人场下注',
    'hiloH_Bet'                             => 'hilo百人场下注',
    'kkkkH_Bet'                             => '4k百人场下注',
    'fishH_Win'                             => 'fis百人场盈利',
    'hiloH_Win'                             => 'hilo百人场盈利',
    'kkkkH_Win'                             => '4k百人场盈利',
    'kkkkWin'                               => '4k玩牌盈利',
    'WinInTable'                            => '9k玩牌盈利',
    'kkkkWinFee'                            => '4k玩牌盈利'
];

foreach($reg_uid as $uid => $v)
{
    $start_time = strtotime('2019/6/28');
    $end_time = strtotime('2019/6/29');
    $db = new ModelBase();
    $db->setSsdbName( SSDB_LOG );

    $analysis = [];
    $i = 0;
    while(true)
    {
        $kvs = $db->hScan( 'chipsLog_'.$uid, $start_time, $end_time, 2000 );
        if( !$kvs )
        {
            break;
        }
        end($kvs);
        $start_time = key($kvs);

        foreach( $kvs as $time => $detail )
        {
            $detail = json_decode( $detail, true );
            if( array_key_exists( $detail['reason'], $reason_list ) )
            {
                $reg_uid_filter[$uid] = 0;
            }
        }

        $i++;
        if( $i%100 == 0 )
        {
            usleep( 100000 );
            echo" sleep ok \n";
        }
    }

}

foreach($login_uid as $uid => $v)
{
    $start_time = strtotime('2019/6/28');
    $end_time = strtotime('2019/6/29');
    $db = new ModelBase();
    $db->setSsdbName( SSDB_LOG );

    $analysis = [];
    $i = 0;
    while(true)
    {
        $kvs = $db->hScan( 'chipsLog_'.$uid, $start_time, $end_time, 2000 );
        if( !$kvs )
        {
            break;
        }
        end($kvs);
        $start_time = key($kvs);

        foreach( $kvs as $time => $detail )
        {
            $detail = json_decode( $detail, true );
            if( array_key_exists( $detail['reason'], $reason_list ) )
            {
                $login_uid_filter[$uid] = 0;
            }
        }

        $i++;
        if( $i%100 == 0 )
        {
            usleep( 100000 );
            echo" sleep ok \n";
        }
    }
}
$reg_ids = count($reg_uid_filter);
echo "注册人数玩牌比率:";
echo round($reg_ids /$reg_num *100,6)."%\n";

$login_ids = count($login_uid_filter);
echo "登录人数玩牌比率:";
echo round($login_ids /$log_num *100,6)."%\n";

这个地方卡了好久,得出的数据一直是错误的。原因在于,没有考虑到$start_time,$end_time这两个变量不能在foreach循环外定义,要定义成局部变量,每次循环都需要重置变量,不然的话,$start_time,$end_time只会不断地被赋值而得不到正确的结果。

你可能感兴趣的:(PHP,php,PHP)