/** * Funkce pro definování úlohy na základě dat z EasyMineru * @return TaskState * @throws \Exception */ public function startMining() { #region kontrola zadání úlohy v JSONu $taskSettingsJson = new TaskSettingsJson($this->task->taskSettingsJson); $this->checkRequiredIMs($taskSettingsJson); $this->task->setTaskSettings($taskSettingsJson->getJsonData()); #endregion //serializace zadání v PMML $cloudDriverGuhaPmmlSerializer = $this->xmlSerializersFactory->createCloudDriverGuhaPmmlSerializer($this->task); $cloudDriverGuhaPmmlSerializer->appendTaskSettings(); $pmml = $cloudDriverGuhaPmmlSerializer->getPmml(); //import úlohy a spuštění dolování... $numRequests = 1; sendStartRequest: try { #region pracovní zjednodušený request $response = self::curlRequestResponse($this->getRemoteMinerUrl() . '/mine', $pmml->asXML(), $this->getApiKey(), $responseCode); $taskState = $this->parseResponse($response, $responseCode); #endregion } catch (\Exception $e) { if (++$numRequests < self::MAX_MINING_REQUESTS) { sleep(self::REQUEST_DELAY); goto sendStartRequest; } } if (!empty($taskState)) { return $taskState; } else { throw new \Exception('Task import failed!'); } }
/** * Funkce pro připravení úlohy na základě jednoduchého pole s konfigurací (například přes API) * *@param Miner $miner * @param array $settingsArr * @param Task|null $updateTask=null * @return Task * @throws \InvalidArgumentException */ public function prepareSimpleTask(Miner $miner, $settingsArr, Task $updateTask = null) { //prepare apropriate task... if ($updateTask instanceof Task) { $task = $updateTask; if ($task->miner->minerId != $miner->minerId) { throw new \InvalidArgumentException('Invalid combination of miner and task!'); } } else { $task = new Task(); } //prepare task settings from $settings if (isset($settingsArr['succedent']) && !isset($settingsArr['consequent'])) { $settingsArr['consequent'] = $settingsArr['succedent']; } $taskSettings = ['limitHits' => max(1, @$settingsArr['limitHits']), 'rule0' => ['id' => 0, 'groupFields' => true, 'antecedent' => ['type' => 'cedent', 'connective' => ['id' => 2, 'name' => 'AND', 'type' => 'and'], 'level' => 1, 'children' => $this->prepareSimpleTaskAttributesArr(@$settingsArr['antecedent'])], 'IMs' => $this->prepareSimpleTaskIMsArr(@$settingsArr['IMs']), 'specialIMs' => $this->prepareSimpleTaskSpecialIMsArr(@$settingsArr['specialIMs']), 'succedent' => ['type' => 'cedent', 'connective' => ['id' => 2, 'name' => 'AND', 'type' => 'and'], 'level' => 1, 'children' => $this->prepareSimpleTaskAttributesArr($settingsArr['consequent'])]], 'rules' => 1, 'debug' => false, 'strict' => false, 'taskMode' => 'task', 'taskName' => $settingsArr['name']]; //configure task object $task->miner = $miner; $task->type = $miner->type; $task->name = $settingsArr['name']; $task->state = Task::STATE_NEW; $task->setTaskSettings($taskSettings); return $task; }