예제 #1
0
        public JsonResult GetByPeriod(string identity, DateTime start_, string parameterGraph = "Amperage1")
        {
            DateTime end = start_.AddHours(1);
            IEnumerable <ElectricAndWaterParams> data = repo_.GetPumpParamsByIdentityAndDate(identity, start_, end);
            EWdata jsonData = new EWdata();

            jsonData.StartDate = start_;
            jsonData.EndDate   = end;
            IEnumerable <ElectricAndWaterParams> temp = data.OrderBy(x => x.RecvDate);

            jsonData.DataTable = temp.ToList();
            PropertyInfo infoprop = (typeof(ElectricAndWaterParams)).GetProperty(parameterGraph);

            jsonData.DataGraph = temp.Select(x => new DataForVisual()
            {
                RecvDate = x.RecvDate, Value = (double)infoprop.GetValue(x)
            }).ToList();
            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public JsonResult GetDataBySmallPeriod(string identity, string parameterGraph)
        {
            DateTime end            = DateTime.Now;
            double   interval       = 1;  // 1 час для построения графика
            int      interval_table = 30; // 30 мин для данных

            try
            {
                interval       = Convert.ToDouble(ConfigurationManager.AppSettings["DataVisualInterval"], CultureInfo.GetCultureInfo("en-US").NumberFormat);
                interval_table = Convert.ToInt32(ConfigurationManager.AppSettings["DataTableInterval"], CultureInfo.GetCultureInfo("en-US").NumberFormat);
            }
            catch (Exception ex)
            {
                LogMessage message = new LogMessage()
                {
                    MessageDate = DateTime.Now,
                    MessageType = "error",
                    MessageText = ex.Message + ex.StackTrace
                };

                loger.LogToFile(message);
                loger.LogToDatabase(message);
                interval       = 1;
                interval_table = 30;
            }

            DateTime start = end.AddHours(-interval);
            IEnumerable <ElectricAndWaterParams> data = repo_.GetPumpParamsByIdentityAndDate(identity, start, end);
            EWdata jsonData = new EWdata();

            jsonData.StartDate = start;
            jsonData.EndDate   = end;
            IEnumerable <ElectricAndWaterParams> temp = data.OrderByDescending(x => x.RecvDate);

            jsonData.DataTable = temp.Where(x => x.RecvDate > end.AddMinutes(-interval_table)).ToList();
            PropertyInfo infoprop = (typeof(ElectricAndWaterParams)).GetProperty(parameterGraph);

            jsonData.DataGraph = temp.Select(x => new DataForVisual()
            {
                RecvDate = x.RecvDate, Value = infoprop.GetValue(x) == null ? 0 : (double)infoprop.GetValue(x)
            }).ToList();
            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }