Skip to content

Commit

Permalink
limiting GD view based on course enrollment (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushyamig committed Sep 12, 2023
1 parent 2dd6de3 commit ff3bddb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion assets/src/containers/GradeDistribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import UserSettingSnackbar from '../components/UserSettingSnackbar'
import ViewHeader from '../components/ViewHeader'
import { roundToXDecimals } from '../util/math'
import { useGradeData } from '../service/api'
import { isObjectEmpty } from '../util/object'
import { isObjectEmpty, isObjectGDLimit } from '../util/object'
import useSetUserSetting from '../hooks/useSetUserSetting'
import useUserSetting from '../hooks/useUserSetting'
import { isTeacherOrAdmin } from '../util/roles'
Expand Down Expand Up @@ -122,6 +122,8 @@ function GradeDistribution (props) {
let gradeContent
if (gradeLoaded && isObjectEmpty(gradeData)) {
gradeContent = (<AlertBanner>Grade data is not available.</AlertBanner>)
} else if (gradeLoaded && isObjectGDLimit(gradeData)) {
gradeContent = (<AlertBanner>{gradeData.gd_msg}</AlertBanner>)
} else {
gradeContent = gradeLoaded
? (<BuildGradeView />)
Expand Down
13 changes: 12 additions & 1 deletion assets/src/util/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ const isObjectEmpty = obj => Object.keys(obj).length === 0
// could use Object.values but support isn't widespread yet
const getObjectValues = obj => Object.keys(obj).map(key => obj[key])

const isObjectGDLimit = obj => {
const expectedProperties = ['gd_disable', 'gd_msg']
const hasAllProperties = expectedProperties.every(property => Object.keys(obj).includes(property))
if (hasAllProperties) {
return true
} else {
return false
}
}

const eventLogExtra = (v, eventLog, currentGrade, maxPossibleGrade) => {
// only sending current and max grade when user change the setting for first time since these are not user controlled parameters
if (eventLog.count === 0) {
Expand All @@ -20,5 +30,6 @@ const eventLogExtra = (v, eventLog, currentGrade, maxPossibleGrade) => {
export {
isObjectEmpty,
getObjectValues,
eventLogExtra
eventLogExtra,
isObjectGDLimit
}
3 changes: 2 additions & 1 deletion dashboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ def apply_env_overrides(env: Dict[str, Any], environ: os._Environ) -> Dict[str,
CONSTANCE_CONFIG = {
'SURVEY_URL': ('', 'Full URL to Qualtrics survey. If left blank no survey link will display.', str),
'SURVEY_TEXT': ('Take Survey', 'Custom text for Qualtrics survey link and title. If left blank will default to "Take Survey". Must also configure SURVEY_URL. For best mobile fit keep this text to under 6 words/30 characters.', str),
'RESOURCE_LIMIT': (100, 'Maximum number of resources shown in the Resources Accessed visualization.', int)
'RESOURCE_LIMIT': (100, 'Maximum number of resources shown in the Resources Accessed visualization.', int),
'GRADE_DISTRIBUTION_MINIMUM': (10, 'Minimum number of student enrollments required to show the Grade Distribution visualization.', int)
}

# the url strings for Canvas Caliper events
Expand Down
8 changes: 7 additions & 1 deletion dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ def grade_distribution(request, course_id=0):

current_user = request.user.get_username()

MINIMUM_GRADE_DISTRIBUTION_SCORES = 6

grade_score_sql = f"""select current_grade,
(select show_grade_counts From course where id=%(course_id)s) as show_number_on_bars,
(select current_grade from user where sis_name=%(current_user)s and course_id=%(course_id)s) as current_user_grade
Expand All @@ -460,7 +462,11 @@ def grade_distribution(request, course_id=0):
'course_id': course_id,
'enrollment_type': 'StudentEnrollment'
})
if df.empty or df.count().current_grade < 6:
if len(df) <= config.GRADE_DISTRIBUTION_MINIMUM:
grade_distribution_limit_msg = f'Grade Distribution view is disabled because the course enrollment is less than {config.GRADE_DISTRIBUTION_MINIMUM}'
logger.error(f"Course enrollment count {len(df)} Hence the {grade_distribution_limit_msg}")
return HttpResponse(json.dumps({'gd_disable':'true','gd_msg': grade_distribution_limit_msg}), content_type='application/json')
if df.empty or df.count().current_grade < MINIMUM_GRADE_DISTRIBUTION_SCORES :
logger.info(f"Not enough students grades (only {df.count().current_grade}) in a course {course_id} to show the view")
return HttpResponse(json.dumps({}), content_type='application/json')

Expand Down

0 comments on commit ff3bddb

Please sign in to comment.