Skip to content

Commit

Permalink
Merge pull request #21 from lukaskavouras/master
Browse files Browse the repository at this point in the history
Improved classifier, new rocrate modal functionality, new buttons in history view
  • Loading branch information
zagganas authored Mar 5, 2021
2 parents 6f7ee49 + d1f21c1 commit c02e524
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 58 deletions.
26 changes: 4 additions & 22 deletions components/RoCrateModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class ROCrateModal
{
public static function addModal($jobid)
public static function addModal($result,$model, $fields, $software, $soft_type)
{
$software_icon='<i class="fas fa-question-circle" title="Software url to a public repository like dockerhub"></i>';
$publication_icon='<i class="fas fa-question-circle" title="Include the DOI of the publication that describes the experiment"></i>';
Expand All @@ -50,32 +50,14 @@ public static function addModal($jobid)
$download_icon='<i class="fas fa-download"></i>';
$required='<span style="color:red">*</span>';

$history=RunHistory::find()->where(['jobid'=>$jobid])->one();
$software_id=$history->software_id;

$public_url='';
$image_url='';

if($history->type=='job')
{
$software=Software::find()->where(['id'=>$software_id])->one();
$soft_type='Software';
$fields=SoftwareInput::find()->where(['softwareid'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($jobid,$fields);
}
elseif ($history->type=='workflow')
{
$workflow=Workflow::find()->where(['id'=>$software_id])->one();
$soft_type='Workflow';
$fields=WorkflowInput::find()->where(['workflow_id'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Workflow::getRerunFieldValues($jobid,$fields);

}
$history=$result;
$jobid=$history->jobid;


$model=RoCrate::find()->where(['jobid'=>$jobid])->one();
$software_id=$history->software_id;

//print_r($history->jobid);
$disabled_fields=false;
if(!empty($model))
{
Expand Down
47 changes: 45 additions & 2 deletions controllers/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,10 @@ public function actionHistory($crate_id='')
$user=User::getCurrentUser()['username'];






// $inactiveJobs=Software::getInactiveJobs();
// print_r($inactiveJobs);
// exit(0);
Expand All @@ -1072,8 +1076,44 @@ public function actionHistory($crate_id='')
->limit($pagination->limit)
->all();


return $this->render('history',['results'=>$results,'pagination'=>$pagination,'available'=>$available,'available_workflows'=>$available_workflows,'crate_id'=>$crate_id]);
$rocrates=[];
$softwares=[];
$field_matrix=[];
$soft_types=[];
$job_ids=array_column($results, 'jobid');


foreach ($results as $result)
{
if($result->type=='job')
{
$software=Software::find()->where(['id'=>$result->software_id])->one();
$soft_type='Software';
$fields=SoftwareInput::find()->where(['softwareid'=>$result->software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($result->jobid,$fields);


}
elseif ($result->type=='workflow')
{
$workflow=Workflow::find()->where(['id'=>$result->software_id])->one();
$soft_type='Workflow';
$fields=WorkflowInput::find()->where(['workflow_id'=>$result->software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Workflow::getRerunFieldValues($result->jobid,$fields);
}

if ($result->type=='job' || $result->type=='workflow')
{

$rocrates[$result->jobid]=RoCrate::find()->where(['jobid'=>$result->jobid])->one();
$softwares[$result->jobid]=$software;
$field_matrix[$result->jobid]=$fields;
$soft_types[$result->jobid]=$soft_type;
}

}

return $this->render('history',['results'=>$results,'pagination'=>$pagination,'available'=>$available,'available_workflows'=>$available_workflows,'crate_id'=>$crate_id, 'rocrates'=>$rocrates, 'softwares'=>$softwares, 'field_matrix'=>$field_matrix, 'soft_types'=>$soft_types]);
}

public function actionRerun($jobid)
Expand Down Expand Up @@ -1198,6 +1238,9 @@ public function actionRerun($jobid)
->count();
$type=1;




return $this->render('run', ['form_params'=>$form_params, 'name'=>$name,
'version'=>$version, 'jobid'=>'',
'errors'=>'', 'runErrors'=>'', 'podid'=>'', 'machineType'=>'',
Expand Down
3 changes: 3 additions & 0 deletions models/RunHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use Yii;
use yii\db\Query;



/**
* This is the model class for table "run_history".
*
Expand All @@ -45,6 +47,7 @@
*/
class RunHistory extends \yii\db\ActiveRecord
{
public $rocrate_fields=[];
/**
* {@inheritdoc}
*/
Expand Down
16 changes: 13 additions & 3 deletions scheduler_files/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn import svm
from sklearn.feature_selection import VarianceThreshold
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2

import csv
import sys
Expand Down Expand Up @@ -100,7 +103,7 @@
if has_header:
next(reader)

print("=> Reading benign samples file ("+bsamples_file.name+")")
print("=> Reading samples file ("+bsamples_file.name+")")
bsamples_read = 0
for bsample in bsamples_it:
if len(bsample)!=0: #avoid empty lines (separators between different benchmarks)
Expand Down Expand Up @@ -154,7 +157,9 @@
print("=> Normalizing inputs...")
min_max_scaler = preprocessing.MinMaxScaler()
X = min_max_scaler.fit_transform(X)
# X= SelectKBest(chi2, k=1).fit_transform(X, y)
print("\t- Done.")
print(X)

# data set split
print("=> Splitting dataset...")
Expand All @@ -163,7 +168,7 @@

# selecting classification method

class_approaches=["log_regression", "log_regression_cs", "random_forest", "random_forest_cs", "svm"]
class_approaches=["log_regression", "log_regression_cs","svm","random_forest", "random_forest_cs"]


# # grid search for optimal hyperparameters
Expand All @@ -176,7 +181,7 @@
if class_approach == "log_regression" or class_approach == "log_regression_cs": # logistic regression / logistic regression cost sensitive
# params for cross-validation
tuned_parameters = {
"max_iter": [60, 80, 100, 120, 140, 160, 180, 200, 220, 240],
"max_iter": [2000,3000,10000],
"solver": ['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga']
}
# determine classifier
Expand Down Expand Up @@ -222,7 +227,12 @@
best_params[i]=clf.best_params_
best_scores[i]=clf.best_score_

predictions=clf.predict(testX)
i=i+1

for row_index, (input, prediction, label) in enumerate(zip (testX, predictions, testy)):
if prediction != label:
print('Row', row_index, 'has been classified as ', prediction, 'and should be ', label)

best_score=0
best_clf=''
Expand Down
2 changes: 1 addition & 1 deletion scheduler_files/node-selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
X_std = (X - scaler['min']) / (scaler['max'] - scaler['min'])
X= X_std * (1 - 0) + 0


result=model.predict(X)
nodeType=classes[result[0]]

print(nodeType)


Expand Down
69 changes: 39 additions & 30 deletions views/software/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
use app\components\Headers;
use app\components\RoCrateModal;
use app\models\RoCrate;
use app\components\SoftIndexButton;

$this->title="Job history";

echo Html::cssFile('@web/css/software/history.css');
$this->registerJsFile('@web/js/software/history.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
/*
* Users are able to view the name, version, start date, end date, mountpoint
Expand Down Expand Up @@ -102,7 +104,7 @@
*/

$play_icon='<i class="fas fa-play"></i>';
$experiment_icon='<i class="fa fa-flask" aria-hidden="true" style="color:white"></i>';
$experiment_icon='<i class="fa fa-flask" aria-hidden="true"></i>';
$details_icon='<i class="fas fa-eye"></i>';


Expand All @@ -111,11 +113,11 @@
{
if ($res->status=='Complete')
{
$completed='';
$completed=true;
}
else
{
$completed='hidden';
$completed=false;
}
$key=$res['software_id'];
?>
Expand Down Expand Up @@ -165,32 +167,33 @@
<?php
if (empty($res->status))
{

?>
<?= Html::a("$play_icon",[$controller . '/reattach','jobid'=>$res->jobid],['class'=>'btn btn-success btn-md', 'title'=>'Re-attach' ])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-secondary btn-md', 'title'=>'Details'])?>
<?= Html::a("$play_icon",[$controller . '/reattach','jobid'=>$res->jobid],['class'=>'btn btn-run', 'title'=>'Re-attach' ])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-details', 'title'=>'Details'])?>

<?php
}
else
{
?> <?= Html::a("$play_icon",[$controller . '/rerun','jobid'=>$res->jobid],
['class'=>'btn btn-success btn-md', 'title'=>'Re-run'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-secondary btn-md', 'title'=>'Details'])?>
['class'=>'btn btn-run', 'title'=>'Re-run'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-details', 'title'=>'Details'])?>
<?php
$experiment=RoCrate::find()->where(['jobid'=>$res->jobid])->one();
if (!empty($experiment))
$experiment=$rocrates[$res->jobid];

if (!empty($experiment) && $completed)
{
$experiment_icon='<i class="fa fa-flask" aria-hidden="true" style="color:rgb(127, 255, 0)"></i>';
$title='Edit the RO-crate object of this run';
echo Html::a("$experiment_icon", null,
['class'=>"btn btn-experiment-exists experiment", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>'Edit the RO-crate object of this run', 'id'=>"$res->jobid", ]);
}
else
elseif (empty($experiment) && $completed)
{
$experiment_icon='<i class="fa fa-flask" aria-hidden="true" style="color:white"></i>';
$title='Save the run in an RO-crate object, to facilitate the reproducibility of the corresponding experiment';
echo Html::a("$experiment_icon", null,
['class'=>"btn btn-experiment-new experiment", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>'Save the run in an RO-crate object, to facilitate the reproducibility of the corresponding experiment', 'id'=>"$res->jobid", ]);
}
?>
<?= Html::a("$experiment_icon", null,
['class'=>"btn btn-secondary btn-md experiment $completed", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>"$title", 'id'=>"$res->jobid", ])?>

<?php
}
?>
Expand Down Expand Up @@ -219,32 +222,33 @@
if (empty($res->status))
{
?>
<?= Html::a("$play_icon",['workflow/reattach','jobid'=>$res->jobid],['class'=>'btn btn-success btn-md', 'title'=>'Re-attach'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-secondary btn-md', 'title'=>'Details'])?>
<?= Html::a("$play_icon",['workflow/reattach','jobid'=>$res->jobid],['class'=>'btn btn-run', 'title'=>'Re-attach'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>'btn btn-details', 'title'=>'Details'])?>

<?php
}
else
{

?> <?= Html::a("$play_icon",['workflow/rerun','jobid'=>$res->jobid],
['class'=>'btn btn-success btn-md', 'title'=>'Re-run'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>' btn btn-secondary btn-md', 'title'=>'Details'])?>
['class'=>'btn btn-run', 'title'=>'Re-run'])?>
<?= Html::a("$details_icon",['software/job-details', 'jobid'=>$res->jobid],['class'=>' btn btn-details', 'title'=>'Details'])?>
<?php
$experiment=RoCrate::find()->where(['jobid'=>$res->jobid])->one();
if (!empty($experiment))

$experiment=$rocrates[$res->jobid];

if (!empty($experiment) && $completed)
{
$experiment_icon='<i class="fa fa-flask" aria-hidden="true" style="color:rgb(127, 255, 0)"></i>';
$title='Edit the RO-crate object of this run';
echo Html::a("$experiment_icon", null,
['class'=>"btn btn-experiment-exists experiment", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>'Edit the RO-crate object of this run', 'id'=>"$res->jobid", ]);
}
else
elseif (empty($experiment) && $completed)
{
$experiment_icon='<i class="fa fa-flask" aria-hidden="true" style="color:white"></i>';
$title='Save the run in an RO-crate object, to facilitate the reproducibility of the corresponding experiment';
echo Html::a("$experiment_icon", null,
['class'=>"btn btn-experiment-new experiment", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>'Save the run in an RO-crate object, to facilitate the reproducibility of the corresponding experiment', 'id'=>"$res->jobid", ]);
}
?>
<?= Html::a("$experiment_icon", null,
['class'=>"btn btn-secondary btn-md experiment $completed", 'data-target'=>"#experiment-modal-$res->jobid", 'title'=>"$title", 'id'=>"$res->jobid", ])?>

<?php
}
?>
Expand Down Expand Up @@ -283,9 +287,14 @@
<?php
foreach ($results as $result)
{

if ($result->type=='job' || $result->type=='workflow')
{
RoCrateModal::addModal($result->jobid);
$software=$softwares[$result->jobid];
$soft_type=$soft_types[$result->jobid];
$model=$rocrates[$result->jobid];
$fields=$field_matrix[$result->jobid];
RoCrateModal::addModal($result, $model, $fields, $software, $soft_type);
}
}

Expand Down
12 changes: 12 additions & 0 deletions web/css/software/history.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.btn-run, .btn-experiment-exists
{
font-size: 16px !important;
color: green !important;
}

.btn-details, .btn-experiment-new
{
font-size: 16px !important;
color: #6c757d !important;
}

0 comments on commit c02e524

Please sign in to comment.