Commit 5ca953c7 authored by Vincent Mazenod's avatar Vincent Mazenod
Browse files

add constraint mining consecutive with tids

parent 5722e75b
......@@ -20,4 +20,10 @@ CONSTRAINT_MINING_DISTANT_IDLE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_PATH=bin/sourceCode.R
CONSTRAINT_MINING_CONSECUTIVE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_IDLE_TIMEOUT=60
\ No newline at end of file
CONSTRAINT_MINING_CONSECUTIVE_IDLE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_PATH=bin
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_CMD="/usr/bin/Rscript"
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_R_SCRIPT="source_code_graduel_avec_tid.R"
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_IDLE_TIMEOUT=60
\ No newline at end of file
......@@ -18,4 +18,10 @@ CONSTRAINT_MINING_DISTANT_IDLE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_PATH=bin/sourceCode.R
CONSTRAINT_MINING_CONSECUTIVE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_IDLE_TIMEOUT=60
\ No newline at end of file
CONSTRAINT_MINING_CONSECUTIVE_IDLE_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_PATH=bin
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_CMD="/usr/bin/Rscript"
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_R_SCRIPT="source_code_graduel_avec_tid.R"
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_TIMEOUT=60
CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_IDLE_TIMEOUT=60
\ No newline at end of file
......@@ -20,6 +20,12 @@ parameters:
constraint_mining_consecutive_timeout: '%env(CONSTRAINT_MINING_CONSECUTIVE_TIMEOUT)%'
constraint_mining_consecutive_idle_timeout: '%env(CONSTRAINT_MINING_CONSECUTIVE_IDLE_TIMEOUT)%'
constraint_mining_consecutive_with_tids_path: '%kernel.project_dir%/%env(CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_PATH)%'
constraint_mining_consecutive_with_tids_cmd: '%env(CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_CMD)%'
constraint_mining_consecutive_with_tids_r_script: '%env(CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_R_SCRIPT)%'
constraint_mining_consecutive_with_tids_timeout: '%env(CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_TIMEOUT)%'
constraint_mining_consecutive_with_tids_idle_timeout: '%env(CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_IDLE_TIMEOUT)%'
constraint_mining_distant_path: '%kernel.project_dir%/%env(CONSTRAINT_MINING_DISTANT_PATH)%'
constraint_mining_distant_timeout: '%env(CONSTRAINT_MINING_DISTANT_TIMEOUT)%'
constraint_mining_distant_idle_timeout: '%env(CONSTRAINT_MINING_DISTANT_IDLE_TIMEOUT)%'
......
......@@ -87,6 +87,14 @@ class MiningCommand extends Command {
$memory = intval(memory_get_usage())-intval($memory);
$time = intval(hrtime(true))-intval($time);
$results = unserialize(
file_get_contents(
$this->datasheetsDir.'/'.$job->getOutputDatasheet()
)
);
dump($results);
$output->writeln("<bg=green> ✔ OK</> ".$filePath);
$output->writeln(" * constraint: ".$constraint);
$output->writeln(" * frequency: ".$frequency);
......
......@@ -6,17 +6,21 @@ use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use App\Services\ConstraintMiningConsecutive;
use App\Services\ConstraintMiningConsecutiveWithTids;
use App\Services\ConstraintMiningDistant;
class ConstraintMining
{
public const CONSTRAINT_MINING_CONSECUTIVE = 'consecutive';
public const CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS = 'consecutive_with_tids';
public const CONSTRAINT_MINING_DISTANT = 'distant';
public const CONSTRAINT_MINING_CONSECUTIVE_LABEL = 'Temporal constraint between consecutive objects';
public const CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_LABEL = 'Temporal constraint between consecutive objects with tids';
public const CONSTRAINT_MINING_DISTANT_LABEL = 'Temporal constraint between distant objects';
public static $constraintMiningChoices = [
self::CONSTRAINT_MINING_CONSECUTIVE_LABEL => self::CONSTRAINT_MINING_CONSECUTIVE,
self::CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS_LABEL => self::CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS,
self::CONSTRAINT_MINING_DISTANT_LABEL => self::CONSTRAINT_MINING_DISTANT,
];
......@@ -24,10 +28,12 @@ class ConstraintMining
public function __construct(
ConstraintMIningConsecutive $constraintMiningConsecutive,
ConstraintMIningConsecutiveWithTids $constraintMiningConsecutiveWithTids,
ConstraintMIningDistant $constraintMiningDistant
)
{
$this->constraintMinings[self::CONSTRAINT_MINING_CONSECUTIVE] = $constraintMiningConsecutive;
$this->constraintMinings[self::CONSTRAINT_MINING_CONSECUTIVE_WITH_TIDS] = $constraintMiningConsecutiveWithTids;
$this->constraintMinings[self::CONSTRAINT_MINING_DISTANT] = $constraintMiningDistant;
}
......
<?php
namespace App\Services;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class ConstraintMiningConsecutiveWithTids
{
private $datasheetsDir;
private $binaryPath;
private $timeout;
private $idleTimeOut;
public function __construct(ParameterBagInterface $params)
{
$this->datasheetsDir = $params->get('datasheets_dir');
$this->path = $params->get('constraint_mining_consecutive_with_tids_path');
$this->cmd = $params->get('constraint_mining_consecutive_with_tids_cmd');
$this->rScript = $params->get('constraint_mining_consecutive_with_tids_r_script');
$this->timeout = $params->get('constraint_mining_consecutive_with_tids_timeout');
$this->idleTimeOut = $params->get('constraint_mining_consecutive_with_tids_idle_timeout');
}
public function compute($job)
{
$inputDatasheetPath = $this->datasheetsDir.'/'.$job->getInputDatasheet();
$outputDatasheetPath = $this->datasheetsDir.'/'.$job->getOutputDatasheet();
$line = fgets(fopen($inputDatasheetPath, 'r'));
$job->setColumns(preg_split('/\s+/', trim($line)));
$job->setStartDate(new \DateTime('now'));
$cmd = [
$this->cmd,
$this->rScript,
$inputDatasheetPath,
$job->getFrequency()/100,
$outputDatasheetPath
];
$process = new Process($cmd);
$process->setWorkingDirectory($this->path);
$process->setTimeout($this->timeout);
$process->setIdleTimeout($this->idleTimeOut);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$patterns = array_map(
function ($c) {
$regexp = preg_replace('/(.+)/','/${1}/', $c);
$regexp = str_replace("-", ".", $regexp);
return $regexp;
},
$job->getColumns()
);
$replacements = array_map(
function ($c) {
return $c+1;
},
array_keys($job->getColumns())
);
// structure results as array
$results = Array();
$data = file_get_contents($outputDatasheetPath);
$lines = explode("\n", $data);
$lines = array_slice($lines, 1, -4);
$job->setNbLines(count($lines));
foreach($lines as $k => $line)
{
$results[$k] = Array();
preg_match_all('/([\w\.]+=[\+|\-])/', $line, $columns);
$results[$k]['columns'] = array_map(
function ($c) use ($patterns, $replacements) {
$regexp = preg_replace($patterns, $replacements, $c);
$regexp = str_replace("=", "", $regexp);
return $regexp;
},
$columns[0]
);
$columns = preg_split('/\s+/', trim($line));
$frequency = array_slice($columns, -2, -1)[0];
$tids = array_slice($columns, -3, -2)[0];
$tids = trim(trim(trim($tids, '"'),'{'),'}');
$results[$k]['frequency'] = intval(round($frequency*100));
$results[$k]['tids'] = explode(';', $tids);
}
// store serialized array
file_put_contents($outputDatasheetPath, serialize($results));
$job->setEndDate(new \DateTime('now'));
return $job;
}
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment