Skip to content

Commit

Permalink
adding --terry option to preprocess.py & auxiliary files
Browse files Browse the repository at this point in the history
  • Loading branch information
Harniver committed Apr 25, 2023
1 parent 3d4844f commit 9fa7a4f
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ __pycache__/
media/
photos/
*.jpg
.DS_Store
.log

55 changes: 55 additions & 0 deletions clock.asy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
settings.tex = "pdflatex";

string to_string(int x) {
return (x < 10 ? "0" : "") + string(x);
}

void clock(string date, int h, int m) {
picture pic;
label(pic, graphic("screenshots/background.png"), (0,0));
layer(pic);
path c = circle((0,0), 460);
picture subpic;
label(subpic, graphic("screenshots/filler.png"), (0,0));
clip(subpic, c);
add(pic, subpic);
layer(pic);
draw(pic, c, black+48);
for (int i=0; i<60; ++i)
dot(pic, 400*dir(6*i), black+16);
for (int i=0; i<12; ++i) {
real l = i%3 == 0 ? 64 : 32;
pair p = dir(30*i);
draw(pic, (400-l)*p -- 400*p, black+24);
}
path hl = (0,0) -- (-5,30) -- (0,60) -- (5,30) -- cycle;
fill(pic, rotate(-30*h)*scale(4)*hl, black);
path ml = (0,0) -- (-5,60) -- (0,90) -- (5,60) -- cycle;
fill(pic, rotate(-6*m)*scale(4)*ml, black);
fill(pic, circle((0,0), 12), black);
fill(pic, circle((0,0), 6), white);
shipout("screenshots/" + date + "T" + to_string(h) + ":" + to_string(m) + ":00.0", pic);
}

string[] words = split(stdin, " ");
string start = words[0];
string end = words[1];
words = split(start, "T");
string date = words[0];
words = split(words[1], ":");
int h = (int)words[0];
int m = (int)words[1];
words = split(end, "T");
words = split(words[1], ":");
int eh = (int)words[0];
int em = (int)words[1];

while (true) {
clock(date, h, m);
if (h == eh && m == em) break;
++m;
if (m == 60) {
++h;
m = 0;
}
}
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
3: "III",
4: "IV",
5: "V",
6: "I",
7: "II",
8: "III",
}
TIMELAPSE_DURATION = 5
33 changes: 33 additions & 0 deletions overlays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from manim import *

class Countdown(Scene):
def construct(self):
for i in reversed(range(61)):
t = Text(("0" if i<10 else "") + str(i), font="OCR A Extended", font_size=144)
self.play(FadeIn(t, scale=0, run_time=0.5))
self.play(FadeOut(t, scale=5, run_time=0.5))

class NameMarker(Scene):
def construct(self):
name = "Name Surname"
title = "Why are we considering him"
r = Rectangle(height = 1, width = 8)
r.set_fill("#C0C0C0", opacity = 0.8)
r.set_stroke(width = 0)
r.to_edge(RIGHT, buff=0)
r.to_edge(DOWN, buff=0.5)
n = Text(name, font="Futura", font_size=36, color=BLACK)
t = Text(title, font="Futura", font_size=24, color=BLACK)
g = VGroup()
g.add(n)
g.add(t)
g.arrange(DOWN, center=False, aligned_edge=LEFT, buff=0)
g.to_edge(LEFT, buff=6.4)
g.to_edge(DOWN, buff=0.55)
self.play(Wait(0.5))
self.play(Write(r))
self.play(LaggedStart(Write(n), Write(t), lag_ratio=0.3))
self.play(Wait(3))
self.play(LaggedStart(Unwrite(t), Unwrite(n), lag_ratio=0.3))
self.play(Unwrite(r))
self.play(Wait(0.5))
74 changes: 67 additions & 7 deletions preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import json
import logging
import os.path
from datetime import datetime
import config
import subprocess

logger = logging.getLogger("preprocess")

