Skip to content

Commit 47e2df7

Browse files
committed
Add plotting functionality and validation for summary figures
- Implemented `plot_summary.py` to generate a summary figure with fixed, invented counts using Matplotlib. - Created `check_figure.py` to validate the generated PNG against specified requirements. - Added `plot_summary.R` for R-based plotting with similar functionality. - Developed tests in `run_tests.R` and `test_plot_summary.py` to ensure correctness of plotting and CLI behavior. - Introduced `requirements-plotting.txt` to specify Matplotlib dependency.
1 parent 18aed2e commit 47e2df7

81 files changed

Lines changed: 1662 additions & 4901 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: lab-r-refactor
3+
description: Refactor an existing R script into the lab format with metadata, emoji section headings, readable code, and explanatory comments while preserving its behavior. Use for requests to organize or format R scripts.
4+
---
5+
6+
# Refactor an R script into the lab format
7+
8+
Before editing, read the [lab R template](references/lab-r-template.md). Use its examples to organize the script.
9+
10+
Work from source code and invented examples. Do not inspect data tables or participant records, and do not diagnose individual data points. If a check needs study data, report it as not run.
11+
12+
## Procedure
13+
14+
1. Read the requested script and applicable repository instructions. Identify its arguments, dependencies, calculations, validation, outputs, and existing checks. Save an unchanged copy in permitted scratch space for comparison.
15+
2. Add or tidy the metadata header. Preserve existing authorship, creation dates, and other recorded history. Use `Not recorded` for unknown values; do not infer authorship from the repository owner or use today's date as a creation date. Describe only what the script actually does.
16+
3. Organize the code using only applicable sections from the local template. Add one relevant emoji to each section-heading comment, such as `⚙️ Constants`, `📊 Plotting function`, or `▶️ Command-line arguments`. Keep the words so headings remain clear without the symbol. Use emojis only in comments, never in strings, object names, chart text, or console output. Keep execution order and scope intact. Use two-space indentation, consistent spacing, readable line breaks, and descriptive names where safe. Add short comments explaining intent or a non-obvious decision; avoid narrating each expression.
17+
4. Preserve the script's behavior: argument interface, dependencies, calculations, validation, output contents and formatting, stdout, stderr, and exit status. Do not redirect data from `cat()` or `write.table()` to `message()`. Do not add packages, dependency installation, `optparse`, flags, logging, timestamps, `sessionInfo()`, new validation, or other functional features unless the user requests them. If you notice a defect, report it separately rather than silently changing the calculation during formatting.
18+
5. Run the available automated checks on the original and candidate with the same invented examples and arguments. Let the verifier compare image contents, stdout, stderr, and exit status; use its pass/fail results. For this repository's optional exercise, run `Rscript examples/r_refactor/verify.R <candidate-script>` from the repository root. Inspect the code diff separately to confirm that organization improved. Passing behavior checks alone does not show that refactoring occurred.
19+
6. For repository work, edit the requested file and report the organization changes, commands actually run, outcomes, and any untested behavior. If the user asks for returned code instead, provide the complete refactored script in an R code block; do not replace that deliverable with file edits. Never imply checks ran when they did not.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Lab R formatting template
2+
3+
Use these header and section examples to organize an R script. This template is inspired by Part 1's R refactoring example. Keep the script's behavior unchanged.
4+
5+
## Header
6+
7+
Use the actual filename and preserve recorded authorship and dates. Write `Not recorded` when that information is unknown. This example describes the plotting exercise:
8+
9+
```r
10+
# ==============================================================================
11+
# Script: plot_summary.R
12+
# Description: Draw a chart from invented aggregate measurement counts.
13+
# Author: Not recorded
14+
# Date: Not recorded
15+
# Input: Fixed category labels and counts defined in the source code.
16+
# Output: A PNG chart at the requested output path.
17+
# ==============================================================================
18+
```
19+
20+
## Sections and formatting
21+
22+
Give each useful section a small visual marker: `⚙️ Constants`, `📊 Plotting function`, or `▶️ Command-line arguments`. Keep the descriptive words and omit empty sections. Put emojis in comments only; preserve strings, object names, chart text, and console output. Save the script as UTF-8 and keep execution order unchanged.
23+
24+
```r
25+
# --- ⚙️ Constants -------------------------------------------------------------
26+
# Keep the supplied category order so before/after charts remain comparable.
27+
counts <- rbind(
28+
"Group A" = c(42, 31, 18, 9),
29+
"Group B" = c(64, 18, 12, 6)
30+
)
31+
32+
# --- 📊 Plotting function -----------------------------------------------------
33+
# Keep the existing plotting calls here, with readable spacing and line breaks.
34+
35+
# --- ▶️ Command-line arguments ------------------------------------------------
36+
args <- commandArgs(trailingOnly = TRUE)
37+
```
38+
39+
These snippets show organization, not a replacement implementation. Keep the requested script's own values, plotting calls, validation, messages, and output handling. Do not add logging, packages, or session information just to fill a section.

