Skip to content
View gist:105a4f6e5e2dcdba69b8c5e2868da373
# Extension of https://github.com/psychemedia/futurelearnStatsSketches/blob/master/notebooks/FutureLearn%20Stats%20Recipes.ipynb
def plot_cumulativeCount(df, group, groupset, index, title, start, end):
plt.rc("figure", figsize=(15, 10))
df=df[df[group].isin(groupset)]
df=df.reset_index().set_index(index)
df.sort_index(inplace=True)
df=date_limiter(df, start, end)
df['Total enrollments']=range(len(df))
View gist:c6dd723a79d8b5ca646ceb8827f67242
#generate a calendar heatmap of step visits
# http://stackoverflow.com/a/32492179
# Extension of https://github.com/psychemedia/futurelearnStatsSketches/blob/master/notebooks/FutureLearn%20Stats%20Recipes.ipynb
import datetime as dt
def generate_data():
num = 100
data = np.random.randint(0, 20, num)
start = pd.to_datetime(COURSE_START_DATE)
View gist:99ea405a8aac79f4bc0becfbc950479b
# Enrollment summary graph
# Extension of https://github.com/psychemedia/futurelearnStatsSketches/blob/master/notebooks/FutureLearn%20Stats%20Recipes.ipynb
import matplotlib.ticker as tkr
cat = ['Enrolled learners', 'Visited at least one step', 'Completed at least one step', 'Commented at least once']
count = [len(enrolled_learners),
len(enrolled_learners.intersection(stepstart_learners)),
len(enrolled_learners.intersection(stepcomplete_learners)),
len(commenting_learners)
View getRowsData.gs
// setRowsData fills in one row of data per object defined in the objects Array.
// For every Column, it checks if data objects define a value for it.
// Arguments:
// - sheet: the Sheet Object where the data will be written
// - objects: an Array of Objects, each of which contains data for a row
// - optHeadersRange: a Range of cells where the column headers are defined. This
// defaults to the entire first row in sheet.
// - optFirstDataRowIndex: index of the first row where data should be written. This
// defaults to the row immediately below the headers.
function setRowsData(sheet, objects, optHeadersRange, optFirstDataRowIndex) {
View bloggerAPIExample.gs
var CLIENT_ID = 'YOUR_CLIENT_ID';
var CLIENT_SECRET = 'YOUR_CLIENT_SECRET';
function getService() {
// Create a new service with the given name. The name will be used when
// persisting the authorized token, so ensure it is unique within the
// scope of the property store.
return OAuth2.createService('blogger')
// Set the endpoint URLs, which are the same for all Google services.
View code.gs
var DOC_ID = '1K5IJLwK7qBUfLAG-tic9hOK3L8x4qUIQgd3gryHNE6Y';
function doGet() {
var doc =SpreadsheetApp.openById(DOC_ID);
var auth_user = doc.getViewers();
var auth = auth_user.map(function(user) {
return String(user);
});
var user = Session.getActiveUser().getEmail();
if (auth.indexOf(user) > -1){
View code.gs
// LICENSES http://www.apache.org/licenses/LICENSE-2.0
var DOC_ID = '<INSERT_SPREADSHEET_DOC_ID>';
var SHEET_NAME = 'Sheet1';
/**
* Add a row of data to a sheet.
* @param {Object} parameters passed from script.
* @return {Object} result.
*/
function setData(parameters) {
View quickstart.html
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Google Sheets as a Database – Authenticated INSERT with Apps Script using Execution API - Working Example</title>
<script type="text/javascript">
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = '<INSERT_YOUR_CLIENT_ID>';
var SCRIPT_ID = '<INSERT_YOUR_SCRIPT_ID>';
View emailchart.gs
// Modified from http://stackoverflow.com/a/22200230/1027723
function emailCharts(sheet,emails,emailSubject){
var charts = sheet.getCharts();
if(charts.length==0){
MailApp.sendEmail({
to: emails,
subject: "ERROR:"+emailSubject,
htmlBody: "No charts in the spreadsheet"});
return;
View importioAuthExample.gs
function getResults() {
var connector = {'username':'YOUR_SITE_USERNAME',
'password':'YOUR_SITE_PASSWORD',
'connectorDomain':'YOUR_CONNECTOR_DOMAIN',
'userGuid':'YOUR_USER_GUID',
'connectorGuid':'YOUR_CONNECTOR_GUID',
'apiKey':'YOUR_API_KEY'}
var creds = {};
creds[connector.connectorDomain] = {
Something went wrong with that request. Please try again.