Skip to content

Commit 43d1ce1

Browse files
author
Adam M. Wilson
committed
update grades reporting from github and todos
1 parent b1eb41a commit 43d1ce1

File tree

4 files changed

+155
-1
lines changed

4 files changed

+155
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ packrat/lib*/
77
wc10*
88
*rds*
99
*nc
10-
['~']
10+
['~']
11+
*secrets*
12+
.httr-oauth

TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ Teaching resources: https://www.carlboettiger.info/teaching
1313
* linear modeling
1414
* kriging?
1515

16+
code style:
17+
* more line returns
18+
19+
Viz style:
20+
* log transform color ramps and axis, not data...
21+
22+
1623
# Structure updates
1724

1825
Add a datacamp course/chapter for each/most of the 14 case studies
1926
Use datacamp education for instruction/assignments
2027
Then class time for questions/case studies
2128
Build index of student projects on website to facilitate?
29+
first draft submitted earilier for video feedback.
2230

2331
File Structure
2432

docs/grades/grades.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Process grade-related things....
2+
#
3+
#
4+
## Participation grade
5+
##
6+
##
7+
library(tidyverse)
8+
library(tidyjson)
9+
10+
source("grades/secrets.R")
11+
12+
13+
# Get OAuth credentials
14+
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
15+
16+
# Use API
17+
gtoken <- config(token = github_token)
18+
req <- GET("https://api.github.com/users/AdamWilsonLabEDU/repos", gtoken)
19+
20+
# Take action on http error
21+
stop_for_status(req)
22+
23+
# Extract content from a request
24+
json1 = content(req)
25+
26+
# Convert to a data.frame
27+
d = jsonlite::fromJSON(jsonlite::toJSON(json1))%>%
28+
mutate(type=ifelse(grepl("finalproject",full_name),
29+
"final_project","case_study"))
30+
31+
# Subset data.frame
32+
mutate_at(d,grepl("geo503-2018")
33+

grades/grades.R

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Process grade-related things....
2+
#
3+
#
4+
## Participation grade
5+
##
6+
##
7+
8+
library(tidyverse)
9+
library(tidyjson)
10+
library(foreach)
11+
source("grades/secrets.R")
12+
13+
14+
# Get OAuth credentials
15+
github_token <- oauth2.0_token(oauth_endpoints("github"), myapp)
16+
17+
# Use API
18+
gtoken <- config(token = github_token)
19+
req <- GET("https://api.github.com/users/AdamWilsonLabEDU/repos?per_page=1000", gtoken)
20+
21+
# Take action on http error
22+
stop_for_status(req)
23+
24+
# Extract content from a request
25+
json1 = content(req)
26+
27+
# Convert to a data.frame
28+
d = jsonlite::fromJSON(jsonlite::toJSON(json1))%>%
29+
select(-c(`owner`, `mirror_url`, `license`, `permissions`))%>%
30+
select(c(`full_name`, `html_url`, `forks_url`, `collaborators_url`,`commits_url`,`pulls_url`,`pushed_at`,`homepage`,`size`,`forks_count`))%>%
31+
as.tibble()%>%
32+
mutate(type=ifelse(grepl("finalproject",full_name),
33+
"final_project","class"),
34+
user=gsub("AdamWilsonLabEDU/geo503-2018-","",gsub("finalproject-","",full_name)))
35+
36+
class=d%>%
37+
filter(type=="class")
38+
39+
project=d%>%
40+
filter(type=="final_project")
41+
42+
43+
# copy repository structure repo somewhere
44+
setwd("~/Documents/Work/courses/201809/GEO511/repos/")
45+
i=1
46+
#system(paste("git remote add -f",class$user[i]," ",class$html_url[i]))
47+
#system("git remote update")
48+
#system(paste0("git diff master remotes/",class$user[i],"/master"))
49+
#system(paste("git remote rm ",class$user[i]))
50+
51+
# check out repository diffs, one by one
52+
if(F){
53+
for(i in 1:nrow(class))
54+
system(paste0("meld SpatialDataScience_Structure GEO503-2018-12-07-2018-10-23-37/",class$user[i]," &"))
55+
}
56+
57+
# get class contents
58+
class_summary <- foreach(i=1:nrow(class)) %do% {
59+
content <- GET("https://api.github.com/repos/AdamWilsonLabEDU/geo503-2018-acerpovicz/contents/week_04/case_study", gtoken)%>%
60+
content()%>%toJSON()%>%fromJSON()%>%
61+
select(name,path)%>%filter(name!="README.md")%>%
62+
mutate(user=class$user[i])
63+
}
64+
65+
66+
67+
# summarize pull requests?
68+
# get class contents
69+
repo_url="https://api.github.com/repos/AdamWilsonLabEDU/geo503-2018-finalproject-acerpovicz"
70+
repo_url=project$pulls_url[3]
71+
72+
fpull=function(repo_url){
73+
74+
print(repo_url)
75+
pull_requests <- GET(paste0(gsub("\\{\\/number\\}","",repo_url)), gtoken)%>%
76+
content()%>%toJSON()%>%fromJSON()
77+
if(length(pull_requests)==0) return(NA)
78+
79+
comments_url=pull_requests$review_comments_url
80+
pull_comments=
81+
lapply(comments_url,FUN=function(j){
82+
pull_comments <- GET(j[[1]], gtoken)%>%
83+
content()%>%toJSON()%>%fromJSON()
84+
unlist(pull_comments$body)
85+
})
86+
87+
results=data.frame(
88+
reviewed=gsub("^.*project-","",gsub("\\/p.*$","",repo_url)),
89+
reviewer=unlist(pull_requests$user$login),
90+
description=paste(unlist(pull_requests$body)),
91+
comment=unlist(lapply(pull_comments,FUN=paste,collapse=";")),
92+
comment_count=unlist(lapply(pull_comments,FUN=length)),stringsAsFactors = F)%>%
93+
mutate(
94+
description_words=lengths(strsplit(description, "\\W+")),
95+
comments_words=lengths(strsplit(comment, "\\W+")),
96+
total_words=description_words)%>%
97+
select(-description_words,-comments_words)
98+
99+
return(results)
100+
}
101+
102+
# get and
103+
review=do.call(rbind.data.frame,lapply(project$pulls_url,FUN=fpull))
104+
105+
review%>%
106+
group_by(reviewer)%>%
107+
summarize(pull_requests=n(),comments=sum(comment_count),words=sum(total_words))
108+
109+
110+
filter(review,reviewer=="acerpovicz")
111+

0 commit comments

Comments
 (0)