Пример #1
0
        // This constructor takes in a JSON string and checks the object against the schema in Criteria-Weights-Schema
        // If the JSON is valid then all of the data is extracted from the JSON and is used to create the criteria objects
        // To be assessed against the schedules
        public Evaluator(string criteriaJsonString, bool test = false)
        {
            JsonSchema schema;

            if (test)
            {
                schema = JsonSchema.Parse(File.ReadAllText("./../../../ScheduleEvaluator/Criteria-Weights-Schema.json"));
            }
            else
            {
                // So this file can not be tested due to the fact that the test dll gets executed from a different
                // directory
                schema = JsonSchema.Parse(File.ReadAllText("./../../Criteria-Weights-Schema.json"));
            }

            JObject criteriaJObject = JObject.Parse(criteriaJsonString);

            if (!criteriaJObject.IsValid(schema))
            {
                throw new System.ArgumentException("Invalid JSON Schema");
            }

            JToken crits = criteriaJObject["Criteria"];
            // This for loop gets the number of criteria. It is super inefficent and should be replaced
            // with a non iterative approach
            int count = 0;

            foreach (JToken crit in crits)
            {
                count++;
            }

            CritTyp[] criteriaTypes = new CritTyp[count];
            double[]  weights       = new double[count];
            int       i             = 0;

            foreach (JToken crit in crits)
            {
                Debug.WriteLine(crit);
                criteriaTypes[i] = CriteriaFactory.FromString(crit["CriteriaName"].ToString());
                weights[i]       = Convert.ToDouble(crit["Weight"].ToString());
                i++;
            }
            CriteriaFactory fact;

            try
            {
                fact = new CriteriaFactory(criteriaTypes, weights);
            }
            catch (ArgumentException ag)
            {
                Console.WriteLine("Error in creating Criterias: {0}", ag);
                throw;
            }
            criterias = fact.Criterias;
            client    = new HttpClient();
        }
Пример #2
0
        // Constructor for the evaluator. Creates all of the criteria objects and stores in criterias.
        // For now I dont believe that the criterias should be mutable.
        public Evaluator()
        {
            CritTyp[]       criteriaTypes = { CritTyp.CoreCreditsAQuarter, CritTyp.MaxQuarters, CritTyp.TimeOfDay, CritTyp.CoreClassesLastYear, CritTyp.PreRequisiteOrder, CritTyp.MathBreaks, CritTyp.MajorSpecificBreaks, CritTyp.EnglishStart };
            double[]        weights       = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
            CriteriaFactory fact;

            try
            {
                fact = new CriteriaFactory(criteriaTypes, weights);
            }
            catch (ArgumentException ag)
            {
                Console.WriteLine("Error in creating Criterias: {0}", ag);
                throw;
            }
            client    = new HttpClient();
            criterias = fact.Criterias;
        }