-
Notifications
You must be signed in to change notification settings - Fork 84
Analytics
An example of how to grab data from the server if your @berkeley.edu account has staff access to a class.
Assume, e.g., that you want all submissions for a list of email accounts from your section.
First, download a copy of ok
and place it along with your analysis script. You can authenticate with
import sys
import zipimport
sys.path.insert(0, 'ok')
from ok import authenticate
TOKEN = authenticate()
Next, you need to decide which fields to keep from the data you request. You can specify a dictionary to do so. For example, the FIELDS
dictionary below specifies fields from a submission and its subfields.
FIELDS = {'created':'true',
'id':'true',
'submitter': {'id':'true'},
'messages': 'true',
'assignment': {'name':'proj1'}}
You can see the fields of a model in model.py
https://github.com/Cal-CS-61A-Staff/ok/blob/master/server/app/models.py
Next, specify an endpoint
ENDPOINT = 'http://ok-server.appspot.com/api/v1/submission'
Next, choose the parameters of your query, which can be found in api.py
in each sub-class of an APIResource
. For example, the following params
grab the first 100 submissions (in however the server decides to order them).
params = {'access_token': TOKEN,
'format': 'json',
'fields': json.dumps(FIELDS),
'page': 1,
'stats': "true",
'num_page': 100 }
Pagination is required or the server will run out of memory. Please only request 1000 at a time, using the num_page
parameter. You must request pages in order, or you will not get the data you want. Pagination is implemeneted through memcache, a temporary time-limited data store. In order to query for page n
, you must have already requested page n-1
.