private async Task CreateTeamPlayers(IDbConnection c, IDbTransaction t, FootballData.Team team, Models.Db.Team dbTeam, long idTournament)
        {
            var players = new List <Models.Db.Player>();

            if (team.Players != null)
            {
                foreach (var p in team.Players)
                {
                    var dbPlayer = await CreatePlayer(c, t, p, dbTeam, idTournament);

                    players.Add(dbPlayer);
                }
            }
            else
            {
                Console.WriteLine("Warning: team without players: " + team.Name);
            }

            dbTeam.Players = players;
        }
        private static async Task <Models.Db.Team> CreateTeam(IDbConnection c, IDbTransaction t, IStorageProvider storage, GroupCoords coords, FootballData.Team team, int sequenceOrder)
        {
            var logoImgUrl = ImportImage(c, t, storage, team.CrestUrl);

            var dbTeam = new Models.Db.Team
            {
                Name       = team.Name,
                KeyName    = String.IsNullOrWhiteSpace(team.Code) ? team.Name.Substring(0, 3) : team.Code,
                LogoImgUrl = logoImgUrl,
                Status     = (int)TeamStatus.Inscribed
            };

            dbTeam.Id = await c.InsertAsync(dbTeam, t);

            await c.InsertAsync(new TournamentTeam
            {
                IdTeam       = dbTeam.Id,
                IdTournament = coords.IdTournament
            }, t);

            var teamGroup = new TeamGroup
            {
                IdTeam        = dbTeam.Id,
                IdGroup       = coords.IdGroup,
                IdStage       = coords.IdStage,
                IdTournament  = coords.IdTournament,
                SequenceOrder = sequenceOrder
            };

            await c.InsertAsync(teamGroup, t);

            return(dbTeam);
        }
