예제 #1
0
 /**
  * @param string    $openFormula
  * @param integer   $currentSheetIndex
  * @param string[]  $sheetsNames
  * @param integer[] $cellCoordinates
  * @return Formula
  */
 public static function parse($openFormula, $currentSheetIndex, $sheetsNames, $cellCoordinates)
 {
     $formula = new Formula();
     $openFormula = self::cleanOdsFormula($openFormula);
     $lexicon = self::generateLexicon($openFormula);
     $formulaElements = self::lexer($openFormula, $lexicon);
     $cellDependencies = [];
     $offset = 0;
     foreach ($formulaElements as $key => $formula_element) {
         $temp = str_split($formula_element);
         if ($temp[0] == "[") {
             // If element starts with an "[" it's a range reference
             $external_ref = "file:";
             if (stripos($formula_element, $external_ref) === false) {
                 $formula_element = str_replace(array('[', ']'), '', $formula_element);
                 $range_element = explode(":", $formula_element, 2);
                 if (count($range_element) == 2) {
                     // If RANGE of dimension 2 (more than 1 cell)
                     $head = self::referenceToCoordinates($range_element[0], $currentSheetIndex, $sheetsNames);
                     $tail = self::referenceToCoordinates($range_element[1], $currentSheetIndex, $sheetsNames);
                     $range_token = "[" . implode(',', $head) . "],[" . implode(',', $tail) . "]";
                     for ($i = 0; $i <= $tail[1] - $head[1]; $i++) {
                         for ($j = 0; $j <= $tail[2] - $head[2]; $j++) {
                             $cS = $head[0];
                             $cR = $head[1] + $i;
                             $cC = $head[2] + $j;
                             $cellDependencies[] = array($cS, $cR, $cC);
                         }
                     }
                 } else {
                     // Simple RANGE, i.e one cell
                     $element = self::referenceToCoordinates($range_element[0], $currentSheetIndex, $sheetsNames);
                     $dep_sheet = intval($element[0]);
                     $dep_row = intval($element[1]);
                     $dep_col = intval($element[2]);
                     $cellDependencies[] = array($dep_sheet, $dep_row, $dep_col);
                     $range_token = "[" . implode(',', $element) . "]";
                 }
                 $replacement = array("RANGE", "(", $range_token, ")");
                 // Remove a portion of the array and replace it with something else
                 array_splice($formulaElements, $key + $offset, 1, $replacement);
                 $offset += count($replacement) - 1;
             }
         }
     }
     $formula->setElements($formulaElements);
     //        $formula->dependances = array_unique($cellDependencies);
     $formula->dependances = $cellDependencies;
     $formula->ext_formula_dependances = array_intersect($formulaElements, WebAppConfiguration::externalFunctionDictionary());
     $formula->cell_coord = $cellCoordinates;
     return $formula;
 }
예제 #2
0
 public function store()
 {
     $barang_id = Input::get('barang_id');
     $bahan = Input::get('bahan');
     foreach ($bahan as $key => $b) {
         if ($b['id'] != null) {
             $formula = new Formula();
             $formula->barang_id = $barang_id;
             $formula->formula = $b['id'];
             $formula->qty = $b['qty'];
             $formula->save();
         }
     }
     return Redirect::to('admin/formulas')->with('message', 'berhasil menambahkan formula');
 }