‎.agents/skills/pipeline-review/SKILL.md‎

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: plot-review
3+
description: Review a plotting repair against its code contract, tests, and rendered chart. Use when asked to check plotting changes; do not inspect participant records or diagnose data points.
4+
---
5+
6+
Read `AGENTS.md`, `docs/reference/io_contract.md`, `docs/reference/figure-specifications.md`, the requested source diff, and the selected language's test code. Review `plotting/plot_summary.py` or `plotting/plot_summary.R`.
7+
8+
Check that the repair keeps the four category labels and group assignments unchanged: Group A counts are 42, 31, 18, 9; Group B counts are 64, 18, 12, 6. Preserve category order and show Group A above Group B within each category. Trace plotting options, function calls, and output handling. Do not open data tables, participant records, or study logs, and do not explain why an individual value failed.
9+
10+
When tools permit, run `python -m unittest discover -s plotting/tests` or `Rscript plotting/tests/run_tests.R` and use the pass/fail evidence. Run the selected language's `plotting/check_figure.py` or `plotting/check_figure.R` with `--output` and an ignored PNG path when execution is permitted. The starter intentionally fails this stricter acceptance check. Inspect the rendered chart against every fictional journal requirement, including grouping, legend, and full readable labels. Record image inspection as untested when image tools are unavailable. A passing test suite alone does not establish visual quality.
11+
12+
Review accessibility explicitly: black text on white, visible bar outlines, readable labels at the intended size, and group identification that survives grayscale. Read `runs/with-fix/summary.alt.txt` and compare its group names, values, and summary with the invented constants and chart. Check that the description will be attached when the image is used; a sidecar file alone does not provide screen-reader access. Record visual or assistive-technology checks that were unavailable.
13+
14+
Return concrete findings with source locations, expected behavior, and observed behavior. Separate code/test findings from visual and accessibility observations. Do not modify files during a review unless asked. Report commands actually run and any checks left unrun.

‎.codex/agents/pipeline-reviewer.toml‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎.codex/agents/plot-reviewer.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = "plot-reviewer"
2+
description = "Review plotting code, test evidence, and the rendered chart without inspecting participant data."
3+
sandbox_mode = "read-only"
4+
developer_instructions = """
5+
Read AGENTS.md and use .agents/skills/plot-review/SKILL.md in the target repository.
6+
Review source code, tests, and the chart made from invented summary counts.
7+
Do not inspect data tables, participant records, or study logs.
8+
Report code findings and visual observations separately, with actual check results.
9+
Do not edit files. If permissions prevent execution or image inspection, report
10+
which supplied evidence you reviewed and which checks remain unrun.
11+
"""

‎.codex/agents/r-refactorer.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "r-refactorer"
2+
description = "Refactor an existing R script into the lab format while preserving its results and command-line behavior."
3+
developer_instructions = """
4+
Use the shared lab-r-refactor skill at .agents/skills/lab-r-refactor/SKILL.md
5+
in the target repository; read that file before editing.
6+
Follow applicable repository instructions and the user's requested scope.
7+
For repository work, edit the requested R file, inspect its diff, and report
8+
changes and checks. If the user requests returned code, provide that deliverable.
9+
Keep the formatting procedure in the shared skill rather than duplicating it here.
10+
"""

‎.github/copilot-instructions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
Read `AGENTS.md` for the shared repository instructions and `REPO_MAP.md` for
44
entrypoints. Follow those files when implementing, testing, or documenting a change.
55

6-
Use only synthetic examples. Keep generated runs ignored by Git, whether they use
7-
the default `runs/` directory or another explicitly requested `--runs_dir`.
6+
Use only the invented aggregate examples. Keep generated images in ignored `runs/`
7+
or `tmp/` directories. Explore source code and charts, not participant records.
88
After behavioral changes, run the checks in `AGENTS.md` and report the actual results.

‎.github/instructions/python_pgacg.instructions.md‎

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
applyTo: "plotting/**/*.py"
3+
---
4+
5+
Keep plotting functions small and the invented category labels and counts unchanged.
6+
Use the standard-library unittest checks in plotting/tests.
7+
Inspect the rendered chart separately; test success does not prove readable layout.
8+
Do not inspect participant data or diagnose individual records.

0 commit comments

Comments
 (0)