コード例 #1
0
ファイル: scorelib.php プロジェクト: piter65/spilldec
function raisedbystudent($uid, &$tvc)
{
    $w1vendortotal = 0;
    $w2vendortotal = 0;
    $w3vendortotal = 0;
    $trk = dbGetObj("select * from tracking where user_id={$uid}");
    $pro = dbGetObj("select * from progress where user_id={$uid}");
    $wk = getfld("week", "users", "where id={$uid}");
    $errors = 0;
    $space = "    ";
    if ($wk > 1) {
        $w1vendorcost = $trk->w1cost;
        $w1vendortotal = 0;
        $w1multiplier = 0;
        if ($w1vendorcost > 0) {
            $w1vendor = $trk->w1vendor;
            $w1vendortotal = 25000;
            //Max amount a vendor can raise
            //determine how much of the max amount the vendor actually raised
            $vnum = getvnum(1, $w1vendor, $w1vendorcost);
            if ($vnum == 1) {
                $w1multiplier = 1.0;
            } else {
                if ($vnum == 2) {
                    $w1multiplier = 0.75;
                } else {
                    if ($vnum == 3) {
                        $w1multiplier = 0.5;
                    } else {
                        if ($vnum == 4) {
                            $w1multiplier = 0.25;
                        } else {
                            $errors++;
                            rerr("tsk1: student id={$uid} {$space} w1vendor=\"{$w1vendor}\" {$space} w1vendorcost={$w1vendorcost}");
                            $w1multiplier = 0.625;
                        }
                    }
                }
            }
            //Determine the adjusted vendortotal
            $w1vendortotal *= $w1multiplier;
            $w1vendortotal -= $w1vendorcost;
        }
        //Dock them for hiring an extra vendor
        if (substr($pro->w1nlc_utt, 0, 1) == "c") {
            $w1vendortotal -= 3000;
        }
    }
    if ($wk > 2) {
        $w2vendorcost = $trk->w2cost;
        $w2vendortotal = 0;
        $w2multiplier = 0;
        if ($w2vendorcost > 0) {
            $w2vendor = $trk->w2vendor;
            $w2vendortotal = 50000;
            //Max amount a vendor can raise
            $vnum = getvnum(2, $w2vendor, $w2vendorcost);
            if ($vnum == 1) {
                $w2multiplier = 1.0;
            } else {
                if ($vnum == 2) {
                    $w2multiplier = 0.75;
                } else {
                    if ($vnum == 3) {
                        $w2multiplier = 0.5;
                    } else {
                        if ($vnum == 4) {
                            $w2multiplier = 0.25;
                        } else {
                            $errors++;
                            rerr("tsk2: student id={$uid} {$space} w2vendor=\"{$w2vendor}\" {$space} w2vendorcost={$w2vendorcost}");
                            $w2multiplier = 0.625;
                        }
                    }
                }
            }
            //Determine the adjusted vendortotal
            $w2vendortotal *= $w2multiplier;
            $w2vendortotal -= $w2vendorcost;
        }
        //Dock them for getting insurance
        if (substr($pro->w2nlc_utt, 0, 1) == "c") {
            $w2vendortotal -= 1500;
        }
    }
    if ($wk > 3) {
        $w3vendorcost = $trk->w3cost;
        $w3vendortotal = -12500;
        $w3vendor = $trk->w3vendor;
        if (substr($w3vendor, 0, 7) == "Ramblin") {
            $w3vendor = substr($w3vendor, 0, 7);
        }
        //if($w3vendor != null)
        //p("$uid - w3vendor = $w3vendor");
        //else
        //p("w3vendor = null");
        if ($w3vendor != "" && $w3vendor != null) {
            $vnum = getvnum(3, $w3vendor, $w3vendorcost);
            // p("  vnum = $vnum");
            if ($vnum < 4) {
                $w3vendortotal = -8000;
                // Arrested wrong vendor
            } else {
                if ($vnum == 4) {
                    $w3vendortotal = 0;
                    // Arrested the correct vendor
                } else {
                    $errors++;
                    rerr("tsk3: student id={$uid} {$space} w3vendor=\"{$w3vendor}'\" {$space} w3vendorcost={$w3vendorcost}");
                }
            }
            //p("&emsp w3vendortotal = $w3vendortotal");
            //p("");
        }
        //Dock them for hiring an assistant
        if (substr($pro->w3nlc_utt, 0, 1) == "c") {
            $w3vendortotal -= 1500;
        }
        dbexec("update tracking set w3cost={$w3vendortotal} where user_id={$uid}");
    }
    // Test Calculation
    /*if(($w1vendortotal+$w2vendortotal+$w3vendortotal) > 0){
    		p("$uid - w1raised = $w1vendortotal - w2raised = $w2vendortotal - w3raised = $w3vendortotal");
    		p("Total = ".($w1vendortotal+$w2vendortotal+$w3vendortotal));
    		}*/
    // ===========================
    $raised = $w1vendortotal + $w2vendortotal + $w3vendortotal;
    dbExec("update tracking set raisedmoney={$raised}, errors={$errors} where user_id=" . $uid);
    setvar($uid, 'RAISED', $raised);
    dbExec("update results set raised={$raised} where uid={$uid}");
    $tvc = $w1vendorcost + $w2vendorcost;
    // xxx currently not used ?
    if ($w1vendor == "") {
        $w1vendor = "no one";
    }
    if ($w2vendor == "") {
        $w2vendor = "no one";
    }
    if ($w3vendor == "") {
        $w3vendor = "no one";
    }
    return $raised;
}
コード例 #2
0
ファイル: a_scoring.php プロジェクト: piter65/spilldec
        echo $cr . "&mdash;";
    }
    ob_flush();
    flush();
}
p("Done");
b("updating category scores for students");
$mcscores = $db->MetaColumnNames("scores", true);
$mcpro = $db->MetaColumnNames("progress", true);
foreach ($mcscores as $cat) {
    if ($cat == "decision") {
        continue;
    }
    $bumps = dbGetAssoc("select decision,{$cat} from scores where {$cat} != 0");
    if (!$bumps) {
        rerr("{$cat}: NO BUMPS FOR CATEGORY?");
        dbExec("update results set {$cat}=0");
        continue;
    }
    $rs = dbExec("select uid from results where {$cat} is NULL");
    $rc = $rs->RecordCount();
    if ($rc > 0) {
        echo "{$cat}: {$rc} records to process: ";
        $j = $rc / 10;
        while ($o = $rs->FetchNextObj()) {
            $cr = $rs->CurrentRow() - 1;
            $pro = progress_rec($o->uid);
            $sc = 0;
            $rslts = array();
            foreach ($mcpro as $col) {
                if ($col == "user_id") {