예제 #1
0
        public IActionResult Index(int id, int page = 1)
        {
            var model = new DataViewModel();

            model.Measurement = _context.Measurements
                                .Include(m => m.SensorRoles)
                                .Include(m => m.Calculators)
                                .FirstOrDefault(m => m.Id == id);

            var query = new ReadingsQuery {
                MeasurementId = id, Page = page, PageSize = 10
            };

            model.Data   = _context.GetReadingsPaged(query);
            model.Labels = _calcProvider.GetTypes()
                           .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>() != null)
                           .Select(t => new
            {
                Label = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().DisplayLabel,
                Name  = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().Name
            })
                           .ToDictionary(k => k.Name, e => e.Label ?? e.Name);
            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Index(int?measurementId)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(View("IndexPublic"));
            }

            _dataContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            var model = new HomeViewModel();

            model.Measurement = await _dataContext.Measurements
                                .Include(m => m.SensorRoles)
                                .Include(m => m.Calculators)
                                .Where(m => measurementId == null || m.Id == measurementId)
                                .OrderByDescending(m => m.IsActive)
                                .FirstOrDefaultAsync();

            if (model.Measurement == null)
            {
                return(View("IndexEmpty"));
            }

            model.Readings = _dataContext.GetReadings(model.Measurement.Id, null, 10)
                             .OrderByDescending(r => r.Key)
                             .ToList();

            //model.ChartData = _dataContext.GetReadings(model.Measurement.Id, DateTime.Now.AddHours(-24), 10000);
            model.ChartData = _dataContext.GetReadings(model.Measurement.Id, null, 10000);
            var showOnChart = _calcProvider.GetTypes()
                              .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>() != null)
                              .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().ShowOnChart)
                              .Select(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().Name)
                              .ToList();

            showOnChart.AddRange(model.Measurement.SensorRoles.Select(r => r.RoleName));
            model.CalculatorsOnChart = showOnChart.ToArray();

            var labels = _calcProvider.GetTypes()
                         .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>() != null)
                         .Select(t => new
            {
                Label = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().DisplayLabel,
                Name  = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().Name
            })
                         .ToDictionary(k => k.Name, e => e.Label);

            foreach (var key in labels.Keys.ToList())
            {
                if (string.IsNullOrEmpty(labels[key]))
                {
                    labels[key] = key;
                }
            }
            model.Labels       = labels;
            model.Calculators  = _calcProvider.GetCalculators();
            model.Statistics   = _dataContext.GetMeasurementStats(model.Measurement.Id);
            model.Measurements = _dataContext.Measurements
                                 .OrderByDescending(m => m.IsActive)
                                 .ThenBy(m => m.Name)
                                 .Select(m => new SelectListItem
            {
                Text     = m.Name,
                Value    = m.Id.ToString(),
                Selected = (m.Id == model.Measurement.Id)
            })
                                 .ToList();

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Index(int?measurementId)
        {
            _pageContext.Title      = "Home";
            _pageContext.ActiveMenu = "Home";

            if (!User.Identity.IsAuthenticated)
            {
                return(View("IndexPublic"));
            }

            if (!User.IsInRole("Administrator") && !User.IsInRole("PowerUser"))
            {
                return(View("IndexGuest"));
            }

            var model = new HomeViewModel();

            model.Measurement = await _dataContext.Measurements
                                .Include(m => m.SensorRoles)
                                .Include(m => m.Calculators)
                                .Where(m => measurementId == null || m.Id == measurementId)
                                .OrderByDescending(m => m.IsActive)
                                .FirstOrDefaultAsync();

            if (model.Measurement == null)
            {
                return(View("IndexEmpty"));
            }

            var query = new ReadingsQuery {
                MeasurementId = model.Measurement.Id, PageSize = 10
            };

            model.Readings = _dataContext.GetReadings(query);

            query = new ReadingsQuery {
                MeasurementId = model.Measurement.Id, Ascending = true, PageSize = int.MaxValue
            };
            model.ChartData = _dataContext.GetReadings(query);

            var showOnChart = _calcProvider.GetTypes()
                              .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>() != null)
                              .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().ShowOnChart)
                              .Select(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().Name)
                              .ToList();

            showOnChart.AddRange(model.Measurement.SensorRoles.Select(r => r.RoleName));
            model.CalculatorsOnChart = showOnChart.ToArray();

            var labels = _calcProvider.GetTypes()
                         .Where(t => t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>() != null)
                         .Select(t => new
            {
                Label = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().DisplayLabel,
                Name  = t.GetTypeInfo().GetCustomAttribute <CalculatorAttribute>().Name
            })
                         .ToDictionary(k => k.Name, e => e.Label ?? e.Name);

            model.Labels       = labels;
            model.Calculators  = _calcProvider.GetCalculators();
            model.Statistics   = _dataContext.GetMeasurementStats(model.Measurement.Id);
            model.Measurements = _dataContext.Measurements
                                 .OrderByDescending(m => m.IsActive)
                                 .ThenBy(m => m.Name)
                                 .Select(m => new SelectListItem
            {
                Text     = m.Name,
                Value    = m.Id.ToString(),
                Selected = (m.Id == model.Measurement.Id)
            })
                                 .ToList();
            return(View(model));
        }