public GameSave(string name, Calendar calendar, CompetitorsRuntime competitorsRuntime)
        {
            this.name        = name;
            resultsContainer = new ResultsDatabase();
            this.calendar    = calendar;

            resultsContainer.eventResults          = new EventResults[calendar.events.Count];
            resultsContainer.classificationResults =
                new ClassificationResults[calendar.classifications.Count];

            for (var i = 0; i < resultsContainer.classificationResults.Length; i++)
            {
                resultsContainer.classificationResults[i] = new ClassificationResults();
            }

            classificationsData = calendar.classifications.Select((it, ind) =>
                                                                  new ClassificationData {
                useBib = false, calendarId = ind, priority = ind, classification = it
            })
                                  .ToList();

            var teamsDict = calendar.teams.Select((it, ind) => (it.countryCode, ind))
                            .ToDictionary(it => it.countryCode, it => it.ind);

            competitors = calendar.competitorsIds.Select((item, index) =>
                                                         new CompetitorData
            {
                calendarId = index, registered = true, competitor = competitorsRuntime.GetJumperById(item),
                teamId     = teamsDict[competitorsRuntime.GetJumperById(item).countryCode]
            })
                          .ToList();

            var competitorsByCountry = competitors.ToLookup(it => it.competitor.countryCode, it => it);

            teams = calendar.teams.Select((item, index) => new TeamData
            {
                calendarId  = index, registered = true, team = item,
                competitors = competitorsByCountry[item.countryCode].Select((it, ind) => new CompetitorData
                {
                    calendarId = it.calendarId, teamId = ind, competitor = it.competitor, registered = it.registered
                })
                              .ToList()
            }).ToList();

            for (int i = 0; i < calendar.classifications.Count; i++)
            {
                resultsContainer.classificationResults[i] = new ClassificationResults();
                var cnt = calendar.classifications[i].eventType == EventType.Individual
                    ? calendar.competitorsIds.Count
                    : calendar.teams.Count;
                resultsContainer.classificationResults[i].rank               = Enumerable.Repeat(1, cnt).ToList();
                resultsContainer.classificationResults[i].totalResults       = Enumerable.Repeat(0m, cnt).ToList();
                resultsContainer.classificationResults[i].totalSortedResults = Enumerable.Range(0, cnt).ToList();
            }
        }
        public static IEnumerable <int> GetCompetitors(Calendar calendar, ResultsDatabase resultsDatabase)
        {
            var eventId      = resultsDatabase.eventIndex;
            var eventInfo    = calendar.events[eventId];
            var eventResults = resultsDatabase.eventResults[eventId];
            IEnumerable <int> preQualifiedCompetitors;
            IEnumerable <int> competitorsList;
            ResultsProcessor  ordRankProcessor;

            if (eventInfo.preQualRankType == RankType.None)
            {
                //Add all registered participants
                preQualifiedCompetitors = Enumerable.Empty <int>();
            }
            else
            {
                ResultsProcessor preQualRankProcessor;
                EventType        preQualEventType;
                if (eventInfo.preQualRankType == RankType.Event)
                {
                    preQualRankProcessor =
                        new EventResultsProcessor(resultsDatabase.eventResults[eventInfo.preQualRankId]);
                    preQualEventType = calendar.events[eventInfo.preQualRankId].eventType;
                }
                else
                {
                    preQualRankProcessor =
                        new ClassificationResultsProcessor(
                            resultsDatabase.classificationResults[eventInfo.preQualRankId]);
                    preQualEventType = calendar.classifications[eventInfo.preQualRankId].eventType;
                }

                if (preQualEventType != eventInfo.eventType)
                {
                    preQualifiedCompetitors = Enumerable.Empty <int>();
                }
                else
                {
                    preQualifiedCompetitors = preQualRankProcessor.GetTrimmedFinalResults(eventResults.participants,
                                                                                          eventInfo.preQualLimitType, eventInfo.preQualLimit);
                }
            }

            if (eventInfo.qualRankType == RankType.None)
            {
                //Add all registered participants
                competitorsList = eventResults.participants.Select(x => x.id);
            }
            else
            {
                EventType qualEventType;

                ResultsProcessor qualRankProcessor;
                if (eventInfo.qualRankType == RankType.Event)
                {
                    qualRankProcessor = new EventResultsProcessor(resultsDatabase.eventResults[eventInfo.qualRankId]);
                    qualEventType     = calendar.events[eventInfo.qualRankId].eventType;
                }
                else
                {
                    qualRankProcessor =
                        new ClassificationResultsProcessor(resultsDatabase.classificationResults[eventInfo.qualRankId]);
                    qualEventType = calendar.classifications[eventInfo.qualRankId].eventType;
                }

                if (qualEventType != eventInfo.eventType)
                {
                    competitorsList = eventResults.participants.Select(x => x.id);
                }
                else
                {
                    competitorsList = qualRankProcessor.GetTrimmedFinalResultsPreQual(eventResults.participants,
                                                                                      eventInfo.inLimitType, eventInfo.inLimit, preQualifiedCompetitors);
                }
            }

            EventType ordEventType;

            if (eventInfo.ordRankType == RankType.None)
            {
                return(competitorsList);
            }
            if (eventInfo.ordRankType == RankType.Event)
            {
                ordRankProcessor = new EventResultsProcessor(resultsDatabase.eventResults[eventInfo.ordRankId]);
                ordEventType     = calendar.events[eventInfo.ordRankId].eventType;
            }
            else
            {
                ordRankProcessor =
                    new ClassificationResultsProcessor(resultsDatabase.classificationResults[eventInfo.ordRankId]);
                ordEventType = calendar.classifications[eventInfo.ordRankId].eventType;
            }

            return(eventInfo.eventType == ordEventType
                ? ordRankProcessor.GetFinalResultsWithCompetitorsList(competitorsList)
                : competitorsList);
        }