Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openmole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
RoiArthurB
openmole
Commits
be7c0bff
Commit
be7c0bff
authored
Mar 20, 2020
by
Romain Reuillon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Plugin] enh: implement json outpout for evolution
parent
d8ddbe64
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
39 deletions
+23
-39
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/mole/CSVHook.scala
.../main/scala/org/openmole/core/workflow/mole/CSVHook.scala
+5
-6
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/mole/FormattedFileHook.scala
...a/org/openmole/core/workflow/mole/FormattedFileHook.scala
+4
-2
openmole/plugins/org.openmole.plugin.hook.json/src/main/scala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
...cala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
+4
-5
openmole/plugins/org.openmole.plugin.method.evolution/src/main/scala/org/openmole/plugin/method/evolution/SavePopulationHook.scala
...openmole/plugin/method/evolution/SavePopulationHook.scala
+6
-22
openmole/plugins/org.openmole.plugin.method.evolution/src/main/scala/org/openmole/plugin/method/evolution/package.scala
.../scala/org/openmole/plugin/method/evolution/package.scala
+2
-2
openmole/third-parties/org.openmole.tool.file/src/main/scala/org/openmole/tool/file/package.scala
....file/src/main/scala/org/openmole/tool/file/package.scala
+2
-2
No files found.
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/mole/CSVHook.scala
View file @
be7c0bff
...
...
@@ -31,11 +31,10 @@ object CSVHook {
object
CSVOutputFormat
{
implicit
def
format
:
OutputFormat
[
CSVOutputFormat
]
=
new
OutputFormat
[
CSVOutputFormat
]
{
override
def
write
(
format
:
CSVOutputFormat
,
output
:
WritableOutput
,
ps
:
Seq
[
Val
[
_
]])
:
FromContext
[
Unit
]
=
FromContext
{
p
⇒
override
def
write
(
format
:
CSVOutputFormat
,
output
:
WritableOutput
,
variables
:
Seq
[
Variable
[
_
]])
:
FromContext
[
Unit
]
=
FromContext
{
p
⇒
import
p._
val
vs
=
ps
.
map
(
context
(
_
))
def
headerLine
=
format
.
header
.
map
(
_
.
from
(
context
))
getOrElse
csv
.
header
(
ps
,
vs
,
format
.
arrayOnRow
)
def
headerLine
=
format
.
header
.
map
(
_
.
from
(
context
))
getOrElse
csv
.
header
(
variables
.
map
(
_
.
prototype
),
variables
,
format
.
arrayOnRow
)
output
match
{
case
WritableOutput
.
FileValue
(
file
)
⇒
...
...
@@ -44,12 +43,12 @@ object CSVHook {
val
h
=
if
(
f
.
isEmpty
)
Some
(
headerLine
)
else
None
if
(
create
)
f
.
atomicWithPrintStream
{
ps
⇒
csv
.
writeVariablesToCSV
(
ps
,
h
,
v
s
,
format
.
arrayOnRow
)
}
else
f
.
withPrintStream
(
append
=
true
,
create
=
true
)
{
ps
⇒
csv
.
writeVariablesToCSV
(
ps
,
h
,
v
s
,
format
.
arrayOnRow
)
}
if
(
create
)
f
.
atomicWithPrintStream
{
ps
⇒
csv
.
writeVariablesToCSV
(
ps
,
h
,
v
ariables
.
map
(
_
.
value
)
,
format
.
arrayOnRow
)
}
else
f
.
withPrintStream
(
append
=
true
,
create
=
true
)
{
ps
⇒
csv
.
writeVariablesToCSV
(
ps
,
h
,
v
ariables
.
map
(
_
.
value
)
,
format
.
arrayOnRow
)
}
case
WritableOutput
.
PrintStreamValue
(
ps
)
⇒
val
header
=
Some
(
headerLine
)
csv
.
writeVariablesToCSV
(
ps
,
header
,
vs
,
format
.
arrayOnRow
)
csv
.
writeVariablesToCSV
(
ps
,
header
,
v
ariable
s
,
format
.
arrayOnRow
)
}
}
...
...
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/mole/FormattedFileHook.scala
View file @
be7c0bff
...
...
@@ -4,11 +4,12 @@ import org.openmole.core.workflow.dsl._
import
org.openmole.core.workflow.mole
import
org.openmole.core.workflow.tools.WritableOutput
import
org.openmole.core.context._
import
org.openmole.core.exception.UserBadDataError
import
org.openmole.core.expansion.FromContext
import
org.openmole.core.workflow.builder._
trait
OutputFormat
[
T
]
{
def
write
(
format
:
T
,
output
:
WritableOutput
,
ps
:
Seq
[
Val
[
_
]])
:
FromContext
[
Unit
]
def
write
(
format
:
T
,
output
:
WritableOutput
,
variables
:
Seq
[
Variable
[
_
]])
:
FromContext
[
Unit
]
def
validate
(
format
:
T
)
:
FromContextHook.ValidateParameters
⇒
Seq
[
Throwable
]
def
extension
:
String
}
...
...
@@ -27,8 +28,9 @@ object FormattedFileHook {
val
excludeSet
=
exclude
.
map
(
_
.
name
).
toSet
val
ps
=
{
if
(
values
.
isEmpty
)
context
.
values
.
map
{
_
.
prototype
}.
toVector
else
values
}.
filter
{
v
⇒
!
excludeSet
.
contains
(
v
.
name
)
}
val
variables
=
ps
.
map
(
p
⇒
context
.
variable
(
p
).
getOrElse
(
throw
new
UserBadDataError
(
s
"Variable $p not found in hook $this"
)))
fileFormat
.
write
(
format
,
output
,
p
s
).
from
(
context
)
fileFormat
.
write
(
format
,
output
,
variable
s
).
from
(
context
)
context
}
validate
{
p
⇒
...
...
openmole/plugins/org.openmole.plugin.hook.json/src/main/scala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
View file @
be7c0bff
...
...
@@ -8,21 +8,20 @@ import org.openmole.plugin.tool.json._
object
JSONOutputFormat
{
implicit
def
outputFormat
=
new
OutputFormat
[
JSONOutputFormat
]
{
override
def
write
(
format
:
JSONOutputFormat
,
output
:
WritableOutput
,
ps
:
Seq
[
Val
[
_
]])
:
FromContext
[
Unit
]
=
FromContext
{
p
⇒
override
def
write
(
format
:
JSONOutputFormat
,
output
:
WritableOutput
,
variables
:
Seq
[
Variable
[
_
]])
:
FromContext
[
Unit
]
=
FromContext
{
p
⇒
import
p._
import
org.json4s._
import
org.json4s.jackson.JsonMethods._
implicit
val
formats
=
DefaultFormats
val
vs
=
ps
.
flatMap
(
v
⇒
context
.
variable
[
Any
](
v
.
name
).
toSeq
)
output
match
{
case
WritableOutput
.
FileValue
(
file
)
⇒
file
.
from
(
context
).
withPrintStream
(
append
=
false
,
create
=
true
)
{
ps
⇒
ps
.
print
(
compact
(
render
(
variablesToJValue
(
vs
))))
ps
.
print
(
compact
(
render
(
variablesToJValue
(
v
ariable
s
))))
}
case
WritableOutput
.
PrintStreamValue
(
ps
)
⇒
ps
.
println
(
pretty
(
render
(
variablesToJValue
(
vs
))))
case
WritableOutput
.
PrintStreamValue
(
ps
)
⇒
ps
.
println
(
pretty
(
render
(
variablesToJValue
(
variables
))))
}
}
...
...
openmole/plugins/org.openmole.plugin.method.evolution/src/main/scala/org/openmole/plugin/method/evolution/SavePopulationHook.scala
View file @
be7c0bff
...
...
@@ -28,10 +28,9 @@ object SavePopulationHook {
t
.
operations
.
result
(
context
(
t
.
populationPrototype
).
toVector
,
context
(
t
.
statePrototype
)).
from
(
context
)
}
def
hook
[
F
](
t
:
EvolutionWorkflow
,
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
],
format
:
F
=
CSVOutputFormat
(
overwrite
=
true
)
)(
implicit
name
:
sourcecode.Name
,
definitionScope
:
DefinitionScope
,
outputFormat
:
OutputFormat
[
F
])
=
{
def
hook
[
F
](
t
:
EvolutionWorkflow
,
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
],
format
:
F
)(
implicit
name
:
sourcecode.Name
,
definitionScope
:
DefinitionScope
,
outputFormat
:
OutputFormat
[
F
])
=
{
Hook
(
"SavePopulationHook"
)
{
p
⇒
import
p._
import
org.openmole.core.csv
def
save
=
frequency
.
option
match
{
...
...
@@ -42,27 +41,12 @@ object SavePopulationHook {
}
if
(
save
)
{
val
values
=
resultVariables
(
t
).
from
(
context
).
map
(
_
.
value
)
def
headerLine
=
csv
.
header
(
resultVariables
(
t
).
from
(
context
).
map
(
_
.
prototype
.
array
),
values
)
output
match
{
case
WritableOutput
.
FileValue
(
dir
)
⇒
(
dir
/
ExpandedString
(
"population${"
+
t
.
generationPrototype
.
name
+
"}.csv"
)).
from
(
context
).
withPrintStream
(
overwrite
=
false
,
create
=
true
)
{
ps
⇒
csv
.
writeVariablesToCSV
(
ps
,
Some
(
headerLine
),
values
)
}
case
WritableOutput
.
PrintStreamValue
(
ps
)
⇒
csv
.
writeVariablesToCSV
(
ps
,
Some
(
headerLine
),
values
)
val
outputFile
=
dir
/
ExpandedString
(
"population${"
+
t
.
generationPrototype
.
name
+
"}"
+
outputFormat
.
extension
)
outputFormat
.
write
(
format
,
outputFile
,
resultVariables
(
t
).
from
(
context
)).
from
(
context
)
case
o
⇒
outputFormat
.
write
(
format
,
o
,
resultVariables
(
t
).
from
(
context
)).
from
(
context
)
}
}
context
...
...
@@ -70,9 +54,9 @@ object SavePopulationHook {
}
def
apply
[
T
](
algorithm
:
T
,
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
]
=
None
)(
implicit
wfi
:
WorkflowIntegration
[
T
],
name
:
sourcecode.Name
,
definitionScope
:
DefinitionScope
)
=
{
def
apply
[
T
,
F:
OutputFormat
](
algorithm
:
T
,
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
]
=
None
,
format
:
F
=
CSVOutputFormat
(
overwrite
=
true
)
)(
implicit
wfi
:
WorkflowIntegration
[
T
],
name
:
sourcecode.Name
,
definitionScope
:
DefinitionScope
)
=
{
val
t
=
wfi
(
algorithm
)
hook
(
t
,
output
,
frequency
)
hook
(
t
,
output
,
frequency
,
format
)
}
}
...
...
openmole/plugins/org.openmole.plugin.method.evolution/src/main/scala/org/openmole/plugin/method/evolution/package.scala
View file @
be7c0bff
...
...
@@ -99,9 +99,9 @@ package object evolution {
implicit
def
workflowIntegration
=
WorkflowIntegration
[
DSLContainer
[
EvolutionWorkflow
]](
_
.
data
)
implicit
class
EvolutionMethodContainer
(
dsl
:
DSLContainer
[
EvolutionWorkflow
])
extends
DSLContainerHook
(
dsl
)
{
def
hook
(
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
]
=
None
)
:
DSLContainer
[
EvolutionWorkflow
]
=
{
def
hook
[
F:
OutputFormat
](
output
:
WritableOutput
,
frequency
:
OptionalArgument
[
Long
]
=
None
,
format
:
F
=
CSVOutputFormat
(
overwrite
=
true
)
)
:
DSLContainer
[
EvolutionWorkflow
]
=
{
implicit
val
defScope
=
dsl
.
scope
dsl
.
hook
(
SavePopulationHook
(
dsl
,
output
,
frequency
))
dsl
.
hook
(
SavePopulationHook
(
dsl
,
output
,
frequency
,
format
))
}
}
...
...
openmole/third-parties/org.openmole.tool.file/src/main/scala/org/openmole/tool/file/package.scala
View file @
be7c0bff
...
...
@@ -431,9 +431,9 @@ package file {
def
atomicWithPrintStream
[
T
](
f
:
PrintStream
⇒
T
)
=
{
file
.
createParentDirectory
val
tmpFile
=
java
.
io
.
File
.
createTempFile
(
"
print
stream"
,
".tmp"
,
file
.
getParentFile
)
val
tmpFile
=
java
.
io
.
File
.
createTempFile
(
"stream"
,
".tmp"
,
file
.
getParentFile
)
try
{
val
printStream
=
new
PrintStream
(
f
ile
.
bufferedOutputStream
())
val
printStream
=
new
PrintStream
(
tmpF
ile
.
bufferedOutputStream
())
try
f
(
printStream
)
finally
printStream
.
close
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment