예제 #1
0
        public List <Devices> GetDDevices()
        {
            ION_DataEntities  ion     = new ION_DataEntities();
            Model_Aplications hierarc = new Model_Aplications();

            List <Devices> listDevice = new List <Devices>();

            var pred = (from p in hierarc.TripleView
                        where p.Predicate == "Numerogdis"
                        select p).Where(p => p.ObjectLiteral != null).ToList();

            foreach (var o in pred)
            {
                var ob = (from obi in hierarc.TripleView
                          where obi.Subject == o.Subject
                          select obi).Where(obi => obi.Predicate == "meteredBy").ToList();
                foreach (var d in ob)
                {
                    var obd = Convert.ToInt64(d.Object);
                    var t   = (from tri in hierarc.DataSourceDevice
                               where tri.LogicalDeviceId == obd
                               select tri
                               ).ToList();
                    foreach (var s in t)
                    {
                        var source = (from so in ion.Source
                                      where so.Name == s.Description
                                      select so).ToList();
                        foreach (var dev in source)
                        {
                            listDevice.Add(new Devices
                            {
                                numeroInstalacao   = o.ObjectLiteral,
                                numeroSerieMedidor = dev.Signature,
                                idMedidor          = dev.ID,
                                name = dev.Name
                            });
                        }
                    }
                }
            }
            return(listDevice);
        }
예제 #2
0
        public static List <DrpDrc> GetInDrp_Drc(DateTime inicio, DateTime fim, string tipoMedicao)
        {
            Model_Aplications app        = new Model_Aplications();
            ION_DataEntities  ion        = new ION_DataEntities();
            List <DrpDrc>     drp_drc    = new List <DrpDrc>();
            List <DrpDrc>     indicators = new List <DrpDrc>();

            Devices devices = new Devices();

            var source = devices.GetDDevices().ToList();

            if (tipoMedicao == "1")
            {
                foreach (var d in source)
                {
                    try
                    {
                        ion.MEMT_API_Prodist(d.idMedidor, Convert.ToDateTime(inicio), Convert.ToDateTime(fim), tipoMedicao);
                        var prod = (from p in ion.Api_Transgression
                                    select p).ToList();
                        foreach (var p in prod)
                        {
                            drp_drc.Add(new DrpDrc
                            {
                                numeroInstalacao = d.numeroInstalacao,
                                DRP           = Math.Round(p.DRP.Value, 2),
                                DRC           = Math.Round(p.DRC.Value, 2),
                                inicioMedicao = p.FirstTimestamp,
                                fimMedicao    = p.LastTimestamp
                            });
                        }
                    }
                    catch (System.Exception)
                    {
                    }
                }
            }
            if (tipoMedicao == "2")
            {
                foreach (var meter in source)
                {
                    try
                    {
                        ion.MEMT_API_Prodist(meter.idMedidor, Convert.ToDateTime(inicio), Convert.ToDateTime(fim), tipoMedicao);
                        var prod = (from p in ion.Api_Transgression
                                    select p).ToList();
                        foreach (var p in prod)
                        {
                            if (meter.numeroInstalacao == "n/a")
                            {
                                indicators.Add(new DrpDrc
                                {
                                    numeroInstalacao = meter.name,
                                    DRP           = Math.Round(p.DRP.Value, 2),
                                    DRC           = Math.Round(p.DRC.Value, 2),
                                    inicioMedicao = p.FirstTimestamp,
                                    fimMedicao    = p.LastTimestamp
                                });
                            }
                            else
                            {
                                indicators.Add(new DrpDrc
                                {
                                    numeroInstalacao = meter.numeroInstalacao,
                                    DRP           = Math.Round(p.DRP.Value, 2),
                                    DRC           = Math.Round(p.DRC.Value, 2),
                                    inicioMedicao = p.FirstTimestamp,
                                    fimMedicao    = p.LastTimestamp
                                });
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                var drpMedia = indicators.Sum(x => x.DRP) / indicators.Count();
                var drcMedia = indicators.Sum(x => x.DRC) / indicators.Count();
                foreach (var i in indicators)
                {
                    drp_drc.Add(new DrpDrc
                    {
                        numeroInstalacao = i.numeroInstalacao,
                        DRP           = drpMedia,
                        DRC           = drcMedia,
                        inicioMedicao = i.inicioMedicao,
                        fimMedicao    = i.fimMedicao
                    });
                }
            }
            return(drp_drc);
        }