예제 #3
0
파일: Score.php 프로젝트: xw716825/git_back
 /**
  * 获取大学录取概率
  * @param int $pro_code 省份code
  * @param int $line_wl 文理
  * @param int $score 考分
  * @return array
  */
 public function getChance($pro_code, $line_wl, $score, $col_id)
 {
     //获取当前年份的省控线
     $year = date('Y');
     $sql = 'select line_batch,line_score from line where line_year=? and line_wl=? and pro_code=?';
     $line = $this->fetchAll($sql, [$year, $line_wl, $pro_code]);
     if (!$line) {
         return json_encode(['status' => 404, 'message' => '并无当前省份省控线']);
     }
     //选择批次
     if ($score >= $line[0]['line_score'] + 20) {
         $batch = ' p1.col_sco_batch=1';
     } elseif ($score < $line[0]['line_score'] + 20 && $score >= $line[0]['line_score'] - 10) {
         $batch = ' p1.col_sco_batch<=2 and col_sco_batch>=1';
     } elseif ($score < $line[0]['line_score'] - 10 && $score >= $line[1]['line_score'] + 10) {
         $batch = ' p1.col_sco_batch=2';
     } else {
         $batch = ' p1.col_sco_batch>2';
     }
     //获取大学线差,平均分,难度,最高分,最低分
     $year -= 6;
     $sql = "select p1.col_sco_batch,p1.col_sco_year,p1.col_sco_diff,p1.col_sco_avg,p1.col_sco_max,p1.col_sco_min,p2.col_degree\r\n                from college_score p1\r\n                inner join college p2 on p1.col_id=p2.col_id\r\n                where p1.col_sco_avg>0 and p1.col_sco_diff>=0 and {$batch} and p1.col_sco_wl=? and p1.pro_code=? and p1.col_id=? and p1.col_sco_year>{$year} order by col_sco_batch asc";
     $original = $this->fetchAll($sql, [$line_wl, $pro_code, $col_id]);
     if (!$original) {
         return json_encode(['status' => 404, 'message' => '无当前学校数据']);
     }
     //格式化数据,将平均分,最高分,最低分,线差,年份单独组成数组,以批次划分
     $info = [];
     foreach ($original as $val) {
         if ($val['col_sco_batch'] > 2) {
             $val['col_sco_batch'] = 2;
         }
         $info[$val['col_sco_batch']]['avg'][] = $val['col_sco_avg'];
         //平均分
         $info[$val['col_sco_batch']]['max'][] = $val['col_sco_max'];
         //最高分
         $info[$val['col_sco_batch']]['min'][] = $val['col_sco_min'];
         //最低分
         $info[$val['col_sco_batch']]['diff'][] = $val['col_sco_diff'];
         //线差
         $info[$val['col_sco_batch']]['year'][] = $val['col_sco_year'];
         //年份
     }
     //计算概率
     $data = ['score' => $info];
     foreach ($info as $key => $val) {
         foreach ($line as $v) {
             if ($key == $v['line_batch']) {
                 $diff = \Formula::_singleton()->probability($score, $v['line_score'], $original[0]['col_degree'], $val['diff']);
                 //差值概率
                 $avg = \Formula::_singleton()->probability($score, $v['line_score'], $original[0]['col_degree'], $val['avg'], false);
                 //平均数概率
                 $probable = number_format(($diff * 0.9 + $avg * 0.1) * 100, 2, '.', '');
                 //总概率
                 $data['probable'][] = $probable > 100 ? 100 : $probable;
             }
         }
     }
     return json_encode(['status' => 200, 'data' => $data]);
 }
예제 #4
0
 public static function _singleton()
 {
     if (!self::$_singleton instanceof Formula) {
         self::$_singleton = new self();
     }
     return self::$_singleton;
 }
예제 #5
0
 function parse($input)
 {
     if (empty($input)) {
         return $input;
     }
     if ($this->parsing == true) {
         $parser = end(self::$spareParsers);
         if (!empty($parser) && $parser->parsing == false) {
             $result = $parser->parse($input);
         } else {
             self::$spareParsers[] = $parser = self::initSimpleJson($this->spreadsheets, $this->formulas);
             $result = $parser->parse($input);
         }
     } else {
         $this->parsing = true;
         $result = parent::parse($input);
         $this->parsing = false;
     }
     return $result;
 }
예제 #6
0
 function can_view_formula_as_author(Formula $formula)
 {
     return $formula->view_score($this) > self::author_permissive_view_score_bound();
 }
