//[Authorize(Roles = "admin,moderator,KaragandaRegion,Arys,Almaty,Kazhydromet")] public async Task <ActionResult <IEnumerable <MonitoringPost> > > GetEcoserviceMonitoringPostsInactive(int InactivePastMinutes, int?DataProviderId) { MeasuredDatasController measuredDatasController = new MeasuredDatasController(_context); DateTime minExceedDateTime = DateTime.Now.AddMinutes(-InactivePastMinutes); var monitoringPosts = _context.MonitoringPost .Include(m => m.DataProvider) .Include(m => m.PollutionEnvironment) .Include(m => m.Project) .Where(m => (m.DataProviderId == (int)DataProviderId) || DataProviderId == null); var activePosts = _context.MeasuredData .Where(m => m.DateTime >= minExceedDateTime) .ToList(); List <MonitoringPost> monitoringPostsInactive = new List <MonitoringPost>(); foreach (MonitoringPost monitoringPost in monitoringPosts) { bool active = activePosts .Where(m => m.MonitoringPostId == monitoringPost.Id) //.Include(m => m.MeasuredParameter) //.Where(m => m.Value > m.MeasuredParameter.MPC && m.MeasuredParameter.MPC != null) .FirstOrDefault() != null; if (!active) { monitoringPostsInactive.Add(monitoringPost); } } return(monitoringPostsInactive.ToList()); }
public async Task <ActionResult <IEnumerable <MonitoringPost> > > GetEcoserviceMonitoringPostsExceed(int MPCExceedPastMinutes, int?DataProviderId) { // populate data (delete) MeasuredDatasController measuredDatasController = new MeasuredDatasController(_context); //measuredDatasController.PopulateEcoserviceData(); //measuredDatasController.GetPostsData(); DateTime minExceedDateTime = DateTime.Now.AddMinutes(-MPCExceedPastMinutes); var monitoringPosts = _context.MonitoringPost .Include(m => m.DataProvider) .Include(m => m.PollutionEnvironment) .Include(m => m.Project) .Where(m => (m.DataProviderId == (int)DataProviderId) || DataProviderId == null); foreach (MonitoringPost monitoringPost in monitoringPosts) { bool exceed = _context.MeasuredData .Where(m => m.MonitoringPostId == monitoringPost.Id && m.DateTime >= minExceedDateTime && m.Averaged == true ) .Include(m => m.MeasuredParameter) .ToList() //.Select(m => //{ // m.Value = // //(m.MeasuredParameterId == 7 && (m.MonitoringPostId == 44 || m.MonitoringPostId == 50 || m.MonitoringPostId == 47)) ? m.Value / measuredDatasController.COMPCDivide : // m.MeasuredParameterId == 1 ? m.Value * measuredDatasController.PValueMultiply : // m.MeasuredParameterId == 13 ? m.Value * measuredDatasController.NO2ValueMultiply : // m.MeasuredParameterId == 9 ? m.Value * measuredDatasController.SO2ValueMultiply : // m.MeasuredParameterId == 20 ? m.Value * measuredDatasController.H2SValueMultiply : // m.MeasuredParameterId == 2 ? m.Value * measuredDatasController.PM10ValueMultiply : // m.MeasuredParameterId == 3 ? m.Value * measuredDatasController.PM25ValueMultiply : // m.Value; // return m; //}) .Where(m => m.Value > m.MeasuredParameter.MPCMaxSingle && m.MeasuredParameter.MPCMaxSingle != null) .FirstOrDefault() != null; if (!exceed) { monitoringPosts = monitoringPosts .Where(m => m.Id != monitoringPost.Id); } } return(await monitoringPosts.ToListAsync()); }