Ejemplo n.º 1
0
        static string GetRandomClassification()
        {
            BNolan.RandomSelection.Selector <string> classificationSelector = new BNolan.RandomSelection.Selector <string>();

            // Weights come from how many items fit the search criteria. This can be found by hitting:
            // https://api.harvardartmuseums.org/object?apikey=API_KEY&hasimage=1&classification=Furniture
            // and replacing Furniture with the name of the material.
            // For scale, there are around 200,000 total objects.
            classificationSelector.TryAddItem("Armor", "Armor", 50);                                    // 37
            classificationSelector.TryAddItem("Recreational+Artifacts", "Recreational+Artifacts", 50);  // 72
            classificationSelector.TryAddItem("Amulets", "Amulets", 100);                               // 138
            classificationSelector.TryAddItem("Timepieces", "Timepieces", 150);                         // 139
            classificationSelector.TryAddItem("Furniture", "Furniture", 150);                           // 141
            classificationSelector.TryAddItem("Mirrors", "Mirrors", 100);                               // 142
            classificationSelector.TryAddItem("Weapons+and+Ammunition", "Weapons+and+Ammunition", 200); // 184
            classificationSelector.TryAddItem("Boxes", "Boxes", 150);                                   // 223
            classificationSelector.TryAddItem("Lighting+Devices", "Lighting+Devices", 300);             // 457
            classificationSelector.TryAddItem("Jewelry", "Jewelry", 200);                               // 680
            classificationSelector.TryAddItem("Tools+and+Equipment", "Tools+and+Equipment", 300);       // 637
            classificationSelector.TryAddItem("Ritual+Implements", "Ritual+Implements", 200);           // 902
            classificationSelector.TryAddItem("Textile+Arts", "Textile+Arts", 200);                     // 1833
            classificationSelector.TryAddItem("Sculpture", "Sculpture", 200);                           // 4549
            classificationSelector.TryAddItem("Vessels", "Vessels", 100);                               // 5021

            return(classificationSelector.RandomSelect(1).First().Value);
        }
Ejemplo n.º 2
0
        static int GetRandomObjectID(System.Random random)
        {
            BNolan.RandomSelection.Selector <string> materialSelector = new BNolan.RandomSelection.Selector <string>();

            // Weights come from how many items fit the search criteria. This can be found by hitting:
            // https://collectionapi.metmuseum.org/public/collection/v1/search?medium=Furniture&q=Furniture&hasImages=true
            // and replacing Furniture with the name of the material.
            // For scale, there are around 470,000 total objects.
            materialSelector.TryAddItem("Bags", "Bags", 3);
            materialSelector.TryAddItem("Jewelry", "Jewelry", 17);
            materialSelector.TryAddItem("Sculpture", "Sculpture", 232);
            materialSelector.TryAddItem("Bowls", "Bowls", 19);
            materialSelector.TryAddItem("Furniture", "Furniture", 66);
            materialSelector.TryAddItem("Musical%20instruments", "Musical%20instruments", 6);
            materialSelector.TryAddItem("Vessels", "Vessels", 41);
            materialSelector.TryAddItem("Ceramics", "Ceramics", 66);
            materialSelector.TryAddItem("Wood", "Wood", 110);
            materialSelector.TryAddItem("Paintings", "Paintings", 491);
            materialSelector.TryAddItem("Timepieces", "Timepieces", 2);
            materialSelector.TryAddItem("Arms", "Arms", 7);
            materialSelector.TryAddItem("Costume", "Costume", 42);
            materialSelector.TryAddItem("Cases", "Cases", 10);
            materialSelector.TryAddItem("Metal", "Metal", 384);
            materialSelector.TryAddItem("Lithographs", "Lithographs", 55);
            materialSelector.TryAddItem("Prints", "Prints", 352);
            materialSelector.TryAddItem("Silk", "Silk", 91);

            string material = materialSelector.RandomSelect(1).First().Value;

            string searchURL = GetMetSearchAPIUrl(material);

            MetSearchResponse response = Web.GetWebResponse <MetSearchResponse>(searchURL);

            System.Console.WriteLine();

            System.Console.WriteLine("Material: " + material + " Total items in category: " + response.total);

            if (response.total == 0)
            {
                throw new System.Exception("Not enough items meet search criteria.");
            }

            return(response.objectIDs.RandomElement(random));
        }