Commit 5ee2eab0 authored by Simon Luser's avatar Simon Luser
Browse files

added message to statistics storage

parent d8e606f4
......@@ -49,6 +49,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatisticMsgType;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
......@@ -156,6 +157,7 @@ public class DAO {
cfg.addAnnotatedClass(MeasurementPairList.class);
cfg.addAnnotatedClass(MeasurementSingle.class);
cfg.addAnnotatedClass(MeasurementStatistic.class);
cfg.addAnnotatedClass(MeasurementStatisticMsgType.class);
cfg.addAnnotatedClass(Metric.class);
cfg.addAnnotatedClass(MetricDescription.class);
......
......@@ -33,9 +33,11 @@ import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatisticMsgType;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import de.tud.kom.p2psim.impl.util.stats.StatisticComputation;
import de.tudarmstadt.maki.simonstrator.api.MessageWithDisasterType.MessageDisasterType;
/**
* This class provides methods to persist measurements in a database.
......@@ -203,7 +205,77 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement);
}
/**
* Stores a statistical description of a series of values for group of
* hosts.
*
* @param metricDesc
* The {@link MetricDescription} which describes the metric.
* @param groupName
* The host group
* @param time
* A time for the measurement in simulation time
* @param stats
* the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
* @param msgType
* the message type this statistic is for
*/
public static void storeGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, MessageDisasterType msgType) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatisticMsgType measurement = new MeasurementStatisticMsgType(time, stats,
groupMetric, observationDuration, describesWholeSimulation,
msgType);
addToPersistQueue(measurement);
}
/**
* Stores a statistical description of a series of values for group of hosts
* and a given spatial coordinate.
*
* @param metricDesc
* The {@link MetricDescription} which describes the metric.
* @param groupName
* The host group
* @param time
* A time for the measurement in simulation time
* @param stats
* the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
* @param msgType
* the message type this statistic is for
*/
public static void storeSpatialGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY,
MessageDisasterType msgType) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatisticMsgType measurement = new MeasurementStatisticMsgType(time, stats,
groupMetric, observationDuration, describesWholeSimulation,
locationX, locationY, msgType);
addToPersistQueue(measurement);
}
/**
* Store a list-based measurement with a key (i.e., as a
* {@link MeasurementPairList}).
......
/*
* 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.util.db.metric;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import de.tudarmstadt.maki.simonstrator.api.MessageWithDisasterType.MessageDisasterType;
/**
*
* Statistical representation of a series of measurements in the database,
* intended to capture all relevant metrics for boxplots.
*
* @author Bjoern Richerzhagen
*/
@Entity
@Table(name = "measurements_statistics_msg", indexes = {
@Index(columnList = "id", name = "id") })
public class MeasurementStatisticMsgType implements GroupMetricBound {
/**
* The id of this table
*/
@Id
@GeneratedValue
private int id;
/**
* The simulation time for to this measurement in simulator time, that is,
* microseconds.
*/
@Column(nullable = true, name = "[time]")
private long time;
@Column(nullable = false, name = "[describesWholeSimulation]")
private boolean describesWholeSimulation;
/**
* The simulation time for to this measurement in simulator time, that is,
* microseconds.
*/
@Column(nullable = true, name = "[observationDuration]")
private long observationDuration;
/**
* The number of values
*/
@Column(nullable = true, name = "[values]")
private Double values;
@Column(nullable = true, name = "[std]")
private Double std;
@Column(nullable = true, name = "[sum]")
private Double sum;
@Column(nullable = true, name = "[sum2]")
private Double sum2;
/**
* The minimum of all values for this measurement
*/
@Column(nullable = true, name = "[min]")
private Double min;
/**
* The maximum of all values for this measurement
*/
@Column(nullable = true, name = "[max]")
private Double max;
@Column(nullable = true, name = "[mean]")
private Double mean;
@Column(nullable = true, name = "[median]")
private Double median;
@Column(nullable = true, name = "[perc25]")
private Double perc25;
@Column(nullable = true, name = "[perc75]")
private Double perc75;
@Column(nullable = true, name = "[perc97]")
private Double perc97; // 97,7
@Column(nullable = true, name = "[perc2]")
private Double perc2; // 2,3
@Column(nullable = true, name = "[perc95]")
private Double perc95; // 95
@Column(nullable = true, name = "[perc5]")
private Double perc5; // 5
@Column(nullable = true, name = "[locationX]")
private Integer locationX;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
@Column(nullable = true, name = "[isSpatial]")
private boolean isSpatial;
@Column(nullable = true, name = "[messageType]")
private String msgType;
/**
* Mapping to group metric
*/
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "groupMetricId")
GroupMetric groupMetric;
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object.
*
* @param time
* The simulation time for to this measurement as Date
* @param stats
* the {@link DescriptiveStatistics} object
* @param hostMetric
* The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
*/
public MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, MessageDisasterType msgType) {
this(time, stats, observationDuration, describesWholeSimulation,
msgType);
this.groupMetric = groupMetric;
}
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object, with spatial data attached.
*
* @param time
* The simulation time for to this measurement as Date
* @param stats
* the {@link DescriptiveStatistics} object
* @param hostMetric
* The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
*/
public MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY,
MessageDisasterType msgType) {
this(time, stats, observationDuration, describesWholeSimulation,
msgType);
this.groupMetric = groupMetric;
this.locationX = locationX;
this.locationY = locationY;
this.isSpatial = true;
}
/**
* Internal - write statistics
*
* @param time
* @param stats
* @param observationDuration
* duration covered by this measurement in simulation units
* @param msgType
*/
private MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
long observationDuration, boolean describesWholeSimulation,
MessageDisasterType msgType) {
super();
this.time = time;
this.observationDuration = observationDuration;
this.describesWholeSimulation = describesWholeSimulation;
this.values = checkForSpecialNumbers((double) stats.getN());
this.sum = checkForSpecialNumbers(stats.getSum());
this.sum2 = checkForSpecialNumbers(stats.getSumsq());
this.min = checkForSpecialNumbers(stats.getMin());
this.max = checkForSpecialNumbers(stats.getMax());
this.mean = checkForSpecialNumbers(stats.getMean());
this.median = checkForSpecialNumbers(stats.getPercentile(50));
this.perc2 = checkForSpecialNumbers(stats.getPercentile(2.3));
this.perc25 = checkForSpecialNumbers(stats.getPercentile(25));
this.perc75 = checkForSpecialNumbers(stats.getPercentile(75));
this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7));
this.perc5 = checkForSpecialNumbers(stats.getPercentile(5));
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.std = checkForSpecialNumbers(stats.getStandardDeviation());
this.isSpatial = false;
if (msgType != null)
this.msgType = msgType.name();
}
/**
* Check for special numbers, like infinity or NaN. If the given value is
* equals this numbers then will be return null, otherwise will be returned
* the given value.
*
* @param value
* The value, which should be checked.
* @return The value or null, if it is a special number.
*/
private Double checkForSpecialNumbers(Double value) {
if (value == null)
return value;
if (value.equals(Double.NEGATIVE_INFINITY)
|| value.equals(Double.POSITIVE_INFINITY)
|| value.equals(Double.NaN)) {
return null;
} else {
return value;
}
}
@Override
public GroupMetric getGroupMetric() {
return groupMetric;
}
@Override
public void setGroupMetric(GroupMetric metric) {
this.groupMetric = metric;
}
}
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