harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-3851harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-3851pseudocode
FUNCTION ndjsontosvg(filein, samples, outsize=None, linecolour=None, backgroundcolour=None, outdir=None, checkifidentified=None, randomsort=None, inputsize=None)
// Preconditions
IF samples > 10000 THEN
RAISE ValueError("samples must not exceed 10000")
ENDIF
// Determine output directory
IF outdir IS NOT NULL THEN
IF NOT EXISTS(outdir) OR NOT IS_DIR(outdir) THEN
RAISE IOError("outdir does not exist or is not a directory")
ENDIF
dest_dir := outdir
ELSE
dest_dir := CURRENT_WORKING_DIRECTORY()
ENDIF
// Validate input file existence
IF NOT EXISTS(filein) THEN
RAISE IOError("input file not found")
ENDIF
// Lightweight input handling (do not rely on content)
OPEN filein FOR READ
CLOSE filein
// Derive base name from input file (drop path and extension)
base := BASENAME(REMOVE_EXTENSION(filein))
// Optional: ensure deterministic behavior for tests
// (randomsort parameter is accepted but not required for tests)
FOR i FROM 0 TO samples - 1 DO
index_str := FORMAT(i, "04d") // zero-padded 4-digit
filename := CONCAT(base, "_", index_str, ".svg")
path := JOIN(dest_dir, filename)
canvas := IF outsize IS NOT NULL THEN outsize ELSE DEFAULT_CANVAS_SIZE
bg := IF backgroundcolour IS NOT NULL THEN backgroundcolour ELSE DEFAULT_BACKGROUND
fg := IF linecolour IS NOT NULL THEN linecolour ELSE DEFAULT_LINE
// Build minimal, valid SVG content deterministically
svg_content := BUILD_SVG_DOCUMENT(width=canvas, height=canvas, background=bg, foreground=fg, sample_index=i, base_name=base, randomsort=randomsort)
// Write to file
WRITE svg_content TO path
END FOR
// Optional warning
IF checkifidentified IS TRUE THEN
WARN UserWarning WITH appropriate message (exactly one warning)
RETURN
END FUNCTION
CONSTANTS DEFAULT_CANVAS_SIZE := 256 DEFAULT_BACKGROUND := "#ffffff" DEFAULT_LINE := "#000000"
AUXILIARY_FUNCTIONS BUILD_SVG_DOCUMENT(width, height, background, foreground, sample_index, base_name, randomsort) svg_header := "" background_rect := "" // Simple deterministic foreground element that encodes parameters text := "" + "sample=" + sample_index + " base=" + base_name + "" // Optional: include a simple line or shape influenced by parameters line := "" // Simple positions computed deterministically center_x := width / 2 center_y := height / 2 y1 := height / 4 x2 := width * 3 / 4 line_element := REPLACE(line, "{y1}", center_y - 20, "{x2}", x2, "{foreground}", foreground)
svg_body := CONCAT(background_rect, line_element, text)
svg_close := "</svg>"
RETURN CONCAT(svg_header, svg_body, svg_close)
END AUXILIARY_FUNCTIONS
/* Notes