public ActionResult GetProductionUnitMeasures(int id) { var db = new ApplicationDbContext(); var currentProductionUnit = db.ProductionUnits.Where(p => p.picturePath != null).ToList()[id]; var pHSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.ph, db); var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.waterTemperature, db); var airTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.airTemperature, db); var humiditySensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.humidity, db); if (db.ProductionUnitOwners.FirstOrDefault(o => o.user.UserName == this.User.Identity.Name).hasFahrenheitSetting == true) { if (waterTempSensorValueSet.CurrentCaptureTime != "-") { waterTempSensorValueSet.AverageDayValue = Math.Round(waterTempSensorValueSet.AverageDayValue * 9 / 5, 1) + 32; waterTempSensorValueSet.AverageHourValue = Math.Round(waterTempSensorValueSet.AverageHourValue * 9 / 5, 1) + 32; waterTempSensorValueSet.CurrentValue = Math.Round(waterTempSensorValueSet.CurrentValue * 9 / 5, 1) + 32; } if (airTempSensorValueSet.CurrentCaptureTime != "-") { airTempSensorValueSet.AverageDayValue = Math.Round(airTempSensorValueSet.AverageDayValue * 9 / 5, 1) + 32; airTempSensorValueSet.AverageHourValue = Math.Round(airTempSensorValueSet.AverageHourValue * 9 / 5, 1) + 32; airTempSensorValueSet.CurrentValue = Math.Round(airTempSensorValueSet.CurrentValue * 9 / 5, 1) + 32; } } return(Json(new { CurrentPhValue = pHSensorValueSet.CurrentValue, CurrentPhCaptureTime = pHSensorValueSet.CurrentCaptureTime, AverageHourPhValue = pHSensorValueSet.AverageHourValue, AverageDayPhValue = pHSensorValueSet.AverageDayValue, LastDayPhCaptureTime = pHSensorValueSet.LastDayCaptureTime, CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, CurrentAirTempValue = airTempSensorValueSet.CurrentValue, CurrentAirTempCaptureTime = airTempSensorValueSet.CurrentCaptureTime, AverageHourAirTempValue = airTempSensorValueSet.AverageHourValue, AverageDayAirTempValue = airTempSensorValueSet.AverageDayValue, LastDayAirTempCaptureTime = airTempSensorValueSet.LastDayCaptureTime, CurrentHumidityValue = humiditySensorValueSet.CurrentValue, CurrentHumidityCaptureTime = humiditySensorValueSet.CurrentCaptureTime, AverageHourHumidityValue = humiditySensorValueSet.AverageHourValue, AverageDayHumidityValue = humiditySensorValueSet.AverageDayValue, LastDayHumidityCaptureTime = humiditySensorValueSet.LastDayCaptureTime, }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProductionUnitMeasures(int id) { var db = new ApplicationDbContext(); var currentProductionUnit = db.ProductionUnits.Where(p => p.picturePath != null).ToList()[id]; var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.waterTemperature, db); return(Json(new { CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProductionUnitDetail(int id) { ApplicationDbContext db = new ApplicationDbContext(); MeasureService measureService = new MeasureService(db); var currentProductionUnit = db.ProductionUnits.Include(p => p.owner.user) .Include(p => p.productionUnitType) .Include(p => p.options) .Where(p => p.Id == id).FirstOrDefault(); if (currentProductionUnit == null) { return(Json("")); } var averageMonthlyProduction = PerformanceManager.GetEstimatedMonthlyProduction(currentProductionUnit.productionUnitType.Id); var onlineSinceWeeks = Math.Round((DateTime.Now - currentProductionUnit.startDate).TotalDays / 7); var averageMonthlySparedCO2 = averageMonthlyProduction * 0.3; var pHSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.ph, db); var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.waterTemperature, db); var airTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.airTemperature, db); var humiditySensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.humidity, db); if (db.ProductionUnitOwners.FirstOrDefault(o => o.user.UserName == this.User.Identity.Name).hasFahrenheitSetting == true) { if (waterTempSensorValueSet.CurrentCaptureTime != "-") { waterTempSensorValueSet.AverageDayValue = Math.Round(waterTempSensorValueSet.AverageDayValue * 9 / 5, 1) + 32; waterTempSensorValueSet.AverageHourValue = Math.Round(waterTempSensorValueSet.AverageHourValue * 9 / 5, 1) + 32; waterTempSensorValueSet.CurrentValue = Math.Round(waterTempSensorValueSet.CurrentValue * 9 / 5, 1) + 32; } if (airTempSensorValueSet.CurrentCaptureTime != "-") { airTempSensorValueSet.AverageDayValue = Math.Round(airTempSensorValueSet.AverageDayValue * 9 / 5, 1) + 32; airTempSensorValueSet.AverageHourValue = Math.Round(airTempSensorValueSet.AverageHourValue * 9 / 5, 1) + 32; airTempSensorValueSet.CurrentValue = Math.Round(airTempSensorValueSet.CurrentValue * 9 / 5, 1) + 32; } } var options = db.OptionLists.Include(o => o.productionUnit) .Include(o => o.option) .Where(p => p.productionUnit.Id == id) .Select(p => p.option); var optionList = string.Empty; if (options.Count() > 0) { options.ToList().ForEach(o => { optionList += o.name + " / "; }); } return(Json(new { PioneerCitizenName = currentProductionUnit.owner.pioneerCitizenName, PioneerCitizenNumber = currentProductionUnit.owner.pioneerCitizenNumber, ProductionUnitVersion = currentProductionUnit.version, ProductionUnitType = currentProductionUnit.productionUnitType.name, PicturePath = currentProductionUnit.picturePath, ProductionUnitOptions = optionList, OnlineSinceWeeks = onlineSinceWeeks, AverageMonthlyProduction = averageMonthlyProduction, AverageMonthlySparedCO2 = averageMonthlySparedCO2, CurrentPhValue = pHSensorValueSet.CurrentValue, CurrentPhCaptureTime = pHSensorValueSet.CurrentCaptureTime, AverageHourPhValue = pHSensorValueSet.AverageHourValue, AverageDayPhValue = pHSensorValueSet.AverageDayValue, LastDayPhCaptureTime = pHSensorValueSet.LastDayCaptureTime, CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, CurrentAirTempValue = airTempSensorValueSet.CurrentValue, CurrentAirTempCaptureTime = airTempSensorValueSet.CurrentCaptureTime, AverageHourAirTempValue = airTempSensorValueSet.AverageHourValue, AverageDayAirTempValue = airTempSensorValueSet.AverageDayValue, LastDayAirTempCaptureTime = airTempSensorValueSet.LastDayCaptureTime, CurrentHumidityValue = humiditySensorValueSet.CurrentValue, CurrentHumidityCaptureTime = humiditySensorValueSet.CurrentCaptureTime, AverageHourHumidityValue = humiditySensorValueSet.AverageHourValue, AverageDayHumidityValue = humiditySensorValueSet.AverageDayValue, LastDayHumidityCaptureTime = humiditySensorValueSet.LastDayCaptureTime, }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProductionUnitDetail(int id) { ApplicationDbContext db = new ApplicationDbContext(); MeasureService measureService = new MeasureService(db); var currentProductionUnit = db.ProductionUnits.Include(p => p.owner.user) .Include(p => p.productionUnitType) .Include(p => p.options) .Where(p => p.Id == id).FirstOrDefault(); var averageMonthlyProduction = 0; switch (currentProductionUnit.productionUnitType.Id) { case 1: averageMonthlyProduction = 5; break; case 2: averageMonthlyProduction = 10; break; case 3: averageMonthlyProduction = 15; break; case 4: averageMonthlyProduction = 25; break; case 5: averageMonthlyProduction = 50; break; default: break; } var averageMonthlySparedCO2 = averageMonthlyProduction * 0.3; var pHSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.ph, db); var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.waterTemperature, db); var airTempSensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.airTemperature, db); var humiditySensorValueSet = SensorValueManager.GetSensorValueSet(currentProductionUnit.Id, SensorTypeEnum.humidity, db); var options = db.OptionLists.Include(o => o.productionUnit) .Include(o => o.option) .Where(p => p.productionUnit.Id == id) .Select(p => p.option); var optionList = string.Empty; if (options.Count() > 0) { options.ToList().ForEach(o => { optionList += o.name + " / "; }); } var onlineSinceWeeks = Math.Round((DateTime.Now - currentProductionUnit.startDate).TotalDays / 7); return(Json(new { PioneerCitizenName = currentProductionUnit.owner.pioneerCitizenName, PioneerCitizenNumber = currentProductionUnit.owner.pioneerCitizenNumber, ProductionUnitVersion = currentProductionUnit.version, ProductionUnitType = currentProductionUnit.productionUnitType.name, PicturePath = currentProductionUnit.picturePath, ProductionUnitOptions = optionList, OnlineSinceWeeks = onlineSinceWeeks, AverageMonthlyProduction = averageMonthlyProduction, AverageMonthlySparedCO2 = averageMonthlySparedCO2, CurrentPhValue = pHSensorValueSet.CurrentValue, CurrentPhCaptureTime = pHSensorValueSet.CurrentCaptureTime, AverageHourPhValue = pHSensorValueSet.AverageHourValue, AverageDayPhValue = pHSensorValueSet.AverageDayValue, LastDayPhCaptureTime = pHSensorValueSet.LastDayCaptureTime, CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, CurrentAirTempValue = airTempSensorValueSet.CurrentValue, CurrentAirTempCaptureTime = airTempSensorValueSet.CurrentCaptureTime, AverageHourAirTempValue = airTempSensorValueSet.AverageHourValue, AverageDayAirTempValue = airTempSensorValueSet.AverageDayValue, LastDayAirTempCaptureTime = airTempSensorValueSet.LastDayCaptureTime, CurrentHumidityValue = humiditySensorValueSet.CurrentValue, CurrentHumidityCaptureTime = humiditySensorValueSet.CurrentCaptureTime, AverageHourHumidityValue = humiditySensorValueSet.AverageHourValue, AverageDayHumidityValue = humiditySensorValueSet.AverageDayValue, LastDayHumidityCaptureTime = humiditySensorValueSet.LastDayCaptureTime, }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProductionUnitDetail(string SelectedProductionUnitCoord) { var db = new ApplicationDbContext(); var strLat = Double.Parse(SelectedProductionUnitCoord.Split('|')[0]); var strLong = Double.Parse(SelectedProductionUnitCoord.Split('|')[1]); var responseData = db.ProductionUnits.Where(p => p.locationLatitude == strLat && p.locationLongitude == strLong) .Include(p => p.owner.preferedMoment) .Include(p => p.productionUnitType) .Include(p => p.productionUnitStatus).ToList()[0]; var options = db.OptionLists.Include(o => o.productionUnit) .Include(o => o.option) .Where(o => o.productionUnit.Id == responseData.Id) .Select(o => o.option); var optionList = string.Empty; if (options.Count() > 0) { options.ToList().ForEach(o => { optionList += o.name + "/"; }); } var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(responseData.Id, SensorTypeEnum.waterTemperature, db); var pHSensorValueSet = SensorValueManager.GetSensorValueSet(responseData.Id, SensorTypeEnum.ph, db); var lst = new object(); lst = new { CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, CurrentpHValue = pHSensorValueSet.CurrentValue, CurrentpHCaptureTime = pHSensorValueSet.CurrentCaptureTime, AverageHourpHValue = pHSensorValueSet.AverageHourValue, AverageDaypHValue = pHSensorValueSet.AverageDayValue, LastDaypHCaptureTime = pHSensorValueSet.LastDayCaptureTime, PioneerCitizenName = responseData.owner.pioneerCitizenName, PioneerCitizenNumber = responseData.owner.pioneerCitizenNumber, ProductionUnitStartDate = responseData.startDate, ProductionUnitInfo = responseData.info, ProductionUnitType = responseData.productionUnitType.name, ProductionUnitStatus = responseData.productionUnitStatus.name, PhoneNumber = responseData.owner.phoneNumber == null ? "00 33 3 67 37 00 56" : responseData.owner.phoneNumber, ContactMail = responseData.owner.contactMail == null ? "*****@*****.**" : responseData.owner.contactMail, PicturePath = responseData.picturePath == null ? "NoImage.png" : responseData.picturePath, PreferedMoment = responseData.owner.preferedMoment == null ? "" : responseData.owner.preferedMoment.name, Location = responseData.owner.location == null ? "" : responseData.owner.location, ProductionUnitOptions = optionList, }; return(Json(lst)); }
public ActionResult GetProductionUnitDetailListSlider() { var db = new ApplicationDbContext(); var prodUnitListCount = db.ProductionUnits.Where(p => p.productionUnitStatus.Id == 3).Count(); if (prodUnitListCount == 0) { return(null); } var currentProductionUnitList = db.ProductionUnits.Where(p => p.picturePath != null && p.productionUnitStatus.Id == 3) .Include(p => p.owner.preferedMoment) .Include(p => p.productionUnitType) .Include(p => p.productionUnitStatus).ToList(); var lst = new List <object>(); currentProductionUnitList.ForEach(p => { var options = db.OptionLists.Include(o => o.productionUnit) .Include(o => o.option) .Where(o => o.productionUnit.Id == p.Id) .Select(o => o.option); var optionList = string.Empty; if (options.Count() > 0) { options.ToList().ForEach(o => { optionList += o.name + "/"; }); } var waterTempSensorValueSet = SensorValueManager.GetSensorValueSet(p.Id, SensorTypeEnum.waterTemperature, db); var pHSensorValueSet = SensorValueManager.GetSensorValueSet(p.Id, SensorTypeEnum.ph, db); lst.Add(new { PioneerCitizenName = p.owner.pioneerCitizenName, PioneerCitizenNumber = p.owner.pioneerCitizenNumber, ProductionUnitVersion = p.version, ProductionUnitStartDate = p.startDate, ProductionUnitType = p.productionUnitType.name, ProductionUnitStatus = p.productionUnitStatus.name, PhoneNumber = p.owner.phoneNumber == null ? "00 33 3 67 37 00 56" : p.owner.phoneNumber, ContactMail = p.owner.contactMail == null ? "*****@*****.**" : p.owner.contactMail, PicturePath = p.picturePath, LocationLatitude = p.locationLatitude, LocationLongitude = p.locationLongitude, PreferedMoment = p.owner.preferedMoment == null ? "" : p.owner.preferedMoment.name, Location = p.owner.location == null ? "" : p.owner.location, ProductionUnitOptions = optionList, CurrentWaterTempValue = waterTempSensorValueSet.CurrentValue, CurrentWaterTempCaptureTime = waterTempSensorValueSet.CurrentCaptureTime, AverageHourWaterTempValue = waterTempSensorValueSet.AverageHourValue, AverageDayWaterTempValue = waterTempSensorValueSet.AverageDayValue, LastDayWaterTempCaptureTime = waterTempSensorValueSet.LastDayCaptureTime, CurrentpHValue = pHSensorValueSet.CurrentValue, CurrentpHCaptureTime = pHSensorValueSet.CurrentCaptureTime, AverageHourpHValue = pHSensorValueSet.AverageHourValue, AverageDaypHValue = pHSensorValueSet.AverageDayValue, LastDaypHCaptureTime = pHSensorValueSet.LastDayCaptureTime, }); }); return(Json(lst, JsonRequestBehavior.AllowGet)); }