Beispiel #1
0
        public async Task <CartesianChartConfigModel> PersonalDivideByBossRoundComparision(GranularityModel granularity)
        {
            var personsGrouping = GetPersonalDictionary(granularity, out var titlePrefix);

            var personBossDic = personsGrouping.ToDictionary(k => k.Key,
                                                             k =>
            {
                var dic = new Dictionary <int, int>();
                foreach (var challengeModel in k)
                {
                    if (dic.ContainsKey(challengeModel.BossNum))
                    {
                        dic[challengeModel.BossNum] += challengeModel.Damage;
                    }
                    else
                    {
                        dic.Add(challengeModel.BossNum, challengeModel.Damage);
                    }
                }

                return(dic);
            });

            var list = new List <PersonalDamageModel>();

            foreach (var kvp in personBossDic)
            {
                var cycleModel = new PersonalDamageModel
                {
                    Name = $"{await QQService.GetQqNickNameAsync(kvp.Key)} ({kvp.Key})"
                };

                for (int i = 0; i < 5; i++)
                {
                    var bossNum    = cycleModel.Damages.Count + 1;
                    var bossDamage = kvp.Value.ContainsKey(bossNum) ? kvp.Value[bossNum] : 0L;
                    cycleModel.Damages.Add((int)bossDamage);
                }

                list.Add(cycleModel);
            }

            list = list.OrderBy(k => k.Damages.Sum()).ToList();

            var configModel = GetSharedConfigModel(titlePrefix, list);

            for (int i = 0; i < 5; i++)
            {
                configModel.SeriesCollection.Add(new StackedRowSeries
                {
                    Title      = $"BOSS {i + 1}",
                    Values     = new ChartValues <int>(list.Select(k => k.Damages[i]).ToList()),
                    DataLabels = true
                });
            }

            ConfigAxises(configModel);

            return(configModel);
        }
Beispiel #2
0
        public async Task <CartesianChartConfigModel> PersonalDivideByChallengeTimesDayComparision(
            GranularityModel granularity)
        {
            var personsGrouping = GetPersonalDictionary(granularity, out var titlePrefix);

            var list = new List <PersonalDamageModel>();

            foreach (var kvp in personsGrouping)
            {
                var qqId = kvp.Key;

                var byDate = kvp.GroupBy(k => k.ChallengeTime.AddHours(-5).Date);
                // multi date support

                var damageModel = new PersonalDamageModel
                {
                    Name    = $"{await QQService.GetQqNickNameAsync(qqId)} ({qqId})",
                    Damages = new List <int> {
                        0, 0, 0, 0, 0, 0
                    }
                };

                foreach (var grouping in byDate)
                {
                    int i = 0;
                    foreach (var challengeModel in grouping)
                    {
                        if (challengeModel.IsContinue)
                        {
                            if (i % 2 == 0)
                            {
                                i++;
                            }
                            damageModel.Damages[i] += challengeModel.Damage;
                        }
                        else
                        {
                            if (i % 2 != 0)
                            {
                                i++;
                            }
                            damageModel.Damages[i] += challengeModel.Damage;
                        }

                        i++;
                    }
                }

                list.Add(damageModel);
            }

            list = list.OrderBy(k => k.Damages.Sum()).ToList();

            var configModel = GetSharedConfigModel(titlePrefix, list);

            for (int i = 0; i < 6; i++)
            {
                var challengeIndex = i / 2 + 1;
                configModel.SeriesCollection.Add(new StackedRowSeries
                {
                    Title      = i % 2 == 0 ? $"第{challengeIndex}刀" : $"第{challengeIndex}刀(补偿刀)",
                    Values     = new ChartValues <int>(list.Select(k => k.Damages[i]).ToList()),
                    DataLabels = true
                });
            }

            ConfigAxises(configModel);

            return(configModel);
        }
