Esempio n. 1
0
        /// <summary>统计指定日期的数据,每分钟,耗时较小</summary>
        /// <param name="date"></param>
        public static void ProcessDate2(DateTime date)
        {
            // 这一天的所有统计数据
            var sts = FindAllByDate(date);

            // 最高在线
            if (date == DateTime.Today)
            {
                var dic = DeviceOnline.SearchGroupByProduct();
                foreach (var item in dic)
                {
                    if (item.Key == 0)
                    {
                        continue;
                    }

                    var st = GetStat(sts, item.Key, date);
                    if (item.Value > st.MaxOnline)
                    {
                        st.MaxOnline     = item.Value;
                        st.MaxOnlineTime = DateTime.Now;
                    }
                }
            }

            // 计算所有产品
            {
                var st = GetStat(sts, 0, date);

                var sts2 = sts.Where(e => e.ProductId > 0).ToList();
                st.Total      = sts2.Sum(e => e.Total);
                st.Actives    = sts2.Sum(e => e.Actives);
                st.News       = sts2.Sum(e => e.News);
                st.T7Actives  = sts2.Sum(e => e.T7Actives);
                st.T7News     = sts2.Sum(e => e.T7News);
                st.T30Actives = sts2.Sum(e => e.T30Actives);
                st.T30News    = sts2.Sum(e => e.T30News);
                st.Registers  = sts2.Sum(e => e.Registers);

                var max = sts2.Sum(e => e.MaxOnline);
                if (max > st.MaxOnline)
                {
                    st.MaxOnline     = max;
                    st.MaxOnlineTime = DateTime.Now;
                }
            }

            // 保存统计数据
            sts.Save(true);
        }
Esempio n. 2
0
        /// <summary>统计指定日期的数据,每小时,耗时较大</summary>
        /// <param name="date"></param>
        public static void ProcessDate(DateTime date)
        {
            // 这一天的所有统计数据
            var sts = FindAllByDate(date);

            // 活跃数
            {
                var dic = Device.SearchGroupByLastLogin(date, date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.Actives = item.Value;
                }
            }
            // 7天活跃数
            {
                var dic = Device.SearchGroupByLastLogin(date.AddDays(-7 + 1), date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.T7Actives = item.Value;
                }
            }
            // 30天活跃数
            {
                var dic = Device.SearchGroupByLastLogin(date.AddDays(-30 + 1), date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.T30Actives = item.Value;
                }
            }

            // 新增数
            {
                var dic = Device.SearchGroupByCreateTime(date, date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.News = item.Value;
                }
            }
            // 7天新增
            {
                var dic = Device.SearchGroupByCreateTime(date.AddDays(-7 + 1), date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.T7News = item.Value;
                }
            }
            // 30天新增
            {
                var dic = Device.SearchGroupByCreateTime(date.AddDays(-30 + 1), date.AddDays(1));
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.T30News = item.Value;
                }
            }

            // 注册数
            {
                //var his = DeviceHistory.Search(-1, -1, -1, "动态注册", null, date, date, null, null);
                var his = DeviceHistory.SearchGroupByDevice("动态注册", date, date);
                var dvs = his.Select(e => e.Key).Select(Device.FindByID).ToList();
                var dic = dvs.Where(e => e != null).GroupBy(e => e.ProductId).ToDictionary(e => e.Key, e => e.ToList());
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.Registers = item.Value.Count;
                }
            }

            // 总数
            {
                var dic = Device.SearchCountByCreateDate(date);
                foreach (var item in dic)
                {
                    var st = GetStat(sts, item.Key, date);
                    st.Total = item.Value;
                }
            }

            // 最高在线
            if (date == DateTime.Today)
            {
                var dic = DeviceOnline.SearchGroupByProduct();
                foreach (var item in dic)
                {
                    if (item.Key == 0)
                    {
                        continue;
                    }

                    var st = GetStat(sts, item.Key, date);
                    if (item.Value > st.MaxOnline)
                    {
                        st.MaxOnline     = item.Value;
                        st.MaxOnlineTime = DateTime.Now;
                    }
                }
            }

            // 计算所有产品
            {
                var st = GetStat(sts, 0, date);

                var sts2 = sts.Where(e => e.ProductId > 0).ToList();
                //st.Total = sts2.Sum(e => e.Total);
                //st.Actives = sts2.Sum(e => e.Actives);
                //st.News = sts2.Sum(e => e.News);
                //st.T7Actives = sts2.Sum(e => e.T7Actives);
                //st.T7News = sts2.Sum(e => e.T7News);
                //st.T30Actives = sts2.Sum(e => e.T30Actives);
                //st.T30News = sts2.Sum(e => e.T30News);
                //st.Registers = sts2.Sum(e => e.Registers);

                var max = st.MaxOnline;
                st.Merge(sts2);

                //var max = sts2.Sum(e => e.MaxOnline);
                if (max < st.MaxOnline)
                {
                    //st.MaxOnline = max;
                    st.MaxOnlineTime = DateTime.Now;
                }
            }

            // 保存统计数据
            sts.Save(true);
        }