92 lines
1.8 KiB
Python
92 lines
1.8 KiB
Python
import csv
|
|
import dataclasses
|
|
import datetime
|
|
import pathlib
|
|
|
|
from matplotlib import patches
|
|
from matplotlib import pyplot as plt
|
|
|
|
LOW = 13
|
|
HIGH = 15
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class Postbox:
|
|
owner: str
|
|
x: int
|
|
y: int
|
|
z: int
|
|
|
|
|
|
postboxes = []
|
|
texts = []
|
|
|
|
with open("data.csv", "rt", newline="") as fr:
|
|
for line in csv.reader(fr):
|
|
x, y, z, owner = line
|
|
postboxes.append(Postbox(owner, int(x), int(y), int(z)))
|
|
|
|
fig: plt.Figure
|
|
ax: plt.Axes
|
|
|
|
fig, ax = plt.subplots(1, 1)
|
|
|
|
minx, maxx = float("inf"), -float("inf")
|
|
minz, maxz = float("inf"), -float("inf")
|
|
|
|
legend = {}
|
|
|
|
for box in postboxes:
|
|
if "#" in box.owner:
|
|
continue
|
|
|
|
color = "green"
|
|
label = "Available"
|
|
if box.owner:
|
|
color = "red"
|
|
label = "Occupied"
|
|
|
|
offset = 0
|
|
if box.y == HIGH:
|
|
offset = 0.5
|
|
|
|
minx, maxx = min(minx, box.x), max(maxx, box.x)
|
|
minz, maxz = min(minz, box.z), max(maxz, box.z)
|
|
|
|
legend[bool(box.owner)] = ax.add_patch(
|
|
patches.Rectangle(
|
|
(box.x, box.z + offset), 1, 0.5, fill=True, color=color, label=label
|
|
)
|
|
)
|
|
|
|
if box.owner:
|
|
texts.append(
|
|
ax.annotate(
|
|
box.owner,
|
|
(box.x + 0.5, box.z + offset + 0.25),
|
|
color="black",
|
|
ha="center",
|
|
va="center",
|
|
fontvariant="small-caps",
|
|
fontsize="small",
|
|
)
|
|
)
|
|
|
|
ax.legend()
|
|
|
|
plt.grid(True)
|
|
minx, minz = minx - 1, minz - 1
|
|
maxx, maxz = maxx + 2, maxz + 2 # 1 from offset, 1 from rectangle width
|
|
|
|
ax.set_xlim(minx, maxx)
|
|
ax.set_ylim(minz, maxz)
|
|
ax.set_aspect(0.25)
|
|
ax.set_title("Haven Post Office\n" + str(datetime.date.today()))
|
|
plt.legend = ax.legend(handles=legend.values())
|
|
|
|
|
|
fig.set_size_inches((22, 10))
|
|
fig.savefig(pathlib.Path.home() / "YL-postoffice.png", dpi=144)
|
|
|
|
plt.show()
|