Beispiel #3
0
        private void HiddenWebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
        {
            try
            {
                _loading = false;
                var url = _hiddenWebBrowser.Source.ToString();
                if (url.EndsWith("/yobot/user/reset-password/") && !IsLogin) // 用户未设定密码会自动跳转
                {
                    Execute.OnUiThread(() => _hiddenWebBrowser.Navigate($"{Origin}/yobot/user/"));
                }
                else if (url.EndsWith("/yobot/user/") && !IsLogin)     // 爬取个人信息、公会信息
                {
                    Console.WriteLine("用户中心界面加载完成");
                    var outerHtml = _hiddenWebBrowser.GetDocumentOuterHtml();

                    var htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(outerHtml);

                    var docNode = htmlDoc.DocumentNode;

                    var elRows          = docNode.Descendants("el-row").ToList();
                    var elRowChildNodes = elRows[0].ChildNodes.Where(k => k.Name == "a").ToArray();
                    // 功能按钮列表
                    if (elRowChildNodes.Length <= 1)
                    {
                        return;
                    }

                    var btnMyCenter = elRowChildNodes.First(); // 个人中心按钮
                    var href        = btnMyCenter.GetAttributeValue("href", null);
                    if (href != null)
                    {
                        QqId = href.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                        if (!long.TryParse(QqId, out var lQqId))
                        {
                            Console.WriteLine("错误:非法的QQ号,可能页面已发生改变");
                        }
                        else
                        {
                            Execute.OnUiThread(() =>
                            {
                                SharedVm.Default.LoginUser.QQ        = lQqId;
                                SharedVm.Default.LoginUser.AvatarUri =
                                    $"http://q1.qlogo.cn/g?b=qq&nk={lQqId}&s=640";
                            });
                            new Task(() =>
                            {
                                Execute.ToUiThread(async() =>
                                {
                                    SharedVm.Default.LoginUser.QQNick =
                                        await QQService.GetQqNickNameAsync(lQqId);
                                });
                            }).Start();

                            Console.WriteLine("QQ: " + QqId);
                        }
                    }

                    if (elRows.Count <= 1)
                    {
                        if (elRowChildNodes.Length < 4)
                        {
                            Console.WriteLine("警告:没有加入公会");
                            return;
                        }

                        var btnClan = elRowChildNodes[1]; // 选择最后一个
                        href = btnClan.GetAttributeValue("href", null);
                        if (href != null)
                        {
                            GroupId = href.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries)
                                      .LastOrDefault();
                            var groupName = btnClan.InnerText.Trim('\n').Trim().Replace("公会:", "");
                            SharedVm.Default.LoginUser.ClanNick = groupName;
                            if (!long.TryParse(GroupId, out var lGroupId))
                            {
                                Console.WriteLine("错误:非法的QQ群号,可能页面已发生改变");
                            }
                            else
                            {
                                SharedVm.Default.LoginUser.ClanId = lGroupId;
                                Console.WriteLine("QQ群: " + GroupId);
                            }
                        }
                    }
                    else
                    {
                        elRowChildNodes = elRows[1].ChildNodes.Where(k => k.Name == "a").ToArray();
                        // 公会(可能多个)按钮
                        if (elRowChildNodes.Length < 1)
                        {
                            Console.WriteLine("警告:没有加入公会");
                            return;
                        }

                        var btnClan = elRowChildNodes.Last(); // 选择最后一个
                        href = btnClan.GetAttributeValue("href", null);
                        if (href != null)
                        {
                            GroupId = href.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries)
                                      .LastOrDefault();
                            var groupName = btnClan.InnerText.Trim('\n').Trim().Replace("公会:", "");
                            SharedVm.Default.LoginUser.ClanNick = groupName;
                            if (!long.TryParse(GroupId, out var lGroupId))
                            {
                                Console.WriteLine("错误:非法的QQ群号,可能页面已发生改变");
                            }
                            else
                            {
                                SharedVm.Default.LoginUser.ClanId = lGroupId;
                                Console.WriteLine("QQ群: " + GroupId);
                            }
                        }
                    }

                    _hiddenWebBrowser.Navigate($"{Origin}/yobot/clan/{GroupId}");
                    // ↓ 如果跳转至公会信息,则上面爬取的内容无误
                }
                else if (url.Contains("/yobot/clan/") && !IsLogin)
                {
                    Console.WriteLine("公会界面加载完成");
                    var cookie = _hiddenWebBrowser.GetCookie();
                    Cookie  = cookie;
                    IsLogin = true;
                    _mre.Set();

                    _hiddenWebBrowser.Navigate($"{Origin}/yobot/user/");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }