public void SetPackets(LogPacket[] packets) { _packets = packets; if (packets.Length > 0) { _bytag = packets.GroupBy(p => String.IsNullOrWhiteSpace(p.Tag) ? "Unknown Tag" : p.Tag).ToDictionary(g => g.Key, g => g.ToList()); comboBoxTag.Items.Clear(); comboBoxTag.Items.Add(Properties.Resources.HistogramChartControl_AllTags); foreach (KeyValuePair<string, List<LogPacket>> pair in _bytag) { comboBoxTag.Items.Add(pair.Key); } comboBoxTag.SelectedIndex = 0; } else { _bytag = new Dictionary<string, List<LogPacket>>(); } }
public void SetPackets(LogPacket[] packets) { _packets = packets; if (packets.Length > 0) { _bytag = packets.GroupBy(p => String.IsNullOrWhiteSpace(p.Tag) ? "Unknown Tag" : p.Tag).ToDictionary(g => g.Key, g => g.ToList()); _startTime = DateTime.MaxValue; _endTime = DateTime.MinValue; foreach (LogPacket packet in _packets) { if (packet.Timestamp < _startTime) { _startTime = packet.Timestamp; } if (packet.Timestamp > _endTime) { _endTime = packet.Timestamp; } } double secs = _endTime.Subtract(_startTime).TotalSeconds; double bucketLength = secs / (double)MAX_BUCKETS; int bucketCount = MAX_BUCKETS+1; if(bucketLength < MIN_TIME_DIVISION) { bucketCount = (int)Math.Ceiling(secs / MIN_TIME_DIVISION) + 1; bucketLength = MIN_TIME_DIVISION; } _bucketsByteCount = new Dictionary<string, long>[bucketCount]; _bucketLength = bucketLength; for (int i = 0; i < bucketCount; ++i) { _bucketsByteCount[i] = new Dictionary<string, long>(); } foreach (LogPacket packet in _packets) { TimeSpan currSpan = packet.Timestamp.Subtract(_startTime); int bucketNumber = (int)Math.Truncate(currSpan.TotalSeconds / bucketLength); string tag = packet.Tag ?? "Unknown Tag"; Dictionary<string, long> bucket = _bucketsByteCount[bucketNumber]; if (!bucket.ContainsKey(tag)) { bucket[tag] = 0; } bucket[tag] = bucket[tag] + packet.Length; } } else { _bytag = new Dictionary<string, List<LogPacket>>(); } UpdateChart(); }