mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-10 21:47:08 +01:00
749 findings across six labs and two projects. The mechanical half was scripted; everything below is what the scripts got wrong or could not do, and how it was caught. Three regressions I introduced and then found by RUNNING the code, not by reading it: - Converting print() to logger.info() made the programs SILENT. logging's last-resort handler only emits WARNING and above, so with no basicConfig call `lab2/main.py -t 1 1` printed nothing at all. Fifteen files across the repo now configure logging where they log. - The same conversion dropped `end=""`. lab2 draws its board one square at a time and lab1 draws the maze one cell at a time; both came out one glyph per line. Those thirteen call sites are sys.stdout.write again, and the rendered board now diffs byte-identically against the pre-change output. - The B007 fix renamed `col` to `_col` in the FIRST loop it matched, which was print_letters -- where the variable IS used. That would have been a NameError on the first call. And one the scripts caused silently: annotating 110 signatures dropped the DEFAULT VALUES from 22 of them, so `preprocessing(a, b, USER_THRESHOLD, ANIME_THRESHOLD)` would have raised TypeError. Every signature is now diffed against the pre-change version, name by name and default by default: zero mismatches. Real defects the lint surfaced: - `alpha_beta` ended with an unreachable `return None` that violated its own return type. Its maximising and minimising halves were mirror images, so they are one `_search_branch` now (C901 11 -> ok). - `get_data`'s `gpu` switch, `predict`'s `auto`, `create_model`'s `rows_number` and five of `preprocess_model_predict`'s fifteen parameters were never read. Gone, with their call sites. - np.random.* -> Generator throughout (NPY002), `.values` -> `.to_numpy()`, `datetime.now()` with a tzinfo, `inplace=True` removed, `except:` given a type, `random.*` -> `SystemRandom` (S311). - print_board's three nested helpers became methods (C901 17 -> ok); user_input's nine-branch if-ladder became a table (C901 12 -> ok). Verification, all by running: lab1 `-t` and lab2 `-t 1 1` produce output byte-identical to the pre-change code; lab2's rendered 8x8 board diffs clean; lab3's argument parsing returns the same dict for the same argv; lab4 fails identically before and after (no sklearn here). Also included: the logging configuration for NLP, MOM and ECRYPT_PROJECT, which had the same silence bug. Repo-wide: 2,775 findings -> 1,883. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
69 lines
1.9 KiB
Python
Executable File
69 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Matplotlib scatter demo the lab-3 plotting is modelled on."""
|
|
|
|
import logging
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import cv2
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# cv2.waitKey returns the ASCII code of the key pressed; 'q' quits.
|
|
KEY_Q = ord("q")
|
|
# NumPy's legacy np.random.* functions share one global state; Generator is
|
|
# the modern API and is what NPY002 asks for.
|
|
RNG = np.random.default_rng()
|
|
|
|
|
|
def main() -> None:
|
|
# define number of data points
|
|
"""Draw the scatter demo this lab's plotting is based on."""
|
|
point_count = 10
|
|
|
|
# define the visualization params
|
|
colors = RNG.random(point_count)
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f:
|
|
# iterate over the optimization steps
|
|
for _i in range(10):
|
|
# generate random 2D data - replace it with the results from your algorithm
|
|
x = RNG.random(point_count)
|
|
y = RNG.random(point_count)
|
|
|
|
# plot the data
|
|
plt.cla()
|
|
plt.figure()
|
|
plt.scatter(x, y, c=colors, alpha=0.5)
|
|
plt.xlim([0, 1])
|
|
plt.ylim([0, 1])
|
|
plt.savefig(f.name)
|
|
|
|
# read image
|
|
image = cv2.imread(f.name)
|
|
|
|
# show the image, provide window name first
|
|
cv2.imshow("visualization", image)
|
|
|
|
# add wait key. window waits until user presses a key and quits if the key
|
|
# is 'q'
|
|
if cv2.waitKey(0) == KEY_Q:
|
|
# and finally destroy/close all open windows
|
|
cv2.destroyAllWindows()
|
|
sys.exit()
|
|
|
|
try:
|
|
f.close()
|
|
Path(f.name).unlink()
|
|
except Exception:
|
|
logger.exception("could not close the preview window")
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|