public void DoFitCalculation(string stockName, string fitMethod) { CurveEntity curveInfo = this._iCurveDao.GetCurveByName(stockName); if (curveInfo == null) { LogHelper.Warn(typeof(ValueComplementBusinessImpl), "Cannot find certain stock information"); return; } List <CurveDataEntity> curveDataList = this._iCurveDataDao.GetCurveDataByCurveId(curveInfo.CurveId); if (ListHelper.IsNullOrEmpty(curveDataList)) { LogHelper.Warn(typeof(ValueComplementBusinessImpl), "Stock " + curveInfo.CurveName + " doesnot have any data"); return; } int missIdx = FindMissingValueIdx(curveDataList); CurveDataEntity missingCurveDataEntity = curveDataList[missIdx]; List <PointDto> modelPoints = ConvertValueItemsToPoints(curveDataList); if (missIdx != -1 && !ListHelper.IsNullOrEmpty(modelPoints)) { IFitStrategy fitStrategy = StrategyFactory.GetStrategyByName(fitMethod); PointDto fitResultPoint = fitStrategy.FitCalculation(modelPoints, missIdx); missingCurveDataEntity.Value = System.Convert.ToDecimal(fitResultPoint.Y); //更新至db this._iCurveDataDao.Update(missingCurveDataEntity); } }
//Dto转换 private List <PointDto> ConvertValueItemsToPoints(List <CurveDataEntity> curveDataList) { List <PointDto> results = new List <PointDto>(); if (ListHelper.IsNullOrEmpty(curveDataList)) { return(results); } CurveDataEntity firstEntity = curveDataList[0]; DateTime firstDate = DateTime.ParseExact(firstEntity.EffectiveDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); foreach (CurveDataEntity curveData in curveDataList) { DateTime thisDate = DateTime.ParseExact(curveData.EffectiveDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); PointDto newPoint = new PointDto() { X = DaysDiff(firstDate, thisDate), Y = System.Convert.ToDouble(curveData.Value) }; results.Add(newPoint); } return(results); }
public List <CurveDataEntity> GetCurveDataByCurveId(long curveId) { List <CurveDataEntity> results = new List <CurveDataEntity>(); if (curveId <= 0) { return(results); } StringBuilder buildSQL = new StringBuilder(200); buildSQL.Append(" SELECT CurveDataId, CurveId, EffectiveDate, Value, DataChange_CreateTime, DataChange_LastTime FROM curve_data WHERE 1=1 "); buildSQL.AppendFormat(" AND CurveId = {0} ", curveId); buildSQL.Append(" Order By CurveDataId "); // open connection if (this.OpenConnection() == true) { MySqlCommand mysqlCmd = new MySqlCommand(buildSQL.ToString(), connection); MySqlDataReader dataReader = mysqlCmd.ExecuteReader(); while (dataReader.Read()) { CurveDataEntity curveItem = new CurveDataEntity() { CurveDataId = dataReader.GetInt64(0), CurveId = dataReader.GetInt64(1), EffectiveDate = dataReader.GetString(2), Value = dataReader.GetDecimal(3), DataChange_CreateTime = dataReader.GetDateTime(4), DataChange_LastTime = dataReader.GetDateTime(5) }; results.Add(curveItem); } // close connection this.CloseConnection(); } return(results); }
public void Update(CurveDataEntity curveData) { if (curveData == null) { LogHelper.Warn(typeof(CurveDaoMySQLImpl), "Empty update operation"); } StringBuilder buildSQL = new StringBuilder(200); buildSQL.Append(" UPDATE curve_data "); buildSQL.AppendFormat(" SET CurveId={0} ", curveData.CurveId); buildSQL.AppendFormat(", EffectiveDate='{0}' ", curveData.EffectiveDate); buildSQL.AppendFormat(", Value={0} ", curveData.Value); buildSQL.AppendFormat(" WHERE CurveDataId = {0} ", curveData.CurveDataId); // open connection if (this.OpenConnection() == true) { MySqlCommand mysqlCmd = new MySqlCommand(buildSQL.ToString(), connection); mysqlCmd.ExecuteNonQuery(); // close connection this.CloseConnection(); } }
public void Update(CurveDataEntity curveData) { }
/// <summary> /// GC计算 /// </summary> /// <param name="GCLevelDataList">GC标准表的数据集合</param> /// <param name="ECP_TWYCurve">已经存在的ECP—TWY绘图曲线</param> /// <param name="B_X">馏分曲线中的已知的18个点数据集合</param> /// <param name="itemCode">判断哪个物性进行GC内插计算</param> /// <returns>表格中需要填充的数据,和B_X数据对应</returns> public static Dictionary <float, float> getGCInterpolationDIC(List <OilDataEntity> GCLevelDataList, CurveEntity ECP_TWYCurve, List <float> B_X, string itemCode) { Dictionary <float, float> DIC = new Dictionary <float, float>();//GC字典 #region "输入处理" if (GCLevelDataList.Count <= 0) { return(DIC); } if (ECP_TWYCurve == null) { return(DIC); } if (ECP_TWYCurve.curveDatas.Count <= 0) { return(DIC); } if (B_X.Count <= 0) { return(DIC); } OilDataEntity ICPEntity = GCLevelDataList.Where(o => o.OilTableRow.itemCode == "ICP").FirstOrDefault(); OilDataEntity ECPEntity = GCLevelDataList.Where(o => o.OilTableRow.itemCode == "ECP").FirstOrDefault(); if (ICPEntity == null || ECPEntity == null) { return(DIC); } if (ICPEntity.calData == string.Empty || ECPEntity.calData == string.Empty) { return(DIC); } float TotalICP = 0, TotalECP = 0; if (!(float.TryParse(ICPEntity.calData, out TotalICP) && float.TryParse(ECPEntity.calData, out TotalECP))) { return(DIC); } #endregion List <float> XList = B_X.Where(o => o >= TotalICP && o <= TotalECP).ToList(); if (XList.Count <= 0) { return(DIC); } if (XList.Count == 1) { float CUTICP = TotalICP; float CUTECP = XList[0]; } else if (XList.Count > 1) { for (int i = 1; i < XList.Count; i++) { float CUTICP = XList[i - 1]; float CUTECP = XList[i]; CurveDataEntity ICPData = ECP_TWYCurve.curveDatas.Where(o => o.xValue == CUTICP).FirstOrDefault(); CurveDataEntity ECPData = ECP_TWYCurve.curveDatas.Where(o => o.xValue == CUTECP).FirstOrDefault(); if (ICPData == null || ECPData == null) { continue; } if (ICPData.yValue.Equals(float.NaN) || ECPData.yValue.Equals(float.NaN)) { continue; } float WY = ECPData.yValue - ICPData.yValue; Dictionary <string, float> gcDIC = OilApplyBll.getGCInterpolationDIC(GCLevelDataList, CUTICP, CUTECP, WY); List <float> tempList = gcDIC.Values.ToList(); float sum = 0; foreach (string key in gcDIC.Keys) { sum += gcDIC[key]; } float?result = null; switch (itemCode) { case "D20": result = OilApplySupplement.getGC_D20Value(gcDIC, WY); break; case "MW": result = OilApplySupplement.getGC_MWValue(gcDIC, WY); break; case "RNC": result = OilApplySupplement.getGC_RNCValue(gcDIC, WY); break; case "PAN": result = OilApplySupplement.getGC_PANValue(gcDIC, WY); break; case "PAO": result = OilApplySupplement.getGC_PAOValue(gcDIC, WY); break; case "NAH": result = OilApplySupplement.getGC_NAHValue(gcDIC, WY); break; case "MON": result = OilApplySupplement.getGC_MONValue(gcDIC, WY); break; case "ARM": result = OilApplySupplement.getGC_ARMValue(gcDIC, WY); break; case "ARP": result = OilApplySupplement.getGC_ARPValue(gcDIC, WY); break; case "RVP": // result = OilApplySupplement.getGC_RVPValue(gcDIC, WY); break; } if (!DIC.Keys.Contains(CUTECP) && result != null) { DIC.Add(CUTECP, result.Value); } } } return(DIC); }
/// <summary> /// 从应用库中取出曲线 /// </summary> /// <param name="oilInfoBID"></param> /// <param name="DataBaseBDIC"></param> /// <param name="typeCode"></param> /// <param name="CurveXParmType"></param> /// <param name="CurveYParmType"></param> /// <returns></returns> public static CurveEntity getCurrentCurveFromDataBaseB(int oilInfoBID, Dictionary <float, float> DataBaseBDIC, CurveTypeCode typeCode, CurveParmTypeEntity CurveXParmType, CurveParmTypeEntity CurveYParmType) { if (DataBaseBDIC == null || CurveXParmType == null || CurveYParmType == null) { return(null); } if (DataBaseBDIC.Count <= 0) { return(null); } if (typeCode == CurveTypeCode.YIELD) { if (CurveXParmType.ItemCode != PartCurveItemCode.ECP.ToString())//只有X轴为ECP的曲线才保存 { return(null); } } else if (typeCode == CurveTypeCode.DISTILLATE) { if (CurveXParmType.ItemCode != PartCurveItemCode.ECP.ToString())//只有X轴为ECP的曲线才保存 { return(null); } } else if (typeCode == CurveTypeCode.RESIDUE) { if (CurveXParmType.ItemCode != PartCurveItemCode.WY.ToString()) { return(null); } } Dictionary <float, float> tempDiC = DataBaseBDIC; #region "曲线的数据点集合赋值" List <CurveDataEntity> curveDatas = new List <CurveDataEntity>(); foreach (float Key in tempDiC.Keys) { CurveDataEntity curveDataEntity = new CurveDataEntity(); curveDataEntity.cutPointCP = Key; curveDataEntity.xValue = Key; curveDataEntity.yValue = tempDiC[Key]; curveDataEntity.XItemCode = CurveXParmType.ItemCode; curveDataEntity.YItemCode = CurveYParmType.ItemCode; curveDatas.Add(curveDataEntity); } #endregion #region "向原油中添加曲线" if (curveDatas.Count > 0) { //CurveEntity currentCurve = oilInfoB.curves.Where(o => o.propertyX == CurveXParmType.ItemCode && o.propertyY == CurveYParmType.ItemCode).FirstOrDefault(); OilTableRowEntity tempRowY = OilTableRowBll._OilTableRow.Where(o => o.itemCode == CurveYParmType.ItemCode).FirstOrDefault(); //注意此处的曲线没有ID CurveEntity curve = new CurveEntity(); curve.curveTypeID = (int)typeCode; curve.oilInfoID = oilInfoBID; curve.propertyX = CurveXParmType.ItemCode; curve.propertyY = CurveYParmType.ItemCode; curve.unit = tempRowY.itemUnit; curve.descript = tempRowY.itemName; curve.decNumber = tempRowY.decNumber == null ? tempRowY.valDigital : tempRowY.decNumber.Value; curve.curveDatas.AddRange(curveDatas); return(curve); } #endregion return(null); }
/// <summary> /// 从当前的DataGridView中获取数据添加到原油的曲线集合中 /// </summary> /// <param name="oilInfoB">当前原油的曲线集合</param> /// <param name="dataGridView">从此表格中获取数据填到原油的曲线数据集合</param> /// <param name="typeCode">YIELD收率曲线,DISTILLATE性质曲线,RESIDUE渣油曲线</param> /// <param name="CurveXParmType">判断当前原油曲线的X轴参数</param> /// <param name="CurveYParmType">判断当前原油曲线的Y轴参数</param> public static void getCurrentCurveFromDataGridViewDataBaseB(ref OilInfoBEntity oilInfoB, DataGridView dataGridView, CurveTypeCode typeCode, CurveParmTypeEntity CurveXParmType, CurveParmTypeEntity CurveYParmType) { if (oilInfoB == null || dataGridView == null || CurveXParmType == null || CurveYParmType == null) { return; } if (dataGridView.Rows.Count < 5) { return; } if (typeCode == CurveTypeCode.YIELD) { if (CurveXParmType.ItemCode != PartCurveItemCode.ECP.ToString())//只有X轴为ECP的曲线才保存 { return; } } else if (typeCode == CurveTypeCode.DISTILLATE) { if (CurveXParmType.ItemCode != PartCurveItemCode.ECP.ToString())//只有X轴为MCP的曲线才保存 { return; } } else if (typeCode == CurveTypeCode.RESIDUE) { if (CurveXParmType.ItemCode != PartCurveItemCode.WY.ToString()) { return; } } Dictionary <float, float> tempDiC = getDataBaseBfromDataGridView(dataGridView); if (tempDiC.Count <= 0) { return; } OilTableRowEntity tempRowY = OilTableRowBll._OilTableRow.Where(o => o.itemCode == CurveYParmType.ItemCode).FirstOrDefault(); #region "曲线的数据点集合赋值" List <CurveDataEntity> curveDatas = new List <CurveDataEntity>(); foreach (float Key in tempDiC.Keys) { CurveDataEntity curveDataEntity = new CurveDataEntity(); curveDataEntity.cutPointCP = Key; curveDataEntity.xValue = Key; curveDataEntity.yValue = tempDiC[Key]; curveDataEntity.XItemCode = CurveXParmType.ItemCode; curveDataEntity.YItemCode = CurveYParmType.ItemCode; curveDatas.Add(curveDataEntity); } #endregion #region "向原油中添加曲线" if (curveDatas.Count > 0) { CurveEntity currentCurve = oilInfoB.curves.Where(o => o.propertyX == CurveXParmType.ItemCode && o.propertyY == CurveYParmType.ItemCode).FirstOrDefault(); if (currentCurve != null) //从内存中找到曲线、删除。 { oilInfoB.curves.Remove(currentCurve); //此处要考虑从B库取出的数据 currentCurve.curveDatas.Clear(); currentCurve.curveDatas.AddRange(curveDatas); oilInfoB.curves.Add(currentCurve); } else { //注意此处的曲线没有ID CurveEntity curve = new CurveEntity(); curve.curveTypeID = (int)typeCode; curve.oilInfoID = oilInfoB.ID; curve.propertyX = CurveXParmType.ItemCode; curve.propertyY = CurveYParmType.ItemCode; curve.unit = tempRowY.itemUnit; curve.descript = tempRowY.itemName; curve.decNumber = tempRowY.decNumber == null ? tempRowY.valDigital : tempRowY.decNumber.Value; //curve.decNumber = tempRowY.decNumber; curve.curveDatas.AddRange(curveDatas); oilInfoB.curves.Add(curve); } } #endregion }