Esempio n. 1
0
function collectUser($userId)
{
    $minYear = 2006;
    $dwSum = $dwDays = $oldWeek = 0;
    for ($y = $minYear; $y <= date('Y'); $y++) {
        $qSum = $qDays = $oldQuarter = 0;
        for ($m = 1; $m < 13; $m++) {
            if ($oldQuarter != quarter($m)) {
                if ($qDays > 0) {
                    setWeight($userId, sprintf("Q%04d-%d", $y, $oldQuarter), $qSum / $qDays, 'q');
                }
                $qSum = $qDays = 0;
                $oldQuarter = quarter($m);
            }
            if (sprintf('%04d%02d', $y, $m) > date('Ym')) {
                break;
            }
            $days = date('t', mktime(0, 0, 0, $m, 1, $y));
            $sum = $qty = 0;
            for ($i = 1; $i <= $days; $i++) {
                if ($oldWeek != doubleWeek($y, $m, $i)) {
                    if ($dwDays > 0) {
                        setWeight($userId, sprintf("D%s", $oldWeek), $dwSum / $dwDays, 'dw');
                    }
                    $dwDays = $dwSum = 0;
                    $oldWeek = doubleWeek($y, $m, $i);
                }
                $a = getKoeff($userId, date('o.W', mktime(0, 0, 0, $m, $i, $y)));
                if ($a > 0) {
                    $sum += $a;
                    $qSum += $a;
                    $dwSum += $a;
                    $qDays++;
                    $qty++;
                    $dwDays++;
                }
            }
            if ($qty > 0) {
                //				printf("%04d-%02d sum: %d\n",$y,$m,$sum);
                setWeight($userId, sprintf("%04d-%02d", $y, $m), $sum / $qty);
            }
        }
        if ($qDays > 0) {
            setWeight($userId, sprintf("Q%04d-%d", $y, $oldQuarter), $qSum / $qDays, 'q');
        }
    }
    if ($dwDays > 0) {
        setWeight($userId, sprintf("D%s", $oldWeek), $dwSum / $dwDays, 'dw');
    }
}
Esempio n. 2
0
    $a++;
}
addone($a);
echo $a . '<br />';
addone($a);
echo $a . '<br />';
addone($a);
echo $a . '<br />';
function quarter()
{
    $b = 1600;
    echo $b / 4 . '<br />';
}
quarter();
quarter();
quarter();
function quarte()
{
    static $b = 1600;
    //$b=1600;static $b;--all 0 | static $b;$b=1600;--all 400
    $b = $b / 4;
    echo $b . '<br />';
}
quarte();
quarte();
quarte();
quarte();
quarte();
$b = 400;
//no matter
quarte();