<commit_before>;;;; Export sampling results to Gnuplot compatible graph data files.

(in-package :soundlab.sampling)

(defparameter *graph-output-format* "~8f ~8f~%"
  "Gnuplot compatible representation for samples.")

(defun sample-graph (function length frequency stream)
  "Sample FUNCTION from zero to LENGTH with FREQUENCY and write it to
STREAM as a Gnuplot compatible data file."
  (let ((samples (sample-function function length frequency)))
    (loop for (x-value . y-value) across samples
       do (format stream *graph-output-format* x-value y-value))
    samples))

(defun export-graph (function length frequency path
			      &key (if-exists :error))
  "Direct output of SAMPLE-GRAPH to PATH. If PATH already exists use
IF-EXISTS to control behaviour, default is :ERROR."
  (with-open-file (out path
		       :direction :output
		       :if-exists if-exists)
    (sample-function-graph function length frequency out)))<commit_msg>Fixed refactoring bug in SOUNDLAB.SAMPLING:SAMPLE-GRAPH.<commit_after>;;;; Export sampling results to Gnuplot compatible graph data files.

(in-package :soundlab.sampling)

(defparameter *graph-output-format* "~8f ~8f~%"
  "Gnuplot compatible representation for samples.")

(defun sample-graph (function length frequency stream)
  "Sample FUNCTION from zero to LENGTH with FREQUENCY and write it to
STREAM as a Gnuplot compatible data file."
  (let ((samples (sample-function function length frequency)))
    (loop for (x-value . y-value) across samples
       do (format stream *graph-output-format* x-value y-value))
    samples))

(defun export-graph (function length frequency path
			      &key (if-exists :error))
  "Direct output of SAMPLE-GRAPH to PATH. If PATH already exists use
IF-EXISTS to control behaviour, default is :ERROR."
  (with-open-file (out path
		       :direction :output
		       :if-exists if-exists)
    (sample-graph function length frequency out)))
{'fraction_non_alphanumeric': 0.09833506763787721, 'fraction_numerical': 0.002081165452653486, 'mean_word_length': 3.918158567774936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256035', 'n_tokens_mistral': 576, 'n_tokens_neox': 540, 'n_words': 211}