Skip to content

Instantly share code, notes, and snippets.

@kevinlin1
Created June 5, 2020 02:43
Show Gist options
  • Save kevinlin1/810558b595c7e56e9983ecef8f73c7ea to your computer and use it in GitHub Desktop.
Save kevinlin1/810558b595c7e56e9983ecef8f73c7ea to your computer and use it in GitHub Desktop.
import aiohttp
import asyncio
import io
import pandas as pd
lessons = [
# Ed Lesson IDs
]
token = "" # Ed login token
params = {
'numbers': '0',
'scores': '0',
'students': '1',
'completions': '1',
'strategy': 'best',
'ignore_late': '0',
'late_no_points': '1',
'tz': 'America/Los_Angeles',
}
async def completion(session, lesson):
async with session.post(
f"https://us.edstem.org/api/lessons/{lesson}/results.csv",
params=params,
data={"_token": token}
) as response:
payload = await response.text()
return (
pd.read_csv(io.StringIO(payload))
.set_index("email")
.iloc[:, 4:]
.notna()
.sum(axis=1)
.rename(lesson)
)
async def main():
async with aiohttp.ClientSession() as session:
values = await asyncio.gather(*[completion(session, lesson) for lesson in lessons])
return pd.concat(values, axis=1)
loop = asyncio.get_event_loop()
completions = loop.run_until_complete(main())
print((completions >= completions.median()).sum(axis=1).to_csv(index=True, header=False, sep="\t"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment