Skip to content

Commit 1f94d72

Browse files
committed
Add tufts-weather benchmark
1 parent 3a181ea commit 1f94d72

File tree

7 files changed

+6829
-0
lines changed

7 files changed

+6829
-0
lines changed

tuft-weather/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.png
2+
*.txt

tuft-weather/clean.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rm *.txt
2+
rm *.png

tuft-weather/input

+6,749
Large diffs are not rendered by default.

tuft-weather/inputs.sh

Whitespace-only changes.

tuft-weather/run.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
input="input"
4+
5+
cat "$input" \
6+
| grep -v "\-99" \
7+
| sort -n \
8+
| awk '{ printf "%02d-%02d %s %s\n", $1, $2, $3, $4 }' > formatted.txt
9+
10+
input="formatted.txt"
11+
12+
# Get max and min per month date across all years
13+
cat "$input" \
14+
| awk '{
15+
key = sprintf("%s", $1);
16+
if (!(key in max) || $3 > max[key]) max[key] = $3;
17+
if (!(key in min) || $3 < min[key]) min[key] = $3;
18+
}
19+
END {
20+
for (key in max) {
21+
printf "%s %s %s\n", key, max[key], min[key];
22+
}
23+
}' \
24+
| sort -n > max_min.txt
25+
26+
for year in $(seq 1995 2013); do
27+
join -1 1 -2 1 -o "0 1.2 1.3 2.2" -e "NA" max_min.txt <(grep "$year" "$input" | cut -d' ' -f 1,3) \
28+
| grep -v "NA" \
29+
| ./scripts/plot.py "$year" > "$year.png"
30+
done

tuft-weather/scripts/plot.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import datetime
4+
import io
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
import sys
8+
9+
# Read data from stdin
10+
data = sys.stdin
11+
year = sys.argv[1]
12+
13+
to_dt = lambda x: datetime.datetime.strptime(f"{year}-{x}", "%Y-%m-%d")
14+
15+
data = [ line.strip().replace("\r", "") for line in data ]
16+
data = [ (to_dt(date), float(_min), float(_max), float(temp)) for date, _min, _max, temp in [ line.split() for line in data if line ] ]
17+
data = { key: [ x for x in values ] for key, values in zip(["date", "min", "max", "temp"], zip(*data)) }
18+
19+
dates = data["date"]
20+
historic_max = data["max"]
21+
historic_min = data["min"]
22+
temps = data["temp"]
23+
24+
# Plotting
25+
plt.figure(figsize=(10, 5))
26+
27+
# Historic ranges (shaded areas)
28+
plt.fill_between(dates, historic_min, historic_max, color="tan", alpha=0.3, label='Normal range')
29+
30+
plt.plot(dates, temps, color="black", label=f"{year} temperature")
31+
32+
# Labels and titles
33+
plt.xlabel(f"Days in {year}")
34+
plt.ylabel("Temperature (°F)")
35+
plt.title(f"Temperature Records for {year}")
36+
37+
# Legend
38+
plt.legend(loc="upper right")
39+
40+
# Show the plot
41+
plt.grid(True)
42+
43+
buf = io.BytesIO()
44+
plt.savefig(buf, format='png')
45+
plt.close()
46+
sys.stdout.buffer.write(buf.getvalue())

tuft-weather/verify.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)