Expand All @@ -29,14 +32,59 @@ def get_subchanges_data(dir: str):
subchanges.append(data)
return subchanges

def get_terry_data(dir: str):
submissions = {}
subchanges = []
for path in glob.glob(os.path.join(dir, "*", "*", "*", "info.txt")):
with open(path, "r") as f:
date, score = f.readlines()
date = int(datetime.strptime(date[6:-1], "%Y-%m-%d %H:%M:%S").timestamp())
score = int(float(score[7:-1]))
p = os.path.dirname(path)
p, sub = os.path.split(p)
p, user = os.path.split(p)
task = os.path.basename(p)
sub = path
submissions[sub] = {
"user" : user,
"task" : task,
"time" : date,
}
subchanges.append({
"submission" : sub,
"time" : date,
"score" : score,
"extra" : [score],
})
return submissions, subchanges

def fake_screenshots(dir: str, usernames, start, end):
screens = glob.glob(os.path.join(dir, "20*00.png"))
if len(screens) == 0:
subprocess.run(
["asy", "clock.asy", "-f", "png", "-globalwrite", "-antialias", "4"],
input=bytes(config.CONTEST_START + " " + config.CONTEST_END, "utf-8")
)
screens = glob.glob(os.path.join(dir, "20*00.png"))
for user in usernames:
if not os.path.exists(os.path.join(dir, user)):
os.makedirs(os.path.join(dir, user))
for path in screens:
file = os.path.basename(path)
if not os.path.exists(os.path.join(dir, user, file[:-4]+".0.png")):
os.symlink(os.path.join("..", file), os.path.join(dir, user, file[:-4]+".0.png"))

def main(args):
if not os.path.exists(args.ranking_dir):
raise RuntimeError("Missing ranking directory")
os.makedirs(args.output_dir, exist_ok=True)

submissions = get_submissions_data(os.path.join(args.ranking_dir, "submissions"))
subchanges = get_subchanges_data(os.path.join(args.ranking_dir, "subchanges"))
if args.terry:
submissions, subchanges = get_terry_data(args.ranking_dir)
else:
submissions = get_submissions_data(os.path.join(args.ranking_dir, "submissions"))
subchanges = get_subchanges_data(os.path.join(args.ranking_dir, "subchanges"))

subchanges.sort(key=lambda x: x["time"])

logger.info("%s submissions", len(submissions))
Expand Down Expand Up @@ -81,6 +129,9 @@ def main(args):
with open(os.path.join(args.output_dir, "ranking.json"), "w") as f:
json.dump(ranking, f, indent=4)

if args.terry:
fake_screenshots("./screenshots", [user["username"] for user in ranking if user["medal"]], config.CONTEST_START, config.CONTEST_END)

logger.info("Resizing faces...")
os.makedirs(os.path.join(args.output_dir, "faces"), exist_ok=True)
for path in glob.glob(os.path.join(args.faces_dir, "*")):
Expand Down Expand Up @@ -108,25 +159,34 @@ def main(args):
parser = argparse.ArgumentParser()
parser.add_argument(
"--faces-dir",
help="Directory with the faces",
help="directory with the faces",
default="./faces/",
)
parser.add_argument(
"--ranking-dir",
help="Directory with the ranking",
help="directory with the ranking",
default="./ranking/",
)
parser.add_argument(
"--ranking-csv",
help="Path to ranking.csv",
help="path to ranking.csv",
default="./ranking.csv",
)
parser.add_argument(
"--output-dir",
help="Directory to write the output",
help="wirectory to write the output",
default="./output/",
)
parser.add_argument("--verbose", "-v", action="store_true")
parser.add_argument(
"--terry", "-t",
help="import data in terry format",
action="store_true",
)
parser.add_argument(
"--verbose", "-v",
help="enable verbose output",
action="store_true",
)
args = parser.parse_args()
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO,
Expand Down

0 comments on commit 9fa7a4f

Please sign in to comment.