{"id":21,"date":"2026-11-26T21:46:02","date_gmt":"2026-11-26T21:46:02","guid":{"rendered":"https:\/\/joshjh.tech\/?p=21"},"modified":"2026-11-26T21:46:02","modified_gmt":"2026-11-26T21:46:02","slug":"classcharts-to-oracle-pipeline","status":"publish","type":"post","link":"https:\/\/joshjh.tech\/?p=21","title":{"rendered":"From ClassCharts to Oracle: anatomy of an automated school-data pipeline"},"content":{"rendered":"<p><em>How a parent-portal feed with no API becomes a queryable Oracle table \u2014 via a browser agent, a normaliser that runs inside the page, a Postgres staging database in Docker, and a small batch bridge into an OCI Autonomous Database.<\/em><\/p>\n<h2>The short version<\/h2>\n<pre><code>ClassCharts parent portal (SPA, no API)\n  \u2192 OpenClaw browser agent harvests the rendered Activity feed\n  \u2192 normalise in-page to 17 columns\n  \u2192 data\/activity-normalized.{json,csv}\n  \u2192 python\/load_activity.py\n  \u2192 Postgres \"mydb\" on orzo (docker staging)\n  \u2192 sync_classcharts_activity.py\n  \u2192 Oracle ADB, schema FOON_DETECT<\/code><\/pre>\n<p>Every stage is idempotent, every stage has a gate, and the part that runs unattended is deliberately boring: one agent, one run-book, three plain commands.<\/p>\n<h2>1. The problem: a feed, not an API<\/h2>\n<p>ClassCharts&#8217; parent portal is a mobile-style single-page app. There is no supported API key, no CSV export and no paginated endpoint we can call. What exists is a rendered <strong>Activity<\/strong> feed under a hash route:<\/p>\n<pre><code>https:\/\/www.classcharts.com\/mobile\/parent#&lt;pupilId&gt;,behaviour<\/code><\/pre>\n<p>Everything the pipeline needs is visible text in that feed: a day heading, a signed points bubble, a sentence naming the award or detention, an optional comment, and a trailing time. The browser is therefore not a workaround bolted onto an API \u2014 it <em>is<\/em> the data source.<\/p>\n<p>Authentication is handled once, by hand. The agent drives a managed Chromium profile whose cookies survive browser restarts, so a logged-in session persists. Credentials never enter the repository, a script, a log, or a prompt. If the portal shows a login form during an unattended run, the run stops rather than guessing.<\/p>\n<h2>2. Reading the feed<\/h2>\n<h3>Opening the right view<\/h3>\n<p>After login the app lands on <code>\/mobile\/parent<\/code>. Because it is hash-routed, the agent deep-links straight to the pupil&#8217;s behaviour section instead of clicking through the dashboard. No brittle element ids, no coordinate clicking.<\/p>\n<h3>Setting the window<\/h3>\n<p>The date range uses a Material-UI picker with a <strong>read-only<\/strong> range field. Typing into it fails by design; the field only opens a calendar. The picker is driven by month label and day number, and the dates are computed at run time \u2014 the start is a fixed parameter, the end is the machine&#8217;s current date:<\/p>\n<pre><code>const startISO = '2026-05-01';\nconst endISO   = iso(new Date());   \/\/ end of window = today<\/code><\/pre>\n<p>Month arrows are unnamed SVG icon buttons, so they are clicked through the DOM, not through accessibility refs. One subtle bug is worth recording: while the calendar slides between months, the header contains <em>both<\/em> the outgoing and incoming month, separated by a newline. Parsing the whole string makes the navigation compare against the wrong month and overshoot. Taking the first non-empty line fixes it.<\/p>\n<p>After applying, the script asserts that the header matches the expected range and day count. A mismatch means a click landed in the wrong month, and the run stops.<\/p>\n<h3>Harvesting an infinite scroll<\/h3>\n<p>The Activity feed is not paginated. Ten rows load per scroll and the document grows by roughly 1,500 px each time. The harvest loop extracts every <code>.activity-entry<\/code>, scrolls to the bottom, waits, and repeats until the page height stops growing twice in a row. Rows accumulate in a page-level object keyed by <code>iso|time|value|text<\/code>, which makes re-extraction idempotent.<\/p>\n<p>The completion gate is simple and strong: the number of collected rows must equal the number of <code>.activity-entry<\/code> nodes in the DOM. If they differ, the dedupe key has collapsed real rows and the run must not continue.<\/p>\n<h3>Interpreting a row<\/h3>\n<ul>\n<li><strong>Day heading:<\/strong> the nearest preceding <code>h6<\/code> that is <em>outside<\/em> any activity entry. Inside a row, <code>h6<\/code> is the pupil&#8217;s name \u2014 a trap that silently corrupts a naive selector.<\/li>\n<li><strong>Points bubble:<\/strong> the leaf element whose text matches a signed integer.<\/li>\n<li><strong>Polarity:<\/strong> read from the bubble&#8217;s computed background colour \u2014 green <code>rgb(126,215,93)<\/code> positive, red <code>rgb(255,74,81)<\/code> negative, otherwise neutral. Polarity is not inferred from the sign of the number, although the two agree on every row seen so far.<\/li>\n<li><strong>Time:<\/strong> the trailing <code>HH:MM<\/code>; the row&#8217;s <code>time[datetime]<\/code> attribute provides the exact instant.<\/li>\n<\/ul>\n<h3>Three data quirks that must be handled before storage<\/h3>\n<ol>\n<li><strong>Detentions lie about time.<\/strong> On a detention row, <code>time[datetime]<\/code> is not the event instant \u2014 it is the detention&#8217;s scheduled slot. The calendar date must come from the day heading, and the due date\/time must be parsed from the row&#8217;s inner <code>Date:<\/code>\/<code>Time:<\/code> fields.<\/li>\n<li><strong>Notes have no bubble.<\/strong> Rows that say a teacher &#8220;left a note&#8221; carry no points element. The correct value is <code>NULL<\/code>, not zero.<\/li>\n<li><strong>The portal returns one extra day.<\/strong> A window starting 1 May includes 30 April. That is the app&#8217;s inclusive behaviour, not a parsing error. The loader accepts it; strictness can be applied with a filter if ever needed.<\/li>\n<\/ol>\n<h2>3. Normalising inside the page<\/h2>\n<p>Rather than dumping flat text and reparsing it later, the normaliser runs in the page and walks the Activity section in document order, carrying the day heading forward. Each row yields 17 columns:<\/p>\n<pre><code>pupil_id  pupil  activity_date  activity_time  event_at  points  polarity\nkind  reason  teacher  class_group  comment\ndetention_location  detention_type  detention_due_date  detention_due_time\nraw_text<\/code><\/pre>\n<p>Sentences are parsed by grammar, not by position:<\/p>\n<table>\n<thead>\n<tr>\n<th>Rendered pattern<\/th>\n<th>kind<\/th>\n<th>reason<\/th>\n<th>teacher<\/th>\n<th>class<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>&lt;Award&gt; awarded by &lt;Teacher&gt; in &lt;Class&gt;.<\/code><\/td>\n<td>award<\/td>\n<td>award name<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td><code>&lt;Award&gt; awarded by &lt;Teacher&gt;.<\/code><\/td>\n<td>award<\/td>\n<td>award name<\/td>\n<td>yes<\/td>\n<td>null<\/td>\n<\/tr>\n<tr>\n<td><code>Detention issued for &lt;Cause&gt; in &lt;Class&gt; by &lt;Teacher&gt;<\/code><\/td>\n<td>detention<\/td>\n<td>cause<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td><code>Detention issued for &lt;Cause&gt; by &lt;Teacher&gt;<\/code><\/td>\n<td>detention<\/td>\n<td>cause<\/td>\n<td>yes<\/td>\n<td>null<\/td>\n<\/tr>\n<tr>\n<td><code>&lt;Teacher&gt; left a note.<\/code><\/td>\n<td>note<\/td>\n<td>&#8220;Note&#8221;<\/td>\n<td>yes<\/td>\n<td>null<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Detention detail blocks yield location, type, due date and due time. The trailing period on class codes is stripped; everything else stays verbatim. <code>raw_text<\/code> is the untouched row text, retained for audit and re-parsing \u2014 it is also what makes the dedupe hash stable.<\/p>\n<p>The latest verified harvest (25 November 2026) produced <strong>177 rows<\/strong> spanning 30 April to 25 November, with zero rows missing a teacher or reason and kind counts summing to the row count.<\/p>\n<h2>4. Staging in Postgres<\/h2>\n<p>The landing zone is the <code>mydb<\/code> database on the LAN host <code>orzo<\/code>, a Docker-hosted Postgres. Keeping a staging copy has three practical benefits: the browser session and the Oracle wallet never have to be live at the same moment; a bad harvest can be inspected without touching the reporting database; and the loader can be re-run as often as needed without writing to Oracle.<\/p>\n<h3>Schema with real constraints<\/h3>\n<p>The table is not a generic dumping ground. Its constraints encode rules learned from the source:<\/p>\n<ul>\n<li><code>polarity<\/code> is limited to positive, negative or neutral.<\/li>\n<li><code>kind<\/code> is limited to award, detention or note.<\/li>\n<li>Points may be null <em>only<\/em> for notes (there is no bubble to read).<\/li>\n<li>Non-detention rows must have all four detention fields null; detentions must have a due date.<\/li>\n<li><code>source_hash<\/code> must be 32 lowercase hex characters, unique per pupil.<\/li>\n<\/ul>\n<p>Two indexes cover the obvious access paths: pupil plus date descending, and pupil plus kind plus date. Column comments document where each value came from, including the awkward ones (detention due slot versus issue instant).<\/p>\n<h3>Idempotency that is actually tested<\/h3>\n<p>The loader computes:<\/p>\n<pre><code>source_hash = md5( event_at in UTC  +  \\x1f  +  raw_text )<\/code><\/pre>\n<p>and inserts with:<\/p>\n<pre><code>ON CONFLICT (pupil_id, source_hash) DO NOTHING\nRETURNING id<\/code><\/pre>\n<p>Every harvest re-reads a whole window, so most rows on a later run already exist. The loader reports <code>inserted<\/code> and <code>skipped<\/code> separately, and the apply step runs the loader <strong>twice<\/strong>: the second run must insert zero rows. If it inserts anything, the hash is unstable and the pipeline stops. That is a stronger guarantee than &#8220;it looked fine once&#8221;.<\/p>\n<h3>Chunked transport out of the browser<\/h3>\n<p>A single evaluate call returning the full normalised array is around 20 KB and gets truncated. The rows are therefore sliced into 43-row chunks, each written to <code>data\/.parts\/norm-N.json<\/code>, then merged by a Python subcommand that also enforces the gates: row count, unique hashes, <code>raw_text<\/code> present, 17 CSV columns, day heading agreeing with <code>activity_date<\/code>, and kind counts summing correctly. Only after those hold are the JSON and CSV artefacts written.<\/p>\n<p>A dry run inserts inside a transaction, reports counts, then rolls back via a sentinel exception. A real run commits. Both paths validate the same invariants first.<\/p>\n<h2>5. Transporting to Oracle<\/h2>\n<p>The reporting target is an Oracle Autonomous Database, schema <code>FOON_DETECT<\/code>, where the data feeds an APEX application. The bridge is a standalone Python script in the APEX repository, deliberately separate from the harvester.<\/p>\n<h3>Reading from Postgres<\/h3>\n<p>The script opens a named server-side cursor and reads <code>classcharts_activity<\/code> ordered by <code>id<\/code>, in batches of 500. A server-side cursor matters: the source table grows, and the bridge should not try to hold the whole history in memory.<\/p>\n<h3>Writing to Oracle<\/h3>\n<p>For each batch it executes an insert-only <code>MERGE<\/code>:<\/p>\n<pre><code>merge into foon_detect.classcharts_activity target\nusing (select :source_id source_id, ... from dual) source_row\non (target.source_id = source_row.source_id)\nwhen not matched then insert (...);<\/code><\/pre>\n<p>The Postgres identity <code>id<\/code> is carried across as Oracle&#8217;s <code>source_id<\/code> primary key. That single decision makes the whole bridge idempotent: a row that already exists is ignored, and a row that was never copied is inserted. There is no update path, so a repeated full scan cannot rewrite history.<\/p>\n<h3>Type mapping is where these projects usually break<\/h3>\n<ul>\n<li>Postgres <code>date<\/code> becomes an Oracle <code>DATE<\/code> at midnight.<\/li>\n<li>Oracle has no <code>TIME<\/code> type, so <code>activity_time<\/code> and <code>detention_due_time<\/code> are stored as <code>varchar2(32)<\/code> in ISO form.<\/li>\n<li><code>event_at<\/code> and <code>harvested_at<\/code> map to <code>timestamp with time zone<\/code>.<\/li>\n<li><code>comment<\/code> is renamed <code>activity_comment<\/code> (the original name is reserved-ish in practice and confusing next to other comments).<\/li>\n<li>Free-text fields are <code>CLOB<\/code>, and the cursor declares those input sizes explicitly so the driver binds them correctly.<\/li>\n<\/ul>\n<p>The Oracle table mirrors the Postgres uniqueness rule with <code>unique (pupil_id, source_hash)<\/code>, in addition to the <code>source_id<\/code> primary key. If the same logical row somehow arrives twice under different source ids, Oracle refuses it.<\/p>\n<h3>Why a full scan every time<\/h3>\n<p>Copying &#8220;only ids greater than the last one seen&#8221; looks efficient but is wrong under concurrent commits: a transaction with a lower id can commit after a higher one was already read, and the row is missed forever. The bridge therefore scans everything, ordered by id, and lets the merge discard what is already there. At this data volume the cost is trivial; the correctness is not.<\/p>\n<p>Credentials follow the same discipline as the rest of the project: Postgres from the gitignored two-line file, Oracle from an environment variable or the desktop Secret Service keyring, with a wallet and Instant Client in thick mode. Nothing is printed, and <code>--dry-run<\/code> counts pending rows without writing.<\/p>\n<h2>6. The automation: OpenClaw as the operator<\/h2>\n<p>The harvest is scheduled as an OpenClaw automation named <strong>Classcharts fetch<\/strong>. Its shape matters more than its schedule:<\/p>\n<ul>\n<li><strong>Agent:<\/strong> a dedicated <code>classcharts<\/code> agent, not the main assistant.<\/li>\n<li><strong>Session:<\/strong> isolated, so every run starts with a clean context and cannot drift into unrelated work.<\/li>\n<li><strong>Schedule:<\/strong> every 5 days \u2014 frequent enough to keep the window fresh, sparse enough not to hammer a school portal.<\/li>\n<li><strong>Model:<\/strong> a small, fast model; the intelligence is in the run-book, not in improvisation.<\/li>\n<li><strong>Delivery:<\/strong> none. The run records its own status; it does not announce itself.<\/li>\n<\/ul>\n<h3>The prompt is an operating procedure<\/h3>\n<p>The automation message does not say &#8220;scrape ClassCharts&#8221;. It names the repository, the reading order (<code>AGENTS.md<\/code>, then the harvest run-book), and the exact stages: open the portal, confirm the session, deep-link to behaviour, set the computed date range, scroll to exhaustion, run the stage-5 normaliser verbatim, export in 43-row chunks, then run three commands:<\/p>\n<pre><code>python3 python\/harvest_tools.py merge\npython3 python\/load_activity.py --dry-run\npython3 python\/harvest_tools.py apply<\/code><\/pre>\n<p>It also defines success and failure in machine-checkable terms: a login page means stop; a header mismatch means stop; <code>apply<\/code> must report a second run with zero inserts; if nothing new was inserted, reply with silence rather than a notification.<\/p>\n<h3>The command contract exists because nobody is watching<\/h3>\n<p>This is the least obvious and most important design constraint. The agent runs unattended, so a command that lands in an approval prompt is a failed run. The run-book therefore forbids:<\/p>\n<ul>\n<li><code>cd repo &amp;&amp; ...<\/code> chains, <code>;<\/code>, <code>||<\/code>, pipes, redirects and heredocs;<\/li>\n<li>inline environment prefixes such as <code>VAR=x cmd<\/code>;<\/li>\n<li>ad-hoc scripts written at run time.<\/li>\n<\/ul>\n<p>One plain command per call, with the working directory passed as a parameter. New logic goes into <code>harvest_tools.py<\/code> as a subcommand, where it can be reviewed and reused. The result is a pipeline shaped by the permission model rather than fighting it: every step is a single allowlisted invocation, and the run never needs a human to click approve.<\/p>\n<h3>What a run actually looks like<\/h3>\n<p>At the time of writing the automation&#8217;s last run was <strong>25 November 2026<\/strong>, status <strong>ok<\/strong>, duration about <strong>161 seconds<\/strong>, next run in four days. That run produced the 177-row harvest described above. The first full load, on 16 November, landed 170 rows covering 1 May to 16 November: 138 awards, 28 detentions and 4 notes.<\/p>\n<h2>7. What is automated, and what is not<\/h2>\n<p>Being precise about the boundary is worth more than a tidy diagram:<\/p>\n<ul>\n<li><strong>Automated:<\/strong> opening the portal, confirming the session, setting the range, harvesting, normalising, merging, dry-running, loading into Postgres, proving idempotency, writing a one-line run note.<\/li>\n<li><strong>Not automated:<\/strong> the Postgres \u2192 Oracle bridge. <code>sync_classcharts_activity.py<\/code> is run on demand, with a dry run first. Nothing schedules it today.<\/li>\n<li><strong>Human, once:<\/strong> the initial portal login. The managed browser profile keeps the session afterwards.<\/li>\n<\/ul>\n<p>So the current end-to-end story is &#8220;scheduled harvest into staging, deliberate transport into Oracle&#8221;. That is a defensible split while the Oracle side is still being shaped, but it is a split: if the bridge is meant to be hands-off, it needs its own step in the automation (after <code>apply<\/code>) or a second job with its own schedule. Until then, a green automation status only proves that staging is current.<\/p>\n<h2>8. Failure modes worth knowing<\/h2>\n<p>The run-book carries a &#8220;traps already paid for&#8221; section, and it earns its place:<\/p>\n<ul>\n<li>Browser refs renumber after a restart; never persist them across calls.<\/li>\n<li>The calendar&#8217;s month arrows have no accessible name; the range input is read-only.<\/li>\n<li>The month label contains two months mid-transition; parse the first line.<\/li>\n<li>Inside a row, <code>h6<\/code> is the pupil&#8217;s name; only an <code>h6<\/code> outside an entry is a day heading.<\/li>\n<li>Detention rows put the scheduled slot in the inner fields; the row timestamp is the issue instant.<\/li>\n<li>A hand-written 16-column CSV projection once failed the load because it dropped <code>raw_text<\/code>; the merge now fixes the column list in one place.<\/li>\n<li>Hard-coded calendar months rot. The picker is driven from computed dates, and the run-book records that it previously contained a hard-coded November 2026.<\/li>\n<\/ul>\n<p>Two operational gaps are worth stating plainly. First, the automation prompt still says to expect the range to end on 16 November 2026, while the run-book computes &#8220;today&#8221;; the agent copes, but the prompt is stale and should be updated. Second, delivery is set to none, so a failed run does not notify anyone \u2014 the failure lives in <code>lastRunStatus<\/code>\/<code>lastError<\/code> until someone looks. For a pipeline that is supposed to be autonomous, adding a failure notification is probably the next small win.<\/p>\n<h2>9. Why this design holds together<\/h2>\n<p>Three decisions do most of the work:<\/p>\n<ol>\n<li><strong>Normalise as close to the source as possible.<\/strong> The page knows what a points bubble, a day heading and a detention block are. Doing that work in the page avoids shipping a fragile text parser downstream.<\/li>\n<li><strong>Make every layer idempotent for its own reasons.<\/strong> Postgres dedupes on a content hash; Oracle dedupes on the source primary key. The full re-read at each layer is safe because the writes are insert-only.<\/li>\n<li><strong>Treat the unattended agent as a constrained executor.<\/strong> The run-book, the command contract and the gates exist so a small model can succeed without judgement calls \u2014 and fail loudly when the page changes.<\/li>\n<\/ol>\n<p>The result is not glamorous: a browser, a spreadsheet-shaped table, a second table in a second database, and a scheduler. But it turns a feed that only exists while someone is logged in into history that can be queried, charted and trusted \u2014 which is the whole point.<\/p>\n<p><em>Privacy note: the harvested artefacts contain a real pupil&#8217;s school records. <code>data\/<\/code> is gitignored, only aggregate counts appear in run reports, and no pupil identifiers or credentials are reproduced here.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A browser-only school portal becomes a queryable Oracle table: harvest with an OpenClaw agent, normalise in-page, stage in Docker Postgres, then bridge idempotently into an OCI Autonomous Database.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":0,"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}