Пример #1
0
        public static DM.Contest ToDbModel(this XmlModels.Contest xcontest, string problemIdPrefix)
        {
            var contest = new  DM.Contest();

            contest.LastUpdate = DateTime.Now;
            contest.Name       = xcontest.Name;
            var problems = xcontest.Challenge.Problems
                           .Select(p => new DM.Problem().SetName(p.Name).SetAlias(p.Alias));

            var studentDict = new Dictionary <string, DM.Student>();
            Func <string, DM.Student> getStudent = (string name) =>
            {
                if (!studentDict.ContainsKey(name))
                {
                    studentDict[name] = new DM.Student().SetName(name);
                }
                return(studentDict[name]);
            };

            var problms = xcontest.Sessions
                          .SelectMany(s =>
                                      s.Problems.Select(p =>
                                                        new DM.Problem()
                                                        .SetAlias(p.Alias)
                                                        .SetId(problemIdPrefix + p.Id)
                                                        .SetSubmitters(new [] { getStudent(s.Party) })
                                                        .SetSubmissions(p.Runs
                                                                        .TakeWhile(run => run.Accepted == "no")
                                                                        .Concat(p.Runs.Where(run => run.Accepted == "yes").Take(1))
                                                                        .Select(r => new DM.Submission()
                                                                                .SetFromRun(r)
                                                                                .SetContest(contest)
                                                                                .SetSubmitter(getStudent(s.Party))))))
                          .GroupBy(p => p.Alias)
                          .Select(g => new DM.Problem()
                                  .SetContest(contest)
                                  .SetAlias(g.First().Alias)
                                  .SetId(g.First().Id)
                                  .SetSubmissions(g.SelectMany(p => p.Submissions))
                                  .SetSubmitters(g.SelectMany(p => p.Submitters.Select(sp => sp.Student))))
                          .Select(p => p.SetName(problems.First(pr => pr.Alias == p.Alias).Name));

            contest.Problems    = problms.Select(pr => pr.SetSubmissions(pr.Submissions.Select(s => s.SetProblem(pr)))).ToList();
            contest.Submissions = contest.Problems.SelectMany(p => p.Submissions).ToList();
            return(contest);
        }
Пример #2
0
 public static DM.Contest SetNameAndGeneration(this DM.Contest contest, string name, string generation)
 {
     contest.PcmsId     = name;
     contest.Generation = generation;
     return(contest);
 }
Пример #3
0
 public static DM.Problem SetContest(this DM.Problem problem, DM.Contest contest)
 {
     problem.Contest = contest;
     return(problem);
 }
Пример #4
0
 public static DM.Submission SetContest(this DM.Submission submission, DM.Contest contest)
 {
     submission.Contest = contest;
     return(submission);
 }