You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

872 lines
25 KiB

1 month ago
/*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text;
namespace bill_statistics
{
public partial class BillInfoEveryDay
{
//一天的数据读完了,计算一下,清理临时数据,节省内存
public void CalcAfterThisDayAllHourReadFinish()
{
TreasureUserCount = m_tmpTreasureUser.Count;
m_tmpTreasureUser.Clear();
}
private int CalcThisOnlineTimeOnLogout(DateTime dateTime,DateTime curedateTime, int uid,int totalOnlineTime, out int newUserOnlineTime)
{
newUserOnlineTime = 0;
if (m_newUser.ContainsKey(uid))
{
newUserOnlineTime = totalOnlineTime - m_activeUser[uid].OnlineTime;
}
if (m_activeUser.ContainsKey(uid))
{
return totalOnlineTime - m_activeUser[uid].OnlineTime;
}
BillInfoEveryDay info = BillAlldays.Instance.GetBillInfoByDay(dateTime.AddDays(-1),false);
if(info != null)
{
if(info.m_activeUser.ContainsKey(uid))
{
return totalOnlineTime - info.m_activeUser[uid].OnlineTime;
}
}
return totalOnlineTime;
}
public int _CPECount(Dictionary<int, UserInfo> m)
{
int _count = 0;
foreach (var a in m)
{
if (a.Value.AdjustFullChannel != null)
{
if (a.Value.AdjustFullChannel.Contains("_CPE"))
{
_count++;
}
}
}
//Console.WriteLine("_CPEActiveCount {0}", _count);
return _count;
}
public int IOSCount(Dictionary<int, UserInfo> m)
{
int count = 0;
foreach (var a in m)
{
if (a.Value.platform == 2)
{
count++;
}
}
return count;
}
public Dictionary<int, UserInfo> _CPENewUser(Dictionary<int, UserInfo> m)
{
//int key = 0;
Dictionary<int, UserInfo> n = null;
n = m;
var list = n.Where(o => o.Value.AdjustFullChannel != null
&& o.Value.AdjustFullChannel.Contains("_CPE")).ToList();
foreach (var i in list)
{
n.Remove(i.Key);
}
return n;
}
public void CalcThis()
{
ActiveUser = m_activeUser.Count > 0 ? m_activeUser.Count : 1;
NewUser = m_newUser.Count > 0 ? m_newUser.Count : 1;
//IOSNewUser = m_IOSNewUser.Count > 0 ? m_IOSNewUser.Count : 1;
//IOSActiveUser = m_IOSActiveUser.Count > 0 ? m_IOSActiveUser.Count : 1;
int _CPENewUserCount = _CPECount(m_newUser);
int _CPEActiveUserCount = _CPECount(m_activeUser);
IOSActiveUser = IOSCount(m_activeUser) > 0 ? IOSCount(m_activeUser) : 0;
IOSNewUser = IOSCount(m_newUser) > 0 ? IOSCount(m_newUser) : 0;
NewUserMinus_CPE = m_newUser.Count > 0 ?
m_newUser.Count - _CPENewUserCount <= 0 ?
1 : m_newUser.Count - _CPENewUserCount : 1;
ActiveUserMinus_CPE = m_activeUser.Count > 0 ?
m_activeUser.Count - _CPEActiveUserCount <= 0 ?
1 : m_activeUser.Count - _CPEActiveUserCount : 1;
//新进Facebook用户
foreach (var userInfo in m_newUser)
{
if(userInfo.Value.AccType == 1)
{
NewUserFB++;
}
if(string.IsNullOrEmpty(userInfo.Value.AdjustFullChannel) == false)
{
if(m_userChannelInfo.ContainsKey(userInfo.Value.AdjustFullChannel))
{
m_userChannelInfo[userInfo.Value.AdjustFullChannel].NewUserCount++;
}
//子渠道
if(userInfo.Value.AdjustFullChannel.Contains("|"))
{
string channel = userInfo.Value.AdjustFullChannel.Split('|')[0];
if (m_userChannelInfo.ContainsKey(channel))
{
m_userChannelInfo[channel].NewUserCount++;
}
}
}
}
//付费活跃用户
foreach(var userInfo in m_activeUser)
{
if(userInfo.Value.TotalPayCount > 0)
{
this.ActivePayUser++;
}
}
RoundUser = m_roundUser.Count;
//渗透率
PayUserPer = m_PayGoogleSuccessResUser.Count()*100.0/(double)ActiveUser; //付费渗透率
MoneyUSD = PayMoney/BillTypeUtils.USD_TK_DOLLA;
IOSMoneyUSD = IOSPayMoney / BillTypeUtils.USD_TK_DOLLA;
ARPPU = 0.0;
if (m_PayGoogleSuccessResUser.Count() > 0)
{
ARPPU = MoneyUSD/m_PayGoogleSuccessResUser.Count(); //付费用户UP值
}
ARPU = 0.0;
if (m_activeUser.Count() > 0)
{
ARPU = MoneyUSD / m_activeUser.Count(); //活跃用户UP值
}
// 特殊用户付费
foreach (var pay in m_PayGoogleSuccessResUser.Values)
{
if(m_activeUser.ContainsKey(pay.uid))
{
var actUser = m_activeUser[pay.uid];
//分渠道付费
if(string.IsNullOrEmpty(actUser.AdjustFullChannel) == false)
{
if(m_userChannelInfo.ContainsKey(actUser.AdjustFullChannel))
{
UserChannelInfo channelInfo = m_userChannelInfo[actUser.AdjustFullChannel];
channelInfo.PayMoney += pay.money;
channelInfo.PayMoneyUSD = channelInfo.PayMoney / BillTypeUtils.USD_TK_DOLLA;
}
//子渠道
if (actUser.AdjustFullChannel.Contains("|"))
{
string channel = actUser.AdjustFullChannel.Split('|')[0];
if (m_userChannelInfo.ContainsKey(channel))
{
UserChannelInfo channelInfo = m_userChannelInfo[channel];
channelInfo.PayMoney += pay.money;
channelInfo.PayMoneyUSD = channelInfo.PayMoney / BillTypeUtils.USD_TK_DOLLA;
}
}
}
}
}
}
//计算月数据
public void AddForMonth(BillInfoEveryDay beforDayThisMonth)
{
//月活跃
foreach (var activeUid in beforDayThisMonth.m_activeUser.Keys)
{
if (m_activeUserMonth.ContainsKey(activeUid) == false)
{
m_activeUserMonth.Add(activeUid, 1);
}
}
//月新进
foreach (var newUid in beforDayThisMonth.m_newUser.Keys)
{
if (m_newUserMonth.ContainsKey(newUid) == false)
{
m_newUserMonth.Add(newUid, 1);
}
}
//月支付
foreach (var payUserUid in beforDayThisMonth.m_PayGoogleSuccessResUser.Keys)
{
if (m_payUserMonth.ContainsKey(payUserUid) == false)
{
m_payUserMonth.Add(payUserUid, 1);
}
}
PayMoneyMon += beforDayThisMonth.PayMoney;
PayCountMon += beforDayThisMonth.PayCount;
//渗透率
if (m_activeUserMonth.Count > 0)
{
PayUserPerMon = m_payUserMonth.Count()*100.0/m_activeUserMonth.Count; //付费渗透率
}
MoneyUSDMon = PayMoneyMon/BillTypeUtils.USD_TK_DOLLA;
ARPPUMon = 0.0;
if (m_payUserMonth.Count() > 0)
{
ARPPUMon = MoneyUSDMon/m_payUserMonth.Count(); //付费用户UP值
}
ARPUMon = 0.0;
if (m_activeUserMonth.Count() > 0)
{
ARPUMon = MoneyUSDMon / m_activeUserMonth.Count(); //活跃用户UP值
}
}
//新用户留存
private void CalcUserKeepNew(int days, BillInfoEveryDay newDayInfo)
{
CalcUserKeepNewAll(days, newDayInfo);
BillAlldays.Instance.m_adjustAllChannel = BillAlldays.Instance.m_adjustAllChannel.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
foreach (var channel in BillAlldays.Instance.m_adjustAllChannel.Keys)
{
CalcUserKeepNewChannel(days, newDayInfo, channel);
}
}
//所有新用户留存
private void CalcUserKeepNewAll(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓留存就是新进用户在新的一天是否活跃
foreach (KeyValuePair<int, UserInfo> pair in m_newUser)
{
if (pair.Value.AdjustFullChannel != null)
{
if (!pair.Value.AdjustFullChannel.Contains("_CPE"))
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
}
else
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
}
switch (days)
{
case 1:
m_newUserRetentionInfo.Retention1 = iKeep;
break;
case 2:
m_newUserRetentionInfo.Retention2 = iKeep;
break;
case 3:
m_newUserRetentionInfo.Retention3 = iKeep;
break;
case 4:
m_newUserRetentionInfo.Retention4 = iKeep;
break;
case 5:
m_newUserRetentionInfo.Retention5 = iKeep;
break;
case 6:
m_newUserRetentionInfo.Retention6 = iKeep;
break;
case 7:
m_newUserRetentionInfo.Retention7 = iKeep;
break;
case 15:
m_newUserRetentionInfo.Retention15 = iKeep;
break;
case 30:
m_newUserRetentionInfo.Retention30 = iKeep;
break;
}
}
//渠道新进用户留存
private void CalcUserKeepNewChannel(int days, BillInfoEveryDay newDayInfo, string channel)
{
int iKeep = 0;
//所谓留存就是新进用户在新的一天是否活跃
foreach (KeyValuePair<int, UserInfo> pair in m_newUser)
{
//考虑子渠道
if (pair.Value.AdjustFullChannel == channel ||
(string.IsNullOrEmpty(pair.Value.AdjustFullChannel)==false && pair.Value.AdjustFullChannel.Contains(channel)))
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
}
UserChannelInfo info = null;
if(m_userChannelInfo.ContainsKey(channel))
{
info = m_userChannelInfo[channel];
}
else
{
info = new UserChannelInfo();
m_userChannelInfo.Add(channel, info);
}
switch (days)
{
case 1:
info.Retention1 = iKeep;
break;
case 2:
info.Retention2 = iKeep;
break;
case 3:
info.Retention3 = iKeep;
break;
case 4:
info.Retention4 = iKeep;
break;
case 5:
info.Retention5 = iKeep;
break;
case 6:
info.Retention6 = iKeep;
break;
case 7:
info.Retention7 = iKeep;
break;
case 15:
info.Retention15 = iKeep;
break;
case 30:
info.Retention30 = iKeep;
break;
}
}
//新用户留存(长久)
public void CalcUserKeepNewLongKeep(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓留存就是新进用户在新的一天是否活跃
foreach (KeyValuePair<int, UserInfoLongKeep> pair in m_newUserLongKeep)
{
if (newDayInfo.m_activeUserLongKeep.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
switch (days)
{
case 1:
m_newUserRetentionInfo.Retention1 = iKeep;
break;
case 2:
m_newUserRetentionInfo.Retention2 = iKeep;
break;
case 3:
m_newUserRetentionInfo.Retention3 = iKeep;
break;
case 4:
m_newUserRetentionInfo.Retention4 = iKeep;
break;
case 5:
m_newUserRetentionInfo.Retention5 = iKeep;
break;
case 6:
m_newUserRetentionInfo.Retention6 = iKeep;
break;
case 7:
m_newUserRetentionInfo.Retention7 = iKeep;
break;
case 15:
m_newUserRetentionInfo.Retention15 = iKeep;
break;
case 30:
m_newUserRetentionInfo.Retention30 = iKeep;
break;
case 60:
m_newUserRetentionInfo.Retention60 = iKeep;
break;
case 90:
m_newUserRetentionInfo.Retention90 = iKeep;
break;
case 120:
m_newUserRetentionInfo.Retention120 = iKeep;
break;
case 150:
m_newUserRetentionInfo.Retention150 = iKeep;
break;
case 180:
m_newUserRetentionInfo.Retention180 = iKeep;
break;
}
}
//活跃留存
private void CalcUserKeepAct(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓活跃留存就是活跃用户在新的一天是否活跃
foreach (KeyValuePair<int, UserInfo> pair in m_activeUser)
{
if (pair.Value.AdjustFullChannel != null)
{
if (!pair.Value.AdjustFullChannel.Contains("_CPE"))
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
}
else
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Value.Uid))
{
iKeep++;
}
}
}
switch (days)
{
case 1:
ActRetention1 = iKeep;
break;
case 2:
ActRetention2 = iKeep;
break;
case 3:
ActRetention3 = iKeep;
break;
case 4:
ActRetention4 = iKeep;
break;
case 5:
ActRetention5 = iKeep;
break;
case 6:
ActRetention6 = iKeep;
break;
case 7:
ActRetention7 = iKeep;
break;
case 15:
ActRetention15 = iKeep;
break;
case 30:
ActRetention30 = iKeep;
break;
}
}
//付费留存
private void CalcUserKeepPay(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓付费留存就是付费用户在新的一天是否活跃
foreach (var uid in m_PayGoogleSuccessResUser.Keys)
{
if (newDayInfo.m_activeUser.ContainsKey(uid))
{
iKeep++;
}
}
switch (days)
{
case 1:
PayRetention1 = iKeep;
break;
case 2:
PayRetention2 = iKeep;
break;
case 3:
PayRetention3 = iKeep;
break;
case 4:
PayRetention4 = iKeep;
break;
case 5:
PayRetention5 = iKeep;
break;
case 6:
PayRetention6 = iKeep;
break;
case 7:
PayRetention7 = iKeep;
break;
case 15:
PayRetention15 = iKeep;
break;
case 30:
PayRetention30 = iKeep;
break;
}
}
//比赛留存
private void CalcUserKeepArena(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓xx留存就是xx用户在新的一天是否活跃
foreach (var user in m_activeUser)
{
if (user.Value.IsArenaUser)
{
if (newDayInfo.m_activeUser.ContainsKey(user.Key))
{
iKeep++;
}
}
}
switch (days)
{
case 1:
ArenaRetention1 = iKeep;
break;
case 2:
ArenaRetention2 = iKeep;
break;
case 3:
ArenaRetention3 = iKeep;
break;
case 4:
ArenaRetention4 = iKeep;
break;
case 5:
ArenaRetention5 = iKeep;
break;
case 6:
ArenaRetention6 = iKeep;
break;
case 7:
ArenaRetention7 = iKeep;
break;
case 15:
ArenaRetention15 = iKeep;
break;
case 30:
ArenaRetention30 = iKeep;
break;
}
}
//新进用户比赛留存
private void CalcUserKeepArenaNew(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
//所谓xx留存就是xx用户在新的一天是否活跃
foreach (var user in m_newUser)
{
if (user.Value.IsArenaUser)
{
if (newDayInfo.m_activeUser.ContainsKey(user.Key))
{
iKeep++;
}
}
}
switch (days)
{
case 1:
ArenaNewRetention1 = iKeep;
break;
case 2:
ArenaNewRetention2 = iKeep;
break;
case 3:
ArenaNewRetention3 = iKeep;
break;
case 4:
ArenaNewRetention4 = iKeep;
break;
case 5:
ArenaNewRetention5 = iKeep;
break;
case 6:
ArenaNewRetention6 = iKeep;
break;
case 7:
ArenaNewRetention7 = iKeep;
break;
case 15:
ArenaNewRetention15 = iKeep;
break;
case 30:
ArenaNewRetention30 = iKeep;
break;
}
}
//IOS新进用户留存
private void CalcUserKeepNewIOS(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
foreach (var pair in m_newUser)
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Key) && pair.Value.platform == 2)
{
iKeep++;
}
}
switch (days)
{
case 1:
IOSNewRetention1 = iKeep;
break;
case 2:
IOSNewRetention2 = iKeep;
break;
case 3:
IOSNewRetention3 = iKeep;
break;
case 4:
IOSNewRetention4 = iKeep;
break;
case 5:
IOSNewRetention5 = iKeep;
break;
case 6:
IOSNewRetention6 = iKeep;
break;
case 7:
IOSNewRetention7 = iKeep;
break;
case 15:
IOSNewRetention15 = iKeep;
break;
case 30:
IOSNewRetention30 = iKeep;
break;
}
}
//IOS活跃留存
private void CalcUserKeepActiveIOS(int days, BillInfoEveryDay newDayInfo)
{
int iKeep = 0;
foreach (var pair in m_activeUser)
{
if (newDayInfo.m_activeUser.ContainsKey(pair.Key) && pair.Value.platform == 2)
{
iKeep++;
}
}
switch (days)
{
case 1:
IOSActiveRetention1 = iKeep;
break;
case 2:
IOSActiveRetention2 = iKeep;
break;
case 3:
IOSActiveRetention3 = iKeep;
break;
case 4:
IOSActiveRetention4 = iKeep;
break;
case 5:
IOSActiveRetention5 = iKeep;
break;
case 6:
IOSActiveRetention6 = iKeep;
break;
case 7:
IOSActiveRetention7 = iKeep;
break;
case 15:
IOSActiveRetention15 = iKeep;
break;
case 30:
IOSActiveRetention30 = iKeep;
break;
}
}
//破产流失
private void CalcBrokenUserLostCount(int days, BillInfoEveryDay newDayInfo)
{
//只算次日
if(days == 1)
{
//所谓流失就是破产用户在次日不活跃
foreach (var user in m_activeUser)
{
//破产
if (user.Value.GetBrokenGrantTimes > 0)
{
if (newDayInfo.m_activeUser.ContainsKey(user.Key) == false)
{
if (user.Value.GetBrokenGrantTimes == 1)
{
BrokenLostNextDayCount1++;
}
if (user.Value.GetBrokenGrantTimes == 2)
{
BrokenLostNextDayCount2++;
}
if (user.Value.GetBrokenGrantTimes == 3)
{
BrokenLostNextDayCount3++;
}
if (user.Value.GetBrokenGrantTimes == 4)
{
BrokenLostNextDayCount4++;
}
}
}
}
}
}
public void CalcUserKeep(int days, BillInfoEveryDay newDayInfo)
{
CalcUserKeepNew(days, newDayInfo);
CalcUserKeepAct(days, newDayInfo);
CalcUserKeepPay(days, newDayInfo);
CalcUserKeepArena(days, newDayInfo);
CalcUserKeepArenaNew(days, newDayInfo);
CalcUserKeepNewIOS(days, newDayInfo);
CalcUserKeepActiveIOS(days, newDayInfo);
CalcBrokenUserLostCount(days, newDayInfo);
}
public void CalcNewUserRound(BillInfoEveryDay otherDayInfo)
{
foreach (var item in m_roundNewUser)
{
if (otherDayInfo.m_roundNewUser.ContainsKey(item.Key))
{
m_roundNewUser.Remove(item.Key);
}
}
}
public void CalcLostUserChip(int newdayIndex, BillInfoEveryDay newDayInfo)
{
//BillInfoEveryDay newDayInfo
foreach (KeyValuePair<int, UserInfo> pair in m_activeUser)
{
//一天没登陆,+1,如果n天都没有登录则表示流失
if (!newDayInfo.m_activeUser.ContainsKey(pair.Key))
{
pair.Value.notLoginDayCount++;
//第二天流失
if (newdayIndex == 1)
{
pair.Value.secondDayNotLogin = true;
}
}
}
}
public void CalcLostNewUserChip(int newdayIndex, BillInfoEveryDay newDayInfo)
{
//BillInfoEveryDay newDayInfo
foreach (KeyValuePair<int, UserInfo> pair in m_newUser)
{
//一天没登陆,+1,如果n天都没有登录则表示流失
if (!newDayInfo.m_activeUser.ContainsKey(pair.Key))
{
pair.Value.notLoginDayCount++;
//第二天流失
if (newdayIndex == 1)
{
pair.Value.secondDayNotLogin = true;
}
}
}
}
}
}