Commit 01a0c104 authored by Marc Schiller's avatar Marc Schiller
Browse files

Merge branch 'nr/monitoring-model' of...

Merge branch 'nr/monitoring-model' of dev.kom.e-technik.tu-darmstadt.de:simonstrator/simonstrator-peerfactsim into nr/monitoring-model
parents 2cef2da2 d9491c91
......@@ -206,7 +206,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
if (isOverallMetric) {
M overall = getDerivedMetricValueFor(DerivedMetric.this,
incoming, null);
setOverallMetric(overall);
if (overall != null) {
setOverallMetric(overall);
}
} else {
for (Host host : hosts) {
M perHost = getDerivedMetricValueFor(DerivedMetric.this,
......
......@@ -83,14 +83,17 @@ public abstract class StatisticsFilter extends
Metric<?> derivedMetric, List<Metric<?>> inputs, Host host) {
assert inputs.size() == 1;
assert host == null;
Metric<?> input = inputs.get(0);
Metric<? extends MetricValue<?>> input = inputs.get(0);
if (input.isOverallMetric()) {
throw new AssertionError(
"Only available for per-host input metrics.");
}
LinkedList<MetricValue> mvs = new LinkedList<MetricValue>(
input.getAllPerHostMetrics());
return new StatisticsMetricValue(mvs);
List<? extends MetricValue<?>> values = input.getAllPerHostMetrics();
if (values == null || values.isEmpty()) {
return null;
}
LinkedList<MetricValue> mvs = new LinkedList<MetricValue>(values);
return new StatisticsMetricValue(mvs);
}
/**
......
......@@ -239,12 +239,32 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
* host.
*/
PositionVector attractionCenter = (PositionVector) newAssignment;
PositionVector destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3);
destination.add(offset);
PositionVector destination = null;
int tries = 0;
do {
destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3);
destination.add(offset);
// Check constraints
if (destination.getX() < 0.0
|| destination.getX() > Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() || destination.getY() < 0.0
|| destination.getY() > Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getY()) {
destination = null;
if (tries > 100) {
throw new AssertionError("Unable to find a valid target destination within <100 tries.");
}
}
tries++;
} while (destination == null);
currentTarget.put(component, destination);
}
......
......@@ -20,6 +20,8 @@
package de.tud.kom.p2psim.impl.topology.views.visualization.world;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
......@@ -165,15 +167,56 @@ public class NodeInfoComponentVis extends JComponent
private final Color activeGreen = new Color(0, 200, 0);
private final Color[] colors = { Color.ORANGE, Color.BLUE, Color.RED,
Color.MAGENTA, Color.GRAY, Color.GREEN, Color.CYAN,
Color.PINK };
private final Color[] baseColors = { Color.ORANGE, Color.BLUE, Color.RED,
Color.PINK, Color.GRAY, Color.GREEN, Color.CYAN,
Color.WHITE };
private final Color[] tuColors = {
new Color(93, 133, 195), // 1a
new Color(80, 182, 149), // 3a
// new Color(221,223,72), // 5a
new Color(248,186,60), // 7a
new Color(233,80,62), // 9a
new Color(128, 69, 151), // 11a
new Color(0, 78, 138), // 1c
new Color(0, 136, 119), // 3c
// new Color(177, 189, 0), // 5c
new Color(210, 135, 0), // 7c
new Color(185, 15, 34), // 9c
new Color(97, 28, 115), // 11c
};
private Color[][] colors = null;
public NodeVis(Host host, NodeInformation nodeInfo) {
this.nodeInfo = nodeInfo;
this.host = (SimHost) host;
this.loc = this.host.getTopologyComponent().getRealPosition();
this.visNodeInfo = VisualizationInjector.getNodeInformation(host.getId());
/*
* Create per-info-option colors by deriving the color from the base color
*/
colors = new Color[nodeInfo.getNodeColorDimensions()][];
for (int dim = 0; dim < colors.length; dim++) {
Color baseColor = baseColors[dim];
int dimensionSize = nodeInfo
.getNodeColorDescriptions(dim).length;
colors[dim] = new Color[dimensionSize];
/*
* http://stackoverflow.com/questions/2355157/dynamically-
* creating-colors-with-different-brightness
*/
// float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(),
// baseColor.getGreen(), baseColor.getBlue(), null);
for (int i = 0; i < dimensionSize; i++) {
float hue = i / (float) dimensionSize;
// colors[dim][i] = Color.getHSBColor(hue, hsbVals[1],
// hsbVals[2]);
colors[dim][i] = tuColors[i];
}
}
}
/**
......@@ -184,24 +227,28 @@ public class NodeInfoComponentVis extends JComponent
*/
public void drawLegend(Graphics2D g2) {
String[] dimensions = nodeInfo.getNodeColorDimensionDescriptions();
int radius = 4;
for (int dim = 0; dim < dimensions.length; dim++) {
radius += 2;
if (!activeLayers[dim]) {
int segments = dimensions.length;
int segmentDegrees = (int) (360 / (double) segments);
int arcSize = 8;
g2.setStroke(new BasicStroke(3));
for (int color = 0; color < segments; color++) {
if (!activeLayers[color]) {
continue;
}
g2.setColor(Color.DARK_GRAY);
g2.drawOval(10, 20 * (dim + 1) - 10, radius * 2, radius * 2);
g2.drawString(dimensions[dim], 30, 20 * (dim + 1));
String[] colorDescs = nodeInfo.getNodeColorDescriptions(dim);
g2.drawArc(10, 20 * (color + 1)+10, 2*arcSize, 2*arcSize, color*segmentDegrees, segmentDegrees);
String[] colorDescs = nodeInfo.getNodeColorDescriptions(color);
for (int i = 0; i < colorDescs.length; i++) {
g2.setColor(colors[i]);
g2.fillRect(30 + (i + 1) * 90, 20 * (dim + 1) - 10, 8, 8);
g2.setColor(colors[color][i]);
g2.fillRect(40 + i * 90, 20 * (color + 1)+10, 8, 8);
g2.setColor(Color.DARK_GRAY);
g2.drawString(colorDescs[i], 40 + (i + 1) * 90,
20 * (dim + 1));
g2.drawString(colorDescs[i], 50 + i * 90,
20 * (color + 2));
}
}
g2.setStroke(new BasicStroke(1));
}
public void draw(Graphics2D g2) {
......@@ -222,24 +269,26 @@ public class NodeInfoComponentVis extends JComponent
if (!nodeInfo.isActive()) {
return;
}
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1.0f));
/*
* TODO add offline/online info here as well (removes the need for a
* custom object that visualizes the underlay!)
*/
int numColors = nodeInfo.getNodeColorDimensions();
radius = 4;
for (int color = 0; color < numColors; color++) {
int value = nodeInfo.getNodeColor(color);
radius += 2;
if (value < 0 || !activeLayers[color]) {
int segments = nodeInfo.getNodeColorDimensions();
int segmentDegrees = (int) (360 / (double) segments);
int arcSize = 8;
g2.setStroke(new BasicStroke(8, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
for (int dim = 0; dim < segments; dim++) {
int value = nodeInfo.getNodeColor(dim);
if (value < 0 || !activeLayers[dim]) {
continue;
}
g2.setColor(colors[value]);
g2.drawOval(center.x - radius, center.y - radius, radius * 2,
radius * 2);
g2.setColor(colors[dim][value]);
g2.drawArc(center.x-arcSize, center.y-arcSize, 2*arcSize, 2*arcSize, dim*segmentDegrees, segmentDegrees);
}
g2.setStroke(new BasicStroke(1));
String nodeDesc = nodeInfo.getNodeDescription();
g2.drawString(nodeDesc, center.x + 4, center.y + 4);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment