Research Labs

2026-09-17 20:37 UTCopen field data · live

cron/clients/_base.php

Snapshot 2026.09.17-a2894de (current) · 21 lines · 1,233 bytes · tree · plain text

SHA-256 257302304e0e6b90bef9aac3d078a717cb873aeecf62843ad62299e2db425c8f
Functions: ingest_reading L3-L21
1<?php
2/* Shared ingest helpers for vendor clients. */
3function ingest_reading(string $streamCode, string $ts, float $value, string $rawPath='', string $rawBody='', string $srcUrl=''): void {
4 $s=stream_by_code($streamCode); if(!$s) return;
5 if($rawBody!==''){
6 $dir=__DIR__.'/../../data/raw/'.date('Y/m/d').'/'.$streamCode;
7 @mkdir($dir,0775,true);
8 $rawPath='data/raw/'.date('Y/m/d').'/'.$streamCode.'/'.date('His').'.json';
9 file_put_contents(__DIR__.'/../../'.$rawPath,$rawBody);
10 db()->prepare('INSERT INTO files_raw(stream_id,path,sha256,bytes,pulled_at,source_url,is_placeholder) VALUES(?,?,?,?,NOW(),?,0)')
11 ->execute([$s['id'],$rawPath,hash('sha256',$rawBody),strlen($rawBody),$srcUrl]);
12 }
13 db()->prepare('INSERT INTO readings(stream_id,ts,value,is_placeholder) VALUES(?,?,?,0)')->execute([$s['id'],$ts,$value]);
14 if($s['mode']!=='live'){
15 db()->prepare("UPDATE streams SET mode='live' WHERE id=?")->execute([$s['id']]);
16 db()->prepare('INSERT INTO events(instrument_id,ts,class,detail,is_public) VALUES(?,NOW(),?,?,1)')
17 ->execute([$s['instrument_id'],'info',$s['label'].': first live data received; placeholder retired']);
18 log_activity('cron','stream_went_live',$streamCode);
19 }
20}
21

Lines can be cited as cron/clients/_base.php L120-L140, platform code 2026.09.17-a2894de; add #L120-L140 to this page's address to highlight them. Source shown for scrutiny of the research platform. All rights reserved. Not offered as installable software.