Ejemplo n.º 1
0
        /*
         * Creates the correct string for the supplied question group qGroup.
         *  - sr - A dictionary containing the number of times the supplied student c
         * 			has been mentioned in each question group.
         *  - cs - A dictionary containing the sizes of each class.
         */
        private string CalculateQuestionGroup(string qGroup, ClassMember c)
        {
            Dictionary<string, int> sr = c.GetSumInstances();
            Dictionary<string, int> cs = GetClassSizes();
            StringBuilder sb = new StringBuilder();

            /*
             * If the summarized instances dictionary contains the supplied question group (qGroup),
             * then calculate the percentage of people in the students class that mentioned him/her.
             * The resulting string will contain the number of times the student was mentioned
             *  and the percentage separated by tabs.
             *
             *  - sr[qGroup] - Number of times student was mentioned in this question group
             *  - cs[c.GetClassId()] - The number of people in student c's class.
             *  - percentage - The result of (sr[qGroup] / (cs[c.classId] - 1)) * 100
             *  (cs[c.classId] -1 because a student cannot pick him/herself)
             */

            /*
             * If student has not been nominated in question group, manually add question group
             * and set its value to zero.
             */
            if(!sr.ContainsKey(qGroup))
                c.ZeroInstance(qGroup);
            float percentage = ((float)sr[qGroup] / ((float)cs[c.ClassId] -1)) * 100;
                sb.Append(sr[qGroup] + delimString +
                          string.Format("{0:0.00}", percentage) + delimString);
            return sb.ToString();
        }
Ejemplo n.º 2
0
        /*
         * Creates the correct string for the supplied question group qGroup.
         *  - sr - A dictionary containing the number of times the supplied student c
         * 			has been mentioned in each question group.
         *  - cs - A dictionary containing the sizes of each class.
         */
        private string CalculateQuestionGroup(string qGroup, ClassMember c)
        {
            Dictionary<string, int> sr = c.GetSumInstances();
            Dictionary<string, int> cs = GetClassSizes();
            StringBuilder sb = new StringBuilder();

            /*
             * If the summarized instances dictionary contains the supplied question group (qGroup),
             * then calculate the percentage of people in the students class that mentioned him/her.
             * The resulting string will contain the number of times the student was mentioned
             *  and the percentage separated by tabs.
             *
             *  - sr[qGroup] - Number of times student was mentioned in this question group
             *  - cs[c.GetClassId()] - The number of people in student c's class.
             *  - percentage - The result of (sr[qGroup] / (cs[c.classId] - 1)) * 100
             *  (cs[c.classId] -1 because a student cannot pick him/herself)
             */
            if(sr.ContainsKey(qGroup))
            {
                float percentage = ((float)sr[qGroup] / ((float)cs[c.ClassId] -1)) * 100;
                //sb.Append(sr[qGroup] + delimString + "\"" + string.Format("{0:0.00}", percentage) + "\"" + delimString);
                sb.Append(sr[qGroup] + delimString +
                          string.Format("{0:0.00}", percentage) + delimString);
            }
            /*
             * Student was never mentioned in the supplied question group. add 0 in both instances and percentage
             * to the result string.
             */
            else
            {
                //sb.Append("\"0\"" + delimString + "\"0\"" + delimString);
                sb.Append("0" + delimString + "0" + delimString);
            }

            return sb.ToString();
        }