Ejemplo n.º 1
0
        /// <summary>
        /// Reads the braille file manifest
        /// </summary>
        /// <param name="brailleManifest">Path to the braille manifest</param>
        /// <returns></returns>
        public static async Task <ImmutableArray <BrailleFileInfo> > GetBrailleFileInfo(AppSettings settings)
        {
            string brailleManifest = settings.SettingsConfig.BrailleFileManifest;

            using (var ftpClient = new FtpClient(new FtpClientConfiguration
            {
                Host = settings.SettingsConfig.SmarterBalancedFtpHost,
                Username = settings.SettingsConfig.SmarterBalancedFtpUsername,
                Password = settings.SettingsConfig.SmarterBalancedFtpPassword
            }))
            {
                await ftpClient.LoginAsync();

                List <BrailleFileInfo> fileInfo = new List <BrailleFileInfo>();
                using (var inputStream = await ftpClient.OpenFileReadStreamAsync(brailleManifest))
                    using (var reader = new StreamReader(inputStream))
                        using (var csv = new CsvReader(reader))
                        {
                            csv.ReadHeader();
                            while (csv.Read())
                            {
                                var subject     = csv.GetField <string>("Subject");
                                var grade       = csv.GetField <int>("Grade");
                                var itemId      = csv.GetField <int>("ItemOrStimId");
                                var brailleType = csv.GetField <string>("UebCode");
                                fileInfo.Add(
                                    new BrailleFileInfo(
                                        itemKey: itemId,
                                        subject: subject,
                                        grade: GradeLevelsUtils.FromString(grade.ToString()),
                                        brailleType: $"TDS_BT_{brailleType}"
                                        )
                                    );
                            }
                        }
                return(fileInfo.ToImmutableArray());
            }
        }
        public void TestItemToItemDigest()
        {
            int    testItemKey  = 1;
            int    testItemBank = 2;
            string testGrade    = "5";

            ItemMetadata metadata = new ItemMetadata();
            ItemContents contents = new ItemContents();

            metadata.Metadata                           = new SmarterAppMetadataXmlRepresentation();
            contents.Item                               = new ItemXmlFieldRepresentation();
            metadata.Metadata.ItemKey                   = testItemKey;
            metadata.Metadata.GradeCode                 = testGrade;
            metadata.Metadata.TargetAssessmentType      = "Test target string";
            metadata.Metadata.SufficientEvidenceOfClaim = "Test claim string";
            metadata.Metadata.InteractionType           = "EQ";
            metadata.Metadata.SubjectCode               = "MATH";
            metadata.Metadata.StandardPublications      = new List <StandardPublication>();
            metadata.Metadata.StandardPublications.Add(
                new StandardPublication
            {
                PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2"
            });

            contents.Item.ItemKey  = testItemKey;
            contents.Item.ItemBank = testItemBank;
            contents.Item.Contents = new List <Content>();

            var interactionTypes = new List <InteractionType>
            {
                new InteractionType(code: "EQ", label: "", description: "", order: 0)
            };

            var subjects = new List <Subject>
            {
                new Subject(
                    code: "MATH",
                    label: string.Empty,
                    shortLabel: string.Empty,
                    claims: ImmutableArray.Create <Claim>(),
                    interactionTypeCodes: ImmutableArray.Create <string>())
            };

            var placeholderText = new RubricPlaceHolderText
            {
                RubricPlaceHolderContains = new string[0],
                RubricPlaceHolderEquals   = new string[0]
            };

            var settings = new SettingsConfig
            {
                SupportedPublications = new string[] { "" }
            };

            AppSettings appSettings = new AppSettings
            {
                SettingsConfig        = settings,
                RubricPlaceHolderText = placeholderText
            };


            ItemDigest digest = ItemDigestTranslation.ToItemDigest(metadata, contents, appSettings);

            Assert.Equal(testItemKey, digest.ItemKey);
            Assert.Equal(testItemBank, digest.BankKey);
            Assert.Equal(GradeLevels.Grade5, GradeLevelsUtils.FromString(digest.GradeCode));
            Assert.Equal("Test target string", digest.TargetAssessmentType);
            Assert.Equal("Test claim string", digest.SufficentEvidenceOfClaim);
            Assert.Equal("MATH", digest.SubjectCode);
            Assert.Equal("EQ", digest.InteractionTypeCode);
        }
        public void TestItemstoItemDigests()
        {
            int testItemCount = 3;
            List <ItemContents>      contentsList = new List <ItemContents>();
            List <ItemMetadata>      metadataList = new List <ItemMetadata>();
            IEnumerable <ItemDigest> digests;

            // Get a range of numbers from 50 to the number of items being tested.
            // Use the same numer for an item's key and bank to make it easy to validate that
            // ItemMetadata and ItemContents objects are being paired correctly.
            int[]  itemKeys            = Enumerable.Range(50, testItemCount).ToArray();
            int[]  banksKeys           = itemKeys;
            string testTarget          = "Test target string";
            string testClaimEvidence   = "Test claim string";
            string testInteractionType = "EQ";
            string testSubject         = "MATH";

            int i;

            for (i = 0; i < testItemCount; i++)
            {
                ItemMetadata metadata = new ItemMetadata();
                ItemContents contents = new ItemContents();

                metadata.Metadata = new SmarterAppMetadataXmlRepresentation();
                contents.Item     = new ItemXmlFieldRepresentation();

                //Test metadata attributes
                metadata.Metadata.ItemKey                   = itemKeys[i];
                metadata.Metadata.GradeCode                 = (itemKeys[i] % 9 + 3).ToString();
                metadata.Metadata.TargetAssessmentType      = testTarget + itemKeys[i];
                metadata.Metadata.SufficientEvidenceOfClaim = testClaimEvidence + itemKeys[i];
                metadata.Metadata.InteractionType           = testInteractionType;
                metadata.Metadata.SubjectCode               = testSubject;
                metadata.Metadata.StandardPublications      = new List <StandardPublication>();
                metadata.Metadata.StandardPublications.Add(
                    new StandardPublication
                {
                    PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2"
                });

                //Test contents attributes
                contents.Item.ItemKey  = itemKeys[i];
                contents.Item.ItemBank = banksKeys[i];
                contents.Item.Contents = new List <Content>();

                metadataList.Add(metadata);
                contentsList.Add(contents);
            }

            var interactionTypes = new List <InteractionType>
            {
                new InteractionType(code: testInteractionType, label: "", description: "", order: 0)
            };

            var subjects = new List <Subject>
            {
                new Subject(
                    code: testSubject,
                    label: string.Empty,
                    shortLabel: string.Empty,
                    claims: ImmutableArray.Create <Claim>(),
                    interactionTypeCodes: ImmutableArray.Create <string>())
            };

            var settings = new AppSettings
            {
                SettingsConfig = new SettingsConfig
                {
                    AccessibilityTypes    = new List <AccessibilityType>(),
                    SupportedPublications = new string[] { "" }
                }
            };

            digests = ItemDigestTranslation.ToItemDigests(metadataList, contentsList, settings);

            Assert.Equal(itemKeys.Length, digests.Count());

            foreach (var digest in digests)
            {
                int id = digest.ItemKey;
                Assert.Equal(digest.ItemKey, digest.BankKey);
                Assert.Equal(GradeLevelsUtils.FromString((digest.ItemKey % 9 + 3).ToString()), GradeLevelsUtils.FromString(digest.GradeCode));
                Assert.Equal(testTarget + id, digest.TargetAssessmentType);
                Assert.Equal(testClaimEvidence + id, digest.SufficentEvidenceOfClaim);
                Assert.Equal(testInteractionType, digest.InteractionTypeCode);
                Assert.Equal(testSubject, digest.SubjectCode);
            }
        }
        /// <summary>
        /// Translates metadata, itemcontents and lookups to item digest
        /// </summary>
        public static SampleItem ToSampleItem(
            ItemDigest itemDigest,
            CoreStandardsXml standardsXml,
            IList <Subject> subjects,
            IList <InteractionType> interactionTypes,
            IList <MergedAccessibilityFamily> resourceFamilies,
            IList <ItemPatch> patches,
            IList <BrailleFileInfo> brailleFileInfo,
            AppSettings settings)
        {
            var supportedPubs       = settings.SettingsConfig.SupportedPublications;
            var rubrics             = GetRubrics(itemDigest, settings);
            var brailleItemCodes    = GetBrailleItemCodes(itemDigest.ItemKey, brailleFileInfo);
            var braillePassageCodes = GetBraillePassageCodes(itemDigest, brailleFileInfo);
            var interactionType     = interactionTypes.FirstOrDefault(t => t.Code == itemDigest.InteractionTypeCode);
            var grade            = GradeLevelsUtils.FromString(itemDigest.GradeCode);
            var patch            = patches.FirstOrDefault(p => p.ItemId == itemDigest.ItemKey);
            var copiedItemPatch  = patches.FirstOrDefault(p => p.BrailleCopiedId == itemDigest.ItemKey.ToString());
            var subject          = subjects.FirstOrDefault(s => s.Code == itemDigest.SubjectCode);
            var depthOfKnowledge = itemDigest.DepthOfKnowledge;
            var itemType         = itemDigest.ItemType;

            var fieldTestUseAttribute = itemDigest.ItemMetadataAttributes?.FirstOrDefault(a => a.Code == "itm_FTUse");
            var fieldTestUse          = FieldTestUse.Create(fieldTestUseAttribute, itemDigest.SubjectCode);

            StandardIdentifier identifier    = StandardIdentifierTranslation.ToStandardIdentifier(itemDigest, supportedPubs);
            CoreStandards      coreStandards = StandardIdentifierTranslation.CoreStandardFromIdentifier(standardsXml, identifier);
            int?copiedFromItem = null;

            if (patch != null)
            {
                int tmp;
                copiedFromItem   = int.TryParse(patch.BrailleCopiedId, out tmp) ? (int?)tmp : null;
                depthOfKnowledge = !string.IsNullOrEmpty(patch.DepthOfKnowledge) ? patch.DepthOfKnowledge : depthOfKnowledge;
                itemType         = !string.IsNullOrEmpty(patch.ItemType) ? patch.ItemType : itemType;
                coreStandards    = ApplyPatchToCoreStandards(identifier, coreStandards, standardsXml, patch);
            }

            if (copiedItemPatch != null)
            {
                var copyBrailleItemCodes = GetBrailleItemCodes(copiedItemPatch.ItemId, brailleFileInfo);
                brailleItemCodes = brailleItemCodes.Concat(copyBrailleItemCodes).Distinct().ToImmutableArray();
            }

            if (patch != null && !string.IsNullOrEmpty(patch.QuestionNumber))
            {
                fieldTestUse = ApplyPatchFieldTestUse(fieldTestUse, patch);
            }

            var  claim         = subject?.Claims.FirstOrDefault(t => t.ClaimNumber == coreStandards.ClaimId);
            bool brailleOnly   = copiedFromItem.HasValue;
            bool isPerformance = fieldTestUse != null && itemDigest.AssociatedPassage.HasValue;

            if (itemDigest.AssociatedPassage.HasValue)
            {
                braillePassageCodes = brailleFileInfo
                                      .Where(f => f.ItemKey == itemDigest.AssociatedPassage.Value)
                                      .Select(b => b.BrailleType).ToImmutableArray();
            }
            else
            {
                braillePassageCodes = ImmutableArray.Create <string>();
            }

            bool aslSupported = AslSupported(itemDigest);

            var groups = GetAccessibilityResourceGroups(itemDigest, resourceFamilies, grade,
                                                        isPerformance, aslSupported, claim, interactionType, brailleItemCodes, settings);

            string interactionTypeSubCat = "";

            settings.SettingsConfig.InteractionTypesToItem.TryGetValue(itemDigest.ToString(), out interactionTypeSubCat);

            SampleItem sampleItem = new SampleItem(
                itemType: itemType,
                itemKey: itemDigest.ItemKey,
                bankKey: itemDigest.BankKey,
                targetAssessmentType: itemDigest.TargetAssessmentType,
                depthOfKnowledge: depthOfKnowledge,
                sufficentEvidenceOfClaim: itemDigest.SufficentEvidenceOfClaim,
                associatedStimulus: itemDigest.AssociatedStimulus,
                aslSupported: aslSupported,
                allowCalculator: itemDigest.AllowCalculator,
                isPerformanceItem: isPerformance,
                accessibilityResourceGroups: groups,
                rubrics: rubrics,
                interactionType: interactionType,
                subject: subject,
                claim: claim,
                grade: grade,
                coreStandards: coreStandards,
                fieldTestUse: fieldTestUse,
                interactionTypeSubCat: interactionTypeSubCat,
                brailleItemCodes: brailleItemCodes,
                braillePassageCodes: braillePassageCodes,
                brailleOnlyItem: brailleOnly,
                copiedFromitem: copiedFromItem);

            return(sampleItem);
        }
        public void TestToSampleItems()
        {
            var digests = ImmutableArray.Create(digest);
            ImmutableArray <AccessibilityFamilyResource> noPartialResources = ImmutableArray.Create <AccessibilityFamilyResource>();
            var subjectMath = ImmutableArray.Create("MATH");
            AccessibilityFamily noPartialResourcesFamily = new AccessibilityFamily(
                subjects: subjectMath,
                grades: GradeLevels.Grade5,
                resources: noPartialResources);

            MergedAccessibilityFamily resourceFamily = AccessibilityResourceTranslation.MergeGlobalResources(noPartialResourcesFamily, Resources);
            var resourceFamilies = ImmutableArray.Create(resourceFamily);

            Claim1 = new Claim("claim1", "1", "ELA Claim 1");
            Claim2 = new Claim("claim2", "2", "3");
            ItMath = new InteractionType("2", "EQ", "", 2);
            ItEla  = new InteractionType("1", "WER", "", 1);
            Math   = Subject.Create("MATH", "Mathematics", "Math", ImmutableArray.Create(Claim2), ImmutableArray.Create(ItMath.Code));
            Ela    = Subject.Create("ELA", "English", "ELA", ImmutableArray.Create(Claim1), ImmutableArray.Create(ItEla.Code));
            var interactionTypes = ImmutableArray.Create(ItEla, ItMath);
            var subjects         = ImmutableArray.Create(Ela, Math);

            StandardIdentifier identifier = StandardIdentifierTranslation.StandardStringToStandardIdentifier("SBAC-ELA-v1:3-L|4-6|6.SL.2");
            var coreStandardsRowCcss      = ImmutableArray.Create(
                CoreStandardsRow.Create(
                    subjectCode: "ELA",
                    key: "3-l|4-6|6.SL.2",
                    name: "",
                    description: "CCSS Desc",
                    levelType: "CCSS",
                    identifier: identifier));

            var coreStandardsRowTarget = ImmutableArray.Create(
                CoreStandardsRow.Create(
                    subjectCode: "ELA",
                    key: "4-6|3-6",
                    name: "",
                    description: "Target Desc",
                    levelType: "Target",
                    identifier: identifier));

            CoreStandardsXml coreStandardsXml = new CoreStandardsXml(coreStandardsRowTarget, coreStandardsRowCcss);
            var itemPatch       = ImmutableArray.Create(new ItemPatch());
            var brailleFileInfo = new List <BrailleFileInfo>();
            var items           = SampleItemTranslation.ToSampleItems(digests, resourceFamilies, interactionTypes, subjects, coreStandardsXml, itemPatch, brailleFileInfo, appSettings);

            Assert.NotNull(items);
            Assert.Equal(items[0].AccessibilityResourceGroups[0].AccessibilityResources[0].Label, Resources[0].Label);
            Assert.Equal(items[0].AccessibilityResourceGroups[0].AccessibilityResources[0].Order, Resources[0].Order);
            Assert.Equal(items[0].AccessibilityResourceGroups[0].AccessibilityResources[0].ResourceCode, Resources[0].ResourceCode);
            Assert.Equal(items[0].AccessibilityResourceGroups[0].AccessibilityResources[0].ResourceTypeId, Resources[0].ResourceTypeId);
            Assert.Equal(items[0].SufficentEvidenceOfClaim, metadata.Metadata.SufficientEvidenceOfClaim);
            Assert.Equal(items[0].TargetAssessmentType, metadata.Metadata.TargetAssessmentType);
            Assert.Equal(items[0].Grade, GradeLevelsUtils.FromString(digest.GradeCode));
            Assert.Equal(items[0].ItemKey, digest.ItemKey);
            Assert.Equal(items[0].BankKey, digest.BankKey);
            Assert.Equal(items[0].CoreStandards.CommonCoreStandardsDescription, coreStandardsRowCcss[0].Description);
            Assert.Equal(items[0].CoreStandards.TargetDescription, coreStandardsRowTarget[0].Description);
            Assert.Equal(items[0].InteractionType.Code, ItMath.Code);
            Assert.Equal(items[0].InteractionType.Label, ItMath.Label);
            Assert.Equal(items[0].Subject.Code, digest.SubjectCode);
        }