public static StimulusDigest ToStimulusDigest( ItemMetadata itemMetadata, ItemContents itemContents) { if (itemMetadata == null) { throw new ArgumentNullException(nameof(itemMetadata)); } if (itemMetadata.Metadata == null) { throw new ArgumentNullException(nameof(itemMetadata.Metadata)); } if (itemContents == null) { throw new ArgumentNullException(nameof(itemContents)); } if (itemContents.Passage == null) { throw new ArgumentNullException(nameof(itemContents.Passage)); } StimulusDigest digest = new StimulusDigest() { ItemKey = itemContents.Passage.ItemKey, BankKey = itemContents.Passage.ItemBank, Contents = itemContents.Passage.Contents, }; return(digest); }
/// <summary> /// Digests a collection of ItemMetadata objects and a collection of ItemContents objects into a collection of ItemDigest objects. /// Matches the ItemMetadata and ItemContents objects based on their ItemKey fields. /// </summary> public static IReadOnlyCollection <ItemDigest> ToItemDigests( IReadOnlyCollection <ItemMetadata> itemMetadata, IReadOnlyCollection <ItemContents> itemContents, AppSettings settings) { BlockingCollection <ItemDigest> digests = new BlockingCollection <ItemDigest>(); Parallel.ForEach(itemMetadata, metadata => { if (metadata.Metadata?.InteractionType == "Stimulus") { return; } var matchingItems = itemContents.Where(c => c.Item?.ItemKey == metadata.Metadata?.ItemKey); var itemsCount = matchingItems.Count(); var stimContents = itemContents.FirstOrDefault(c => metadata.Metadata?.AssociatedStimulus == c.Passage?.ItemKey); var stimMeta = itemMetadata.FirstOrDefault(c => metadata.Metadata?.AssociatedStimulus == c.Metadata?.ItemKey); StimulusDigest stimDigest = null; if (stimContents != null && stimMeta != null) { stimDigest = ToStimulusDigest(stimMeta, stimContents); } if (itemsCount == 1) { ItemDigest itemDigest = ToItemDigest(metadata, matchingItems.First(), settings, stimDigest); digests.Add(itemDigest); } else if (itemsCount > 1) { throw new SampleItemsContextException("Multiple ItemContents with ItemKey: " + metadata.Metadata.ItemKey + " found."); } }); return(digests); }
/// <summary> /// Translates metadata, itemcontents and lookups to item digest /// </summary> public static ItemDigest ToItemDigest( ItemMetadata itemMetadata, ItemContents itemContents, AppSettings settings, StimulusDigest stimulusDigest = null) { if (itemMetadata == null) { throw new ArgumentNullException(nameof(itemMetadata)); } if (itemMetadata.Metadata == null) { throw new ArgumentNullException(nameof(itemMetadata.Metadata)); } if (itemContents == null) { throw new ArgumentNullException(nameof(itemContents)); } if (itemContents.Item == null) { throw new ArgumentNullException(nameof(itemContents.Item)); } if (itemContents.Item.ItemKey != itemMetadata.Metadata.ItemKey) { throw new SampleItemsContextException("Cannot digest items with different ItemKey values.\n" + $"Content Item Key: {itemContents.Item.ItemKey} Metadata Item Key:{itemMetadata.Metadata.ItemKey}"); } string itemType = itemContents.Item.ItemType ?? string.Empty; string interactionCode = itemMetadata.Metadata.InteractionType ?? string.Empty; var oldToNewInteraction = settings?.SettingsConfig?.OldToNewInteractionType; if (oldToNewInteraction != null && oldToNewInteraction.ContainsKey(itemType)) { settings.SettingsConfig.OldToNewInteractionType.TryGetValue(itemType, out itemType); } if (oldToNewInteraction != null && oldToNewInteraction.ContainsKey(interactionCode)) { settings.SettingsConfig.OldToNewInteractionType.TryGetValue(interactionCode, out interactionCode); } ItemDigest digest = new ItemDigest() { ItemType = itemType, ItemKey = itemContents.Item.ItemKey, BankKey = itemContents.Item.ItemBank, TargetAssessmentType = itemMetadata.Metadata.TargetAssessmentType, SufficentEvidenceOfClaim = itemMetadata.Metadata.SufficientEvidenceOfClaim, AssociatedStimulus = itemMetadata.Metadata.AssociatedStimulus, AslSupported = itemMetadata.Metadata.AccessibilityTagsASLLanguage.AslSupportedStringToBool(), AllowCalculator = itemMetadata.Metadata.AllowCalculator == "Y", DepthOfKnowledge = itemMetadata.Metadata.DepthOfKnowledge, Contents = itemContents.Item.Contents, InteractionTypeCode = interactionCode, AssociatedPassage = itemContents.Item.AssociatedPassage, GradeCode = itemMetadata.Metadata.GradeCode, MaximumNumberOfPoints = itemMetadata.Metadata.MaximumNumberOfPoints, StandardPublications = itemMetadata.Metadata.StandardPublications, SubjectCode = itemMetadata.Metadata.SubjectCode, ItemMetadataAttributes = itemContents.Item.ItemMetadataAttributes, StimulusDigest = stimulusDigest, SmarterAppItemDescriptor = itemMetadata.Metadata.SmarterAppItemDescriptor }; return(digest); }