Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
portal-backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HBP Medical Informatics Platform
portal-backend
Commits
e98b52a9
Commit
e98b52a9
authored
6 years ago
by
Manuel Spuhler
Browse files
Options
Downloads
Patches
Plain Diff
I/O for Exareme K_MEANS - wip
parent
52cd42a8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
+8
-16
8 additions, 16 deletions
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
src/main/java/eu/hbp/mip/model/Experiment.java
+80
-43
80 additions, 43 deletions
src/main/java/eu/hbp/mip/model/Experiment.java
with
88 additions
and
59 deletions
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
+
8
−
16
View file @
e98b52a9
...
@@ -6,6 +6,7 @@ import com.google.gson.Gson;
...
@@ -6,6 +6,7 @@ import com.google.gson.Gson;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
eu.hbp.mip.akka.WokenClientController
;
import
eu.hbp.mip.akka.WokenClientController
;
import
eu.hbp.mip.configuration.SecurityConfiguration
;
import
eu.hbp.mip.configuration.SecurityConfiguration
;
import
eu.hbp.mip.model.AlgorithmParam
;
import
eu.hbp.mip.model.Experiment
;
import
eu.hbp.mip.model.Experiment
;
import
eu.hbp.mip.model.ExperimentQuery
;
import
eu.hbp.mip.model.ExperimentQuery
;
import
eu.hbp.mip.model.User
;
import
eu.hbp.mip.model.User
;
...
@@ -83,12 +84,12 @@ public class ExperimentApi extends WokenClientController {
...
@@ -83,12 +84,12 @@ public class ExperimentApi extends WokenClientController {
LOGGER
.
info
(
"Experiment saved"
);
LOGGER
.
info
(
"Experiment saved"
);
if
(
isExaremeAlgo
(
expQuery
))
{
if
(!
experiment
.
isExaremeAlgorithm
())
{
String
algoCode
=
expQuery
.
getAlgorithms
().
get
(
0
).
getCode
();
sendExaremeExperiment
(
experiment
,
algoCode
);
}
else
{
sendExperiment
(
experiment
);
sendExperiment
(
experiment
);
}
else
{
String
algoCode
=
expQuery
.
getAlgorithms
().
get
(
0
).
getCode
();
List
<
AlgorithmParam
>
params
=
expQuery
.
getAlgorithms
().
get
(
0
).
getParameters
();
sendExaremeExperiment
(
experiment
,
algoCode
,
params
);
}
}
return
new
ResponseEntity
<>(
gsonOnlyExposed
.
toJson
(
experiment
.
jsonify
()),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
gsonOnlyExposed
.
toJson
(
experiment
.
jsonify
()),
HttpStatus
.
OK
);
...
@@ -286,11 +287,11 @@ public class ExperimentApi extends WokenClientController {
...
@@ -286,11 +287,11 @@ public class ExperimentApi extends WokenClientController {
},
ec
);
},
ec
);
}
}
private
void
sendExaremeExperiment
(
Experiment
experiment
,
String
algoCode
)
{
private
void
sendExaremeExperiment
(
Experiment
experiment
,
String
algoCode
,
List
<
AlgorithmParam
>
params
)
{
// >> Temporary: we should integrate exareme in a proper way in the future
// >> Temporary: we should integrate exareme in a proper way in the future
// this runs in the background. For future optimization: use a thread pool
// this runs in the background. For future optimization: use a thread pool
new
Thread
(()
->
{
new
Thread
(()
->
{
String
query
=
experiment
.
computeExaremeQuery
();
String
query
=
experiment
.
computeExaremeQuery
(
params
);
String
url
=
miningExaremeQueryUrl
+
"/"
+
algoCode
;
String
url
=
miningExaremeQueryUrl
+
"/"
+
algoCode
;
// Results are stored in the experiment object
// Results are stored in the experiment object
try
{
try
{
...
@@ -322,13 +323,4 @@ public class ExperimentApi extends WokenClientController {
...
@@ -322,13 +323,4 @@ public class ExperimentApi extends WokenClientController {
LOGGER
.
info
(
"Experiment updated (finished)"
);
LOGGER
.
info
(
"Experiment updated (finished)"
);
}
}
private
static
boolean
isExaremeAlgo
(
ExperimentQuery
expQuery
)
{
String
code
=
expQuery
.
getAlgorithms
().
get
(
0
).
getCode
();
return
expQuery
.
getAlgorithms
().
size
()
>
0
&&
(
"WP_"
.
equals
(
code
.
substring
(
0
,
3
))
||
"glm_exareme"
.
equals
(
code
)
||
"K_MEANS"
.
equals
(
code
));
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/eu/hbp/mip/model/Experiment.java
+
80
−
43
View file @
e98b52a9
package
eu.hbp.mip.model
;
package
eu.hbp.mip.model
;
import
ch.chuv.lren.mip.portal.WokenConversions
;
import
ch.chuv.lren.mip.portal.WokenConversions
;
import
com.google.gson.Gson
;
import
com.google.gson.*
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.reflect.TypeToken
;
import
com.google.gson.reflect.TypeToken
;
import
ch.chuv.lren.woken.messages.datasets.DatasetId
;
import
ch.chuv.lren.woken.messages.datasets.DatasetId
;
...
@@ -21,10 +18,7 @@ import scala.collection.JavaConversions;
...
@@ -21,10 +18,7 @@ import scala.collection.JavaConversions;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.UUID
;
/**
/**
...
@@ -137,44 +131,60 @@ public class Experiment {
...
@@ -137,44 +131,60 @@ public class Experiment {
}
}
public
String
computeExaremeQuery
()
{
public
String
computeExaremeQuery
(
List
<
AlgorithmParam
>
params
)
{
List
<
ExaremeQueryElement
>
queryElements
=
new
LinkedList
<>();
List
<
ExaremeQueryElement
>
queryElements
=
new
LinkedList
<>();
for
(
Variable
var
:
model
.
getQuery
().
getVariables
())
// columns
List
<
String
>
columns
=
new
ArrayList
<>();
for
(
Variable
var
:
model
.
getQuery
().
getVariables
())
{
columns
.
add
(
var
.
getCode
());
}
for
(
Variable
var
:
model
.
getQuery
().
getCovariables
())
{
columns
.
add
(
var
.
getCode
());
}
for
(
Variable
var
:
model
.
getQuery
().
getGrouping
())
{
columns
.
add
(
var
.
getCode
());
}
StringBuilder
sb
=
new
StringBuilder
();
int
i
=
0
;
for
(
String
s
:
columns
)
{
{
ExaremeQueryElement
el
=
new
ExaremeQueryElement
()
;
i
++
;
el
.
setName
(
"variable"
);
sb
.
append
(
s
);
el
.
setDesc
(
""
);
if
(
i
<
columns
.
size
())
{
el
.
setValue
(
var
.
getCode
()
);
sb
.
append
(
","
);
queryElements
.
add
(
el
);
}
}
}
for
(
Variable
var
:
model
.
getQuery
().
getCovariables
())
ExaremeQueryElement
columnsEl
=
new
ExaremeQueryElement
();
{
columnsEl
.
setName
(
"columns"
);
ExaremeQueryElement
el
=
new
ExaremeQueryElement
();
columnsEl
.
setDesc
(
""
);
el
.
setName
(
"covariables"
);
columnsEl
.
setValue
(
sb
.
toString
());
el
.
setDesc
(
""
);
queryElements
.
add
(
columnsEl
);
el
.
setValue
(
var
.
getCode
());
queryElements
.
add
(
el
);
// parameters
if
(
params
!=
null
)
{
for
(
AlgorithmParam
p
:
params
)
{
ExaremeQueryElement
paramEl
=
new
ExaremeQueryElement
();
paramEl
.
setName
(
p
.
getCode
());
paramEl
.
setDesc
(
""
);
paramEl
.
setValue
(
p
.
getValue
());
queryElements
.
add
(
paramEl
);
}
}
}
for
(
Variable
var
:
model
.
getQuery
().
getGrouping
())
// datasets
StringBuilder
datasets
=
new
StringBuilder
();
List
<
Variable
>
trainingDatasets
=
model
.
getQuery
().
getTrainingDatasets
();
int
j
=
0
;
for
(
Variable
var
:
trainingDatasets
)
{
{
ExaremeQueryElement
el
=
new
ExaremeQueryElement
()
;
j
++
;
el
.
setName
(
"groupings"
);
datasets
.
append
(
var
.
getCode
()
);
el
.
setDesc
(
""
);
if
(
j
<
trainingDatasets
.
size
()
)
{
el
.
setValue
(
var
.
getCode
()
);
datasets
.
append
(
","
);
queryElements
.
add
(
el
);
}
}
}
ExaremeQueryElement
tableEl
=
new
ExaremeQueryElement
();
ExaremeQueryElement
datasetsEl
=
new
ExaremeQueryElement
();
tableEl
.
setName
(
"showtable"
);
datasetsEl
.
setName
(
"dataset"
);
tableEl
.
setDesc
(
""
);
datasetsEl
.
setDesc
(
""
);
tableEl
.
setValue
(
"TotalResults"
);
datasetsEl
.
setValue
(
datasets
.
toString
());
queryElements
.
add
(
tableEl
);
queryElements
.
add
(
datasetsEl
);
ExaremeQueryElement
formatEl
=
new
ExaremeQueryElement
();
formatEl
.
setName
(
"format"
);
formatEl
.
setDesc
(
""
);
formatEl
.
setValue
(
"True"
);
queryElements
.
add
(
formatEl
);
return
gson
.
toJson
(
queryElements
);
return
gson
.
toJson
(
queryElements
);
}
}
...
@@ -197,11 +207,30 @@ public class Experiment {
...
@@ -197,11 +207,30 @@ public class Experiment {
exp
.
add
(
"validations"
,
jsonValidations
);
exp
.
add
(
"validations"
,
jsonValidations
);
}
}
if
(
this
.
result
!=
null
&&
!
this
.
hasServerError
)
if
(
this
.
result
!=
null
&&
!
this
.
hasServerError
)
{
{
exp
.
remove
(
"result"
);
exp
.
remove
(
"result"
);
JsonArray
jsonResult
=
parser
.
parse
(
this
.
result
).
getAsJsonArray
();
exp
.
add
(
"result"
,
jsonResult
);
if
(!
this
.
isExaremeAlgorithm
())
{
JsonArray
jsonResult
=
parser
.
parse
(
this
.
result
).
getAsJsonArray
();
exp
.
add
(
"result"
,
jsonResult
);
}
else
{
JsonArray
jsonArrayResult
=
new
JsonArray
();
JsonObject
jsonObjectResult
=
new
JsonObject
();
exp
.
remove
(
"result"
);
JsonObject
jsonData
=
parser
.
parse
(
this
.
result
).
getAsJsonArray
().
get
(
0
).
getAsJsonObject
();
jsonObjectResult
.
add
(
"data"
,
jsonData
);
JsonObject
algoObject
=
parser
.
parse
(
this
.
algorithms
).
getAsJsonArray
().
get
(
0
).
getAsJsonObject
();
jsonObjectResult
.
add
(
"algorithm"
,
algoObject
.
get
(
"name"
));
jsonObjectResult
.
add
(
"code"
,
algoObject
.
get
(
"code"
));
jsonObjectResult
.
add
(
"type"
,
new
JsonPrimitive
(
"application/vnd.highcharts+json"
));
jsonArrayResult
.
add
(
jsonObjectResult
);
exp
.
add
(
"result"
,
jsonArrayResult
);
}
}
}
return
exp
;
return
exp
;
...
@@ -310,4 +339,12 @@ public class Experiment {
...
@@ -310,4 +339,12 @@ public class Experiment {
public
void
setShared
(
boolean
shared
)
{
public
void
setShared
(
boolean
shared
)
{
this
.
shared
=
shared
;
this
.
shared
=
shared
;
}
}
public
boolean
isExaremeAlgorithm
()
{
String
algorithms
=
this
.
algorithms
;
Boolean
isExareme
=
algorithms
.
contains
(
"WP_"
)
||
algorithms
.
contains
(
"K_MEANS"
);
return
isExareme
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment