Batch Trend-Chart Capture with Local Color Recognition
Repetitive trend-chart collection fails less from missing clicks than from layout drift, popups, visual misreads, and rework. This article describes a pipeline that captures trusted screenshots in the browser, converts known color blocks to numbers locally, interprets those numbers with a versioned algorithm dictionary, and aggregates only structured results—without treating a conversational agent as the production reader.
Repetitive trend-chart collection looks like “open the page, search, screenshot, read values, and summarize.” What actually consumes time is layout drift, popup interference, visual misreads, and repeated rework. If every step is left to a conversational agent improvising in the moment, the system often rewrites the same step in a new way and still cannot reproduce it reliably. A steadier approach is to treat the flow as a data pipeline: the browser only obtains a trusted image, a local program turns known color blocks into numbers, an algorithm dictionary interprets those numbers, and the statistics module consumes only structured results.
Draw the automation boundary first
A target is suitable for automation when four conditions hold: the entry URL is stable, search criteria can be parameterized, chart colors are discrete and have fixed meanings, and results can be expressed as a table or matrix. If the page is redesigned often, chart colors change randomly with the theme, or reading depends on complex semantics, a one-off script should not be expected to remain valid forever.
Split the chain into independent stages, and define inputs, outputs, and failure signals for each:
- Session setup: sign in, open the target section, and confirm that key regions are visible.
- Filtered search: submit the query by date, category, or another dimension, and verify the result-page marker.
- Image capture: screenshot the main chart and any comparison views at a fixed viewport, and save resolution and source parameters.
- Matrix recovery: count color blocks inside predetermined coordinates or contours, and produce a numeric matrix.
- Rule calculation: interpret the matrix with a versioned algorithm dictionary and emit metrics.
- Aggregate checks: verify counts, nulls, duplicates, and abnormal distributions before archiving.
Stages pass only files and structured data. A later stage must not reread an earlier stage’s natural-language logs. When one stage fails, rerun that stage instead of discarding the whole job.
Confirm page state; do not click blindly
Sign-in and search failures usually come from unobserved page state, not from a missing click. There may be several similar search fields, overlays may appear late, and captchas, consent dialogs, or ad layers can change the clickable area. An agent that writes selectors from a single snapshot can hit the wrong element or even close the window.
Page actions should be an explicit state machine. Each state has entry conditions, allowed actions, and exit conditions. “Search page ready,” for example, requires all of the following: a signed-in marker is present, the search field accepts input, the target result container is visible, and overlays are gone. After an action, read the state again. Sending a click is not the same as success.
A schematic wait-and-close flow:
wait for element(search box, timeout=T)if overlay exists:click only the pre-marked close regionconfirm the search box is still visiblefill(query)submit searchassert(result-page marker == expected value)save screenshot and metadata at a fixed viewport
Prefer stable semantic attributes for selectors, and keep a manual review path. At nodes that require human judgment, such as a captcha, pause and record the scene instead of clicking in a loop. Limit popup dismissal to a known container. If a key element disappears after closing, roll back to the last confirmed state. Log timeouts, retry counts, and screenshot evidence so slow networks, page redesigns, and script errors can be distinguished.
Standardize screenshots as well: fixed zoom, window size, and scroll position, plus query parameters and capture time. Downstream recognition should accept only images that match the agreed size, so an unfinished frame is never sent into calculation.
Visual reading: decide whether a model is actually required
When a chart uses a small, stable set of colors for categories or states, sending every screenshot to a general multimodal model is usually a poor trade. The model must interpret the whole image and is easily misled by anti-aliasing, compression noise, legend text, and background gradients, so it misreads adjacent colors or similar digits. Call volume grows linearly with image count, so batch cost is hard to bound. Output is probabilistic: the same image can yield different matrices, which is a weak production source.
A better path is to turn the business legend into a color dictionary. Capture one sample that a person has confirmed, sample colors inside the target grid, record a channel range for each color, then count pixels across the image. Local calculation does not depend on an external network. Rules decide the result, so the same input should produce the same output.
load imagesplit into grid cellsfor each cell:count pixels that fall in each color rangeif the dominant color share exceeds the threshold, record that categoryotherwise record unknown and keep the coordinatesemit the matrix, the unknown-cell list, and the sample version
Thresholds, grid origin, cell size, and color ranges belong in configuration, not in a chat transcript. Leave enough tolerance for compression and rendering differences, but too much tolerance will merge two business colors. Before release, regress on samples that include boundary colors, blank charts, occlusion, and legend changes. Mark unknown cells and send them to a person rather than forcing a value.
If the chart depends on continuous curves, text labels, or complex shapes, pixel counts are not enough. First check whether values can come from a page API, an export file, or an accessible data table. When raw data is available, do not infer it from a screenshot. Local recognition is reasonable only when the image is the sole source and the visual pattern is stable. Multimodal models fit exploratory checks or anomaly sampling, not a metering step that every image must pass.
Separate recognition from calculation with an algorithm dictionary
A matrix records visual categories; it is not a business conclusion. Keep an algorithm dictionary in the middle layer. Each version states input dimensions, category codes, formulas, missing-value handling, and the effective date. Upgrading the recognizer does not change formulas; changing formulas does not change sampling parameters. Results must carry the dictionary version, the sample version, and the original screenshot index so they can be replayed later.
Before aggregation, run four checks: the task list matches the file count, matrix dimensions match, the unknown-value ratio stays within the agreed limit, and key metrics fall in a historically reasonable range. On failure, keep the original images and intermediate matrices. Do not write incomplete results into the official report.
Break the correct–forget–repeat cycle
Telling an agent about an error in chat does not create an executable rule. As context grows, older constraints are diluted by newer instructions. On the next regeneration, the agent may remember the symptom but not the trigger or the acceptance criteria, so fixing one place breaks another.
Switch collaboration to artifact-driven work:
- Describe state, inputs, outputs, prohibitions, and the definition of done in a short spec. Do not stack contradictory patches in a long conversation.
- Turn each defect into a minimal reproduction and an assertion, such as “when an overlay is present, do not click the page close button” or “when the dominant-color share is too low, output unknown.”
- Run the existing samples before changing code. After a change, the full set must pass—not only the latest image.
- Manage selectors, color ranges, grid parameters, and algorithm versions separately, and record why each change was made.
- Limit the scope of a single edit. Sign-in, capture, recognition, and calculation are different modules. Do not rewrite the whole chain at once.
- Review agent diffs. Reject large unexplained replacements and deletions of assertions.
When the same failure repeats, stop asking follow-up questions. Shrink the input, fix random factors, and locate the fault manually. Agents are useful for drafting boilerplate and adding tests. They should not own production logic without a regression set.
Running, cost, and maintenance
Schedule work in batches by query dimension and keep checkpoints, so one failure among hundreds of images does not force a full restart. Store raw screenshots, matrices, and summaries in separate layers, with retention periods. Logs should record location, duration, retries, and exception type—not passwords or full session data. Keep account credentials in a separate secret store. Do not put plaintext secrets in the script repository.
The main cost of local recognition is building and maintaining samples, not a per-image fee. It assumes stable colors and layout. After a redesign, a palette change, or a display-scale change, old parameters fail, so sample checks belong in routine work. A multimodal spot check can compare a small sample with local results, but a deviation is only an alert. Final judgment still rests on human confirmation and rule regression.
Monitor at least capture success rate, unknown-cell ratio, task duration, and result latency. A sudden rise in unknowns usually means misaligned screenshots, a theme-color change, or invalid grid parameters. Pause ingestion instead of automatically widening thresholds.
Order of rollout
Do not start with “one agent does every step.” Manually confirm a minimal loop first: one sign-in, one query, one standard screenshot, one correct matrix, and one summary. Then harden, in order, the popup state machine, screenshot metadata, color configuration, algorithm versions, and regression samples. When adding a dimension, extend the samples before extending the code.
After that, people stop reading charts one by one and instead maintain rules, sample anomalies, and explain business changes. Reliability does not depend on how well a model performs once. It depends on whether the same input repeatedly yields the same traceable result.
