Example #1
0
 public static ChallengeTimelineModel ToModel(this ChallengeTimeline timeline)
 {
     return(new ChallengeTimelineModel
     {
         CreatedAt = timeline.CreatedAt,
         Duration = timeline.Duration.Ticks,
         StartedAt = timeline.StartedAt,
         ClosedAt = timeline.ClosedAt
     });
 }
        protected override async Task SeedProductionAsync()
        {
            var scoring = new Scoring(
                new Dictionary <string, float>
            {
                ["Kills"]   = 4.5F,
                ["Deaths"]  = -4F,
                ["Assists"] = 3.5F,
                ["TotalDamageDealtToChampions"] = 0.0009F,
                ["TotalDamageTaken"]            = 0.00125F,
                ["TotalMinionsKilled"]          = 0.04F,
                ["VisionScore"] = 0.38F,
                ["Winner"]      = 20F
            });

            var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !;

            var file = File.OpenRead(Path.Combine(assemblyPath, "Setup/Challenges.Production.csv"));

            using var csvReader = file.OpenCsvReader();

            var challenges = csvReader.GetRecords(
                new
            {
                Id       = default(Guid),
                Name     = default(string),
                Game     = default(int),
                Entries  = default(int),
                BestOf   = default(int),
                Duration = default(long),
                State    = default(int)
            })
                             .Select(
                record =>
            {
                var timeline = new ChallengeTimeline(
                    new UtcNowDateTimeProvider(),
                    new ChallengeDuration(TimeSpan.FromSeconds(record.Duration)));

                return(new Challenge(
                           ChallengeId.FromGuid(record.Id),
                           new ChallengeName(record.Name !),
                           Game.FromValue(record.Game),
                           new BestOf(record.BestOf),
                           new Entries(record.Entries),
                           timeline,
                           scoring));
            });

            Challenges.AddRange(
                challenges.Where(challenge => Challenges.All(x => x.Id != challenge.Id))
                .Select(challenge => challenge.ToModel()));

            await this.CommitAsync();
        }
        private async Task SeedChallengesAsync()
        {
            var scoring = new Scoring(
                new Dictionary <string, float>
            {
                ["Kills"]   = 4.5F,
                ["Deaths"]  = -4F,
                ["Assists"] = 3.5F,
                ["TotalDamageDealtToChampions"] = 0.0009F,
                ["TotalDamageTaken"]            = 0.00125F,
                ["TotalMinionsKilled"]          = 0.04F,
                ["VisionScore"] = 0.38F,
                ["Winner"]      = 20F
            });

            var timeline = new ChallengeTimeline(new UtcNowDateTimeProvider(), new ChallengeDuration(TimeSpan.FromDays(1)));

            var challenges = new List <IChallenge>
            {
                new Challenge(
                    ChallengeId.Parse("d53b366f-e717-43d4-ac12-6e13d37f5cef"),
                    new ChallengeName("2$ CHALLENGE BEST OF 1 (2)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Two,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("369ae69d-b10d-4d72-84ba-698691646ba6"),
                    new ChallengeName("3$ CHALLENGE BEST OF 1 (2)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Two,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("eb76fa60-700f-4dce-b312-d69897563437"),
                    new ChallengeName("2$ CHALLENGE BEST OF 1 (4)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Four,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("82592581-e6ac-41e0-9c61-773d924f233d"),
                    new ChallengeName("3$ CHALLENGE BEST OF 1 (4)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Four,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("9457ae9a-4e5c-436f-b10f-33134af68439"),
                    new ChallengeName("2$ CHALLENGE BEST OF 1 (6)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Six,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("91f6d007-b458-4f1c-9814-755b32059e00"),
                    new ChallengeName("3$ CHALLENGE BEST OF 1 (6)"),
                    Game.LeagueOfLegends,
                    BestOf.One,
                    Entries.Six,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("4ecb13a4-0742-4140-93b0-27ee582e5cab"),
                    new ChallengeName("2$ CHALLENGE BEST OF 3 (2)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Two,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("fa38f697-2ef3-40e9-a165-d62c3cc750a8"),
                    new ChallengeName("3$ CHALLENGE BEST OF 3 (2)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Two,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("ac6851b4-2cb7-42ab-bf44-fb197d21221b"),
                    new ChallengeName("2$ CHALLENGE BEST OF 3 (4)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Four,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("bb5f6e0c-ada7-47b4-9d24-a3c9ec7df034"),
                    new ChallengeName("3$ CHALLENGE BEST OF 3 (4)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Four,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("6ec217f7-3d6a-41c2-b2eb-4cc8799d2af5"),
                    new ChallengeName("2$ CHALLENGE BEST OF 3 (6)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Six,
                    timeline,
                    scoring),
                new Challenge(
                    ChallengeId.Parse("7d96b314-8d5b-4393-9257-9c0e2cf7c0f1"),
                    new ChallengeName("3$ CHALLENGE BEST OF 3 (6)"),
                    Game.LeagueOfLegends,
                    BestOf.Three,
                    Entries.Six,
                    timeline,
                    scoring)
            };

            Challenges.AddRange(challenges.Where(challenge => Challenges.All(x => x.Id != challenge.Id)).Select(challenge => challenge.ToModel()));

            await this.CommitAsync();
        }
Example #4
0
        public IChallenge FakeChallenge(ChallengeModel model)
        {
            var challengeFaker = new ChallengeFaker();

            challengeFaker.CustomInstantiator(
                faker =>
            {
                faker.User().Reset();

                var name = new ChallengeName(model.Name);

                var game = Game.FromValue(model.Game);

                var entries = new Entries(model.Entries);

                var bestOf = new BestOf(model.BestOf);

                var duration = new ChallengeDuration(TimeSpan.FromTicks(model.Timeline.Duration));

                var state = ChallengeState.FromValue(model.State);

                var utcNowDate = DateTime.UtcNow.Date;

                var createdAt = faker.Date.Recent(1, utcNowDate);

                var startedAt = faker.Date.Between(createdAt, utcNowDate);

                var endedAt = startedAt + duration;

                var synchronizationBuffer = endedAt + TimeSpan.FromHours(2);

                var closedAt = faker.Date.Soon(1, synchronizationBuffer);

                var synchronizedAt = faker.Date.Between(synchronizationBuffer, closedAt);

                var timeline = new ChallengeTimeline(new DateTimeProvider(startedAt), duration);

                var scoring = new Scoring
                {
                    [new StatName("StatName1")] = new StatWeighting(0.00015F),
                    [new StatName("StatName2")] = new StatWeighting(1),
                    [new StatName("StatName3")] = new StatWeighting(0.77F),
                    [new StatName("StatName4")] = new StatWeighting(100),
                    [new StatName("StatName5")] = new StatWeighting(-3)
                };

                var challenge = new Challenge(
                    model.Id.ConvertTo <ChallengeId>(),
                    name,
                    game,
                    bestOf,
                    entries,
                    timeline,
                    scoring);

                var participantFaker = new ParticipantFaker(game, createdAt, startedAt);

                participantFaker.UseSeed(faker.Random.Int());

                var participants = participantFaker.Generate(this.ParticipantCount(state, challenge.Entries));

                participants.ForEach(participant => challenge.Register(participant));

                if (state != ChallengeState.Inscription)
                {
                    challenge.Start(new DateTimeProvider(startedAt));

                    participants.ForEach(
                        participant =>
                    {
                        var matchFaker = new MatchFaker(challenge.Scoring, synchronizedAt);

                        matchFaker.UseSeed(faker.Random.Int());

                        var matches = matchFaker.Generate(this.MatchCount(state, challenge.BestOf));

                        participant.Snapshot(matches, new DateTimeProvider(synchronizedAt));
                    });

                    challenge.Synchronize(new DateTimeProvider(synchronizedAt));

                    if (state == ChallengeState.Ended || state == ChallengeState.Closed)
                    {
                        challenge.Start(new DateTimeProvider(startedAt - duration));
                    }

                    if (state == ChallengeState.Closed)
                    {
                        challenge.Close(new DateTimeProvider(closedAt));
                    }
                }

                return(challenge);
            });

            return(challengeFaker.Generate());
        }