/** * Cars Per Hour model works by creating 24 normal distributions (1 for each hour of the day). * After the model is generated, you can sample it with the sampleCarsPerHourModel function */ public void generateCarsPerHourModel() { // Get statistical data for counts at each hour Map<Integer, SummaryStatistics> summaries = new HashMap<>(); for (Map.Entry<String, Integer> count : hourlyTrafficCountData.entrySet()) { // Java stores times in milliseconds since epoch, hence the *1000. String key = count.getKey(); long timestamp = Long.parseLong(key) * 1000; int cars_per_hour = count.getValue(); DateTime time = new DateTime(timestamp, DateTimeZone.UTC); int hour = time.getHourOfDay(); SummaryStatistics stats; if (summaries.containsKey(hour)) { // Started gathering statistics, add to it stats = summaries.get(hour); } else { // Will now start gathering statistics stats = new SummaryStatistics(); summaries.put(hour, stats); } stats.addValue(cars_per_hour); } // Make model based on statistics gathered carsPerHour = new HashMap<>(); for (Map.Entry<Integer, SummaryStatistics> per_hour_stats : summaries.entrySet()) { int hour = per_hour_stats.getKey(); SummaryStatistics stats = per_hour_stats.getValue(); // Create distribution based on stats NormalDistribution distribution; try { distribution = new NormalDistribution(stats.getMean(), stats.getStandardDeviation()); } catch (Exception ignored) { // No distribution made, as all counts had the same number (no deviation). // We'll assume our counts are pretty close to historical values. distribution = new NormalDistribution(stats.getMean(), 10 / stats.getN()); } carsPerHour.put(hour, distribution); } }
/** * Get the Standard Deviation of all the stats that are watched, for all the stats added with * add() since the last call to clear() in JSON. * * @return The Standard Deviation of all the stats since last clear() in JSON. */ public String getStandardDeviationJSON() { String str = String.format( FakeUserStats.jsonMediaStreamStatsTemplate, -1, // ssrc not needed here downloadJitterMs.getStandardDeviation(), downloadPercentLoss.getStandardDeviation(), downloadRateKiloBitPerSec.getStandardDeviation(), jitterBufferDelayMs.getStandardDeviation(), jitterBufferDelayPackets.getStandardDeviation(), nbDiscarded.getStandardDeviation(), nbDiscardedFull.getStandardDeviation(), nbDiscardedLate.getStandardDeviation(), nbDiscardedReset.getStandardDeviation(), nbDiscardedShrink.getStandardDeviation(), nbFec.getStandardDeviation(), nbPackets.getStandardDeviation(), nbPacketsLost.getStandardDeviation(), nbReceivedBytes.getStandardDeviation(), nbSentBytes.getStandardDeviation(), packetQueueCountPackets.getStandardDeviation(), packetQueueSize.getStandardDeviation(), percentDiscarded.getStandardDeviation(), rttMs.getStandardDeviation(), uploadJitterMs.getStandardDeviation(), uploadPercentLoss.getStandardDeviation(), uploadRateKiloBitPerSec.getStandardDeviation()); return str; }
/** @return Standard deviation for peak values for all TACs in cluster. */ public double getPeakStdev() { long n = peak_stats.getN(); if (n == 1) return getPeakMean(); else return peak_stats.getStandardDeviation(); }