def commit_outliers_to_db(self, outlier_assignments, cursor, conn): for assignment in outlier_assignments: COMMIT_QUERY = f''' INSERT INTO outliers (student_name, student_lms_id, assignment_name, course_lms_id, ci_left, ci_right, assignment_score, due_date) VALUES( ?, ?, ?, ?, ?, ?, ?, ?); ''' params = (self.name, str(self.lms_id), assignment.assignment_name, str(self.course.course_id), self.ci_left, self.ci_right, assignment.score, assignment.due_date.strftime('%Y-%m-%d')) run_query(COMMIT_QUERY, cursor, params) conn.commit()
def show_table(num): result = db.run_query(f''' SELECT * FROM person ''') print(result.shape) return result if num is None else result.head(num)
def show_table(num=None): result = db.run_query(''' SELECT * FROM league ''') print(result.shape) return result if num is None else result.head(num)
import config from collections import defaultdict import datetime from logzero import logger import os if __name__ == '__main__': logger.info('Starting...') # Bootstrap if needed and get the connection and a cursor conn, cursor = bootstrap(config.GenericConfig.DB_ENDPOINT, db) logger.info('Connected to database') # Get all schools SCHOOL_QUERY = 'SELECT DISTINCT id FROM schools;' schools = db.run_query(SCHOOL_QUERY, cursor) logger.info(f'{len(schools)} schools retrieved') for school_id in schools: logger.info(f'Processing school {school_id}') if os.environ.get('TESTING'): logger.info('====== TESTING MODE ========') SCHOOL_API_QUERY = '''SELECT DISTINCT config_test_class_name AS "config_class" FROM schools WHERE id = %s;''' else: SCHOOL_API_QUERY = '''SELECT DISTINCT config_class_name AS "config_class" FROM schools WHERE id = %s;''' params = (school_id['id'], ) school_info = db.run_query(SCHOOL_API_QUERY, cursor, params) if len(school_info) > 1: logger.error( f'Multiple entries found for school with id {school_id["id"]}, using first' ) school_info = school_info[0]
def show_table(num): result = db.run_query(f''' SELECT * FROM team_appearence ''') print(result.shape) return result if num is None else result.head(num)