예제 #1
0
class CourseTableQuery(object):
    '''
    classdocs
    '''

    #===========================================================================
    # __init__
    #===========================================================================
    def __init__(self, query={}, table_size=25):
        '''
        Constructor
        '''
        self.course_query = CourseQuery()
        self.cursor = None
        self.query = None
        self.set_query(query)
        self.set_table_size(table_size)
        
        
    def __del__(self):
        pass
        
        
    #===========================================================================
    # connect
    #===========================================================================
    def connect(self):
        self.course_query.connect()
        
        
    #===========================================================================
    # disconnect
    #===========================================================================
    def disconnect(self):
        self.course_query.disconnect()
        
        
    #===========================================================================
    # set_cursor
    #    Not advised, but can be used in place of set_query
    #===========================================================================
    def set_cursor(self, cursor):
        self.cursor = cursor
        self.query = None
        
        
    #===========================================================================
    # set_query
    #===========================================================================
    def set_query(self, query):
        self.query = query
        
        
    #===========================================================================
    # set_table_size
    #===========================================================================
    def set_table_size(self, table_size):
        self.table_size = table_size
        
        
    #===========================================================================
    # get_table_page_cursor
    #===========================================================================
    def get_table_page_cursor(self, page_num):
        temp_cursor = None
        if self.query:
            temp_cursor = self.course_query.get_cursor(query)
        elif self.cursor:
            temp_cursor = self.cursor.clone()
        else:
            temp_cursor = self.course_query.get_cursor({})
        start = self.table_size * (page_num - 1)
        end = self.table_size * page_num
        return temp_cursor[start:end]
    
    
    #===========================================================================
    # get_table_page_JSON_list
    #===========================================================================
    def get_table_page_JSON_list(self, page_num):
        cursor = self.get_table_page_cursor(page_num)
        JSON_list = []
        for json in cursor:
            JSON_list.append(json)
        return JSON_list
예제 #2
0
class Test(unittest.TestCase):

    def testProf(self):
        self.pq = ProfQuery()
        self.pq.connect()
        self.assertEqual(self.pq.get_prof_cursor_first_initial('L', 'Angrave').count(), 1)
        self.assertEqual(self.pq.get_prof_cursor('Lawrence', 'Angrave')[0], self.pq.get_prof_cursor_first_initial('L', 'Angrave')[0])
        self.assertEqual(self.pq.get_prof_cursor('Lawrence', 'Angrave').count(), self.pq.get_prof_cursor_first_initial('L', 'Angrave').count())
        self.pq.disconnect()
        
    def testCourse(self):
        self.cq = CourseQuery()
        self.cq.connect()
        subject_code = "CS"
        id_num = "125"
        cursor1 = self.cq.get_cursor({'code':subject_code, 'course_id':id_num})
        cursor2 = self.cq.get_course_cursor(subject_code, id_num)
        self.assertEqual(cursor1.count(), 1)
        self.assertEqual(cursor1.count(), cursor2.count())
        self.assertEqual(cursor1[0], cursor2[0])
        cursor1 = self.cq.get_cursor({'code':subject_code})
        cursor2 = self.cq.get_courses_cursor_subject(subject_code)
        self.assertEqual(cursor1.count(), cursor2.count())
        self.assertEqual(cursor1[0], cursor2[0])
        self.assertEqual(cursor1[cursor1.count()-1], cursor2[cursor2.count()-1])
        self.cq.disconnect()
        
    def testSection(self):
        self.sq = SectionQuery()
        self.sq.connect()
        crn = '31359'
        cursor1 = self.sq.get_section_cursor_crn(crn)
        cursor2 = self.sq.get_cursor({'crn': crn})
        self.assertEqual(cursor1.count(), 1)
        self.assertEqual(cursor1.count(), cursor2.count())
        self.assertEqual(cursor1[0], cursor2[0])
        self.sq.disconnect()
        
    def testSearchGPA(self):
        self.cq = CourseQuery()
        self.cq.connect()
        min_gpa = 3
        cursor = self.cq.search_for_course_cursor(min_gpa = min_gpa)
        for json in cursor:
            self.assertGreaterEqual(json['gpa'], min_gpa)
        self.cq.disconnect()
            
    def testSearchProfRating(self):
        self.cq = CourseQuery()
        self.cq.connect()
        prof_rating = 4.5
        cursor = self.cq.search_for_course_cursor(min_prof_rating = prof_rating)
        for json in cursor:
            self.assertGreaterEqual(json['prof_rating'], min_prof_rating)
        self.cq.disconnect()
            
    def testSearchCreditHour(self):
        self.cq = CourseQuery()
        self.cq.connect()
        credit_hour = 4
        cursor = self.cq.search_for_course_cursor(credit_hours = credit_hour)
        for json in cursor:
            self.assertIsNotNone(set([credit_hour, str(credit_hour)]).intersection(set(json['credit_hours'])))
        self.cq.disconnect()
            
    def testSearchCreditHours(self):
        self.cq = CourseQuery()
        self.cq.connect()
        credit_hours = [4, 6, '4', '6']
        credit_hours_set = set(credit_hours)
        cursor = self.cq.search_for_course_cursor(credit_hours = credit_hours)
        for json in cursor:
            self.assertIsNotNone(credit_hours_set.intersection(set(json['credit_hours'])))
        self.cq.disconnect()
        
    def testSearchTime(self):
        self.cq = CourseQuery()
        self.sq = SectionQuery()
        self.cq.connect()
        self.sq.connect()
        start_num = 1000
        end_num = 1400
        list = self.cq.search_for_course_with_time_cursor(subject_code = 'CS', start_time = start_num, end_time = end_num)
        for json in list:
            boolean = False
            start_end_list
            for crn in json['crns']:
                section_cursor = self.sq.get_section_cursor_crn(crn)
                if section_cursor.count() > 0:
                    section_json = section_cursor[0]
                    if 'start_num' in section_json and 'end_num' in section_json:
                        start_end_list.append((section_json['start_num'], section_json['end_num']))
            for pair in start_end_list:
                if start_num < pair[0] and pair[1] < end_num:
                    boolean = True
                    break
            self.assertTrue(boolean)
        self.cq.disconnect()
        self.sq.disconnect()
예제 #3
0
 print(course_query.get_course_JSON('CS', '125'))
 print(course_query.get_subject_codes())
 print(course_query.get_course_ids_for_subject('CS'))
 #print(course_query.get_course_ids_all_subjects())
 course_query.disconnect()
 
 course_query.connect()
 print(course_query.search_for_course_cursor(min_gpa = 3)[0])
 print(course_query.get_credit_hour_list())
     
 course_query.disconnect()
 
 query = CourseTableQuery()
 query.connect()
 retVal = query.get_table_page_JSON_list(1)
 retVal = query.get_table_page_JSON_list(1000)
 query.disconnect()
 print(retVal)
 
 cq = CourseQuery()
 cq.connect()
 
 print(cq.get_cursor({'credit_hours':{'$in': [3]}}).count())
 print(cq.get_cursor({'credit_hours':{'$in': ['3']}}).count())
 print(cq.get_cursor({'credit_hours':{'$in': [3, '3']}}).count())
 print(cq.get_cursor({'credit_hours':{'$in': ['3']}}).count()+cq.get_cursor({'credit_hours':{'$in': [3]}}).count())
 
 print(cq.get_course_cursor('CS', '125')[0])
 print(cq.get_course_cursor('CS', '125')[1])
 print(cq.get_course_cursor('CS', '125')[2])
 cq.disconnect()