/**
  * @param Task $task
  * @param Datasource $testingDatasource
  * @return ScoringResult
  */
 public function evaluateTask(Task $task, Datasource $testingDatasource)
 {
     $rulesXmlFileName = $task->taskId . '.xml';
     /** @var string $rulesXmlFilePath - cesta souboru s pravidly v XML */
     $rulesXmlFilePath = @$this->params['tempDirectory'] . '/' . $rulesXmlFileName;
     $associationRulesXmlSerializer = new AssociationRulesXmlSerializer($task->rules);
     $rulesXml = $associationRulesXmlSerializer->getXml()->asXML();
     file_put_contents($rulesXmlFilePath, $rulesXml);
     $database = $this->databaseFactory->getDatabaseInstance($testingDatasource->getDbConnection(), $task->miner->user);
     $dbDatasource = $database->getDbDatasource($testingDatasource->dbDatasourceId > 0 ? $testingDatasource->dbDatasourceId : $testingDatasource->dbTable);
     $dbRowsCount = $dbDatasource->size;
     $testedRowsCount = 0;
     /** @var ScoringResult[] $partialResults */
     $partialResults = [];
     //export jednotlivých řádků z DB a jejich otestování
     while ($testedRowsCount < $dbRowsCount) {
         $csv = CsvSerializer::prepareCsvFromDatabase($database, $dbDatasource, $testedRowsCount, self::ROWS_PER_TEST, ';', '"');
         $csvFileName = $testingDatasource->datasourceId . '-' . $testedRowsCount . '-' . self::ROWS_PER_TEST . '.csv';
         /** @var string $csvFilePath - cesta k CSV souboru s částí dat */
         $csvFilePath = @$this->params['tempDirectory'] . '/' . $csvFileName;
         file_put_contents($csvFilePath, $csv);
         $url = $this->serverUrl . '?rulesXml=' . $this->getTempFileUrl($rulesXmlFileName) . '&dataCsv=' . $this->getTempFileUrl($csvFileName);
         //try{
         $response = self::curlRequestResponse($url);
         $xml = simplexml_load_string($response);
         $partialResult = new ScoringResult();
         $partialResult->truePositive = (string) $xml->truePositive;
         $partialResult->falsePositive = (string) $xml->falsePositive;
         $partialResult->rowsCount = (string) $xml->rowsCount;
         $partialResults[] = $partialResult;
         unset($xml);
         //}catch (\Exception $e){
         //  /*ignore error...*/
         //}
         unlink($csvFilePath);
         $testedRowsCount += self::ROWS_PER_TEST;
     }
     //XXX unlink($rulesXmlFilePath);
     //sestavení celkového výsledku
     return ScoringResult::merge($partialResults);
 }
 /**
  * @param int|null $id=null
  * @throws BadRequestException
  * @SWG\Get(
  *   tags={"Datasources"},
  *   path="/datasources/{id}/csv",
  *   summary="Get data source rows as CSV",
  *   produces={"text/csv"},
  *   security={{"apiKey":{}},{"apiKeyHeader":{}}},
  *   @SWG\Parameter(
  *     name="id",
  *     description="Datasource ID",
  *     required=true,
  *     type="integer",
  *     in="path"
  *   ),
  *   @SWG\Parameter(
  *     name="offset",
  *     description="Skip rows",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="limit",
  *     description="Result rows count",
  *     required=false,
  *     type="integer",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="separator",
  *     description="Columns separator",
  *     required=true,
  *     type="string",
  *     in="query"
  *   ),
  *   @SWG\Parameter(
  *     name="enclosure",
  *     description="Enclosure character",
  *     required=false,
  *     type="string",
  *     in="query"
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="CSV"
  *   ),
  *   @SWG\Response(
  *     response=400,
  *     description="Invalid API key supplied",
  *     @SWG\Schema(ref="#/definitions/StatusResponse")
  *   ),
  *   @SWG\Response(response=404, description="Requested datasource was not found.")
  * )
  */
 public function actionReadCsv($id)
 {
     $datasource = $this->findDatasourceWithCheckAccess($id);
     if (!$datasource->available) {
         $this->error('This datasource is not available!');
     }
     /** @var IDatabase $database */
     $database = $this->datasourcesFacade->getDatasourceDatabase($datasource);
     $dbDatasource = $database->getDbDatasource($datasource->dbDatasourceId ? $datasource->dbDatasourceId : $datasource->getDbTable());
     $inputData = $this->getInput()->getData();
     $offset = @$inputData['offset'];
     $limit = @$inputData['limit'] > 0 ? $inputData['limit'] : 10000;
     $separator = @$inputData['separator'] != '' ? $inputData['separator'] : ';';
     $enclosure = @$inputData['enclosure'] != '' ? $inputData['enclosure'] : '"';
     $csv = CsvSerializer::prepareCsvFromDatabase($database, $dbDatasource, $offset, $limit, $separator, $enclosure);
     $httpResponse = $this->getHttpResponse();
     $httpResponse->setContentType('text/csv', 'UTF-8');
     $this->sendResponse(new TextResponse($csv));
 }