Exemplo n.º 1
0
        public void Generate(GenerateConfig generateConfig)
        {
            int totalItems;
            var query = this.context.Teams.AsQueryable();

            if (generateConfig.League != null)
            {
                query      = query.Where(t => t.Leagues.Any(l => l.LeagueName == generateConfig.League));
                totalItems = query.Count();
            }
            else
            {
                totalItems = query.Count();
            }

            var time = new TimeSpan(generateConfig.StartDate.Ticks);


            for (int i = 0; i < generateConfig.GenerateCount; i++)
            {
                int randomFitstTeam = this.random.Next(0, totalItems - 1);
                var firstTeam       = query.OrderBy(t => t.Id).Skip(randomFitstTeam).Take(1).First();

                int randomSecond = this.random.Next(0, totalItems - 1);
                var secondTeam   = query.OrderBy(t => t.Id).Skip(randomSecond).Take(1).First();

                var randomDate = this.RandomDate(generateConfig.StartDate, generateConfig.EndDate);

                int randomFirstScore  = this.random.Next(0, generateConfig.MaxGoals);
                int randomSecondScore = this.random.Next(0, generateConfig.MaxGoals - randomFirstScore);


                var match = new TeamMatch();
                match.HomeTeam  = firstTeam;
                match.AwayTeam  = secondTeam;
                match.HomeGoals = randomFirstScore;
                match.AwayGoals = randomSecondScore;
                match.MatchDate = randomDate;
                this.context.TeamMatches.Add(match);
                this.context.SaveChanges();

                Console.WriteLine("{0}: {1} - {2}: {3} - {4} ({5})", randomDate.ToString("dd-MMM-yyy", CultureInfo.InvariantCulture), firstTeam.TeamName, secondTeam.TeamName, randomFirstScore, randomSecondScore, generateConfig.League != null ? generateConfig.League : "no league");
            }
        }
Exemplo n.º 2
0
        public void Generate(GenerateConfig generateConfig)
        {
            int totalItems;
            var query = this.context.Teams.AsQueryable();
            if (generateConfig.League != null)
            {
                query = query.Where(t => t.Leagues.Any(l => l.LeagueName == generateConfig.League));
                totalItems = query.Count();
            }
            else
            {
                totalItems = query.Count();
            }

            var time = new TimeSpan(generateConfig.StartDate.Ticks);


            for (int i = 0; i < generateConfig.GenerateCount; i++)
            {
                int randomFitstTeam = this.random.Next(0, totalItems - 1);
                var firstTeam = query.OrderBy(t => t.Id).Skip(randomFitstTeam).Take(1).First();

                int randomSecond = this.random.Next(0, totalItems - 1);
                var secondTeam = query.OrderBy(t => t.Id).Skip(randomSecond).Take(1).First();

                var randomDate = this.RandomDate(generateConfig.StartDate, generateConfig.EndDate);

                int randomFirstScore = this.random.Next(0, generateConfig.MaxGoals);
                int randomSecondScore = this.random.Next(0, generateConfig.MaxGoals - randomFirstScore);


                var match = new TeamMatch();
                match.HomeTeam = firstTeam;
                match.AwayTeam = secondTeam;
                match.HomeGoals = randomFirstScore;
                match.AwayGoals = randomSecondScore;
                match.MatchDate = randomDate;
                this.context.TeamMatches.Add(match);
                this.context.SaveChanges();

                Console.WriteLine("{0}: {1} - {2}: {3} - {4} ({5})", randomDate.ToString("dd-MMM-yyy", CultureInfo.InvariantCulture), firstTeam.TeamName, secondTeam.TeamName, randomFirstScore, randomSecondScore, generateConfig.League != null ? generateConfig.League : "no league");
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var xmlParrent = new Stack <string>();

            using (XmlReader reader = new XmlTextReader("../../generate-matches.xml"))
            {
                var            context        = new FootballEntities();
                var            generator      = new Generator(context);
                GenerateConfig generateConfig = null;
                int            count          = 0;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "generate")
                        {
                            generateConfig = new GenerateConfig();
                            var generateCount = reader.GetAttribute("generate-count");
                            if (generateCount != null)
                            {
                                generateConfig.GenerateCount = int.Parse(generateCount);
                            }

                            var maxGoals = reader.GetAttribute("max-goals");
                            if (maxGoals != null)
                            {
                                generateConfig.MaxGoals = int.Parse(maxGoals);
                            }
                        }

                        xmlParrent.Push(reader.Name);
                    }

                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        switch (xmlParrent.Peek())
                        {
                        case "league":
                            generateConfig.League = reader.Value;
                            break;

                        case "start-date":
                            generateConfig.StartDate = DateTime.Parse(reader.Value);
                            break;

                        case "end-date":
                            generateConfig.EndDate = DateTime.Parse(reader.Value);
                            break;
                        }
                    }

                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.Name == "generate")
                        {
                            count++;
                            Console.WriteLine("Processiong request #" + count);
                            generator.Generate(generateConfig);
                            Console.WriteLine();
                        }

                        xmlParrent.Pop();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var xmlParrent = new Stack<string>();
            using (XmlReader reader = new XmlTextReader("../../generate-matches.xml"))
            {
                var context = new FootballEntities();
                var generator = new Generator(context);
                GenerateConfig generateConfig = null;
                int count = 0;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "generate")
                        {
                            generateConfig = new GenerateConfig();
                            var generateCount = reader.GetAttribute("generate-count");
                            if (generateCount != null)
                            {
                                generateConfig.GenerateCount = int.Parse(generateCount);
                            }

                            var maxGoals = reader.GetAttribute("max-goals");
                            if (maxGoals != null)
                            {
                                generateConfig.MaxGoals = int.Parse(maxGoals);
                            }
                        }

                        xmlParrent.Push(reader.Name);
                    }

                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        switch (xmlParrent.Peek())
                        {
                            case "league":
                                generateConfig.League = reader.Value;
                                break;
                            case "start-date":
                                generateConfig.StartDate = DateTime.Parse(reader.Value);
                                break;
                            case "end-date":
                                generateConfig.EndDate = DateTime.Parse(reader.Value);
                                break;
                        }
                    }

                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (reader.Name == "generate")
                        {
                            count++;
                            Console.WriteLine("Processiong request #" + count);
                            generator.Generate(generateConfig);
                            Console.WriteLine();
                        }

                        xmlParrent.Pop();
                    }
                }
            }
        }