public static HourlyUsage ToHourlyUsage(this List <UsageRow> hourlyUsageRows, int minutesOffset, out UsageRow overflow) { var dailyUsage = HourlyTransformations.GetHourlyUsage(hourlyUsageRows, minutesOffset, out overflow); return(dailyUsage); }
public void FinishRows(out UsageRow overflow) { if (_secondsElapsed > 3600.0f) { DateTime oneHourLater = _startTimeUTC.AddMinutes(-_startTimeUTC.Minute) .AddSeconds(-_startTimeUTC.Second) .AddHours(1); overflow = new UsageRow(new UserUsage { AppNames = new string[] { }, AppUsedNameHashCodes = _overflowFilteredApps.ToArray(), AppUsedSeconds = _overflowFilteredSeconds.ToArray(), Start = oneHourLater }); } else { overflow = null; float secondsTotal = _filteredSeconds.Sum(); if (secondsTotal < 3600.0f) { Log(noActivityApp, 3600.0f - secondsTotal); } } }
private static void AddToAppNames(UsageRow row, HashSet <string> appNames) { foreach (string appName in row.AppNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { appNames.Add(appName); } }
//private DateTime _currentTime; public void StartRow(UsageRow row) { DateTime rowTime = row.GetStartTime(_minutesOffset); if (!_startTime.HasValue) { _startTime = new DateTime(rowTime.Year, rowTime.Month, rowTime.Day, rowTime.Hour, 0, 0); _startTimeUTC = row.GetStartTimeUtc(); _secondsElapsed = 0.0f; } AddGapIfTimeGreaterThan2Seconds(rowTime, _secondsElapsed); TimeSpan ts = rowTime.Subtract(_startTime.Value); _secondsElapsed = (float)ts.TotalSeconds; }
public static HourlyUsage GetHourlyUsage(List <UsageRow> hourlyUsageRows, int minutesOffset, out UsageRow overflow) { var results = new HourlyTransformationResults(minutesOffset); // Create 1 buffer for each hour. This reduces the number of memory allocations. int usageInTotalBytes = GetUsageInSecondsTotal(hourlyUsageRows); var hashCodes = new uint[usageInTotalBytes / 4]; var times = new float[usageInTotalBytes / 4]; int destOffset = 0; foreach (UsageRow row in hourlyUsageRows) { var count = row.Apps.Length; Buffer.BlockCopy(row.UsageInSeconds, 0, times, destOffset, count); Buffer.BlockCopy(row.Apps, 0, hashCodes, destOffset, count); results.StartRow(row); int start = destOffset / 4; int end = start + (count / 4); for (int i = start; i < end; i++) { uint currentApp = hashCodes[i]; float currentAppTime = times[i]; results.Log(currentApp, currentAppTime); } destOffset += count; } results.FinishRows(out overflow); return(results.ToHourlyUsage()); }