-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.qmd
309 lines (281 loc) Β· 8.58 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
---
page-title: "GitHub Wrapped 2023"
format:
dashboard:
scrolling: true
theme: darkly
execute:
echo: false
params:
userid: "schochastics"
highlight: "#DBAC34"
anti_color: "#DB5934"
bg_color: "#2D2D2D"
ignore_lang: "CSS,JavaScript,SCSS,HTML,TeX,Shell,C"
---
```{r}
#| label: load_packages
library("ghql")
library("jsonlite")
library("tidyverse")
library("patchwork")
library("reactable")
source("helper.R")
ignore_lang <- str_split(params$ignore_lang, ",")[[1]]
```
```{r}
#| label: setup_data
#| cache: true
token <- Sys.getenv("GITHUB_TOKEN")
con <- GraphqlClient$new(
url = "https://api.github.com/graphql",
headers = list(Authorization = paste0("Bearer ", token))
)
variables <- list(
userid = params$userid
)
con$load_schema()
qry <- Query$new()
qry$query(
"mydata", ' query getContrib($userid: String!){
user(login:$userid){
avatarUrl
login
contributionsCollection(
from: "2024-01-01T00:00:00.000Z"
to: "2025-01-01T00:00:00.000Z") {
totalCommitContributions
totalIssueContributions
totalRepositoryContributions
totalRepositoriesWithContributedCommits
totalPullRequestContributions
totalPullRequestReviewContributions
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
date
}
}
}
commitContributionsByRepository {
contributions {
totalCount
}
repository {
name
owner {
login
}
isPrivate
languages(first: 5, orderBy: {field: SIZE, direction: DESC}) {
edges {
size
node {
color
name
id
}
}
}
}
}
}
}
}'
)
x <- con$exec(qry$queries$mydata, variables)
res <- jsonlite::fromJSON(x)
stargaze <- gh::gh("/users/{username}/starred", username = params$userid, .accept = "application/vnd.github.v3.star+json", per_page = 100)
```
```{r}
#| label: prep_data
contrib <- res$data$user$contributionsCollection$contributionCalendar$weeks
tbl_contributions <- map_dfr(seq_len(nrow(contrib)), \(x) contrib[x, ][[1]])
contrib_by_repo <- flatten_dfc(res$data$user$contributionsCollection$commitContributionsByRepository)
most_lang <- count(bind_rows(contrib_by_repo$edges)$node, name) |>
filter(!name %in% ignore_lang) |>
top_n(3, n) |>
arrange(-n) |>
mutate(n = n / sum(n))
most_lang_img <- paste0("img/logos/", most_lang$name, ".svg")
tbl_contributions$wday <- lubridate::wday(tbl_contributions$date, label = TRUE, abbr = TRUE)
tbl_contributions$week <- lubridate::week(tbl_contributions$date)
fill_breaks <- pretty(tbl_contributions$contributionCount)
fill_breaks[1] <- ifelse(fill_breaks[1] == 0, 1, fill_breaks[1])
fill_breaks[length(fill_breaks)] <- max(tbl_contributions$contributionCount)
end <- min(Sys.Date(), as.Date("2024-12-31"))
streak <- (tbl_contributions$contributionCount[tbl_contributions$date <= end] != 0) + 0
y <- rle(streak)
streak_len <- max(y$lengths[y$values == 1])
gap_len <- max(y$lengths[y$values == 0])
wkend <- sum(
tbl_contributions$contributionCount[tbl_contributions$wday %in% c("Sun", "Sat")]
) / sum(tbl_contributions$contributionCount)
stars <- map_dfr(stargaze, \(x) tibble(
starred_at = as.POSIXct(x$starred_at),
repo = x$repo$full_name,
descr = x$repo$description
)) |>
filter(lubridate::year(starred_at) == 2023) |>
nrow()
stars <- ifelse(stars == 100, "100+", stars)
```
<h1 style="text-align:center;margin-bottom:0.15em"> πππ GitHub Wrapped 2024 πππ </h1>
<span style="text-align:center">
![](`r res$data$user$avatarUrl`){width=10em}
</span>
<h1 style="text-align:center;margin-top:0.15em"> `r params$userid` </h1>
<center>
![](`r most_lang_img[1]`){width=3em}
![](`r most_lang_img[2]`){width=3em}
![](`r most_lang_img[3]`){width=3em}
</center>
## Row
```{r}
#| content: valuebox
#| title: "Total Contributions"
list(
icon = "stars",
color = params$highlight,
value = res$data$user$contributionsCollection$totalCommitContributions
)
```
```{r}
#| content: valuebox
#| title: "Repositories created"
list(
icon = "journal-arrow-up",
color = "#9BA7C0",
value = res$data$user$contributionsCollection$totalRepositoryContributions
)
```
```{r}
#| content: valuebox
#| title: "Issues opened"
list(
icon = "bullseye",
color = "#9BA7C0",
value = res$data$user$contributionsCollection$totalIssueContributions
)
```
```{r}
#| content: valuebox
#| title: "Pull requests"
list(
icon = "sign-merge-right",
color = "#9BA7C0",
value = res$data$user$contributionsCollection$totalPullRequestContributions
)
```
```{r}
#| content: valuebox
#| title: "Stargazed"
list(
icon = "star-fill",
color = "#9BA7C0",
value = stars
)
```
## Row
```{r}
#| label: contrib-calendar
#| title: Contribution Calendar
p1 <- tbl_contributions |>
mutate(contributionCount = ifelse(contributionCount == 0, NA, contributionCount)) |>
ggplot(aes(x = week, y = fct_rev(wday))) +
geom_tile(aes(fill = contributionCount), size = 1, color = "white") +
# coord_fixed() +
scale_fill_gradient(breaks = fill_breaks, low = "#9BE9A8", high = "#216E39", name = "", na.value = "grey66") +
scale_x_continuous(breaks = NULL, name = "", limits = c(0, 53), expand = c(0, 0)) +
scale_y_discrete(labels = c("", "Fri", "", "Wed", "", "Mon", "")) +
theme_minimal() +
theme(
legend.position = "bottom",
legend.justification = "right",
legend.text = element_text(color = "white"),
axis.text = element_text(color = "white"),
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
axis.ticks.y = element_blank()
) +
guides(fill = guide_legend(
label.position = "bottom",
direction = "horizontal"
))
p2 <- donut_plot(streak_len, streak_len, params$highlight, "white") + labs(title = "longest streak")
p3 <- donut_plot(gap_len, gap_len, params$anti_color, "white") + labs(title = "longest gap")
p4 <- donut_plot(round(100 * wkend), 100, "#216E39", "white") + labs(title = "weekend contribs (%)")
p5 <- donut_plot(sum(streak), 365, "#216E39", "white") + labs(title = "active days")
p <- (p2 | p3 | p5 | p4) / p1 +
plot_annotation(theme = theme(
plot.background = element_rect(fill = params$bg_color, color = params$bg_color),
panel.background = element_rect(fill = params$bg_color)
))
p
```
```{r}
#| label: contrib-repos
#| title: Contributions to repositories
contrib_by_repo |>
select(-edges) |>
filter(!isPrivate) |>
select(repo = name, login, contributions = totalCount) |>
reactable(theme = reactableTheme(backgroundColor = params$bg_color))
```
## Row
```{r}
#| label: bar-wdays
#| title: Contributions by Weekday
tbl_contributions |>
group_by(wday) |>
summarise(count = sum(contributionCount)) |>
mutate(type = case_when(
count == min(count) ~ "min",
count == max(count) ~ "max",
TRUE ~ "regular"
)) |>
ggplot(aes(x = wday, y = count)) +
geom_col(aes(fill = type), show.legend = FALSE) +
geom_text(aes(y = count / 2, label = count), color = params$bg_color) +
scale_fill_manual(values = c("min" = params$anti_color, "max" = params$highlight, "regular" = "white")) +
scale_x_discrete(labels = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")) +
theme_minimal() +
theme(
plot.background = element_rect(fill = params$bg_color, color = "white"),
panel.background = element_rect(fill = params$bg_color),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(color = "white"),
axis.title = element_blank()
)
```
```{r}
#| label: bar-month
#| title: Contributions by Month
tbl_contributions |>
mutate(month = lubridate::month(date, label = TRUE)) |>
group_by(month) |>
summarise(count = sum(contributionCount)) |>
mutate(type = case_when(
count == min(count) ~ "min",
count == max(count) ~ "max",
TRUE ~ "regular"
)) |>
ggplot(aes(x = month, y = count)) +
geom_col(aes(fill = type), show.legend = FALSE) +
geom_text(aes(y = count / 2, label = count), color = params$bg_color) +
scale_fill_manual(values = c("min" = params$anti_color, "max" = params$highlight, "regular" = "white")) +
theme_minimal() +
theme(
plot.background = element_rect(fill = params$bg_color, color = "white"),
panel.background = element_rect(fill = params$bg_color),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(color = "white"),
axis.title = element_blank()
)
```