public ActionResult CompareDevice(List <string> devices, string startTime, string endTime) { var res = new JsonResult <List <CompareDeviceDto> >(); List <CompareDeviceDto> compareResult = new List <CompareDeviceDto>(); foreach (var dev in devices) { CompareDeviceDto dto = new CompareDeviceDto(); Expression <Func <Device, bool> > exp = item => item.DeviceNo == dev; DeviceDto devDto = Mapper.Map <Device, DeviceDto>(evaluateDAL.Single(exp)); dto.Device = devDto; MMDD_SBLY dncData = evaluateDAL.GetDncData(dev, startTime, endTime); DncRelated dncRelateReliability = Reliability.DncRelateReliability(dncData); dto.DncReliability = dncRelateReliability; //string mtbfSql = "select gzjgsj as jgsj from csmtbfsj"; //测试的时候用的,实际调用时应该给定sql语句 string recordsSql = "select app.DeviceNo,app.FailureType,app.BeginTime,app.FirstLocation,app.SecondLocation,app.ThirdLocation, round((" + "(case when app.CHECKTIME is null then to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss') else app.CHECKTIME end)-" + "(app.BEGINTIME)) * 24, 2) AS pausetime FROM REPAIRAPPLICATION app " + "WHERE (app.BEGINTIME > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') AND app.BEGINTIME < to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss'))"; if (!String.IsNullOrEmpty(dev)) { recordsSql += " and app.DeviceNo='" + dev + "'"; } recordsSql += " order by app.begintime"; DataTable sourceTable = evaluateDAL.GetFailureRecords(recordsSql); List <double> intervar = new List <double>(); for (int i = 0; i < sourceTable.Rows.Count - 1; i++) { intervar.Add(Convert.ToDouble((Convert.ToDateTime(sourceTable.Rows[i + 1]["BeginTime"]) - Convert.ToDateTime(sourceTable.Rows[i]["BeginTime"])).TotalHours)); }//真实故障间隔数据 //intervar = evaluateDAL.Interval(mtbfSql); double alph, beta; dto.MTBF = Reliability.MTBF(intervar, out alph, out beta); dto.Alph = alph; dto.Beta = beta; string[] t = new string[2000]; double[] f = new double[2000]; Curve curve = new Curve(); for (int i = 1; i < 2000; i++) { t[i] = i.ToString(); f[i] = Math.Exp(-Math.Pow((i / alph), beta)); } curve.XValues = t; curve.YTimeValues = f; List <Curve> curves = new List <Curve>(); curves.Add(curve); dto.Curves = curves; compareResult.Add(dto); } res.data = compareResult; res.flag = true; return(Content(res.ToJsonString())); }
public ActionResult CompareByBrand(string type, List <string> brands, string startTime, string endTime) { CompareBrandDto compareResultDto = new CompareBrandDto(); compareResultDto.MachineType = type; compareResultDto.DisplayName = type + "对比结果"; compareResultDto.StartTime = startTime; compareResultDto.EndTime = endTime; compareResultDto.BrandList = new List <BrandEvaluateDto>(); var res = new JsonResult <CompareBrandDto>(); if (brands.Count > 0) { foreach (var brand in brands) { String Sql = "select app.DeviceNo,app.FailureType,app.BeginTime,app.FirstLocation,app.SecondLocation,app.ThirdLocation, round((" + "(case when app.CHECKTIME is null then to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss') else app.CHECKTIME end)-" + "(app.BEGINTIME)) * 24, 2) AS pausetime FROM REPAIRAPPLICATION app " + "WHERE (app.BEGINTIME > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') AND app.BEGINTIME < to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss')) " + "and deviceno in (select deviceno from device where type='" + type + "' and brand='" + brand + "' ) order by app.begintime"; DataTable sourceTable = evaluateDAL.GetFailureRecords(Sql); if (sourceTable.Rows.Count > 0) { res.flag = true; BrandEvaluateDto brandDto = new BrandEvaluateDto(); List <string> groupNames = new List <string>() { "FailureType", "SecondLocation" }; //按故障类别,二级故障部位统计,统计故障次数和故障时间 List <DataUnit> groupedData = GroupByColName(sourceTable, groupNames); brandDto.Curves = CreatCurves(groupedData); brandDto.Brand = brand; List <double> intervar = new List <double>(); for (int i = 0; i < sourceTable.Rows.Count - 1; i++) { intervar.Add(Convert.ToDouble((Convert.ToDateTime(sourceTable.Rows[i + 1]["BeginTime"]) - Convert.ToDateTime(sourceTable.Rows[i]["BeginTime"])).TotalHours)); }//真实故障间隔数据 double alph, beta; double mtbf = Reliability.MTBF(intervar, out alph, out beta); brandDto.MTBF = mtbf; brandDto.Alph = alph; brandDto.Beta = beta; compareResultDto.BrandList.Add(brandDto); } } res.data = compareResultDto; } return(Content(res.ToJsonString())); }
private DeviceEvaluateDto SingleDeviceEvaluate(string deviceNo, string startTime, string endTime) { DeviceEvaluateDto deviceEvaluateDto = new DeviceEvaluateDto(); string recordsSql = "select app.DeviceNo,app.FailureType,app.BeginTime,app.FirstLocation,app.SecondLocation,app.ThirdLocation, round((" + "(case when app.CHECKTIME is null then to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss') else app.CHECKTIME end)-" + "(app.BEGINTIME)) * 24, 2) AS pausetime FROM REPAIRAPPLICATION app " + "WHERE (app.BEGINTIME > to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss') AND app.BEGINTIME < to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss')) "; if (!String.IsNullOrEmpty(deviceNo)) { recordsSql += " and app.DeviceNo='" + deviceNo + "'"; } recordsSql += " order by app.begintime"; DataTable sourceTable = evaluateDAL.GetFailureRecords(recordsSql); List <string> groupNames = new List <string>() { "FailureType", "SecondLocation" }; //按故障类别,二级故障部位统计,统计故障次数和故障时间 List <DataUnit> groupedData = GroupByColName(sourceTable, groupNames); deviceEvaluateDto.Curves = CreatCurves(groupedData); deviceEvaluateDto.FailureStas = Statistics(groupedData);//故障数据统计 MMDD_SBLY dncData = evaluateDAL.GetDncData(deviceNo, startTime, endTime); DncRelated dncRelateReliability = Reliability.DncRelateReliability(dncData); deviceEvaluateDto.dncRelateReliability = dncRelateReliability; List <double> intervar = new List <double>(); //for (int i = 0; i < sourceTable.Rows.Count-1; i++) //{ // intervar.Add(Convert.ToDouble((Convert.ToDateTime(sourceTable.Rows[i + 1]["BeginTime"]) - Convert.ToDateTime(sourceTable.Rows[i ]["BeginTime"])).TotalHours)); //}真实故障间隔数据 double alph, beta; string mtbfSql = "select gzjgsj as jgsj from csmtbfsj"; intervar = evaluateDAL.Interval(mtbfSql);//测试的时候用的 deviceEvaluateDto.MTBF = Reliability.MTBF(intervar, out alph, out beta); return(deviceEvaluateDto); }