Service quizgrader - openmrs/openmrs-contrib-itsmresources GitHub Wiki
MPL 2.0
Per our Dev Stages, new developers are
considered /dev/null
until they successfully complete a quiz on
basic OpenMRS development to become /dev/1
.
The Quiz Grader is a small, dockerized node app that scans a Google Spreadsheet containing /dev/1 quiz submissions and grades them. Respondents are notified via a Talk message. Those who pass are automatically granted the Smart Developer badge.
The /dev/1 quiz is administered using a Google Form with results written to a connected spreadsheet (both owned by infrastructure+google@). A script on the spreadsheet is designed to trigger the quizgrader and this script is invoked by an event trigger that fires whenever a form is submitted. In effect, the quizgrader is trigger automatically whenever a form is submitted.
A Google API service account was created for the quiz grader with privilege to access the Google Sheets API (available through the Google developer console when authenticated as infrastructure+google@). The spreadsheet is shared with this service account and the quiz grader is configured to use the account to have read/write access to the spreadsheet. A row near the top of the spreadsheet is used as a key against which to grade responses. The grade for each respondent is placed in the last column by the quiz grader.
The quiz grader is a simple node express app with a couple custom
modules to access the Google Spreadsheet and to access OpenMRS Talk.
The openmrsbot
user account is used on Talk for sending messages and
granting badges. The node app is run within a docker container for
easier and more reliable deployment.
- Initially, a Google Form was conntected to a results in a Google sheet under the infrastructure+google@ account.
- Using the infrastructure+google@ account, a Google API service account was created for the quiz grader to access the Sheets API. The key for this account was downloaded in JSON format and included in the config for the quizgrader node app.
- The API key for
openmrsbot
user on Talk is used for access to OpenMRS Talk.
It's deployed as a docker-compose app, so check How-to-debug-docker-compose-application and where to find the configuration.
Here's the script (added via Extensions > Apps Script) on the Google spreadsheet:
function triggerQuizGrader() {
const options = {
method: 'GET',
followRedirects: true,
muteHttpExceptions: true,
contentType: 'application/json',
};
const response = UrlFetchApp.fetch('http://quizgrader.openmrs.org/ping', options);
if (response.getResponseCode() == 204) {
// Logger.log('Successful GET request');
}
}
Here's a sample config. spreadsheetId
, googleKey
, apiUsername
, and apiKey
were changed to production values.
{
"grader": {
"passingGrade": 60,
"badgeName": "Smart Developer",
"minIntervalSeconds": 30
},
"quizSheet": {
"spreadsheetId": "234lk234jlwlk3j4lGTfjw2e3kJL334kjfjr3kj334fw",
"keyRow": 2,
"nameCol": "C",
"openmrsIdCol": "D",
"emailCol": "B",
"issueCol": "E",
"pullRequestCol": "F",
"responseStartRow": 3,
"responseStartCol": "G",
"responseEndCol": "AN",
"gradeCol": "AO"
},
"googleKey": {
"type": "service_account",
"project_id": "name-of-project",
"private_key_id": "cae0016f10535e205f560bf226ad75ab33dcd4dc",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "394984690303484508303",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/username%name-of-project.iam.gserviceaccount.com"
},
"discourse": {
"host": "talk.openmrs.org",
"apiUsername": "username",
"apiKey": "..."
},
"logger": {
"level": "info"
}
}
Docker logs as usual.
To view the latest logs (from the host):
# docker exec $(docker ps -f name=quizgrader -q) cat logs/quizgrader.log | less
The quizgrader docker image is hosted on Docker Hub at openmrsinfra/quizgrader. This image is automatically rebuilt and pushed to Docker Hub by a GitHub action.
- If there are ungraded responses in the /dev/1 quiz spreadsheet, sending a request to quizgrader's
/ping
endpoint should trigger it to grade any ungraded entries:curl -i https://quizgrader.openmrs.org/ping
Burke Mamlin (@burke) created the quiz grader, which will explain why it's so lame.
Source is availabe at https://github.com/openmrs/openmrs-contrib-quizgrader