/// <summary> /// 用户点击的商品去重后的数量 /// </summary> /// <param name="data"></param> public void SetUniqueScanAndBuyCount(IGrouping <int, T_UserAction> data) { int spanCount = 24 / m_hourSpan * m_relationDays; int[] behaviorTypes = new int[] { 1, 2, 3, 4 }; for (int i = 0; i < behaviorTypes.Length; i++) { for (int span = spanCount; span > 0; span--) { DateTime dateTime = PredictDate.AddHours(-span * m_hourSpan); int value = data.Where(d => d.behaviortype == behaviorTypes[i] && d.actiondate >= dateTime).GroupBy(d => d.itemid).Count(); if (value == 0) { break; } this.UniqueItemFourBehaviorCount.SetValue(i, span - 1, value); } } }
//更新商品类别转化率 private void UpdateTransferRate(IGrouping <int, T_UserAction> items) { for (int span = 24 * m_relationDays; span > 0; span -= m_hourSpan) { var buyCount = this.FourBehaviorCountCollection.ActionData[3][span / m_hourSpan - 1]; DateTime dateTime = PredictDate.AddHours(-span); var data = items.GroupBy(d => d.userid) .Where(d => d.Any(r => r.actiondate >= dateTime)); for (int i = 1; i <= 3; i++) { var count = data.Count(d => d.Any(r => r.behaviortype == i) && d.Any(r => r.behaviortype == 4)); //收藏且购买的 var total = data.Count(d => d.Any(r => r.behaviortype == i)); //收藏总人数 double value = 1.0 * (1 + count) / (2 + total); //进行了一次平滑,假设如果没有记录,购买转化率是0.5 TransferRateCollection.SetValue(i - 1, span / m_hourSpan - 1, value); } } }