/** * Akce pro přiřazení rule setu ke zvolenému mineru * @param int $miner * @param int $ruleSet * @throws BadRequestException * @throws ForbiddenRequestException */ public function actionSetRuleSet($miner, $ruleSet) { $miner = $this->findMinerWithCheckAccess($miner); $ruleSet = $this->ruleSetsFacade->findRuleSet($ruleSet); $miner->ruleSet = $ruleSet; $this->minersFacade->saveMiner($miner); $this->sendJsonResponse(['state' => 'ok', 'miner' => $miner->minerId, 'ruleset_id' => $ruleSet->ruleSetId]); }
/** * Akce pro odebrání celého obsahu rule clipboard z konkrétního rulesetu * @param int $id * @param int $miner * @param int $ruleset * @param string $returnRules ='' - IDčka oddělená čárkami, případně jedno ID * @throws ForbiddenRequestException * @throws BadRequestException */ public function actionRemoveRulesFromRuleSet($id = null, $miner, $ruleset, $returnRules = '') { //načtení dané úlohy a zkontrolování přístupu k mineru $task = $this->tasksFacade->findTask($id); $this->checkMinerAccess($task->miner); $ruleIdsArr = explode(',', str_replace(';', ',', $returnRules)); //najití RuleSetu a kontroly $ruleSet = $this->ruleSetsFacade->findRuleSet($ruleset); $this->ruleSetsFacade->checkRuleSetAccess($ruleSet, $this->user->id); //přidání pravidel $this->ruleSetsFacade->removeAllRuleClipboardRulesFromRuleSet($task, $ruleSet); $result = array(); if (count($ruleIdsArr) > 0) { foreach ($ruleIdsArr as $ruleId) { try { $rule = $this->rulesFacade->findRule($ruleId); //TODO optimalizovat kontroly... $ruleTask = $rule->task; if ($ruleTask->taskId != $task->taskId) { throw new InvalidArgumentException(); } if ($ruleTask->miner->minerId != $miner) { throw new InvalidArgumentException(); } $result[$rule->ruleId] = $rule->getBasicDataArr(); } catch (\Exception $e) { continue; } } } $this->sendJsonResponse(array('rules' => $result)); }
/** * Akce pro odebrání všech pravidel z rulesetu * @param int $id */ public function actionRemoveAllRules($id) { //najití RuleSetu a kontroly $ruleSet = $this->ruleSetsFacade->findRuleSet($id); $this->ruleSetsFacade->checkRuleSetAccess($ruleSet, $this->user->id); //smazání $this->ruleSetsFacade->removeAllRulesFromRuleSet($ruleSet); $this->sendJsonResponse(['state' => 'ok']); }
/** * Akce vracející data description a konfiguraci pro EasyMiner UI * @param int $id_dm * @param int $miner * @throws ForbiddenRequestException */ public function actionGetData($id_dm, $miner) { if (empty($miner)) { $miner = $id_dm; } //------------------------------------------------------------------------------------------------------------------ $miner = $this->findMinerWithCheckAccess($miner); $minerType = $miner->type; $FLPathElement = 'FLPath_' . Strings::upper($minerType); //------------------------------------------------------------------------------------------------------------------ #region připravení informací pro UI - s odděleným připravením DataDictionary $dataDescriptionPMML = null; $dataParser = new DataParser($dataDescriptionPMML, $this->config->{$FLPathElement}, $this->config->FGCPath, null, null, $this->translator->getLang()); $dataParser->loadData(); $responseContent = $dataParser->parseData(); $user = $this->getCurrentUser(); $responseContent['DD'] = ['dataDictionary' => $this->datasourcesFacade->exportDataDictionaryArr($miner->datasource, $user, $rowsCount), 'transformationDictionary' => $this->metasourcesFacade->exportTransformationDictionaryArr($miner->metasource, $user), 'recordCount' => $rowsCount]; #endregion připravení informací pro UI - s odděleným připravením DataDictionary uksort($responseContent['DD']['transformationDictionary'], function ($a, $b) { return strnatcasecmp($a, $b); }); uksort($responseContent['DD']['dataDictionary'], function ($a, $b) { return strnatcasecmp($a, $b); //return strnatcasecmp(mb_strtolower($a,'utf-8'),mb_strtolower($b,'utf-8')); }); $responseContent['status'] = 'ok'; $responseContent['miner_type'] = $miner->type; $responseContent['miner_name'] = $miner->name; if ($miner->ruleSet) { $ruleSet = $miner->ruleSet; } else { $ruleSet = $this->ruleSetsFacade->saveNewRuleSetForUser($miner->name, $this->getCurrentUser()); $miner->ruleSet = $ruleSet; $this->minersFacade->saveMiner($miner); } $responseContent['miner_ruleset'] = ['id' => $ruleSet->ruleSetId, 'name' => $ruleSet->name]; $responseContent['miner_config'] = $miner->getExternalConfig(); $this->sendJsonResponse($responseContent); }
/** * Funkce pro nalezení rule setu dle zadaného ID a kontrolu oprávnění aktuálního uživatele pracovat s daným rule setem * @param int $ruleSetId * @return RuleSet * @throws \Nette\Application\BadRequestException */ private function findRuleSetWithCheckAccess($ruleSetId) { try { /** @var RuleSet $ruleSet */ $ruleSet = $this->ruleSetsFacade->findRuleSet($ruleSetId); } catch (EntityNotFoundException $e) { $this->error('Requested rule set was not found.'); return null; } //kontrola možnosti pracovat s daným rule setem $this->ruleSetsFacade->checkRuleSetAccess($ruleSet, $this->getCurrentUser()->userId); return $ruleSet; }
/** * Funkce pro kontrolu vstupů pro aktualizaci rule setu * @param int $id */ public function validateUpdate($id) { $fieldName = $this->input->field('name'); $fieldName->addRule(IValidator::MIN_LENGTH, 'Minimal length of name is %d characters!', 3)->addRule(IValidator::MAX_LENGTH, 'Maximal length of name is %d characters!', 100)->addRule(IValidator::REQUIRED, 'Name is required!'); if ($user = $this->getCurrentUser()) { $fieldName->addRule(IValidator::CALLBACK, 'RuleSet with this name already exists!', function ($value) use($user, $id) { try { /** @noinspection PhpUndefinedFieldInspection */ $this->ruleSetsFacade->checkUniqueRuleSetNameByUser($value, $user, $id); return true; } catch (\Exception $e) { } return false; }); } $this->input->field('description')->addRule(IValidator::MAX_LENGTH, 'Maximal length of description is %d characters!', 200); }
/** * Akce pro vyhodnocení klasifikace * @SWG\Get( * tags={"Evaluation"}, * path="/evaluation/classification", * summary="Evaluate classification model", * produces={"application/json","application/xml"}, * security={{"apiKey":{}},{"apiKeyHeader":{}}}, * @SWG\Parameter( * name="scorer", * description="Scorer type", * required=true, * type="string", * in="query", * enum={"easyMinerScorer","modelTester"} * ), * @SWG\Parameter( * name="task", * description="Task ID", * required=false, * type="integer", * in="query" * ), * @SWG\Parameter( * name="ruleSet", * description="Rule set ID", * required=false, * type="integer", * in="query" * ), * @SWG\Parameter( * name="datasource", * description="Datasource ID (if not specified, task datasource will be used)", * required=false, * type="integer", * in="query" * ), * @SWG\Response( * response=200, * description="Evaluation result", * @SWG\Schema( * ref="#/definitions/ScoringResultResponse" * ) * ), * @SWG\Response( * response=400, * description="Invalid API key supplied", * @SWG\Schema(ref="#/definitions/StatusResponse") * ) * ) * * @throws BadRequestException * @throws NotImplementedException */ public function actionClassification() { $this->setXmlMapperElements('classification'); $inputData = $this->getInput()->getData(); /** @var IScorerDriver $scorerDriver */ if (empty($inputData['scorer'])) { $scorerDriver = $this->scorerDriverFactory->getDefaultScorerInstance(); } else { $scorerDriver = $this->scorerDriverFactory->getScorerInstance($inputData['scorer']); } if (!empty($inputData['datasource'])) { try { $datasource = $this->datasourcesFacade->findDatasource(@$inputData['datasource']); if (!$this->datasourcesFacade->checkDatasourceAccess($datasource, $this->getCurrentUser())) { throw new \Exception(); } } catch (\Exception $e) { throw new BadRequestException("Requested data source was not found!"); } } elseif (!empty($inputData['task'])) { $task = $this->findTaskWithCheckAccess($inputData['task']); $datasource = $task->miner->datasource; } else { throw new BadRequestException("Data source was not specified!"); } if (!empty($inputData['task'])) { if (empty($task)) { $task = $this->findTaskWithCheckAccess($inputData['task']); } $result = $scorerDriver->evaluateTask($task, $datasource)->getCorrectIncorrectDataArr(); $result['task'] = $task->getDataArr(false); } elseif (!empty($inputData['ruleSet'])) { $ruleSet = $this->ruleSetsFacade->findRuleSet($inputData['ruleSet']); //TODO kontrola oprávnění k rule setu $result = $scorerDriver->evaluateRuleSet($ruleSet, $datasource)->getDataArr(); $result['ruleSet'] = $ruleSet->getDataArr(); } else { throw new BadRequestException("No task or rule set found!"); } $this->resource = $result; $this->sendResource(); }
/** * Funkce pro kontrolu vstupů pro vytvoření nového mineru */ public function validateCreate() { $currentUser = $this->getCurrentUser(); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->input->field('name')->addRule(IValidator::REQUIRED, 'Name is required!'); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->input->field('type')->addRule(IValidator::REQUIRED, 'Miner type is required!'); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->input->field('datasourceId')->addRule(IValidator::REQUIRED, 'Datasource ID is required!')->addRule(IValidator::CALLBACK, 'Requested datasource was not found, or is not accessible!', function ($value) use($currentUser) { try { $this->datasource = $this->datasourcesFacade->findDatasource($value); if ($this->datasourcesFacade->checkDatasourceAccess($this->datasource, $currentUser)) { //kontrola dostupnosti kompatibilního mineru s vybraným datasource $availableMinerTypes = $this->minersFacade->getAvailableMinerTypes($this->datasource->type); return !empty($availableMinerTypes[$this->getInput()->getData()['type']]); } else { return false; } } catch (\Exception $e) { return false; } }); /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->input->field('ruleSetId')->addRule(IValidator::CALLBACK, 'Requested rule set was not found, or is not accessible!', function ($value) use($currentUser) { if (empty($value)) { return true; } try { $this->ruleSet = $this->ruleSetsFacade->findRuleSet($value); $this->ruleSetsFacade->checkRuleSetAccess($this->ruleSet, $currentUser); return true; } catch (\Exception $e) { return false; } }); }