예제 #7
0
 private function generaEstadoDescanso()
 {
     //Generamos estado tras el descanso
     $params = array('difNiv' => (double) $this->dif_niveles, 'aforoMax' => (double) 0, 'aforoLoc' => (double) $this->aforo_local, 'aforoVis' => (double) $this->aforo_visitante, 'moralLoc' => (double) $this->moral_local, 'moralVis' => (double) $this->moral_visitante, 'ofensLoc' => (double) $this->ofensivo_local, 'ofensVis' => (double) $this->ofensivo_visitante, 'defensLoc' => (double) $this->defensivo_local, 'defensVis' => (double) $this->defensivo_visitante, 'estado' => null);
     $this->estado = Formula::siguienteEstado($params);
     //Aumentamos el turno
     $this->turno++;
 }
 public function make_column($name, $errors)
 {
     foreach (self::$registered as $col) {
         if (strcasecmp($col->formula->name, $name) == 0) {
             return $col;
         }
     }
     if (substr($name, 0, 4) === "edit") {
         return null;
     }
     $formula = new Formula($name);
     if (!$formula->check()) {
         if ($errors && strpos($name, "(") !== false) {
             self::make_column_error($errors, $formula->error_html(), 1);
         }
         return null;
     }
     $fdef = new FormulaPaperColumn("formulax" . (count(self::$registered) + 1), $formula);
     self::register($fdef);
     return $fdef;
 }
예제 #9
0
 /**
  * Simulador de la formula estadistica
  *
  * Crea una vista en la que se muestra el simulador de un partido
  *
  * @param int $dn   diferencia de nivel
  * @param int $am   aforo maximo
  * @param int $al   aforo local
  * @param int $av   aforo visitante
  * @param int $ml   moral local
  * @param int $mv   moral visitinate
  * @param int $ol   ofensiva local
  * @param int $ov   ofensiva visitante
  * @param int $dl   defensa local
  * @param int $dv   defensa visitante
  *
  * @route JugadorNum12/scripts/formula
  * @return void
  */
 public function actionFormula($dn = 0, $am = 0, $al = 0, $av = 0, $ml = 0, $mv = 0, $ol = 0, $ov = 0, $dl = 0, $dv = 0)
 {
     // Creamos el array de parámetros a partir de los datos GET
     $params = array('difNiv' => (double) $dn, 'aforoMax' => (double) $am, 'aforoLoc' => (double) $al, 'aforoVis' => (double) $av, 'moralLoc' => (double) $ml, 'moralVis' => (double) $mv, 'ofensLoc' => (double) $ol, 'ofensVis' => (double) $ov, 'defensLoc' => (double) $dl, 'defensVis' => (double) $dv);
     // Obtenemos los pesos y las probabilidades de todos los estados
     for ($i = -10; $i <= 9; $i++) {
         $params['estado'] = $i == -10 ? null : $i;
         $pesos[$params['estado']] = Formula::pesos($params);
         $probs[$params['estado']] = Formula::probabilidades($params);
     }
     // Calculamos los colores para la tabla
     foreach ($probs as $i => $v) {
         $max = max($v);
         foreach ($v as $ii => $vv) {
             $r = 255;
             $g = 255 - (int) round($vv * 255);
             $b = 255 - (int) round($vv / $max * 255);
             $colors[$i][$ii] = "rgb({$r},{$g},{$b})";
         }
     }
     // Simulamos un partido con todos los estados iniciales
     for ($i = -9; $i <= 9; $i++) {
         $estados[$i] = array($i);
         $params['estado'] = $i;
         for ($t = 0; $t < 12; $t++) {
             $estSig = Formula::siguienteEstado($params);
             $params['estado'] = $estSig;
             $estados[$i][] = $estSig;
         }
     }
     foreach ($estados as $i => $v) {
         foreach ($v as $ii => $vv) {
             if ($vv < 0) {
                 $nc = (int) (255 * (1 + $vv / 10));
                 $c = "rgb(255,{$nc},{$nc})";
             } else {
                 if ($vv > 0) {
                     $nc = (int) (255 * (1 - $vv / 10));
                     $c = "rgb({$nc},{$nc},255)";
                 } else {
                     $c = 'white';
                 }
             }
             $estColors[$i][$ii] = $c;
         }
     }
     // Dibujamos la vista
     unset($params['estado']);
     $this->layout = "main";
     $this->render('formula', array('probs' => $probs, 'pesos' => $pesos, 'colors' => $colors, 'params' => $params, 'estados' => $estados, 'estColors' => $estColors));
 }
