예제 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] reporting_metrics entity)
        {
            try
            {
                if (id < 0 || !isValid(entity))
                {
                    return(new BadRequestResult());
                }

                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                entity.last_updated_by = loggedInMember.member_id;
                entity.last_updated    = DateTime.Now;

                return(Ok(await agent.Update <reporting_metrics>(id, entity)));
            }
            catch (Exception ex)
            {
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task Post()
        {
            //Arrange
            var entity = new reporting_metrics()
            {
                report_date = DateTime.Now, event_id = 3, state = "MN", member_id = 1
            };


            //Act
            var response = await controller.Post(entity);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(response);
            var result   = Assert.IsType <reporting_metrics>(okResult.Value);


            Assert.Equal(3, result.event_id);
        }
예제 #3
0
        [HttpGet("DailyReportTotals")] // ?Date={date}&Event={eventId}&State={stateName}
        public async Task <IActionResult> GetDailyReportTotals([FromQuery] string Date, [FromQuery] int Event, [FromQuery] string State)
        {
            try
            {
                if (Date == string.Empty || Event <= 0 || string.IsNullOrEmpty(State))
                {
                    return(new BadRequestResult());
                }

                string   stateAbbrev = State.ToUpper();
                DateTime aDate       = Convert.ToDateTime(Date).Date;

                //statusType 1 : Deployed, statusType 2 : Retrieved, statusType 3 : lost

                //query instruments with specified eventid, state (input can handle state name or abbr name)
                IQueryable <instrument> sensorQuery = agent.Select <instrument>().Include(i => i.instrument_status).Include(i => i.site)
                                                      .Where(i => i.event_id == Event && i.site.state.Equals(stateAbbrev));

                //query instruments by the date being less than status date
                List <instrument> sensorList = sensorQuery.AsEnumerable().Where(i => i.instrument_status.OrderByDescending(instStat => instStat.instrument_status_id)
                                                                                .FirstOrDefault().time_stamp.Value <= aDate).ToList();


                List <instrument> depINSTs  = sensorList.Where(i => i.instrument_status.OrderByDescending(inst => inst.time_stamp).FirstOrDefault().status_type_id == 1).ToList();
                List <instrument> recINSTs  = sensorList.Where(i => i.instrument_status.OrderByDescending(inst => inst.time_stamp).FirstOrDefault().status_type_id == 2).ToList();
                List <instrument> lostINSTs = sensorList.Where(i => i.instrument_status.OrderByDescending(inst => inst.time_stamp).FirstOrDefault().status_type_id == 3).ToList();

                //RDG totals ( S(5) )
                Int32 DEPrapidDeploymentGageCount  = depINSTs.Where(s => s.sensor_type_id == 5).ToList().Count();
                Int32 RECrapidDeploymentGageCount  = recINSTs.Where(s => s.sensor_type_id == 5).ToList().Count();
                Int32 LOSTrapidDeploymentGageCount = lostINSTs.Where(s => s.sensor_type_id == 5).ToList().Count();

                //water level ( S(1), D(1) )
                Int32 DEPwaterLevelCount  = depINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 1).ToList().Count();
                Int32 RECwaterLevelCount  = recINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 1).ToList().Count();
                Int32 LOSTwaterLevelCount = lostINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 1).ToList().Count();

                //wave height ( S(1), D(2) )
                Int32 DEPwaveHeightCount  = depINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 2).ToList().Count();
                Int32 RECwaveHeightCount  = recINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 2).ToList().Count();
                Int32 LOSTwaveHeightCount = lostINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 2).ToList().Count();

                //Barometric totals ( S(1), D(3) )
                Int32 DEPbarometricCount  = depINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 3).ToList().Count();
                Int32 RECbarometricCount  = recINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 3).ToList().Count();
                Int32 LOSTbarometricCount = lostINSTs.Where(s => s.sensor_type_id == 1 && s.deployment_type_id == 3).ToList().Count();

                //Met totals ( S(2) )
                Int32 DEPmetCount  = depINSTs.Where(s => s.sensor_type_id == 2).ToList().Count();
                Int32 RECmetCount  = recINSTs.Where(s => s.sensor_type_id == 2).ToList().Count();
                Int32 LOSTmetCount = lostINSTs.Where(s => s.sensor_type_id == 2).ToList().Count();

                //now go get the HWMs for Flagged and Collected
                IQueryable <hwm> hwmQuery = agent.Select <hwm>().Include(h => h.site).Include(h => h.@event).Where(i => i.event_id == Event && i.site.state.Equals(stateAbbrev));

                //query instruments by the date being less than status date
                hwmQuery = hwmQuery.Where(i => [email protected]_start_date <= aDate.Date);

                Int32 hwmFlagged   = hwmQuery.Where(h => h.flag_date != null).ToList().Count();
                Int32 hwmCollected = hwmQuery.Where(h => h.elev_ft != null).ToList().Count();

                //now populate the report to pass back
                reporting_metrics ReportForTotals = new reporting_metrics();
                ReportForTotals.dep_rapdepl_gage    = DEPrapidDeploymentGageCount >= 1 ? DEPrapidDeploymentGageCount : 0;
                ReportForTotals.rec_rapdepl_gage    = RECrapidDeploymentGageCount >= 1 ? RECrapidDeploymentGageCount : 0;
                ReportForTotals.lost_rapdepl_gage   = LOSTrapidDeploymentGageCount >= 1 ? LOSTrapidDeploymentGageCount : 0;
                ReportForTotals.dep_wtrlev_sensor   = DEPwaterLevelCount >= 1 ? DEPwaterLevelCount : 0;
                ReportForTotals.rec_wtrlev_sensor   = RECwaterLevelCount >= 1 ? RECwaterLevelCount : 0;
                ReportForTotals.lost_wtrlev_sensor  = LOSTwaterLevelCount >= 1 ? LOSTwaterLevelCount : 0;
                ReportForTotals.dep_wv_sens         = DEPwaveHeightCount >= 1 ? DEPwaveHeightCount : 0;
                ReportForTotals.rec_wv_sens         = RECwaveHeightCount >= 1 ? RECwaveHeightCount : 0;
                ReportForTotals.lost_wv_sens        = LOSTwaveHeightCount >= 1 ? LOSTwaveHeightCount : 0;
                ReportForTotals.dep_barometric      = DEPbarometricCount >= 1 ? DEPbarometricCount : 0;
                ReportForTotals.rec_barometric      = RECbarometricCount >= 1 ? RECbarometricCount : 0;
                ReportForTotals.lost_barometric     = LOSTbarometricCount >= 1 ? LOSTbarometricCount : 0;
                ReportForTotals.dep_meteorological  = DEPmetCount >= 1 ? DEPmetCount : 0;
                ReportForTotals.rec_meteorological  = RECmetCount >= 1 ? RECmetCount : 0;
                ReportForTotals.lost_meteorological = LOSTmetCount >= 1 ? LOSTmetCount : 0;
                ReportForTotals.hwm_flagged         = hwmFlagged >= 1 ? hwmFlagged : 0;
                ReportForTotals.hwm_collected       = hwmCollected >= 1 ? hwmCollected : 0;


                if (ReportForTotals == null)
                {
                    return(new BadRequestObjectResult(new Error(errorEnum.e_notFound)));
                }
                //sm(agent.Messages);
                return(Ok(ReportForTotals));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }