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
PeerfactSim.KOM
Commits
b3c75941
Commit
b3c75941
authored
Oct 10, 2018
by
Tobias Meuser
Browse files
Implemented abstract spatial plot functionality
parent
4a2e7fa0
Changes
4
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
View file @
b3c75941
...
...
@@ -37,6 +37,9 @@ import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import
de.tud.kom.p2psim.impl.util.oracle.GlobalOracle
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveMetric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.ActiveSpatialMetricListener
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.SpatialMetricValue
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveMetric.ActiveMetricListener
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue
;
...
...
@@ -57,7 +60,7 @@ public class MetricOutputDAO extends AbstractOutput {
protected
Set
<
String
>
metricsToAggregate
=
new
LinkedHashSet
<>();
protected
List
<
Metric
DaoAdapter
>
daoAdapters
=
new
LinkedList
<>();
protected
List
<
DaoAdapter
>
daoAdapters
=
new
LinkedList
<>();
/**
*
...
...
@@ -133,12 +136,18 @@ public class MetricOutputDAO extends AbstractOutput {
am
.
addActiveMetricListener
(
adapter
);
daoAdapters
.
add
(
adapter
);
}
if
(
metric
instanceof
ActiveSpatialMetric
)
{
ActiveSpatialMetric
asm
=
(
ActiveSpatialMetric
)
metric
;
SpatialMetricDaoAdapter
adapter
=
new
SpatialMetricDaoAdapter
(
asm
);
asm
.
addActiveSpatialMetricListener
(
adapter
);
daoAdapters
.
add
(
adapter
);
}
}
}
@Override
public
void
onStop
()
{
for
(
Metric
DaoAdapter
adapter
:
daoAdapters
)
{
for
(
DaoAdapter
adapter
:
daoAdapters
)
{
adapter
.
onStop
();
}
/*
...
...
@@ -147,13 +156,17 @@ public class MetricOutputDAO extends AbstractOutput {
DAO
.
commitQueue
();
}
private
interface
DaoAdapter
{
void
onStop
();
}
/**
* This class helps in persisting a metric using the {@link MeasurementDAO}
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
private
class
MetricDaoAdapter
implements
ActiveMetricListener
{
private
class
MetricDaoAdapter
implements
ActiveMetricListener
,
DaoAdapter
{
private
final
ActiveMetric
metric
;
...
...
@@ -288,4 +301,91 @@ public class MetricOutputDAO extends AbstractOutput {
}
/**
* This class helps in persisting a spatial metric using the {@link MeasurementDAO}
*
* @author Tobias Meuser
* @version 1.0, 10.10.2018
*/
private
class
SpatialMetricDaoAdapter
implements
ActiveSpatialMetricListener
,
DaoAdapter
{
private
final
MetricDescription
md
;
private
final
MeasurementDAO
dao
=
new
MeasurementDAO
();
private
final
List
<
SimHost
>
hosts
;
private
final
Map
<
String
,
List
<
SimHost
>>
hostsByGroup
;
private
final
Map
<
String
,
DescriptiveStatistics
>
globalStatsByGroup
;
private
double
spatialResolution
=
20
;
public
SpatialMetricDaoAdapter
(
ActiveSpatialMetric
metric
)
{
this
.
md
=
new
MetricDescription
(
MetricOutputDAO
.
class
.
getName
(),
metric
.
getName
(),
metric
.
getDescription
(),
metric
.
getUnit
().
toString
());
this
.
hosts
=
GlobalOracle
.
getHosts
();
this
.
hostsByGroup
=
new
LinkedHashMap
<>();
this
.
globalStatsByGroup
=
new
LinkedHashMap
<>();
for
(
SimHost
simHost
:
hosts
)
{
String
groupId
=
simHost
.
getProperties
().
getGroupID
();
if
(!
this
.
hostsByGroup
.
containsKey
(
groupId
))
{
this
.
hostsByGroup
.
put
(
groupId
,
new
LinkedList
<>());
this
.
globalStatsByGroup
.
put
(
groupId
,
new
DescriptiveStatistics
());
}
this
.
hostsByGroup
.
get
(
groupId
).
add
(
simHost
);
}
}
@Override
public
void
onStop
()
{
// Noting to do here
}
@Override
public
void
onMetricUpdate
(
ActiveSpatialMetric
<?>
metric
)
{
long
time
=
Time
.
getCurrentTime
();
if
(
time
<
timeEnableDao
||
time
>
timeStopDao
)
{
return
;
}
if
(
metric
.
isOverallMetric
())
{
// global
SpatialMetricValue
mv
=
metric
.
getOverallMetric
();
Object
val
=
mv
.
getValue
();
if
(
mv
.
isValid
())
{
if
(
val
instanceof
Number
)
{
double
vd
=
((
Number
)
val
).
doubleValue
();
dao
.
storeGlobalSpatialMeasurement
(
md
,
time
,
vd
,
(
int
)
(
mv
.
getLocation
().
getLongitude
()
/
spatialResolution
),
(
int
)
(
mv
.
getLocation
().
getLatitude
()
/
spatialResolution
));
}
}
}
else
{
for
(
SimHost
host
:
hosts
)
{
SpatialMetricValue
mv
=
metric
.
getPerHostMetric
(
host
.
getId
());
if
(
mv
!=
null
)
{
Object
val
=
mv
.
getValue
();
if
(
mv
.
isValid
())
{
if
(
val
instanceof
Number
)
{
double
vd
=
((
Number
)
val
).
doubleValue
();
if
(
Double
.
isNaN
(
vd
))
{
continue
;
}
dao
.
storeSpatialMeasurement
(
md
,
host
.
getId
().
value
(),
time
,
vd
,
(
int
)
(
mv
.
getLocation
().
getLongitude
()
/
spatialResolution
),
(
int
)
(
mv
.
getLocation
().
getLatitude
()
/
spatialResolution
));
}
}
}
}
}
}
}
}
src/de/tud/kom/p2psim/impl/analyzer/metric/spatial/AbstractSpatialMetric.java
0 → 100755
View file @
b3c75941
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.tud.kom.p2psim.impl.analyzer.metric.spatial
;
import
java.util.ArrayList
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.AbstractMetric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.Metric
;
public
abstract
class
AbstractSpatialMetric
<
T
extends
AbstractSpatialMetricValue
<?>>
extends
AbstractMetric
<
T
>
implements
Metric
<
T
>,
ActiveSpatialMetric
<
T
>
{
public
AbstractSpatialMetric
(
String
pDescription
,
MetricUnit
pUnit
)
{
super
(
pDescription
,
pUnit
);
}
public
AbstractSpatialMetric
(
String
pName
,
String
pDescription
,
MetricUnit
pUnit
)
{
super
(
pName
,
pDescription
,
pUnit
);
}
protected
void
setOverallMetric
(
T
aggregate
)
{
super
.
setOverallMetric
(
aggregate
);
}
private
List
<
ActiveSpatialMetricListener
>
_listeners
=
new
ArrayList
<>();
@Override
public
void
addActiveSpatialMetricListener
(
ActiveSpatialMetricListener
pListener
)
{
_listeners
.
add
(
pListener
);
}
@Override
public
void
notifyListeners
()
{
for
(
ActiveSpatialMetricListener
activeSpatialMetricListener
:
_listeners
)
{
activeSpatialMetricListener
.
onMetricUpdate
(
this
);
}
}
}
src/de/tud/kom/p2psim/impl/analyzer/metric/spatial/AbstractSpatialMetricValue.java
0 → 100755
View file @
b3c75941
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.tud.kom.p2psim.impl.analyzer.metric.spatial
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.SpatialMetricValue
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
abstract
class
AbstractSpatialMetricValue
<
S
extends
Object
>
implements
SpatialMetricValue
<
S
>
{
private
S
value
;
private
Location
location
;
private
ActiveSpatialMetric
<?>
metric
;
public
AbstractSpatialMetricValue
(
ActiveSpatialMetric
<?>
pMetric
)
{
metric
=
pMetric
;
}
public
AbstractSpatialMetricValue
(
ActiveSpatialMetric
<?>
pMetric
,
S
pValue
)
{
metric
=
pMetric
;
value
=
pValue
;
}
public
void
setValue
(
S
pValue
,
Location
pLocation
)
{
value
=
pValue
;
location
=
pLocation
;
metric
.
notifyListeners
();
}
@Override
public
S
getValue
()
{
return
value
;
}
@Override
public
Location
getLocation
()
{
return
location
;
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java
View file @
b3c75941
...
...
@@ -128,6 +128,22 @@ public class MeasurementDAO extends DAO {
addToPersistQueue
(
measurement
);
}
/**
* Store a global single measurement for a host, tied to a specific location.
*
* @param metricDesc
* @param hostId
* @param time
* @param value
* @param locationX
* @param locationY
*/
public
static
void
storeGlobalSpatialMeasurement
(
MetricDescription
metricDesc
,
long
time
,
double
value
,
int
locationX
,
int
locationY
)
{
storeSpatialMeasurement
(
metricDesc
,
GLOBAL_HOST_ID
,
time
,
value
,
locationX
,
locationY
);
}
/**
* Stores for a series of measurements the given values for a host. The
* given values are a statistical representation of the series of
...
...
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