|
11 | 11 | from django.conf import settings
|
12 | 12 | from django.contrib import auth
|
13 | 13 | from django.core.exceptions import ObjectDoesNotExist
|
14 |
| -from django.db import connection as conn |
15 | 14 | from django.forms.models import model_to_dict
|
16 | 15 | from django.http import HttpResponse, HttpResponseForbidden, JsonResponse
|
17 | 16 | from django.shortcuts import redirect, render
|
|
20 | 19 | from rules.contrib.views import permission_required, objectgetter
|
21 | 20 |
|
22 | 21 | from dashboard.common import utils
|
23 |
| -from dashboard.common.db_util import canvas_id_to_incremented_id |
| 22 | +from dashboard.common.db_util import canvas_id_to_incremented_id, create_sqlalchemy_engine |
24 | 23 | from dashboard.event_logs_types.event_logs_types import EventLogTypes
|
25 | 24 | from dashboard.models import Course, CourseViewOption, Resource, UserDefaultSelection, User
|
26 | 25 | from dashboard.settings import COURSES_ENABLED, RESOURCE_VALUES, RESOURCE_VALUES_MAP, \
|
|
44 | 43 |
|
45 | 44 | BinningGrade = namedtuple('BinningGrade', ['value', 'index', 'binning_all'])
|
46 | 45 |
|
| 46 | +app_engine = create_sqlalchemy_engine(settings.DATABASES['default']) |
| 47 | + |
47 | 48 |
|
48 | 49 | def gpa_map(grade):
|
49 | 50 | if grade is None:
|
@@ -285,7 +286,7 @@ def resource_access_within_week(request, course_id=0):
|
285 | 286 | elif (grade == GRADE_C):
|
286 | 287 | total_number_student_sql += " and current_grade >= 70 and current_grade < 80"
|
287 | 288 |
|
288 |
| - total_number_student_df = pd.read_sql(total_number_student_sql, conn, params={ |
| 289 | + total_number_student_df = pd.read_sql(total_number_student_sql, app_engine, params={ |
289 | 290 | "course_id": course_id,
|
290 | 291 | "enrollment_type": "StudentEnrollment"
|
291 | 292 | })
|
@@ -323,7 +324,7 @@ def resource_access_within_week(request, course_id=0):
|
323 | 324 | endTimeString = end.strftime('%Y%m%d') + "000000"
|
324 | 325 | logger.debug(sqlString)
|
325 | 326 | logger.debug("start time=" + startTimeString + " end_time=" + endTimeString)
|
326 |
| - df = pd.read_sql(sqlString, conn, params={ |
| 327 | + df = pd.read_sql(sqlString, app_engine, params={ |
327 | 328 | "start_time": startTimeString,
|
328 | 329 | "end_time": endTimeString,
|
329 | 330 | "course_id": course_id,
|
@@ -387,7 +388,7 @@ def resource_access_within_week(request, course_id=0):
|
387 | 388 | logger.debug(selfSqlString)
|
388 | 389 | logger.debug("current_user=" + current_user)
|
389 | 390 |
|
390 |
| - selfDf= pd.read_sql(selfSqlString, conn, params={"current_user":current_user, "course_id": course_id}) |
| 391 | + selfDf= pd.read_sql(selfSqlString, app_engine, params={"current_user":current_user, "course_id": course_id}) |
391 | 392 | output_df = output_df.join(selfDf.set_index('resource_id_type'), on=['resource_id_type'], how='left')
|
392 | 393 | output_df["total_percent"] = output_df.apply(lambda row: row[GRADE_A] + row[GRADE_B] + row[GRADE_C] + row[GRADE_LOW] + row.NO_GRADE, axis=1)
|
393 | 394 |
|
@@ -448,7 +449,7 @@ def grade_distribution(request, course_id=0):
|
448 | 449 | (select current_grade from user where sis_name=%(current_user)s and course_id=%(course_id)s) as current_user_grade
|
449 | 450 | from user where course_id=%(course_id)s and enrollment_type=%(enrollment_type)s
|
450 | 451 | """
|
451 |
| - df = pd.read_sql(grade_score_sql, conn, params={ |
| 452 | + df = pd.read_sql(grade_score_sql, app_engine, params={ |
452 | 453 | 'current_user': current_user,
|
453 | 454 | 'course_id': course_id,
|
454 | 455 | 'enrollment_type': 'StudentEnrollment'
|
@@ -663,7 +664,7 @@ def get_course_assignments(course_id):
|
663 | 664 | (select distinct assignment_id,avg_score from submission where course_id=%(course_id)s) as sub on sub.assignment_id = assign.assignment_id
|
664 | 665 | """
|
665 | 666 |
|
666 |
| - assignments_in_course = pd.read_sql(sql,conn,params={'course_id': course_id}, parse_dates={'due_date': '%Y-%m-%d'}) |
| 667 | + assignments_in_course = pd.read_sql(sql, app_engine, params={'course_id': course_id}, parse_dates={'due_date': '%Y-%m-%d'}) |
667 | 668 | # No assignments found in the course
|
668 | 669 | if assignments_in_course.empty or (assignments_in_course['assignment_id'] == 0).all():
|
669 | 670 | logger.info('The course %s don\'t seems to have assignment data' % course_id)
|
@@ -697,7 +698,7 @@ def get_course_assignments(course_id):
|
697 | 698 | def get_user_assignment_submission(current_user,assignments_in_course_df, course_id):
|
698 | 699 | sql = "select assignment_id, submitted_at, score, graded_date from submission where " \
|
699 | 700 | "user_id=(select user_id from user where sis_name = %(current_user)s and course_id = %(course_id)s ) and course_id = %(course_id)s"
|
700 |
| - assignment_submissions = pd.read_sql(sql, conn, params={'course_id': course_id, "current_user": current_user}) |
| 701 | + assignment_submissions = pd.read_sql(sql, app_engine, params={'course_id': course_id, "current_user": current_user}) |
701 | 702 | if assignment_submissions.empty:
|
702 | 703 | logger.info('The user %s seems to be a not student in the course.' % current_user)
|
703 | 704 | # manually adding the columns for display in UI
|
@@ -772,7 +773,7 @@ def find_current_week(row):
|
772 | 773 |
|
773 | 774 | def is_weight_considered(course_id):
|
774 | 775 | url = "select consider_weight from assignment_weight_consideration where course_id=%(course_id)s"
|
775 |
| - df = pd.read_sql(url, conn, params={"course_id": course_id}) |
| 776 | + df = pd.read_sql(url, app_engine, params={"course_id": course_id}) |
776 | 777 | value = df['consider_weight'].iloc[0]
|
777 | 778 | return value
|
778 | 779 |
|
|
0 commit comments