Skip to content

Commit

Permalink
use vegalite
Browse files Browse the repository at this point in the history
  • Loading branch information
zehengl committed Oct 6, 2023
1 parent a341e2e commit 6f8bc84
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 31 deletions.
89 changes: 82 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,94 @@

> as of 2023-10-06
- Easy ^425^

- Medium ^22^

- Hard ^1^
```vegalite
{
"data": {
"values": [
{"Difficulty": "Easy", "Count": 425},
{"Difficulty": "Medium", "Count": 22},
{"Difficulty": "Hard", "Count": 1}
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Difficulty", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```

## Summary by Initial

![summary-by-initial](summary-by-initial.png)
```vegalite
{
"data": {
"values": [
{"Initial": "S", "Count": 59},
{"Initial": "C", "Count": 38},
{"Initial": "A", "Count": 33},
{"Initial": "P", "Count": 33},
{"Initial": "B", "Count": 31},
{"Initial": "T", "Count": 29},
{"Initial": "M", "Count": 25},
{"Initial": "H", "Count": 20},
{"Initial": "E", "Count": 19},
{"Initial": "R", "Count": 18},
{"Initial": "D", "Count": 18},
{"Initial": "F", "Count": 17},
{"Initial": "G", "Count": 14},
{"Initial": "L", "Count": 12},
{"Initial": "V", "Count": 10},
{"Initial": "O", "Count": 10},
{"Initial": "W", "Count": 9},
{"Initial": "K", "Count": 9},
{"Initial": "J", "Count": 9},
{"Initial": "I", "Count": 8},
{"Initial": "N", "Count": 5},
{"Initial": "Q", "Count": 5},
{"Initial": "U", "Count": 5},
{"Initial": "Y", "Count": 2},
{"Initial": "Z", "Count": 2},
{"Initial": "1", "Count": 2},
{"Initial": "Ó", "Count": 1},
{"Initial": "3", "Count": 1},
{"Initial": "9", "Count": 1},
{"Initial": "Ú", "Count": 1},
{"Initial": "Ö", "Count": 1},
{"Initial": "4", "Count": 1}
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Initial", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```

## Summary by Language

![summary-by-language](summary-by-language.png)
```vegalite
{
"data": {
"values": [
{"Language": "Python", "Count": 445},
{"Language": "Go", "Count": 36},
{"Language": "Java", "Count": 25},
{"Language": "C++", "Count": 16},
{"Language": "JavaScript", "Count": 8},
{"Language": "Haskell", "Count": 3},
{"Language": "Rust", "Count": 2},
{"Language": "Kotlin", "Count": 2}
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Language", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```

---

Expand Down
Binary file removed docs/summary-by-initial.png
Binary file not shown.
Binary file removed docs/summary-by-language.png
Binary file not shown.
11 changes: 10 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ repo_name: kattis
repo_url: https://github.com/coding-armadillo/kattis
plugins:
- search
- charts
- tags
- glightbox:
auto_caption: true
Expand All @@ -44,7 +45,11 @@ markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.snippets
- pymdownx.superfences
- pymdownx.superfences:
custom_fences:
- name: vegalite
class: vegalite
format: !!python/name:mkdocs_charts_plugin.fences.fence_vegalite
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
Expand All @@ -54,6 +59,10 @@ markdown_extensions:
- pymdownx.caret
- pymdownx.mark
- pymdownx.tilde
extra_javascript:
- https://cdn.jsdelivr.net/npm/vega@5
- https://cdn.jsdelivr.net/npm/vega-lite@5
- https://cdn.jsdelivr.net/npm/vega-embed@6
extra:
social:
- icon: fontawesome/solid/house
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
beautifulsoup4==4.12.2
pip-check-updates==0.22.0
requests==2.31.0
seaborn==0.13.0
tqdm==4.66.1
1 change: 1 addition & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mkdocs-charts-plugin==0.0.10
mkdocs-git-revision-date-localized-plugin==1.2.0
mkdocs-glightbox==0.3.4
mkdocs-material==9.4.4
Expand Down
95 changes: 73 additions & 22 deletions update_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from datetime import date
from pathlib import Path

import matplotlib.pyplot as plt
import requests
import seaborn as sns
import urllib3
from bs4 import BeautifulSoup
from tqdm import tqdm
Expand Down Expand Up @@ -109,19 +107,6 @@
with open("docs/.cache", "wb") as f:
pickle.dump(cache, f)

s = dict(Counter([title[0] for title, _, _ in cache.values()]).most_common())
ax = sns.barplot(x=list(s.keys()), y=list(s.values()))
ax.get_figure().savefig("docs/summary-by-initial.png", bbox_inches="tight")

plt.clf()

s = dict(Counter([language_map[f.name.split(".")[-1]] for f in files]).most_common())
ax = sns.barplot(x=list(s.keys()), y=list(s.values()))
ax.set_xticklabels(ax.get_xticklabels(), rotation=45)
ax.get_figure().savefig("docs/summary-by-language.png", bbox_inches="tight")

plt.clf()

summary = Counter(level for _, _, level in cache.values())

with open(".all-contributorsrc") as f:
Expand All @@ -143,25 +128,91 @@
> as of {date.today()}
"""

for level, total in summary.most_common():
text += f"""
- {level} ^{total}^
"""
text += f"""
data = ",\n ".join(
f'{{"Difficulty": "{level}", "Count": {total}}}'
for level, total in summary.most_common()
)
text += """
```vegalite
{
"data": {
"values": [
%%data%%
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Difficulty", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```
""".replace(
"%%data%%", data
)

data = ",\n ".join(
f'{{"Initial": "{initial}", "Count": {count}}}'
for initial, count in Counter(
[title[0] for title, _, _ in cache.values()]
).most_common()
)
text += """
## Summary by Initial
![summary-by-initial](summary-by-initial.png)
```vegalite
{
"data": {
"values": [
%%data%%
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Initial", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```
""".replace(
"%%data%%", data
)

data = ",\n ".join(
f'{{"Language": "{language}", "Count": {count}}}'
for language, count in Counter(
[language_map[f.name.split(".")[-1]] for f in files]
).most_common()
)
text += """
## Summary by Language
![summary-by-language](summary-by-language.png)
```vegalite
{
"data": {
"values": [
%%data%%
]
},
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"x": {"field": "Language", "type": "nominal", "axis": {"labelAngle": 0}, "sort": "-y"},
"y": {"field": "Count", "type": "quantitative"}
}
}
```
""".replace(
"%%data%%", data
)

text += f"""
---
!!! note ""
Thanks to all {num_contributors} [contributors](https://github.com/coding-armadillo/kattis#contributors-).
"""

f.write(text.lstrip())


Expand Down

0 comments on commit 6f8bc84

Please sign in to comment.