Add art statistics page
This commit is contained in:
parent
4505d41011
commit
6e9a76aa64
3 changed files with 80 additions and 2 deletions
|
@ -44,15 +44,19 @@ def parse_art_json(output_directory, filename, json_file):
|
||||||
|
|
||||||
write_field(f, 'slug', filename)
|
write_field(f, 'slug', filename)
|
||||||
|
|
||||||
|
characters = []
|
||||||
if "characters" in json_data:
|
if "characters" in json_data:
|
||||||
f.write("characters:\n")
|
f.write("characters:\n")
|
||||||
for character in json_data["characters"]:
|
for character in json_data["characters"]:
|
||||||
f.write("- " + character + "\n")
|
f.write("- " + character + "\n")
|
||||||
|
characters.append(character)
|
||||||
|
|
||||||
|
tags = []
|
||||||
if "tags" in json_data:
|
if "tags" in json_data:
|
||||||
f.write("arttags:\n")
|
f.write("arttags:\n")
|
||||||
for tag in json_data["tags"]:
|
for tag in json_data["tags"]:
|
||||||
f.write("- " + tag.lower() + "\n")
|
f.write("- " + tag.lower() + "\n")
|
||||||
|
tags.append(tag.lower())
|
||||||
|
|
||||||
if "nsfw" in json_data:
|
if "nsfw" in json_data:
|
||||||
write_field(f, 'nsfw', str(json_data["nsfw"]).lower())
|
write_field(f, 'nsfw', str(json_data["nsfw"]).lower())
|
||||||
|
@ -75,7 +79,7 @@ def parse_art_json(output_directory, filename, json_file):
|
||||||
f.write(json_data["description"])
|
f.write(json_data["description"])
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
|
||||||
return year
|
return (year, characters, tags)
|
||||||
|
|
||||||
|
|
||||||
art_data_directory = '../art'
|
art_data_directory = '../art'
|
||||||
|
@ -85,6 +89,10 @@ shutil.rmtree(art_output_directory)
|
||||||
os.mkdir(art_output_directory)
|
os.mkdir(art_output_directory)
|
||||||
|
|
||||||
collected_years = set()
|
collected_years = set()
|
||||||
|
year_stats = {}
|
||||||
|
total_art = 0
|
||||||
|
character_stats = {}
|
||||||
|
tag_stats = {}
|
||||||
|
|
||||||
for filename in os.listdir(art_data_directory):
|
for filename in os.listdir(art_data_directory):
|
||||||
f = os.path.join(art_data_directory, filename)
|
f = os.path.join(art_data_directory, filename)
|
||||||
|
@ -93,7 +101,27 @@ for filename in os.listdir(art_data_directory):
|
||||||
filename_without_ext = os.path.splitext(filename)[0]
|
filename_without_ext = os.path.splitext(filename)[0]
|
||||||
|
|
||||||
with open(f, "r") as file:
|
with open(f, "r") as file:
|
||||||
collected_years.add(parse_art_json(art_output_directory, filename_without_ext, file))
|
year, characters, tags = parse_art_json(art_output_directory, filename_without_ext, file)
|
||||||
|
|
||||||
|
if year in year_stats:
|
||||||
|
year_stats[year] += 1
|
||||||
|
else:
|
||||||
|
year_stats[year] = 1
|
||||||
|
|
||||||
|
for character in characters:
|
||||||
|
if character in character_stats:
|
||||||
|
character_stats[character] += 1
|
||||||
|
else:
|
||||||
|
character_stats[character] = 1
|
||||||
|
|
||||||
|
for tag in tags:
|
||||||
|
if tag in tag_stats:
|
||||||
|
tag_stats[tag] += 1
|
||||||
|
else:
|
||||||
|
tag_stats[tag] = 1
|
||||||
|
|
||||||
|
collected_years.add(year)
|
||||||
|
total_art += 1
|
||||||
|
|
||||||
for year in collected_years:
|
for year in collected_years:
|
||||||
with open(os.path.join(art_output_directory, str(year), '_index.md'), 'w') as f:
|
with open(os.path.join(art_output_directory, str(year), '_index.md'), 'w') as f:
|
||||||
|
@ -138,3 +166,30 @@ with open(art_output_directory + '/_index.md', 'w') as f:
|
||||||
f.write('- ' + str(year) + '\n')
|
f.write('- ' + str(year) + '\n')
|
||||||
|
|
||||||
f.write('---\n')
|
f.write('---\n')
|
||||||
|
|
||||||
|
os.mkdir(art_output_directory + "/stats")
|
||||||
|
|
||||||
|
with open(art_output_directory + '/stats/_index.md', 'w') as f:
|
||||||
|
f.write('---\n')
|
||||||
|
|
||||||
|
write_field(f, 'title', 'Stats')
|
||||||
|
write_field(f, 'layout', 'art-stats')
|
||||||
|
|
||||||
|
write_field(f, 'total', str(total_art))
|
||||||
|
|
||||||
|
f.write('years:\n')
|
||||||
|
for year, num in reversed(sorted(year_stats.items(), key=lambda t: t[1])):
|
||||||
|
f.write('- year: ' + str(year) + '\n')
|
||||||
|
f.write(' num: ' + str(num) + '\n')
|
||||||
|
|
||||||
|
f.write('characters:\n')
|
||||||
|
for name, num in sorted(character_stats.items(), key=lambda t: t[1], reverse=True)[:10]:
|
||||||
|
f.write('- name: ' + str(name) + '\n')
|
||||||
|
f.write(' num: ' + str(num) + '\n')
|
||||||
|
|
||||||
|
f.write('tags:\n')
|
||||||
|
for name, num in sorted(tag_stats.items(), key=lambda t: t[1]):
|
||||||
|
f.write('- name: ' + str(name) + '\n')
|
||||||
|
f.write(' num: ' + str(num) + '\n')
|
||||||
|
|
||||||
|
f.write('---\n')
|
|
@ -395,3 +395,20 @@ pre {
|
||||||
vertical-align: sub;
|
vertical-align: sub;
|
||||||
margin-left: 2px;
|
margin-left: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.art-button-container {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.art-button {
|
||||||
|
width: 100%;
|
||||||
|
height: 50px;
|
||||||
|
line-height: 50px;
|
||||||
|
text-align: center;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
|
@ -18,6 +18,12 @@
|
||||||
{{ partial "featured-art" . }}
|
{{ partial "featured-art" . }}
|
||||||
|
|
||||||
{{ partial "art-years" . }}
|
{{ partial "art-years" . }}
|
||||||
|
|
||||||
|
<div class="art-button-container">
|
||||||
|
<a class="art-button" href="/art/characters">Characters</a>
|
||||||
|
<a class="art-button" href="/art/tags">Tags</a>
|
||||||
|
<a class="art-button" href="/art/stats">Stats</a>
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ partial "art-gallery" . }}
|
{{ partial "art-gallery" . }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue