/// <summary> /// Returns the averaged value of CurrentNetworkLoadIncoming, as a value between 0 and 1, for a time window of up to 254 seconds. /// Triggers load analysis upon first call. /// </summary> /// <param name="secondsToAverage">Number of seconds over which historical data should be used to arrive at an average</param> /// <returns>Average network load as a double between 0 and 1</returns> public static double AverageNetworkLoadOutgoing(byte secondsToAverage) { #if !WINDOWS_PHONE && !ANDROID && !NETFX_CORE if (!NetworkComms.commsShutdown && NetworkLoadThread == null) { lock (NetworkComms.globalDictAndDelegateLocker) { if (!NetworkComms.commsShutdown && NetworkLoadThread == null) { currentNetworkLoadValuesIncoming = new CommsMath(); currentNetworkLoadValuesOutgoing = new CommsMath(); NetworkLoadThread = new Thread(NetworkLoadWorker); NetworkLoadThread.Name = "NetworkLoadThread"; NetworkLoadThread.IsBackground = true; NetworkLoadThread.Start(); } } } return(currentNetworkLoadValuesOutgoing.CalculateMean((int)((secondsToAverage * 1000.0) / NetworkLoadUpdateWindowMS))); #else throw new NotSupportedException("This feature is not supported on the current platform."); #endif }
/// <summary> /// Return the mean of the current list. /// </summary> /// <param name="lastNValues">If less than the number of items in the value list returns the mean of the lastNValues</param> /// <returns>The mean of relevant values</returns> public double CalculateMean(int lastNValues) { lock (locker) { int itemsToSkip = 0; if (lastNValues < values.Count) { itemsToSkip = values.Count - lastNValues; } List <double> itemsForMean = new List <double>(lastNValues); List <double> itemWeights = new List <double>(lastNValues); for (int i = itemsToSkip; i < values.Count; ++i) { itemsForMean.Add(values[i]); itemWeights.Add(weights[i]); } return(CommsMath.CalculateMean(itemsForMean, itemWeights)); } }
/// <summary> /// Return the mean of the current list. /// </summary> /// <returns>The mean of all values currently in the list.</returns> public double CalculateMean() { lock (locker) return(CommsMath.CalculateMean(this.values, this.weights)); }