private Dictionary<GrandezaDE, AnalogicDataRegisterDE> BuscarAnalogicos(DateTime corrente) { Dictionary<GrandezaDE, AnalogicDataRegisterDE> ret = new Dictionary<GrandezaDE, AnalogicDataRegisterDE>(); IntegratedDataRegisterReader reader = new IntegratedDataRegisterReader(corrente, _histFileName, _onlineFileName); List<GrandezaDE> listaGrandezas = reader.Grandezas // .Where(g => (new List<string>() { "MW", "MVAR", "KV" }).Contains(g.MeasureUnit)) .Where(g => (new List<string>() { "KV" }).Contains(g.MeasureUnit)) .OrderBy(l => l.Name).ToList(); List<AnalogicDataRegisterDE> listaAnalogicos = reader.GetValues(listaGrandezas.Select(l => l.Name).ToArray(), corrente).ToList(); listaAnalogicos.ForEach(analogico => ret.Add(listaGrandezas.Find(g => g.Name == analogico.Name), analogico)); return ret; }
private Dictionary<GrandezaDE, List<AnalogicDataRegisterDE>> BuscarPorMedida(string[] medidas, DateTime inicio, DateTime fim, TimeSpan intervalo) { Dictionary<GrandezaDE, List<AnalogicDataRegisterDE>> ret = new Dictionary<GrandezaDE, List<AnalogicDataRegisterDE>>(); // Fazer loop a cada intervalo a partir do início até o fim for (DateTime corrente = inicio; corrente < fim; corrente = corrente.Add(intervalo)) { IntegratedDataRegisterReader reader = new IntegratedDataRegisterReader(corrente, _histFileName, _onlineFileName); foreach (string medida in medidas) { GrandezaDE grandeza = reader.Grandezas.ToList().Find(g => g.Name.Trim() == medida.Trim()); if (grandeza != null) { if (!ret.ContainsKey(grandeza)) ret.Add(grandeza, new List<AnalogicDataRegisterDE>()); List<AnalogicDataRegisterDE> listaAnalogicos = reader.GetValues(new string[] { grandeza.Name }, corrente).ToList(); ret[grandeza].AddRange(listaAnalogicos); } } } return ret; }
private void button1_Click(object sender, EventArgs e) { DateTime horario = new DateTime(2015, 10, 01); IntegratedDataRegisterReader reader = new IntegratedDataRegisterReader(horario, _histFileName, _onlineFileName); List<GrandezaDE> lista = reader.Grandezas .Where(g => (new List<string>() { "MW", "MVAR", "KV" }).Contains(g.MeasureUnit)) .OrderBy(l => l.Name).ToList(); List<string> unidades = reader.Grandezas.Select(g => g.MeasureUnit).Distinct().ToList(); List<AnalogicDataRegisterDE> listaAnalogicos = reader.GetValues(lista.Select(l => l.Name).ToArray(), horario) .ToList(); string calculosOutput = CalculosTeste(lista, listaAnalogicos); using (TextWriter f = File.CreateText(@"outputTeste.txt")) { f.WriteLine("Nome do arquivo: {0}", reader.FileName); f.WriteLine("Data: {0}", reader.LastUpdate); f.WriteLine("*******"); f.WriteLine(calculosOutput); f.WriteLine("*******"); foreach (var item in lista) { AnalogicDataRegisterDE analogico = listaAnalogicos.FirstOrDefault(a => a.Name == item.Name); if (analogico == null) continue; f.WriteLine("******************"); f.WriteLine(item); f.WriteLine("-----"); f.WriteLine(analogico); } } this.Close(); }