Exemplo n.º 1
0
        private void AddFinalMatch(
            int tableRowIndex,
            int dataIndex,
            CompareRowResult rowResult,
            MatchQuality matchQuality)
        {
            // Missing TableRows are not added to final
            if (tableRowIndex != _tableRowsCount)
            {
                // A Match calls us to action.
                // We need to remove previous compares.
                // So, that when we finalize... Matches won't get confused with other Match Data
                for (int dataForIndex = 0; dataForIndex < _dataItemsCount; dataForIndex++)
                {
                    _tableRowToDataCompares[tableRowIndex, dataForIndex] = null;
                }

                var tableRowCompareMatchResult = new CompareRowFinalResult();
                tableRowCompareMatchResult.compareRowResult    = rowResult;
                tableRowCompareMatchResult.matchQuality        = matchQuality;
                tableRowCompareMatchResult.index               = dataIndex;
                _tableRowToDataCompareRowFinals[tableRowIndex] = tableRowCompareMatchResult;
            }

            // Missing Datas are not added to final
            if (dataIndex != _dataItemsCount)
            {
                for (int tableRowForIndex = 0; tableRowForIndex < _tableRowsCount; tableRowForIndex++)
                {
                    _tableRowToDataCompares[tableRowForIndex, dataIndex] = null;
                }

                var dataCompareMatchResult = new CompareRowFinalResult();
                dataCompareMatchResult.compareRowResult    = rowResult;
                dataCompareMatchResult.matchQuality        = matchQuality;
                dataCompareMatchResult.index               = tableRowIndex;
                _dataToTableRowCompareRowFinals[dataIndex] = dataCompareMatchResult;
            }
        }
        private void AddCharacterToBestGroup(CharacterDetail characterDetail, TrialGroupConfiguration configuration)
        {
            List <CharacterGroup> groups;

            IEnumerable <CharacterGroup> availableGroups = configuration.Groups.Where(g => !g.Closed &&
                                                                                      !configuration.IsGroupReservedForNarratorOrExtraBiblical(g));

            if (!availableGroups.Any())
            {
                availableGroups = configuration.Groups.Where(g => !g.Closed);
            }

            var groupMatchQualityDictionary = new Dictionary <MatchQuality, List <CharacterGroup> >(configuration.Groups.Count);

            foreach (var characterGroup in availableGroups)
            {
                var voiceActor = characterGroup.VoiceActor;
                var quality    = new MatchQuality(voiceActor.GetGenderMatchQuality(characterDetail), voiceActor.GetAgeMatchQuality(characterDetail));
                if (!groupMatchQualityDictionary.TryGetValue(quality, out groups))
                {
                    groupMatchQualityDictionary[quality] = groups = new List <CharacterGroup>();
                }
                groups.Add(characterGroup);
            }

            var groupToProximityDict = new Dictionary <CharacterGroup, WeightedMinimumProximity>();

            if (groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Perfect, AgeMatchQuality.Perfect), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Perfect, AgeMatchQuality.CloseAdult), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Perfect, AgeMatchQuality.AdultVsChild), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Acceptable, AgeMatchQuality.Perfect), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 1.1);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Acceptable, AgeMatchQuality.CloseAdult), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 1.1);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Acceptable, AgeMatchQuality.AdultVsChild), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 1.1);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Mismatch, AgeMatchQuality.Perfect), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 2.3);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Mismatch, AgeMatchQuality.CloseAdult), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 2.4);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Mismatch, AgeMatchQuality.AdultVsChild), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 2.5);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Perfect, AgeMatchQuality.Mismatch), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 2.7);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Acceptable, AgeMatchQuality.Mismatch), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 2.9);
            }
            if (!groupToProximityDict.Any(i => i.Value.WeightedNumberOfBlocks >= Proximity.kDefaultMinimumProximity || i.Value.NumberOfBlocks >= configuration.MinimumProximity) &&
                groupMatchQualityDictionary.TryGetValue(new MatchQuality(GenderMatchQuality.Mismatch, AgeMatchQuality.Mismatch), out groups))
            {
                CalculateProximityForGroups(characterDetail, groups, groupToProximityDict, 3.2);
            }
            var bestGroupEntry = groupToProximityDict.Aggregate((l, r) => l.Value.WeightedNumberOfBlocks > r.Value.WeightedNumberOfBlocks ? l : r);
            var bestGroup      = bestGroupEntry.Key;

            if (configuration.MinimumProximity > bestGroupEntry.Value.NumberOfBlocks)
            {
                // We're adding the character to the best group we could find, but it is now the *worst* group in the configuration.
                configuration.NoteGroupWithWorstProximity(bestGroupEntry.Key, bestGroupEntry.Value.NumberOfBlocks);
            }
            bestGroup.CharacterIds.Add(characterDetail.CharacterId);
            if (RelatedCharactersData.Singleton.GetCharacterIdsForType(CharacterRelationshipType.SameCharacterWithMultipleAges).Contains(characterDetail.CharacterId))
            {
                foreach (var relatedCharacters in RelatedCharactersData.Singleton.GetCharacterIdToRelatedCharactersDictionary()[characterDetail.CharacterId])
                {
                    bestGroup.CharacterIds.AddRange(relatedCharacters.CharacterIds);
                }
            }
        }
Exemplo n.º 3
0
        private void AddFinalMatch(int tableRowIndex, int dataIndex, CompareRowResult rowResult, MatchQuality matchQuality)
        {
            // Missing TableRows are not added to final
            if (tableRowIndex != _tableRowsCount)
            {
                // A Match calls us to action.
                // We need to remove previous compares.
                // So, that when we finalize... Matches won't get confused with other Match Data
                for (int dataForIndex = 0; dataForIndex < _dataItemsCount; dataForIndex++)
                {
                    tableRowToDataCompares[tableRowIndex, dataForIndex] = null;
                }

                var tableRowCompareMatchResult = new CompareRowFinalResult();
                tableRowCompareMatchResult.compareRowResult = rowResult;
                tableRowCompareMatchResult.matchQuality = matchQuality;
                tableRowCompareMatchResult.index = dataIndex;
                TableRowToDataCompareRowFinals[tableRowIndex] = tableRowCompareMatchResult;
            }

            // Missing Datas are not added to final
            if (dataIndex != _dataItemsCount)
            {
                for (int tableRowForIndex = 0; tableRowForIndex < _tableRowsCount; tableRowForIndex++)
                {
                    tableRowToDataCompares[tableRowForIndex, dataIndex] = null;
                }

                var dataCompareMatchResult = new CompareRowFinalResult();
                dataCompareMatchResult.compareRowResult = rowResult;
                dataCompareMatchResult.matchQuality = matchQuality;
                dataCompareMatchResult.index = tableRowIndex;
                DataToTableRowCompareRowFinals[dataIndex] = dataCompareMatchResult;
            }
        }
Exemplo n.º 4
0
 public MatchQualityAdapter(MatchQuality matchQuality)
 {
     if (matchQuality == null) throw new ArgumentNullException(nameof(matchQuality));
     _matchQuality = matchQuality;
 }