예제 #1
0
        public IEnumerable <DataPoint> Daily([FromUri] DateTime start, [FromUri] DateTime end, [FromBody] string[] FactoryList)
        {
            try
            {
                var energy = EnergyUtils.EnergyHistory(start, end, FactoryList);

                List <DataPoint> result = new List <DataPoint>();

                DateTime time = new DateTime(start.Year, start.Month, start.Day);

                do
                {
                    foreach (string factory in FactoryList)
                    {
                        if (factory != null)
                        {
                            result.Add(new DataPoint {
                                DateTime = time, TagName = factory, Value = EnergyUtils.GetEnergyByDay(energy, time, factory)
                            });
                        }
                    }

                    time = time.AddDays(1);
                } while (time.CompareTo(end) < 0);

                return(result);
            }
            catch { return(new List <DataPoint>()); }
        }
예제 #2
0
        public IEnumerable <DataPoint> Power([FromBody] string[] FactoryList)
        {
            string[] TagNameList = EnergyUtils.FactoryToPowerTag(FactoryList, null);

            List <DataPoint> result = new List <DataPoint>();

            var power = ScadaHisDao.AnalogLive(TagNameList);

            DateTime now = DateTime.Now;

            foreach (string factory in FactoryList)
            {
                if (factory != null)
                {
                    var data = (from p in power where p.TagName.ToUpper().Contains(factory.ToUpper()) && p.OPCQuality >= 192 /*&& Math.Abs((p.DateTime - now).TotalHours) < 1*/ select p);

                    DataPoint dp;

                    if (data.Count <DataPoint>() > 0)
                    {
                        dp = new DataPoint
                        {
                            DateTime = data.FirstOrDefault().DateTime,
                            TagName  = factory,
                            Value    = (from p in data where p.Value.HasValue select p.Value).Sum()
                        };
                    }
                    else
                    {
                        dp = new DataPoint
                        {
                            DateTime = now,
                            TagName  = factory,
                            Value    = null
                        };
                    }

                    result.Add(dp);
                }
            }

            return(result);
        }
예제 #3
0
        public IEnumerable <DataPoint> PowerTrend([FromUri] DateTime start, [FromUri] DateTime end, [FromBody] string[] FactoryList)
        {
            try
            {
                List <DataPoint> result = EnergyUtils.PowerHistory30M(start, end, FactoryList);

                /* group by DateTime and sum = Ptotal */
                List <DataPoint> data = (from p in result where (p.Value.HasValue) select p)
                                        .GroupBy(g => g.DateTime, v => v.Value)
                                        .Select(g => new DataPoint
                {
                    DateTime = g.Key,
                    TagName  = "PTOTAL",
                    Value    = g.Sum()
                }).ToList();

                return(data);
            }
            catch { return(new List <DataPoint>()); }
        }
예제 #4
0
        public IEnumerable <DataPoint> HourlySummary([FromUri] DateTime start, [FromUri] DateTime end, [FromBody] string[] FactoryList)
        {
            try
            {
                var energy = EnergyUtils.EnergyHistory(start, end, FactoryList);

                List <DataPoint> result = new List <DataPoint>();

                DateTime time = new DateTime(start.Year, start.Month, start.Day);

                do
                {
                    // Total Energy per Hour
                    result.Add(new DataPoint {
                        DateTime = time, TagName = "ETOTAL", Value = EnergyUtils.GetTotalEnergyByHour(energy, time)
                    });

                    time = time.AddHours(1);
                } while (time.CompareTo(end) < 0);

                return(result);
            }
            catch { return(new List <DataPoint>()); }
        }