示例#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();
        }
示例#2
0
        /*
         * Parses the file
         */
        public void Execute()
        {
            // List that contains question groups (SK1A/SK1B = SK1X and so on...)
            topRowGrouped = new List<string>();

            // Dictionary to keep track of class sizes (For percentage calculation).
            classSizes = new Dictionary<string, int>();

            /*
             *  Read lines from file into List splitinlines.
             * Also create array topRow which contains the first row of the file, split into strings.
             */
            ReadFromFile(inputFile);

            // "Calculate" number of rows (and columns)
            int numRows = splitinlines.Count;

            /*
             *  Create top row with question groups
             *
             * (topRow[i].Length - 1) + "X" is used so that all questions belonging
             * to the same group gets lumped together. That is, SK10A and SK10B
             * becomes SK10X.
             */
            topRowGrouped.Add(topRow[idCol]);
            topRowGrouped.Add(topRow[classCol]);
            for(int i = qColBegin; i < numCols; ++i)
            {
                if(!topRowGrouped.Contains(topRow[i].Substring(0, (topRow[i].Length - 1)) + "X"))
                {
                    topRowGrouped.Add(topRow[i].Substring(0, (topRow[i].Length - 1)) + "X");
                    topRowGrouped.Add("%");

                    // 100315 - For class nomination average
                    topRowGrouped.Add("Class Average");
                    // 100315 - For class spread (Standard deviation?)
                    topRowGrouped.Add("Spread");
                    // 100315 - For student difference
                    topRowGrouped.Add("Difference");
                }
            }

            /*
             * Create students
             */
            cm = new ClassMember[numRows];
            for(int i = 0; i < numRows; ++i)
                cm[i] = new ClassMember();

            /*
             * Fill student posts with id and class number.
             * Fill class size dictionary with info.
             */
            FillStudentPosts(ref splitinlines);

            /*
             * Go through each line with questions
             */
            GoThroughQuestions();

            /*
             * Finally summarize the number of times a student has been
             * mentioned in each question group.
             */
            foreach(ClassMember c in cm)
            {
                c.SumInstances();
            }
        }
示例#3
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();
        }