Skip to content

Commit

Permalink
Limit resources access view to show only events for enrolled students…
Browse files Browse the repository at this point in the history
… in the course #764 (#1460)

Co-authored-by: Sam Sciolla <35741256+ssciolla@users.noreply.github.com>
  • Loading branch information
zqian and ssciolla committed Nov 29, 2022
1 parent ee3f8ce commit b439275
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions dashboard/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sqlalchemy.engine import ResultProxy

from dashboard.common import db_util, utils
from dashboard.models import Course, Resource, AcademicTerms, ResourceAccess
from dashboard.models import Course, Resource, AcademicTerms, User


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -343,7 +343,7 @@ def update_resource_access(self):
resource_access_df = resource_access_df \
.drop(columns=['user_id_str', 'user_login_name']) \
.dropna()

resource_access_df['user_id'] = pd.to_numeric(resource_access_df['user_id'])
logger.debug(f'resource_access_df:\n'
f'{resource_access_df}\n'
f'{resource_access_df.dtypes}')
Expand Down Expand Up @@ -389,7 +389,17 @@ def update_resource_access(self):
logger.debug(f'resource_access_df:\n'
f'{resource_access_df}\n'
f'{resource_access_df.dtypes}')

# only keep access events generated by students
student_enrollment_type = User.EnrollmentType.STUDENT
student_enrollment_df = pd.read_sql(
'select user_id, course_id from user where enrollment_type= %s',
engine, params={student_enrollment_type})
resource_access_df = pd.merge(
resource_access_df, student_enrollment_df,
on=['user_id', 'course_id'],
# use inner merge to keep only resource access event (left)
# innitiated by people with student enrollment type (right)
how='inner')
# First, update resource table
try:
dtype = {'resource_id': types.VARCHAR(255)}
Expand Down

0 comments on commit b439275

Please sign in to comment.