示例#1
0
        m_names = load_major_names()
        total_students, total_horts, total_outside = 0, 0, 0

        for student in index.student_index.itervalues():
            total_students += 1
            major_id = student.major_id
            t_students[major_id] = t_students.get(major_id, 0) + 1
            for hort_id in student.horts.iterkeys():
                total_horts += 1
                t_majors[major_id] = t_majors.get(major_id, 0) + 1
                if index.student_index[hort_id].major_id != major_id:
                    total_outside += 1
                    majors[major_id] = majors.get(major_id, 0) + 1
        #the list comprehension will only take majors with more than 5 students
        m_list = [(m_id, m_val, float(m_val) / t_majors[m_id]) for m_id, m_val in majors.iteritems() if t_students[m_id] > 5]
        m_list.sort(key=operator.itemgetter(2), reverse=True)
        logging.info("Total students: %i", total_students)
        logging.info("Total horts: %i", total_horts)
        logging.info("Avg horts outside major: %i (%2.2f)", total_outside, float(total_outside) / total_horts)
        logging.info("Highest values with majors with more than 5 students...")
        for m_id, m_val, m_pc in m_list:
            #logging.info("%s: %2.2f (%2.2f): %s(%i)", m_id, m_val, m_pc, m_names[m_id], t_students[m_id])
            logging.info("%s&%2.2f&%2.2f&%s&%i\\\\\hline", m_id, m_val, m_pc, m_names[m_id], t_students[m_id])

    def tearDown(self):
        pass

if __name__ == "__main__":
    setup_logging("test_majors.txt")
    unittest.main()
示例#2
0
#!/usr/bin/env python
"""Performance profiling."""

import cProfile
import logging
import os
import pickle
import time

import Storage

from Constants import DEBUG_REBUILD, STORAGE_CACHE
from Common import setup_logging

#setup logging to file and console
setup_logging(log_file="profiler_log.txt", console_output=True)

# setup storage, use pickling for caching
try:
    if DEBUG_REBUILD:
        try:
            os.remove(STORAGE_CACHE)
        except OSError:
            logging.info("No cache to delete")
    cache_in = open(STORAGE_CACHE, "rb")
    storage = pickle.load(cache_in)
except:
    storage = Storage.Storage()
    storage.update_from_excel("tablea.xls")
    storage.update_from_excel("tableb.xls")
    storage.student_index.update_horting()
示例#3
0
        self.storage = Storage.Storage()
        self.storage.update_from_excel("tablea.xls")
        self.storage.update_from_excel("tableb.xls")

    def testGetHorts(self):
        """
        Test getting horts down to default depths using Dijkstra and recursive method.

        It is important to run test on same data multiple times, because the
        recursive method tends to cache the data.
        """
        self.storage.student_index.update_horting()
        for i in range(10):
            student_id = random.choice(
                self.storage.student_index.student_index.keys())
            horts_recursive_set = self.storage.student_index.get_horts(
                student_id)
            horts_dijkstra = self.storage.student_index.test_build_all_paths_dijkstra(
                student_id)
            horts_dijkstra_set = set(horts_dijkstra)
            self.assertEqual(len(horts_dijkstra), len(horts_dijkstra_set))
            self.assertEqual(horts_recursive_set, horts_dijkstra_set)

    def tearDown(self):
        pass


if __name__ == "__main__":
    setup_logging()
    unittest.main()
示例#4
0
#!/usr/bin/env python
"""Performance profiling."""

import cProfile
import logging
import os
import pickle
import time

import Storage

from Constants import DEBUG_REBUILD, STORAGE_CACHE
from Common import setup_logging

#setup logging to file and console
setup_logging(log_file="profiler_log.txt", console_output=True)

# setup storage, use pickling for caching
try:
    if DEBUG_REBUILD:
        try:
            os.remove(STORAGE_CACHE)
        except OSError:
            logging.info("No cache to delete")
    cache_in = open(STORAGE_CACHE, "rb")
    storage = pickle.load(cache_in)
except:
    storage = Storage.Storage()
    storage.update_from_excel("tablea.xls")
    storage.update_from_excel("tableb.xls")
    storage.student_index.update_horting()
示例#5
0
            major_id = student.major_id
            t_students[major_id] = t_students.get(major_id, 0) + 1
            for hort_id in student.horts.iterkeys():
                total_horts += 1
                t_majors[major_id] = t_majors.get(major_id, 0) + 1
                if index.student_index[hort_id].major_id != major_id:
                    total_outside += 1
                    majors[major_id] = majors.get(major_id, 0) + 1
        #the list comprehension will only take majors with more than 5 students
        m_list = [(m_id, m_val, float(m_val) / t_majors[m_id])
                  for m_id, m_val in majors.iteritems()
                  if t_students[m_id] > 5]
        m_list.sort(key=operator.itemgetter(2), reverse=True)
        logging.info("Total students: %i", total_students)
        logging.info("Total horts: %i", total_horts)
        logging.info("Avg horts outside major: %i (%2.2f)", total_outside,
                     float(total_outside) / total_horts)
        logging.info("Highest values with majors with more than 5 students...")
        for m_id, m_val, m_pc in m_list:
            #logging.info("%s: %2.2f (%2.2f): %s(%i)", m_id, m_val, m_pc, m_names[m_id], t_students[m_id])
            logging.info("%s&%2.2f&%2.2f&%s&%i\\\\\hline", m_id, m_val, m_pc,
                         m_names[m_id], t_students[m_id])

    def tearDown(self):
        pass


if __name__ == "__main__":
    setup_logging("test_majors.txt")
    unittest.main()
示例#6
0
class TestStudentIndex(unittest.TestCase):
    def setUp(self):
        """Setup the storage, that has student index and course index."""
        self.storage = Storage.Storage()
        self.storage.update_from_excel("tablea.xls")
        self.storage.update_from_excel("tableb.xls")

    def testGetHorts(self):
        """
        Test getting horts down to default depths using Dijkstra and recursive method.

        It is important to run test on same data multiple times, because the
        recursive method tends to cache the data.
        """
        self.storage.student_index.update_horting()
        for i in range(10):
            student_id = random.choice(self.storage.student_index.student_index.keys())
            horts_recursive_set = self.storage.student_index.get_horts(student_id)
            horts_dijkstra = self.storage.student_index.test_build_all_paths_dijkstra(student_id)
            horts_dijkstra_set = set(horts_dijkstra)
            self.assertEqual(len(horts_dijkstra), len(horts_dijkstra_set))
            self.assertEqual(horts_recursive_set, horts_dijkstra_set)

    def tearDown(self):
        pass

if __name__ == "__main__":
    setup_logging()
    unittest.main()