Пример #1
0
 function index()
 {
     $this->load->model("comm_model", "comm");
     $content = file_get_contents("./csv/Ac Motors.csv");
     $content = str_replace(array("\r\n", "\r"), "\n", $content);
     $arrcontent = explode("\n", $content);
     foreach ($arrcontent as $k => $v) {
         $attrs = explode(",", $v);
         if ($k == 0) {
             $catname = $attrs[0];
         } else {
             foreach ($attrs as $j => $a) {
                 if (empty($a)) {
                     continue;
                 }
                 if ($j == 0) {
                     $mattrs[$catname][$attrs[0]] = array();
                 } else {
                     $mattrs[$catname][$attrs[0]][] = $a;
                 }
             }
         }
     }
     dump($mattrs);
     die;
     foreach ($mattrs as $k => $m) {
         $catname = $k;
         dump($catname);
         $findcat = $this->comm->find("category", array("catname" => $catname));
         $catid = $findcat['catid'];
         dump($findcat);
         if (!$findcat) {
             dump("catname is not exist");
             die;
         } else {
             if ($findcat['parentid'] != 0) {
                 dump("catname is not parent");
                 die;
             }
         }
         $i = 0;
         foreach ($m as $option => $value) {
             $findoption = $this->comm->find("category_option", array("catid" => $findcat['catid'], "name" => $option));
             if ($findoption) {
                 $oid = $findoption['oid'];
             } else {
                 $oid = $this->comm->create("category_option", array("catid" => $findcat['catid'], "name" => $option));
             }
             foreach ($value as $v) {
                 $findov = $this->comm->find("category_option_value", array("oid" => $oid, "value" => $v));
                 if (!$findov) {
                     $this->comm->create("category_option_value", array("oid" => $oid, "value" => $v));
                 } else {
                     dump($option . " exsit");
                 }
             }
             if ($i < 3) {
                 $this->comm->update("category_option", array("catid" => $findcat['catid'], "oid" => $oid), array("required" => 1, "listorder" => $i));
             } else {
                 $this->comm->update("category_option", array("catid" => $findcat['catid'], "oid" => $oid), array("required" => 2, "listorder" => $i));
             }
             $i++;
         }
     }
     /*
     foreach($mattrs as $k => $m){
     	$catname = $k;
     	dump($catname);
     	$findcat = $this->comm->find("category",array("catname"=>$catname));
     	dump($findcat);
     	if(!$findcat){
     		dump("catname is not exist");
     		die();
     	}else{
     		if($findcat['parentid']!=0){
     			dump("catname is not parent");
     			die();
     		}
     		
     	}
     	
     	
     	
     	foreach($m as $option => $value){
     		$findoption = $this->comm->find("category_option",array("catid"=>$findcat['catid'],"name"=>$option));
     		//dump($findoption);
     		if($findoption){
     			$findov = $this->comm->find("category_option_value",array("oid"=>$findoption['oid'],"value"=>$option));
     			if(!$findov){
     				$this->comm->create("category_option_value",array("oid"=>$findoption['oid'],"value"=>$option));
     			}else{
     				dump($option." exsit");
     			}
     		}
     		
     		
     		$findoption = $this->comm->find("category_option",array("catid"=>$findcat['catid'],"name"=>$option));
     		dump($findoption);
     		
     		if(!$findoption){
     			dump("Create");
     			die();
     			//$this->comm->create("category_option")
     		}else{
     			if($findoption['required'] and !empty($findoption['value'])){
     				dump("already option added");
     				die();
     			}else{
     				dump("update");
     				
     				$values = implode("||",$value);
     				$this->comm->update("category_option",array("catid"=>$findcat['catid'],"oid"=>$findoption['oid']),array("required"=>1,"value"=>$values));
     			}
     		}
     		
     	}
     		
     }
     */
     $option = array();
     foreach ($mattrs[$catname] as $k => $m) {
         if (count($option) < 3) {
             $option[] = $k;
         }
     }
     $this->load->helper("comb");
     global $combres;
     comb($option, 1);
     $one = $combres;
     comb($option, 2);
     comb($option, 3);
     //dump($combres);
     dump($one);
     $all = $combres;
     //dump($all);
     foreach ($one as $k => $v) {
         //$v = str_replace(",","",$v);
         foreach ($mattrs[$catname][$v] as $value) {
             $match_one[] = $value;
             $find = $this->comm->find("attrtag", array("tag" => $value, "catid" => $catid));
             if (!$find) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $v));
                 $ov = $this->comm->find("category_option_value", array("value" => $value, "oid" => $op['oid']));
                 $linkurl = $ov['oid'] . "-" . $ov['id'];
                 $this->comm->create("attrtag", array("tag" => $value, "catid" => $catid, "linkurl" => $linkurl));
             }
         }
         unset($all[$k]);
     }
     dump($match_one);
     dump("===========================取一个" . count($match_one) . "=======================");
     dump($all);
     $total = 0;
     foreach ($all as $k => $v) {
         $match_all = array();
         //$v = substr($v,1);
         $option = explode(",", $v);
         //dump($option);
         foreach ($option as $o) {
             $match_all[] = $mattrs[$catname][$o];
             //$array[] = $mattrs[$catname][$o];
         }
         $result = combination($match_all);
         $total += count($result);
         foreach ($result as $res) {
             $linkurl = array();
             $tag = array();
             foreach ($res as $j => $r) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $option[$j]));
                 $ov = $this->comm->find("category_option_value", array("value" => $r, "oid" => $op['oid']));
                 $linkurl[] = $ov['oid'] . "-" . $ov['id'];
                 $tag[] = $r;
             }
             $linkurl = implode("_", $linkurl);
             $tag = implode(" ", $tag);
             $find = $this->comm->find("attrtag", array("tag" => $tag, "catid" => $catid));
             if (!$find) {
                 $this->comm->create("attrtag", array("tag" => $tag, "catid" => $catid, "linkurl" => $linkurl));
             }
         }
     }
     dump($total);
 }
