public List <FaultRateInfo> GetForecastRate(int objectID, FaultRateInfo.ObjectType objectType, double slope, double intercept, double slope1, double intercept1, int month = 0) { List <FaultRateInfo> ForecastRate = new List <FaultRateInfo>(); for (int i = 0; i < 120; i++) { FaultRateInfo item = new FaultRateInfo(); item.Year = SQLUtil.ConvertInt(i / 12 + 1); item.Month = SQLUtil.ConvertEnum <FaultRateInfo.DateTimeMonth>(i % 12 + 1); item.ObjectID = objectID; item.ObjectTypeID = objectType; if (i > month) { double rate = Math.Round((((i + 1) * slope1 + intercept1) * 100.0), 2); item.Rate = rate; ForecastRate.Add(item); } else { double rate = Math.Round((((i + 1) * slope + intercept) * 100.0), 2); item.Rate = rate; ForecastRate.Add(item); } } return(ForecastRate); }
/// <summary> /// 获取故障率信息 /// </summary> /// <param name="objID">故障对象id</param> /// <param name="type">故障对象类型</param> /// <returns>故障率信息</returns> public JsonResult GetFaultRatesByObjID(int objID, FaultRateInfo.ObjectType type) { if (!CheckSession()) { return(Json(ResultModelBase.CreateTimeoutModel(), JsonRequestBehavior.AllowGet)); } if (CheckSessionID() == false) { return(Json(ResultModelBase.CreateLogoutModel(), JsonRequestBehavior.AllowGet)); } ResultModel <List <FaultRateInfo> > result = new ResultModel <List <FaultRateInfo> >(); try { List <FaultRateInfo> infos = new List <FaultRateInfo>(); infos = this.faultRateDao.GetFaultRateByObject(objID, type); result.Data = infos; } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message); result.SetFailed(ResultCodes.SystemError, ControlManager.GetSettingInfo().ErrorMessage); } return(JsonResult(result)); }
private void GetRateList(int objectID, FaultRateInfo.ObjectType objectType, Dictionary <int, int> eqptContractCount, Dictionary <int, int> eqptRepairCount, int months, out List <FaultRateInfo> RateList, out List <FaultRateInfo> RateList1) { RateList = new List <FaultRateInfo>(); RateList1 = new List <FaultRateInfo>(); for (int i = 0; i < 120; i++) { int eqptCount = (from eqpt in eqptContractCount where eqpt.Value >= i select eqpt).Count(); int repairCount = (from repair in eqptRepairCount where repair.Value == i select repair).Count(); if (eqptCount > 0 && repairCount > 0) { double rate = Math.Round(repairCount * 100.0 / eqptCount, 2); FaultRateInfo item = new FaultRateInfo(); item.Year = SQLUtil.ConvertInt(i / 12 + 1); item.Month = SQLUtil.ConvertEnum <FaultRateInfo.DateTimeMonth>(i % 12 + 1); item.ObjectID = objectID; item.ObjectTypeID = objectType; item.Rate = rate; if (i < months) { RateList.Add(item); } else { RateList1.Add(item); } } } }
private Dictionary <string, object> GetWebData(int objectID, FaultRateInfo.ObjectType objectType, int months, Dictionary <int, int> eqptContractCount, Dictionary <int, int> repairCount) { months = months > 120 ? 120 - 1 : months - 1; Dictionary <string, object> result = new Dictionary <string, object>(); List <FaultRateInfo> ForecastRateList = new List <FaultRateInfo>(); double slope = 0, intercept = 0, slope1 = 0, intercept1 = 0; List <FaultRateInfo> RateList = new List <FaultRateInfo>(); List <FaultRateInfo> RateList1 = new List <FaultRateInfo>(); GetRateList(objectID, objectType, eqptContractCount, repairCount, months, out RateList, out RateList1); if (RateList.Count >= 2) { Tuple <double, double> solpAndIntercept1 = SimpleRegression.Fit(RateList.Select(item => SQLUtil.ConvertDouble((item.Year - 1) * 12 + (int)item.Month)).ToArray(), RateList.Select(item => item.Rate).ToArray()); slope = solpAndIntercept1.Item1; intercept = solpAndIntercept1.Item2; } if (RateList1.Count >= 2) { Tuple <double, double> solpAndIntercept2 = SimpleRegression.Fit(RateList1.Select(item => SQLUtil.ConvertDouble((item.Year - 1) * 12 + (int)item.Month)).ToArray(), RateList1.Select(item => item.Rate).ToArray()); slope1 = solpAndIntercept2.Item1; intercept1 = solpAndIntercept2.Item2; } ForecastRateList = GetForecastRate(objectID, objectType, slope, intercept, slope1, intercept1, months); result.Add("RateList", RateList); result.Add("RateList1", RateList1); result.Add("ForecastRateList", ForecastRateList); result.Add("WebData", ForecastRateList.Concat(RateList).Concat(RateList1)); return(result); }
/// <summary> /// 获取故障率 /// </summary> /// <param name="objectID">关联对象ID</param> /// <param name="type">类型</param> /// <returns>故障率</returns> public List <FaultRateInfo> GetFaultRateByObject(int objectID, FaultRateInfo.ObjectType type) { sqlStr = "SELECT fr.* FROM tblFaultRate fr WHERE fr.ObjectID=@ObjectID AND ObjectTypeID = @ObjectTypeID ORDER BY fr.Year,fr.Month ASC"; using (SqlCommand command = ConnectionUtil.GetCommand(sqlStr)) { command.Parameters.Add("@ObjectID", SqlDbType.Int).Value = objectID; command.Parameters.Add("@ObjectTypeID", SqlDbType.Int).Value = type; return(GetList <FaultRateInfo>(command)); } }
/// <summary> /// 通过关联对象ID删除故障率 /// </summary> /// <param name="objectID">关联对象ID</param> /// <param name="type">类型</param> public void DeleteFaultRateByObjID(int objectID, FaultRateInfo.ObjectType type) { sqlStr = "DELETE tblFaultRate WHERE ObjectID=@ObjectID AND ObjectTypeID = @ObjectTypeID"; using (SqlCommand command = ConnectionUtil.GetCommand(sqlStr)) { // ObjectTypeID , ObjectID , MethodID , Year , Month , Rate command.Parameters.Add("@ObjectID", SqlDbType.Int).Value = objectID; command.Parameters.Add("@ObjectTypeID", SqlDbType.Int).Value = type; command.ExecuteScalar(); } }
/// <summary> /// 批量获取故障率 /// </summary> /// <param name="objectIDs">父对象ID</param> /// <param name="type">类型</param> /// <returns></returns> public Dictionary <int, List <FaultRateInfo> > GetFaultRateByObject(List <int> objectIDs, FaultRateInfo.ObjectType type) { if (objectIDs == null || objectIDs.Count == 0) { return(null); } sqlStr = string.Format("SELECT fr.* FROM tblFaultRate fr WHERE fr.ObjectID in ({0}) AND ObjectTypeID = @ObjectTypeID ORDER BY fr.Year,fr.Month ASC", string.Join(",", objectIDs)); using (SqlCommand command = ConnectionUtil.GetCommand(sqlStr)) { command.Parameters.Add("@ObjectTypeID", SqlDbType.Int).Value = type; List <FaultRateInfo> result = GetList <FaultRateInfo>(command); return(result.GroupBy(info => info.ObjectID).ToDictionary(g => g.Key, g => g.ToList())); } }