Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
API
Commits
195fde5f
Commit
195fde5f
authored
May 09, 2019
by
Tobias Meuser
Browse files
Added data structures for REST handling
parent
6de41a46
Changes
14
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/web/Metric.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlID
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Metric
{
@XmlID
@XmlElement
(
name
=
"name"
)
private
String
_name
;
@XmlElement
(
name
=
"desc"
)
private
String
_description
;
public
String
getName
()
{
return
_name
;
}
public
String
getDescription
()
{
return
_description
;
}
public
void
setName
(
String
pName
)
{
_name
=
pName
;
}
public
void
setDescription
(
String
pDescription
)
{
_description
=
pDescription
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/Scenario.java
View file @
195fde5f
package
de.tudarmstadt.maki.simonstrator.api.web
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -7,12 +9,18 @@ import javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.XmlID
;
import
javax.xml.bind.annotation.XmlTransient
;
import
de.tudarmstadt.maki.simonstrator.api.web.approach.Approach
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
import
de.tudarmstadt.maki.simonstrator.api.web.plotting.BoxPlot
;
import
de.tudarmstadt.maki.simonstrator.api.web.plotting.Plot
;
import
de.tudarmstadt.maki.simonstrator.api.web.plotting.TimePlot
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Scenario
{
@XmlID
@XmlElement
(
name
=
"name"
)
private
String
_name
;
...
...
@@ -27,6 +35,13 @@ public class Scenario {
@XmlElement
(
name
=
"parameter"
)
List
<
Parameter
>
_parameters
=
new
ArrayList
<>();
@XmlElementWrapper
(
name
=
"plots"
)
@XmlElement
(
name
=
"plot"
)
List
<
Plot
>
_plots
=
new
ArrayList
<>();
@XmlTransient
private
int
_currentID
=
-
1
;
public
Scenario
()
{
}
...
...
@@ -63,6 +78,51 @@ public class Scenario {
_parameters
.
add
(
pParameter
);
}
public
void
addPlot
(
Plot
pPlot
)
{
_plots
.
add
(
pPlot
);
}
public
Plot
createBoxPlot
()
{
if
(
_currentID
==
-
1
)
{
for
(
Plot
plot
:
_plots
)
{
if
(
plot
.
getPlotID
()
>
_currentID
)
{
_currentID
=
plot
.
getPlotID
();
}
}
}
return
new
BoxPlot
(++
_currentID
);
}
public
Plot
createTimePlot
()
{
if
(
_currentID
==
-
1
)
{
for
(
Plot
plot
:
_plots
)
{
if
(
plot
.
getPlotID
()
>
_currentID
)
{
_currentID
=
plot
.
getPlotID
();
}
}
}
return
new
TimePlot
(++
_currentID
);
}
public
Plot
createPlot
(
Class
<?
extends
Plot
>
pClass
)
{
if
(
_currentID
==
-
1
)
{
for
(
Plot
plot
:
_plots
)
{
if
(
plot
.
getPlotID
()
>
_currentID
)
{
_currentID
=
plot
.
getPlotID
();
}
}
}
try
{
Constructor
<?
extends
Plot
>
constructor
=
pClass
.
getConstructor
(
Integer
.
TYPE
);
return
constructor
.
newInstance
(++
_currentID
);
}
catch
(
NoSuchMethodException
|
SecurityException
|
InstantiationException
|
IllegalAccessException
|
IllegalArgumentException
|
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
List
<
Parameter
>
getParameters
()
{
return
_parameters
;
}
...
...
@@ -84,4 +144,26 @@ public class Scenario {
}
return
null
;
}
public
Plot
getPlot
(
int
pPlotID
)
{
for
(
Plot
plot
:
_plots
)
{
if
(
plot
.
getPlotID
()
==
pPlotID
)
{
return
plot
;
}
}
return
null
;
}
public
List
<
Plot
>
getPlots
()
{
return
_plots
;
}
public
void
removePlot
(
int
pPlotID
)
{
for
(
Plot
plot
:
_plots
)
{
if
(
plot
.
getPlotID
()
==
pPlotID
)
{
_plots
.
remove
(
plot
);
return
;
}
}
}
}
\ No newline at end of file
src/de/tudarmstadt/maki/simonstrator/api/web/WebConfiguration.java
View file @
195fde5f
...
...
@@ -23,6 +23,10 @@ public class WebConfiguration {
@XmlElement
(
name
=
"scenario"
)
List
<
Scenario
>
_scenarios
=
new
ArrayList
<>();
@XmlElementWrapper
(
name
=
"metrics"
)
@XmlElement
(
name
=
"metric"
)
List
<
Metric
>
_metrics
=
new
ArrayList
<>();
@XmlElement
(
name
=
"options"
)
WebRunnerOptions
_options
=
new
WebRunnerOptions
();
...
...
@@ -83,4 +87,25 @@ public class WebConfiguration {
}
return
null
;
}
public
void
removeScenario
(
Scenario
pScenario
)
{
_scenarios
.
remove
(
pScenario
);
}
public
List
<
Metric
>
getMetrics
()
{
return
_metrics
;
}
public
Metric
getMetric
(
String
pMetricName
)
{
for
(
Metric
metric
:
_metrics
)
{
if
(
metric
.
getName
().
equals
(
pMetricName
))
{
return
metric
;
}
}
return
null
;
}
public
void
addMetric
(
Metric
pMetric
)
{
_metrics
.
add
(
pMetric
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/approach/Approach.java
View file @
195fde5f
...
...
@@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.XmlID
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Approach
{
...
...
@@ -14,6 +15,7 @@ public class Approach {
OWN
,
BASELINE
,
REFERENCE
;
}
@XmlID
@XmlElement
(
name
=
"name"
)
private
String
_name
;
...
...
src/de/tudarmstadt/maki/simonstrator/api/web/options/RuntimeOptions.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.options
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
RuntimeOptions
{
@XmlElement
(
name
=
"processes"
)
private
int
_numberOfProcesses
=
1
;
public
int
getNumberOfProcesses
()
{
return
_numberOfProcesses
;
}
public
void
setNumberOfProcesses
(
int
pNumberOfProcesses
)
{
_numberOfProcesses
=
pNumberOfProcesses
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/options/WebRunnerOptions.java
View file @
195fde5f
package
de.tudarmstadt.maki.simonstrator.api.web.options
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
public
class
WebRunnerOptions
{
@XmlElement
(
name
=
"processes"
)
private
int
_numberOfProcesses
=
1
;
@XmlElement
(
name
=
"username"
)
private
String
username
;
import
de.tudarmstadt.maki.simonstrator.api.web.options.database.DatabaseOptions
;
import
de.tudarmstadt.maki.simonstrator.api.web.options.plotting.PlottingOptions
;
@XmlElement
(
name
=
"password"
)
private
String
password
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
WebRunnerOptions
{
@XmlElement
(
name
=
"runtime"
)
private
RuntimeOptions
_runtime
;
@XmlElement
(
name
=
"database"
)
private
String
database
;
public
int
getNumberOfProcesses
()
{
return
_numberOfProcesses
;
}
public
void
setNumberOfProcesses
(
int
pNumberOfProcesses
)
{
_numberOfProcesses
=
pNumberOfProcesses
;
}
private
DatabaseOptions
_database
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
pUsername
)
{
username
=
pUsername
;
}
public
String
getPassword
()
{
return
password
;
}
@XmlElement
(
name
=
"plotting"
)
private
PlottingOptions
_plotting
;
public
void
setPassword
(
String
pPassword
)
{
password
=
pPassword
;
public
RuntimeOptions
getRuntime
()
{
if
(
_runtime
==
null
)
{
_runtime
=
new
RuntimeOptions
();
}
return
_runtime
;
}
public
String
getDatabase
()
{
return
database
;
public
DatabaseOptions
getDatabase
()
{
if
(
_database
==
null
)
{
_database
=
new
DatabaseOptions
();
}
return
_database
;
}
public
void
setDatabase
(
String
pDatabase
)
{
database
=
pDatabase
;
public
PlottingOptions
getPlotting
()
{
if
(
_plotting
==
null
)
{
_plotting
=
new
PlottingOptions
();
}
return
_plotting
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/options/database/DatabaseOptions.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.options.database
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
DatabaseOptions
{
@XmlElement
(
name
=
"username"
)
private
String
username
;
@XmlElement
(
name
=
"password"
)
private
String
password
;
@XmlElement
(
name
=
"database"
)
private
String
database
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
pUsername
)
{
username
=
pUsername
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
pPassword
)
{
password
=
pPassword
;
}
public
String
getDatabase
()
{
return
database
;
}
public
void
setDatabase
(
String
pDatabase
)
{
database
=
pDatabase
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/options/plotting/PlottingOptions.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.options.plotting
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
PlottingOptions
{
@XmlElement
(
name
=
"python"
)
private
String
_python
;
@XmlElement
(
name
=
"path"
)
private
String
_path
;
public
String
getPath
()
{
return
_path
;
}
public
String
getOutputPath
()
{
return
_path
+
"/../output"
;
}
public
void
setPath
(
String
pPath
)
{
_path
=
pPath
;
}
public
String
getPython
()
{
return
_python
;
}
public
void
setPython
(
String
pPython
)
{
_python
=
pPython
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/parameter/Parameter.java
View file @
195fde5f
...
...
@@ -7,9 +7,11 @@ import javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.XmlID
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Parameter
{
@XmlID
@XmlElement
(
name
=
"name"
)
private
String
_name
;
...
...
@@ -17,6 +19,7 @@ public class Parameter {
@XmlElement
(
name
=
"value"
)
private
List
<
String
>
_values
=
new
ArrayList
<>();
@XmlElement
(
name
=
"default"
)
private
int
_defaultIndex
;
public
Parameter
()
{
...
...
src/de/tudarmstadt/maki/simonstrator/api/web/plotting/BoxPlot.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.plotting
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
de.tudarmstadt.maki.simonstrator.api.web.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
BoxPlot
extends
Plot
{
public
BoxPlot
(
int
pID
)
{
super
(
pID
);
_metrics
=
new
Metric
[
1
];
_parameters
=
new
Parameter
[
1
];
_type
=
PlotType
.
BOX
;
}
public
BoxPlot
()
{
this
(-
1
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/plotting/DefaultPlotter.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.plotting
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Scanner
;
import
de.tudarmstadt.maki.simonstrator.api.web.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.web.WebConfigurationManager
;
import
de.tudarmstadt.maki.simonstrator.api.web.approach.Approach
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
import
de.tudarmstadt.maki.simonstrator.api.web.plotting.Plot.PlotType
;
public
class
DefaultPlotter
implements
Plotter
{
private
File
tempFolder
=
new
File
(
System
.
getProperty
(
"user.home"
)
+
"/.simonstrator/temp"
);
private
final
String
[]
COLORS
=
new
String
[]
{
"#9e0142"
,
"#d53e4f"
,
"#f46d43"
,
"#fdae61"
,
"#fee08b"
,
"#e6f598"
,
"#abdda4"
,
"#66c2a5"
,
"#3288bd"
,
"#5e4fa2"
};
private
Random
random
=
new
Random
();
@Override
public
byte
[]
plotImage
(
Plot
pPlot
,
ImageFormat
pFormat
)
{
if
(!
tempFolder
.
exists
()
&&
!
tempFolder
.
mkdirs
())
{
return
null
;
}
boolean
success
=
true
;
System
.
out
.
println
(
"Plotter called."
);
if
(
success
)
{
StringBuffer
script
=
new
StringBuffer
();
List
<
Approach
>
approaches
=
new
ArrayList
<>();
for
(
Approach
approach
:
pPlot
.
getApproaches
())
{
if
(
approach
!=
null
)
{
approaches
.
add
(
approach
);
}
else
{
success
=
false
;
}
}
Parameter
[]
parameters
=
pPlot
.
getParameters
();
success
&=
createTemplate
(
script
,
approaches
,
parameters
,
pPlot
.
getMetrics
(),
pPlot
.
getFixedValues
(),
pFormat
);
if
(
success
)
{
try
{
File
tempFile
=
new
File
(
tempFolder
,
"plotting."
+
random
.
nextLong
()
+
".tmp"
);
if
(
pPlot
.
getType
().
equals
(
PlotType
.
BOX
))
{
success
&=
setupBoxPlot
(
tempFile
.
getName
(),
script
,
approaches
,
parameters
);
}
else
if
(
pPlot
.
getType
().
equals
(
PlotType
.
TIME
))
{
success
&=
setupTimePlot
(
tempFile
.
getName
(),
script
,
approaches
,
parameters
);
}
else
{
success
=
false
;
}
FileOutputStream
scriptOutput
=
new
FileOutputStream
(
tempFile
);
scriptOutput
.
write
(
script
.
toString
().
getBytes
());
scriptOutput
.
flush
();
scriptOutput
.
close
();
System
.
out
.
println
(
"Created plotting script at : "
+
tempFile
);
File
imageFile
=
new
File
(
WebConfigurationManager
.
getConfig
().
getOptions
().
getPlotting
().
getOutputPath
()
+
"/"
+
tempFile
.
getName
()
+
"."
+
pFormat
.
getExtension
());
if
(
imageFile
.
exists
())
{
imageFile
.
delete
();
}
String
command
=
WebConfigurationManager
.
getConfig
().
getOptions
().
getPlotting
().
getPython
()
+
" "
+
tempFile
.
getAbsolutePath
();
Process
p
=
Runtime
.
getRuntime
().
exec
(
command
);
InputStream
input
=
p
.
getInputStream
();
while
(
input
.
read
()
!=
-
1
)
{
}
if
(
p
.
waitFor
()
==
0
&&
imageFile
.
exists
())
{
FileInputStream
stream
=
new
FileInputStream
(
imageFile
);
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
4096
];
int
length
;
while
((
length
=
stream
.
read
(
buffer
))
>
0
)
{
output
.
write
(
buffer
,
0
,
length
);
}
stream
.
close
();
imageFile
.
delete
();
return
output
.
toByteArray
();
}
}
catch
(
IOException
|
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
return
null
;
}
private
boolean
setupBoxPlot
(
String
pFileName
,
StringBuffer
pScript
,
List
<
Approach
>
pApproaches
,
Parameter
[]
pParameters
)
{
pScript
.
append
(
"plot = BoxPlot(db, PAPER_FULL_LEGEND_OUT, '"
+
pFileName
+
"', metric)"
).
append
(
"\n"
);
pScript
.
append
(
"\n"
);
for
(
int
i
=
0
;
i
<
pParameters
[
0
].
getValues
().
size
();
i
++)
{
pScript
.
append
(
"plot.addGroup(["
);
for
(
int
j
=
0
;
j
<
pApproaches
.
size
();
j
++)
{
if
(
j
!=
0
)
{
pScript
.
append
(
", "
);
}
pScript
.
append
(
"APPROACH_"
).
append
(
j
);
}
pScript
.
append
(
"], basis_environment.combine("
).
append
(
pParameters
[
0
].
getName
()).
append
(
"_"
).
append
(
i
)
.
append
(
"))\n"
);
}
pScript
.
append
(
"\n"
);
pScript
.
append
(
"plot.finish()"
).
append
(
"\n"
);
pScript
.
append
(
"exit()"
);
return
true
;
}
private
boolean
setupTimePlot
(
String
pFileName
,
StringBuffer
pScript
,
List
<
Approach
>
pApproaches
,
Parameter
[]
pParameters
)
{
pScript
.
append
(
"plot = TimePlot(db, PAPER_FULL_LEGEND_OUT, '"
+
pFileName
+
"', metric, timescale=1000000)"
)
.
append
(
"\n"
);
pScript
.
append
(
"\n"
);
for
(
int
i
=
0
;
i
<
pApproaches
.
size
();
i
++)
{
Approach
approach
=
pApproaches
.
get
(
i
);
switch
(
approach
.
getType
())
{
case
OWN:
pScript
.
append
(
"plot.addMainSystem("
);
break
;
case
BASELINE:
pScript
.
append
(
"plot.addBaseline("
);
break
;
case
REFERENCE:
pScript
.
append
(
"plot.addComparison("
);
break
;
default
:
return
false
;
}
pScript
.
append
(
"APPROACH_"
).
append
(
i
).
append
(
", basis_environment)"
).
append
(
"\n"
);
}
pScript
.
append
(
"\n"
);
pScript
.
append
(
"plot.finish()"
).
append
(
"\n"
);
pScript
.
append
(
"exit()"
);
return
true
;
}
private
boolean
createTemplate
(
StringBuffer
script
,
List
<
Approach
>
approaches
,
Parameter
[]
parameters
,
Metric
[]
pMetrics
,
Map
<
Parameter
,
String
>
pFixed
,
ImageFormat
format
)
{
boolean
success
=
true
;
try
{
InputStream
stream
=
new
FileInputStream
(
"assets/web/template.py"
);
Scanner
sc
=
new
Scanner
(
stream
);
while
(
sc
.
hasNextLine
())
{
String
line
=
sc
.
nextLine
();
line
=
replacePlaceholders
(
line
);
script
.
append
(
line
).
append
(
"\n"
);
}
sc
.
close
();
stream
.
close
();
if
(
success
)
{
defineLayout
(
script
,
format
);
script
.
append
(
"\n"
);
defineSystems
(
script
,
approaches
);
script
.
append
(
"\n"
);
for
(
Parameter
parameter
:
parameters
)
{
defineEnvironments
(
script
,
parameter
);
script
.
append
(
"\n"
);
}
System
.
out
.
println
(
"Metrics: "
+
pMetrics
.
length
);
for
(
Metric
metric
:
pMetrics
)
{
defineMetrics
(
script
,
metric
);
script
.
append
(
"\n"
);
}
script
.
append
(
"basis_environment = Environment({}, label=\"basis\")\n"
);
ArrayList
<
Parameter
>
fixedParameters
=
new
ArrayList
<>(
pFixed
.
keySet
());
for
(
int
i
=
0
;
i
<
fixedParameters
.
size
();
i
++)
{
script
.
append
(
"fixed_parameter_"
).
append
(
i
).
append
(
" = Environment({'"
)
.
append
(
fixedParameters
.
get
(
i
).
getName
()).
append
(
"':'"
)
.
append
(
pFixed
.
get
(
fixedParameters
.
get
(
i
)))
.
append
(
"'}, label=\"basis\")\n"
);
script
.
append
(
"basis_environment = basis_environment.combine(fixed_parameter_"
).
append
(
i
)
.
append
(
")\n"
);
}
script
.
append
(
"\n"
);
return
true
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
private
void
defineLayout
(
StringBuffer
pScript
,
ImageFormat
pFormat
)
{
pScript
.
append
(
"PAPER_FULL_LEGEND_OUT = PlotSettings(scale=0.9, heightScale=0.5, formats=['"
+
pFormat
.
getExtension
()
+
"'], titleLeft=True, legendCols=2)\n"
);
pScript
.
append
(
"PAPER_HALF_LEGEND_OUT = PlotSettings(scale=0.5, heightScale=1.0, formats=['"
+
pFormat
.
getExtension
()
+
"'], titleLeft=True, legendCols=2)\n"
);
}
private
void
defineMetrics
(
StringBuffer
pScript
,
Metric
pMetric
)
{
pScript
.
append
(
"metric = SingleMetricDescription('"
).
append
(
pMetric
.
getName
())
.
append
(
"', '"
+
pMetric
.
getDescription
()
+
"')"
).
append
(
"\n"
);
}
private
void
defineEnvironments
(
StringBuffer
pScript
,
Parameter
pParameter
)
{
for
(
int
i
=
0
;
i
<
pParameter
.
getValues
().
size
();
i
++)
{
pScript
.
append
(
pParameter
.
getName
()).
append
(
"_"
).
append
(
i
).
append
(
" = Environment({'"
);
pScript
.
append
(
pParameter
.
getName
()).
append
(
"':'"
).
append
(
pParameter
.
getValues
().
get
(
i
))
.
append
(
"'}, label='"
).
append
(
pParameter
.
getValues
().
get
(
i
)).
append
(
"')"
);
pScript
.
append
(
"\n"
);
}
}
private
void
defineSystems
(
StringBuffer
pScript
,
List
<
Approach
>
pApproaches
)
{
for
(
int
i
=
0
;
i
<
pApproaches
.
size
();
i
++)
{
pScript
.
append
(
"APPROACH_"
).
append
(
i
).
append
(
" = System({"
);
Map
<
String
,
String
>
variableValues
=
pApproaches
.
get
(
i
).
getVariables
();
List
<
String
>
variables
=
new
ArrayList
<>(
variableValues
.
keySet
());
for
(
int
j
=
0
;
j
<
variables
.
size
();
j
++)
{
if
(
j
!=
0
)
{
pScript
.
append
(
", "
);
}
pScript
.
append
(
"'"
).
append
(
variables
.
get
(
j
)).
append
(
"':'"
).
append
(
variableValues
.
get
(
variables
.
get
(
j
)))
.
append
(
"'"
);
}
pScript
.
append
(
"}).withConfiguration(SystemConfiguration('"
).
append
(
pApproaches
.
get
(
i
).
getName
())
.
append
(
"', {}, color='"
).
append
(
COLORS
[
i
]).
append
(
"'))"
).
append
(
"\n"
);
}
}
private
String
replacePlaceholders
(
String
pLine
)
{
String
result
=
pLine
;
result
=
result
.
replace
(
"{{$$DATABASE_HOST$$}}"
,
"127.0.0.1"
);
result
=
result
.
replace
(
"{{$$DATABASE_PORT$$}}"
,
"3306"
);
result
=
result
.
replace
(
"{{$$DATABASE_USER$$}}"
,
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
().
getUsername
());
result
=
result
.
replace
(
"{{$$DATABASE_PASSWORD$$}}"
,
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
().
getPassword
());
result
=
result
.
replace
(
"{{$$DATABASE_NAME$$}}"
,
WebConfigurationManager
.
getConfig
().
getOptions
().
getDatabase
().
getDatabase
());
result
=
result
.
replace
(
"{{$$SIMONSTRATOR_PLOTTING$$}}"
,
WebConfigurationManager
.
getConfig
().
getOptions
().
getPlotting
().
getPath
());
return
result
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/plotting/Plot.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.plotting
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.XmlIDREF
;
import
de.tudarmstadt.maki.simonstrator.api.web.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.web.approach.Approach
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Plot
{
public
enum
DataType
{
PARAMETER
,
APPROACH
,
METRIC
,
NUMBER
,
STRING
}
public
enum
PlotType
{
TIME
,
BOX
}
@XmlElement
(
name
=
"id"
)
protected
int
_plotID
=
-
1
;
@XmlElementWrapper
(
name
=
"fixed"
)
@XmlElement
(
name
=
"value"
)
protected
Map
<
Parameter
,
String
>
_fixedValues
=
new
HashMap
<>();
@XmlIDREF
@XmlElementWrapper
(
name
=
"metrics"
)
@XmlElement
(
name
=
"metric"
)
protected
Metric
[]
_metrics
;
@XmlIDREF
@XmlElementWrapper
(
name
=
"parameters"
)
@XmlElement
(
name
=
"parameter"
)
protected
Parameter
[]
_parameters
;
@XmlIDREF
@XmlElementWrapper
(
name
=
"approaches"
)
@XmlElement
(
name
=
"approach"
)
protected
List
<
Approach
>
_approaches
=
new
ArrayList
<>();
@XmlElement
(
name
=
"type"
)
protected
PlotType
_type
=
PlotType
.
BOX
;
public
Plot
()
{
}
public
Plot
(
int
pID
)
{
_plotID
=
pID
;
}
public
Metric
[]
getMetrics
()
{
return
_metrics
;
}
public
void
setMetric
(
int
pIndex
,
Metric
pMetric
)
{
_metrics
[
pIndex
]
=
pMetric
;
}
public
int
getNumberOfMetrics
()
{
return
_metrics
.
length
;
}
public
Parameter
[]
getParameters
()
{
return
_parameters
;
}
public
void
setParameter
(
int
pIndex
,
Parameter
pParameter
)
{
_parameters
[
pIndex
]
=
pParameter
;
}
public
int
getNumberOfParameters
()
{
return
_parameters
.
length
;
}
public
int
getPlotID
()
{
return
_plotID
;
}
public
List
<
Approach
>
getApproaches
()
{
return
_approaches
;
}
public
void
addFixedValue
(
Parameter
pParameter
,
String
pValue
)
{
_fixedValues
.
put
(
pParameter
,
pValue
);
}
public
void
removeFixedValue
(
Parameter
pParameter
)
{
_fixedValues
.
remove
(
pParameter
);
}
public
Map
<
Parameter
,
String
>
getFixedValues
()
{
return
Collections
.
unmodifiableMap
(
_fixedValues
);
}
public
void
addApproach
(
Approach
pApproach
)
{
_approaches
.
add
(
pApproach
);
}
public
void
removeApproach
(
Approach
pApproach
)
{
_approaches
.
remove
(
pApproach
);
}
public
void
addApproaches
(
List
<
Approach
>
pApproaches
)
{
_approaches
.
addAll
(
pApproaches
);
}
public
PlotType
getType
()
{
return
_type
;
}
public
String
getName
()
{
switch
(
_type
)
{
case
BOX:
return
"Box Plot"
;
case
TIME:
return
"Time Plot"
;
default
:
return
_type
.
toString
();
}
}
public
Map
<
String
,
DataType
>
getRequiredInput
()
{
Map
<
String
,
DataType
>
result
=
new
TreeMap
<>();
for
(
int
i
=
0
;
i
<
_metrics
.
length
;
i
++)
{
result
.
put
(
"Metric "
+
(
i
+
1
),
DataType
.
METRIC
);
}
for
(
int
i
=
0
;
i
<
_parameters
.
length
;
i
++)
{
result
.
put
(
"Parameter "
+
(
i
+
1
),
DataType
.
PARAMETER
);
}
return
result
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/plotting/Plotter.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.plotting
;
public
interface
Plotter
{
public
enum
ImageFormat
{
JPG
(
"jpg"
),
PNG
(
"png"
),
PDF
(
"pdf"
);
private
String
_extension
;
ImageFormat
(
String
pExtension
)
{
_extension
=
pExtension
;
}
public
String
getExtension
()
{
return
_extension
;
}
}
byte
[]
plotImage
(
Plot
pPlot
,
ImageFormat
pFormat
);
}
src/de/tudarmstadt/maki/simonstrator/api/web/plotting/TimePlot.java
0 → 100755
View file @
195fde5f
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tudarmstadt.maki.simonstrator.api.web.plotting
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
de.tudarmstadt.maki.simonstrator.api.web.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
TimePlot
extends
Plot
{
public
TimePlot
()
{
this
(-
1
);
}
public
TimePlot
(
int
pID
)
{
super
(
pID
);
_metrics
=
new
Metric
[
1
];
_parameters
=
new
Parameter
[
0
];
_type
=
PlotType
.
TIME
;
}
}
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