Пример #2
0
            $one = $pair[0];
            $two = $pair[1];
            $query = "SELECT fIndex, n FROM pairsList WHERE studentID1={$one} AND studentID2={$two}";
            $result = $db->query($query) or die($db->error);
            $row = $result->fetch_assoc();
            $tables[$i]->tablevalue += $row["fIndex"] + $row["n"] * $row["n"] * $row["n"];
        }
    }
    //find the difference values
    $sum = 0.0;
    for ($i = 0; $i < $numTables; $i++) {
        for ($j = $i + 1; $j < $numTables; $j++) {
            $sum += abs($tables[$i]->tablevalue - $tables[$j]->tablevalue);
        }
    }
    $vValue = $sum / combination($numTables, 2);
    $threshold += $planID * $planID * $planID / 700000;
} while ($vValue > $threshold);
//insert data into database
$query = "INSERT INTO planList (expiry, vValue) VALUES (DATE_ADD(CURDATE(),INTERVAL 7 DAY),{$vValue})";
//horrible code here, don't kill me pls
$db->query($query) or die($db->error);
$query = "INSERT INTO studentPlan (studentID, planID, tableNum) VALUES ";
$havecomma = false;
for ($i = 0; $i < $numTables; $i++) {
    foreach ($tables[$i]->students as $person) {
        if ($havecomma) {
            $query .= ",";
        }
        $query .= "({$person}, {$planID}, {$i})";
        $havecomma = true;
Пример #3
0
function max_niuji_has_dawang($arr)
{
    //3张能组成牛,一定是牛牛
    $max_niuji = max_niuji_in_arr($arr, 3);
    if (intval($max_niuji) > 1000) {
        $max_niuji = "1010";
        return $max_niuji;
    }
    //2张能组成牛,一定是牛牛
    $max_niuji = max_niuji_in_arr($arr, 2);
    if (intval($max_niuji) > 1000) {
        $max_niuji = "1010";
        return $max_niuji;
    }
    //无法组成牛牛的情况下,只能组成牛
    $res = combination($arr, 2);
    foreach ($res as $value) {
        $left = explode(",", $value);
        $niuji = pai_sum_array($left);
        if ($niuji > $max_niuji) {
            $max_niuji = $niuji;
        }
    }
    $max_niuji = "100" . $max_niuji;
    return $max_niuji;
}
Пример #4
0
 function index()
 {
     ini_set('max_execution_time', 0);
     ini_set('memory_limit', '14048M');
     $this->load->model("comm_model", "comm");
     $catid = $this->uri->rsegment(3, 0);
     $mattrs = array();
     $category = $this->comm->find("category", array("catid" => $catid));
     if (!$category) {
         dump($catid);
         die;
     }
     if ($category['collect']) {
         dump("already make");
         die;
     }
     $catid = $category['catid'];
     $catname = $category['catname'];
     $options = $this->comm->findAll("category_option", array("catid" => $catid, "required" => 1), "listorder asc");
     if (!$options) {
         dump($catid);
         //$this->comm->update("category",array("catid"=>$catid),array("collect"=>1));
         //$redirect_cat = $this->comm->find("category","parentid=0 and collect=0","catid asc");
         //dump($redirect_cat);
         //echo "<script>location.href='/process/readattrs/index/".$redirect_cat['catid']."'</script>";
         die("not attrs");
     }
     foreach ($options as $op) {
         $ov = $this->comm->findAll("category_option_value", array("oid" => $op['oid']));
         foreach ($ov as $v) {
             $mattrs[$category['catname']][$op['name']][] = $v['value'];
         }
     }
     dump($mattrs);
     $option = array();
     foreach ($mattrs[$catname] as $k => $m) {
         //if(count($option)<3){
         $option[] = $k;
         //}
     }
     $this->load->helper("comb");
     global $combres;
     if (count($option) > 4) {
         $combnum = 4;
     } else {
         $combnum = count($option);
     }
     for ($i = 1; $i <= $combnum; $i++) {
         comb($option, $i);
         if ($i == 1) {
             $one = $combres;
         }
     }
     //dump($combres);
     //dump($one);
     $all = $combres;
     //dump($all);
     //die();
     foreach ($one as $k => $v) {
         //$v = str_replace(",","",$v);
         foreach ($mattrs[$catname][$v] as $value) {
             $match_one[] = $value;
             $find = $this->comm->find("attrtag", array("tag" => $value, "catid" => $catid));
             if (!$find) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $v));
                 $ov = $this->comm->find("category_option_value", array("value" => $value, "oid" => $op['oid']));
                 $linkurl = $ov['oid'] . "-" . $ov['id'];
                 $attrs = $ov['oid'] . "|" . $ov['id'];
                 $this->comm->create("attrtag", array("tag" => $value, "catid" => $catid, "catname" => $catname, "attrs" => $attrs, "linkurl" => $linkurl, "num" => 1));
             }
         }
         unset($all[$k]);
     }
     dump($match_one);
     dump("===========================取一个" . count($match_one) . "=======================");
     //dump($all);
     $total = 0;
     foreach ($all as $k => $v) {
         $match_all = array();
         //$v = substr($v,1);
         $option = explode(",", $v);
         //dump($option);
         foreach ($option as $o) {
             $match_all[] = $mattrs[$catname][$o];
             //$array[] = $mattrs[$catname][$o];
         }
         $result = combination($match_all);
         $total += count($result);
         foreach ($result as $res) {
             $linkurl = array();
             $attrs = array();
             $tag = array();
             foreach ($res as $j => $r) {
                 $op = $this->comm->find("category_option", array("catid" => $catid, "name" => $option[$j]));
                 $ov = $this->comm->find("category_option_value", array("value" => $r, "oid" => $op['oid']));
                 $linkurl[] = $ov['oid'] . "-" . $ov['id'];
                 $attrs[] = $ov['oid'] . "|" . $ov['id'];
                 $tag[] = $r;
             }
             $num = count($attrs);
             $linkurl = implode("_", $linkurl);
             $attrs = implode(",", $attrs);
             $tag = implode(" ", $tag);
             $this->db->query("lock tables wl_attrtag write");
             $find = $this->comm->find("attrtag", array("tag" => $tag, "catid" => $catid));
             if (!$find) {
                 $this->comm->create("attrtag", array("tag" => $tag, "catid" => $catid, "catname" => $catname, "attrs" => $attrs, "linkurl" => $linkurl, "num" => $num));
             }
             $this->db->query("unlock tables");
         }
         //释放内存
         unset($result);
     }
     dump($total);
     $this->comm->update("category", array("catid" => $catid), array("collect" => 1));
     //$redirect_cat = $this->comm->find("category","parentid=207 and collect=0","listorder ASC");
     //dump($redirect_cat);
     //echo "<script>location.href='/process/readattrs/index/".$redirect_cat['catid']."'</script>";
 }