public List <AbonentInfo> GetAbonents(DateTime start, DateTime end, double abonentsK) { List <AbonentInfo> abonents = new List <AbonentInfo>(); List <SignalEntry> CurrentEntries = signalEntries.Where(x => x.Time >= start && x.Time < end && x.Type != EntryType.Error).ToList(); if (!CurrentEntries.Any()) { return(abonents); } for (int index = 0; index < signalEntries.Count; index++) { SignalEntry currentEnrty = signalEntries[index]; if (currentEnrty.Type == EntryType.Message) { AbonentInfo current = abonents.FirstOrDefault(x => x.Name == currentEnrty.Abonent.Value); if (current != null) { current.Size += currentEnrty.Size; } else { AbonentInfo newAbonent = new AbonentInfo(currentEnrty.Abonent.Value); newAbonent.Size = currentEnrty.Abonent.Value; abonents.Add(newAbonent); } } else if (currentEnrty.Type == EntryType.Answer) { for (int offset = 1; offset <= index; offset++) { currentEnrty = signalEntries[index - offset]; if (signalEntries[index - offset].Type == EntryType.Answer) { continue; } else { if (currentEnrty.Type == EntryType.Call) { AbonentInfo current = abonents.FirstOrDefault(x => x.Name == currentEnrty.Abonent.Value); if (current != null) { current.Size += currentEnrty.Size; } else { AbonentInfo newAbonent = new AbonentInfo(currentEnrty.Abonent.Value); newAbonent.Size = currentEnrty.Abonent.Value; abonents.Add(newAbonent); } } } } } } if (abonents.Count() > 0) { int max = abonents.Max(x => x.Size); AbonentInfo[] aboInfos = new AbonentInfo[abonents.Count]; abonents.CopyTo(aboInfos, 0); foreach (var abonent in aboInfos) { if (abonent.Size < max * abonentsK) { abonents.Remove(abonent); } Dictionary <int, int> abonentIntervals = GetIntervals(start, end, abonent.Name); abonent.UpdateIntervals(abonentIntervals); } } return(abonents.OrderByDescending(info => info.Size).ToList()); }
public List <SignalEntry> ParseLog(List <string> lines) { List <SignalEntry> entries = new List <SignalEntry>(); for (int i = 0; i < lines.Count(); i++) { string[] lineData = lines[i].Split('\t'); SignalEntry se = new SignalEntry(); int dayNumber = 0; int num = 0; DateTime time; int abonent = 0; int size = 0; int errors = 0; int nInterval = 0; int kInterval = 0; float tuning = 0; // Номер if (Int32.TryParse(lineData[0], out num)) { se.Number = num; // Время if (DateTime.TryParse(lineData[1], out time)) { se.Time = time; // Источник if (lineData[2] == "Глав. Ст.") { se.Source = Source.MainStation; } else { se.Source = Source.Other; } // Тип if (lineData[4] == "Ошибка") { se.Type = EntryType.Error; } else { switch (lineData[3]) { case "Вызов ": se.Type = EntryType.Call; break; case "Ответ ": se.Type = EntryType.Answer; break; case "Сообщение": se.Type = EntryType.Message; break; default: se.Type = EntryType.None; logger.LogMessage("ОШИБКА ПАРСЕРА: не удалось определить тип вхождения.", LogLevel.Error); break; } } // Абонент if (Int32.TryParse(lineData[4], out abonent)) { se.Abonent = abonent; } else { se.Abonent = null; } // Объем if (Int32.TryParse(lineData[5], out size)) { se.Size = size; } else { se.Size = 0; } // Ошибки if (Int32.TryParse(lineData[6], out errors)) { se.Errors = errors; } // Н-Интервал if (Int32.TryParse(lineData[7], out nInterval)) { se.Ninterval = nInterval; } // К-Интервал if (Int32.TryParse(lineData[8], out kInterval)) { se.Kinterval = kInterval; } // Скорость/Длина // Расстройка if (lineData[10].Count() > 2) { string value = lineData[10].Substring(1); if (float.TryParse(value.Replace('.', ','), out tuning)) { se.Tuning = tuning; } if (lineData[10][0] == '-') { se.Tuning = -se.Tuning; } } // Корректирование даты if (entries.Any() && entries.Last().Time > se.Time) { DecrementDay(entries); } se.Time = se.Time.AddDays((double)dayNumber); entries.Add(se); } } } return(entries); }