예제 #10
0
 private function _search_formula($word, &$qt, $quoted)
 {
     if (preg_match('/\\A[^(){}\\[\\]]+\\z/', $word) && !$quoted && ($result = Dbl::qe("select * from Formula where name=?", $word)) && ($row = $result->fetch_object())) {
         $formula = new Formula($row);
         Dbl::free($result);
     } else {
         $formula = new Formula($word);
     }
     if ($formula->check()) {
         $qt[] = new SearchTerm("formula", self::F_XVIEW, $formula);
     } else {
         $this->warn($formula->error_html());
         $qt[] = new SearchTerm("f");
     }
 }
 function saveToItemId($data, $orderIndex, $visitIndex, $productViewIndex, $cartIndex, $days, $keyword)
 {
     $dbObject = new DbObject();
     foreach ($data->breakdown as $itemId) {
         if (stripos($itemId->name, "other") === false && stripos($itemId->name, "Unspecified") === false && stripos($itemId->name, "Others") === false) {
             $id_item_id = md5($itemId->name);
             $dbObject->insert("item_id", array("id" => $itemId->name));
             //foreach($itemId->counts as $metric){
             $metrices = $itemId->counts;
             $itemIdKeyword = array("id" => md5($keyword['id'] . $id_item_id), "id_item_id" => $itemId->name, "id_keyword" => $keyword['id'], "orders" => $metrices[$orderIndex], "visits" => $metrices[$visitIndex], "product_views" => $metrices[$productViewIndex], "carts" => $metrices[$cartIndex]);
             $score = Formula::getScore($keyword, $itemIdKeyword);
             if ($score === false) {
                 continue;
             }
             $dataarray = array_merge($itemIdKeyword, array('score' => $score));
             $dbObject->insert($days . "_days_item_id_ae", $dataarray);
         }
     }
 }
 private function _combine_data($result)
 {
     global $Me;
     $data = [];
     if ($this->fx->result_format() === Fexpr::FREVIEWER) {
         $this->_prepare_reviewer_color($Me);
     }
     $fxf = $this->fx->compile_function($Me);
     list($fytrack, $fycombine) = $this->fy->compile_combine_functions($Me);
     $reviewf = null;
     if ($this->fx->needs_review() || $this->fy->datatypes) {
         $reviewf = Formula::compile_indexes_function($Me, ($this->fx->needs_review() ? $this->fx->datatypes : 0) | $this->fy->datatypes);
     }
     while ($prow = PaperInfo::fetch($result, $Me)) {
         if (!$Me->can_view_paper($prow)) {
             continue;
         }
         $queries = $this->papermap[$prow->paperId];
         $s = $ps = $this->_paper_style($prow);
         $revs = $reviewf ? $reviewf($prow, $Me) : [null];
         foreach ($revs as $rcid) {
             if (($x = $fxf($prow, $rcid, $Me)) === null) {
                 continue;
             }
             if ($ps === self::REVIEWER_COLOR) {
                 $s = get($this->reviewer_color, $d[0]) ?: "";
             }
             $d = [$x, $fytrack($prow, $rcid, $Me), $prow->paperId, $s];
             if ($rcid && ($o = $prow->review_ordinal($rcid))) {
                 $d[2] .= unparseReviewOrdinal($o);
             }
             foreach ($queries as $q) {
                 $q && ($d[4] = $q);
                 $data[] = $d;
             }
         }
     }
     $is_sum = $this->fy->is_sum();
     usort($data, "FormulaGraph::barchart_compare");
     $ndata = [];
     for ($i = 0; $i != count($data); $i = $j) {
         $d = [$data[$i][0], [$data[$i][1]], [$data[$i][2]], $data[$i][3], get($data[$i], 4)];
         for ($j = $i + 1; $j != count($data) && $data[$j][0] == $d[0] && get($data[$j], 4) == $d[4] && (!$is_sum || $data[$j][3] == $d[3]); ++$j) {
             $d[1][] = $data[$j][1];
             $d[2][] = $data[$j][2];
             if ($d[3] && $d[3] != $data[$j][3]) {
                 $d[3] = "";
             }
         }
         $d[1] = $fycombine($d[1]);
         if (!$d[4]) {
             array_pop($d);
             $d[3] || array_pop($d);
         }
         $ndata[] = $d;
     }
     return $ndata;
 }