/// <summary> /// 从 HBase 数据创建 <see cref="StockDailyInfo"/> 封装。 /// </summary> /// <param name="dayCells">日统计数据。</param> /// <param name="predictCells">预测数据。</param> /// <returns></returns> public static Dictionary <DateTime, StockDailyInfo> FromHBaseRowCellCollection( HBaseRowCellCollection dayCells, HBaseRowCellCollection predictCells) { var openPrice = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "open"); var closePrice = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "close"); var lowestPrice = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "lowest"); var highestPrice = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "highest"); var totalDeals = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "total"); var amount = PredictedNumber.FromHBaseRowCellCollection(dayCells, predictCells, "amount"); var dailyInfo = new Dictionary <DateTime, StockDailyInfo>(); foreach (var price in openPrice) { if (!dailyInfo.ContainsKey(price.Key)) { dailyInfo[price.Key] = new StockDailyInfo { Date = price.Key }; } dailyInfo[price.Key].OpenPrice = price.Value; } foreach (var price in closePrice) { if (!dailyInfo.ContainsKey(price.Key)) { dailyInfo[price.Key] = new StockDailyInfo { Date = price.Key }; } dailyInfo[price.Key].SettlementPrice = price.Value; } foreach (var price in lowestPrice) { if (!dailyInfo.ContainsKey(price.Key)) { dailyInfo[price.Key] = new StockDailyInfo { Date = price.Key }; } dailyInfo[price.Key].LowestPrice = price.Value; } foreach (var price in highestPrice) { if (!dailyInfo.ContainsKey(price.Key)) { dailyInfo[price.Key] = new StockDailyInfo { Date = price.Key }; } dailyInfo[price.Key].HighestPrice = price.Value; } foreach (var deal in totalDeals) { if (!dailyInfo.ContainsKey(deal.Key)) { dailyInfo[deal.Key] = new StockDailyInfo { Date = deal.Key }; } dailyInfo[deal.Key].TotalDeals = deal.Value; } foreach (var deal in amount) { if (!dailyInfo.ContainsKey(deal.Key)) { dailyInfo[deal.Key] = new StockDailyInfo { Date = deal.Key }; } dailyInfo[deal.Key].Amount = deal.Value; } return(dailyInfo); }
/// <summary> /// 将day表中的真实值与prediction表中的预测值合并。 /// </summary> /// <param name="dayCells">day表中符合条件的cell</param> /// <param name="predictCells">prediction表中符合条件的cell</param> /// <param name="columnName">要合并的列族名</param> /// <returns></returns> public static Dictionary <DateTime, PredictedNumber> FromHBaseRowCellCollection( HBaseRowCellCollection dayCells, HBaseRowCellCollection predictCells, string columnName) { if (dayCells == null) { throw new ArgumentNullException(nameof(dayCells)); } if (predictCells == null) { throw new ArgumentNullException(nameof(predictCells)); } var pdNum = new Dictionary <DateTime, PredictedNumber>(); foreach (var actualValue in dayCells.Get(columnName, columnName)) { var date = new DateTime(actualValue.Timestamp).Date; if (!pdNum.ContainsKey(date)) { pdNum[date] = new PredictedNumber(); } pdNum[date].ActualValue = double.Parse(Encoding.UTF8.GetString(actualValue.Data)); } foreach (var predictedMinValue in predictCells.Get(columnName, "lower")) { var date = new DateTime(predictedMinValue.Timestamp).Date; if (!pdNum.ContainsKey(date)) { pdNum[date] = new PredictedNumber(); } pdNum[date].PredictedMinValue = double.Parse(Encoding.UTF8.GetString(predictedMinValue.Data)); } foreach (var predictedValue in predictCells.Get(columnName, "value")) { var date = new DateTime(predictedValue.Timestamp).Date; if (!pdNum.ContainsKey(date)) { pdNum[date] = new PredictedNumber(); } pdNum[date].PredictedValue = double.Parse(Encoding.UTF8.GetString(predictedValue.Data)); } foreach (var predictedMaxValue in predictCells.Get(columnName, "upper")) { var date = new DateTime(predictedMaxValue.Timestamp).Date; if (!pdNum.ContainsKey(date)) { pdNum[date] = new PredictedNumber(); } pdNum[date].PredictedMaxValue = double.Parse(Encoding.UTF8.GetString(predictedMaxValue.Data)); } return(pdNum); }