Exemplo n.º 3
0
        private static async Task MainAsync(string id) // Wiki belépés
        {
            var client = new WikiClient
            {
                ClientUserAgent = "Hargitomi"
            };

            // belépünk az oldalra
            var site = new WikiSite(client, "https://www.wikidata.org/w/api.php");
            await site.Initialization;

            try
            {
                await site.LoginAsync("Hargitomi", "jelszo123");
            }
            catch (WikiClientException ex)
            {
                Console.WriteLine(ex.Message);
            }

            var entity = new Entity(site, id); // a lekért entitás
            await entity.RefreshAsync(EntityQueryOptions.FetchClaims);

            // Claimek közül az egyes (P)ropertykhez tartozó DataValue.value érték
            var IdValuePairs             = new List <KeyValuePair <string, string> >();
            HashSet <string> keys        = new HashSet <string>();
            List <string>    teamIdsList = new List <string>();

            foreach (var claim in entity.Claims)
            {
                flag = false;
                try
                {
                    if (claim.MainSnak.PropertyId.Equals("P1923"))
                    {
                        foreach (var qualifierSnak in claim.Qualifiers)
                        {
                            dynamic json = JsonConvert.DeserializeObject(qualifierSnak.RawDataValue.ToString());
                            if (json.value.amount != null)
                            {
                                if (flag == false)
                                {
                                    IdValuePairs.Add(new KeyValuePair <string, string>(claim.MainSnak.PropertyId, claim.MainSnak.DataValue.ToString())); // property - csapat ID
                                    teamIdsList.Add(claim.MainSnak.DataValue.ToString());                                                                // kell P571 (alapítás), P115 (home_venue),
                                    IdValuePairs.Add(new KeyValuePair <string, string>(claim.MainSnak.DataValue.ToString(), (string)json.value.amount)); // csapat ID - ranking
                                    keys.Add(claim.MainSnak.DataValue.ToString());
                                    flag = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        IdValuePairs.Add(new KeyValuePair <string, string>(claim.MainSnak.PropertyId, claim.MainSnak.DataValue.ToString()));
                        keys.Add(claim.MainSnak.PropertyId);
                        if (claim.MainSnak.DataValue.ToString().StartsWith('Q') || claim.MainSnak.DataValue.ToString().StartsWith('P'))
                        {
                            keys.Add(claim.MainSnak.DataValue.ToString());
                        }
                    }
                }
                catch (Exception e) { }
            }

            foreach (var claim in entity.Claims)
            {
                try
                {
                    dynamic json = JsonConvert.DeserializeObject(claim.MainSnak.RawDataValue.ToString());
                    if (json.value.amount != null)
                    {
                        IdValuePairs.Add(new KeyValuePair <string, string>(claim.MainSnak.PropertyId, (string)json.value.amount)); //property - amount érték (ahol csak szám van, pl numberOfGoals)
                        keys.Add(claim.MainSnak.PropertyId);
                    }
                }
                catch (Exception e)
                {
                }
            }
            // Összes P és Q | jellel elválasztva
            string allKeys = "";

            foreach (var element in keys)
            {
                var addedElement = element + "|";
                allKeys += addedElement;
            }

            allKeys = allKeys.Remove(allKeys.Length - 1); // az utolsó | jelet eltávolítjuk
            // Összes P és Q, illetve a hozzájuk tartozó label


            getNames(allKeys);

            Dictionary <string, int> TeamAndFounded = new Dictionary <string, int>();

            foreach (var element in teamIdsList)
            {
                var teamDetails = new Service().GetEntityClaims(element, "P571");

                if (teamDetails == null)
                {
                    continue;
                }

                try
                {
                    foreach (var x in teamDetails)
                    {
                        foreach (var y in x)
                        {
                            foreach (var z in y)
                            {
                                foreach (var w in z)
                                {
                                    foreach (var a in w)
                                    {
                                        string founded = a.mainsnak.datavalue.value.time;
                                        founded = founded.Remove(0, 1);
                                        founded = founded.Substring(0, 4);
                                        TeamAndFounded.Add(element, int.Parse(founded));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { }
            }

            string idList = "";

            foreach (var element in teamIdsList)
            {
                var teamDetails = new Service().GetEntityClaims(element, "P115");

                try
                {
                    foreach (var x in teamDetails)
                    {
                        foreach (var y in x)
                        {
                            foreach (var z in y)
                            {
                                foreach (var w in z)
                                {
                                    foreach (var a in w)
                                    {
                                        string ID = a.mainsnak.datavalue.value.id;
                                        idList += ID + "|";
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { }
            }

            idList = idList.Remove(idList.Length - 1);
            var datax = new Service().GetEntityNames(idList);

            int i = 0;

            try
            {
                foreach (var b in datax)
                {
                    foreach (var c in b)
                    {
                        foreach (var d in c)
                        {
                            foreach (var e in d)
                            {
                                string venue_name = e.labels.en.value.ToString();
                                TeamAndVenue.Add(teamIdsList[i++], venue_name);
                            }
                        }
                    }
                }
            }
            catch (Exception e) { }



            // Console.WriteLine(teamDetails);

            /*foreach(KeyValuePair<string, string> kvp in TeamAndVenue) {
             *   Console.WriteLine(kvp.Key + " " + kvp.Value);
             * }*/

            /*foreach(var element in teamIds)
             * {
             *  Console.WriteLine(element);
             * }*/

            var temp = IdValuePairs.ToLookup(kvp => kvp.Key, kvp => kvp.Value);


            foreach (string key in temp["P3450"])
            {
                wiki.LeagueName = RealIdNamePairs[key];
            }
            // Console.WriteLine(wiki.LeagueName);

            foreach (string key in temp["P17"])
            {
                wiki.Country = RealIdNamePairs[key];
            }
            // Console.WriteLine(wiki.Country);

            foreach (string key in temp["P580"])
            {
                wiki.SeasonStart = key;
            }
            //  Console.WriteLine(wiki.SeasonStart);

            foreach (string key in temp["P582"])
            {
                wiki.SeasonEnd = key;
            }
            //  Console.WriteLine(wiki.SeasonEnd);

            foreach (string key in temp["P2348"])
            {
                wiki.LeagueSeason = RealIdNamePairs[key];
            }
            //  Console.WriteLine(wiki.LeagueSeason);

            foreach (string key in temp["P1132"])
            {
                wiki.numberOfTeams = key;
            }
            //  Console.WriteLine(wiki.numberOfTeams);

            foreach (string key in temp["P1923"])
            {
                foreach (string subKey in temp[key])
                {
                    // teamName
                    string teamName = RealIdNamePairs[key];
                    // ranking
                    //string ranking = subKey;
                    //ranking.Remove(0, 1);
                    //int rank = int.Parse(ranking);
                    // Console.WriteLine(rank);
                    Team team = new Team();
                    team.team_id    = key;
                    team.teamName   = teamName;
                    team.founded    = TeamAndFounded[key];
                    team.venue_name = TeamAndVenue[key];
                    wiki.Teams.Add(team);
                }
            }

            foreach (var team in wiki.Teams)
            {
                //Console.WriteLine(team.teamName + " " + team.founded + " " + team.venue_name);
            }
            foreach (var team in wiki.Teams)
            {
                //     Console.WriteLine(team);
            }

            foreach (string key in temp["P1346"])
            {
                wiki.Winner = RealIdNamePairs[key];
            }
            //Console.WriteLine(wiki.Winner);

            foreach (string key in temp["P2882"])
            {
                string teamName = RealIdNamePairs[key];
                Team   team     = new Team();
                team.team_id    = key;
                team.teamName   = teamName;
                team.founded    = TeamAndFounded[key];
                team.venue_name = TeamAndVenue[key];
                wiki.Relegated.Add(team);
            }
            foreach (var team in wiki.Relegated)
            {
                // Console.WriteLine(team.teamName + " " + team.founded + " " + team.venue_name);
            }

            foreach (string key in temp["P1350"])
            {
                wiki.numberOfMatches = key;
            }
            // Console.WriteLine(wiki.numberOfMatches);

            foreach (string key in temp["P1351"])
            {
                wiki.numberOfGoals = key;
            }
            // Console.WriteLine(wiki.numberOfGoals);
        }