From 16534fd59143ff3af37350db4c0daa7ba9586640 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:49:43 +0000 Subject: [PATCH 1/2] Reports: read hourly report_HH.db files la_mojo now writes one report database per local hour into the day folder (data/reports/YYYY/MM/DD/report_HH.db) instead of a single report.db. Days recorded earlier keep their report.db; a day during the upgrade has both. - lib/php/db/report_files.php (loaded by ajax_asm.php, added to files.list): lists a day's report files and maps ids. Row ids are per file, so ids sent to the browser are global: id = slot * 10000000 + rowid (slot 0..23 = hour, 24 = legacy report.db) The JavaScript treats ids as opaque, so no JavaScript changes are needed. Report files are never created by the web UI (existence is checked). - getHistoryDay: sessions and "Events by Hours" from all files of the day (legacy file split by hour as before, one node per hourly file). - getHistoryEvents, getBubbleAnalysis, setPermanentBubbles: BID..EID range resolved to its file. - getVideoInfo, getPictureInfo, getFrames: event/video ids resolved to their file; video ids returned as global ids. - getStatus (live log): newest hourly file of the newest day; LSID from a previous hour/day restarts at the beginning of the new file. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- files.list | 1 + lib/ajax_asm.php | 1 + lib/controller/getBubbleAnalysis.php | 8 +- lib/controller/getFrames.php | 7 +- lib/controller/getHistoryDay.php | 125 ++++++++++++++----------- lib/controller/getHistoryEvents.php | 10 +- lib/controller/getPictureInfo.php | 9 +- lib/controller/getStatus.php | 25 ++++- lib/controller/getVideoInfo.php | 14 ++- lib/controller/setPermanentBubbles.php | 8 +- lib/php/db/report_files.php | 74 +++++++++++++++ 11 files changed, 201 insertions(+), 81 deletions(-) create mode 100644 lib/php/db/report_files.php diff --git a/files.list b/files.list index 724afda..6276e8c 100644 --- a/files.list +++ b/files.list @@ -5711,6 +5711,7 @@ ./lib/php/db/user_class.php ./lib/php/db/VS_Object_class.php ./lib/php/db/SQLite_Class.php +./lib/php/db/report_files.php ./lib/php/db/VS_Tree_class.php ./lib/php/db/language_class.php ./lib/php/db/external.php diff --git a/lib/ajax_asm.php b/lib/ajax_asm.php index 17fc5f3..2c5e71a 100644 --- a/lib/ajax_asm.php +++ b/lib/ajax_asm.php @@ -16,6 +16,7 @@ if( $TT_123[0] == '4' ){ }; */ require_once( 'php/db/SQLite_Class.php'); +require_once( 'php/db/report_files.php'); // hourly report_HH.db files + global report ids $DATABASE = new SQLite_DB( $SYSPath . '/lib/controller/data/mysqlitedb.db'); diff --git a/lib/controller/getBubbleAnalysis.php b/lib/controller/getBubbleAnalysis.php index 4057267..6be71c2 100644 --- a/lib/controller/getBubbleAnalysis.php +++ b/lib/controller/getBubbleAnalysis.php @@ -75,9 +75,11 @@ }; if( $UID > 1 && $DTS ){ $DS = date("Y/m/d", $DTS ); - $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$BID} AND `id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); - $LREC = $ZIZI->Query( $QS ); + // BID/EID are global ids of one report file (see report_files.php) + list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID ); + $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$RBID} AND `id`<={$REID} ORDER BY `ts` ASC, `ts_ms` ASC"; + $ZIZI = reportOpenSlot( $DS, $SLOT ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); if( count( $LREC ) ){ foreach( $LREC as $REC ){ $bid = serchInBubbles( $REC ); diff --git a/lib/controller/getFrames.php b/lib/controller/getFrames.php index 493154d..9e08eae 100644 --- a/lib/controller/getFrames.php +++ b/lib/controller/getFrames.php @@ -8,9 +8,10 @@ if( isset( $_GET['sf'] ) ) $START_FRAME = intval( $_GET['sf'] ); if( $VID && $DTS ){ $DS = date("Y/m/d", $DTS ); - $QS = "SELECT * FROM `videos` WHERE `id` = {$VID}"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); - $LREC = $ZIZI->Query( $QS ); + // VID is a global video id (see report_files.php) + $QS = "SELECT * FROM `videos` WHERE `id` = " . reportRawId( $VID ); + $ZIZI = reportOpenSlot( $DS, reportSlotOf( $VID ) ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); if( count( $LREC ) ){ $Data = $LREC[0]; diff --git a/lib/controller/getHistoryDay.php b/lib/controller/getHistoryDay.php index 7f25dc6..6e179d6 100644 --- a/lib/controller/getHistoryDay.php +++ b/lib/controller/getHistoryDay.php @@ -13,6 +13,7 @@ $D = date("d", $DTS ); $DS = date("Y/m/d", $DTS ); $NONO = ''; + $EVEVE = ''; $MUMU = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/stat.db' ); $QS = "SELECT * FROM `days` WHERE `year`={$Y} AND `month`={$M} AND `day`={$D}"; $LOLO = $MUMU->Query( $QS ); @@ -23,71 +24,83 @@ $S = intval( $LOLO[0]['session_count'] ); $V = intval( $LOLO[0]['videos_count'] ); $E = intval( $LOLO[0]['evt_count'] ); - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/' . $DS . '/report.db' ); - $QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE ( `evt_type`=52 OR `evt_type`=53 OR `evt_type`=54 )"; - $NDD = $ZIZI->Query( $QS ); - if( count( $NDD ) ){ - $st_ignore = true; - $DH = 0; - $BID = 0; - $EID = 0; - $BTM = 0; - $JIGA = array(); - foreach( $NDD as $N ){ - if( $st_ignore && $N['evt_type']!=52 ) continue; - if( $st_ignore && $N['evt_type']==52 ) $st_ignore = false; - if( $N['evt_type']==52 ) { - $DH = 0; - $BID = intval( $N['id'] ); - $BTM = date( "H:i:s", $N['ts'] ); - } else { - $DH = 1; - $EID = intval( $N['id'] ); + // One report file per hour (report_HH.db) and/or the legacy day report.db - ids are global (see report_files.php) + $JIGA = array(); + $SIGA = array(); + foreach( reportDayFiles( $DS ) as $SLOT => $RFILE ){ + $ZIZI = new SQLite_DB( $RFILE, SQLITE3_OPEN_READWRITE ); + // Sessions (START=52, END=53/54) - with hourly files a session never spans two files + $QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE ( `evt_type`=52 OR `evt_type`=53 OR `evt_type`=54 ) ORDER BY `id`"; + $NDD = $ZIZI->Query( $QS ); + if( count( $NDD ) ){ + $st_ignore = true; + $DH = 0; + $BID = 0; + $EID = 0; + $BTM = 0; + foreach( $NDD as $N ){ + if( $st_ignore && $N['evt_type']!=52 ) continue; + if( $st_ignore && $N['evt_type']==52 ) $st_ignore = false; + if( $N['evt_type']==52 ) { + $DH = 0; + $BID = reportEncodeId( $SLOT, $N['id'] ); + $BTM = date( "H:i:s", $N['ts'] ); + } else { + $DH = 1; + $EID = reportEncodeId( $SLOT, $N['id'] ); + }; + if( $st_ignore == false && $DH == 1 ){ + $JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }"; + }; }; - if( $st_ignore == false && $DH == 1 ){ + if( $st_ignore == false && $DH == 0 ){ + // Session still open in this file (ongoing, or the file was not closed) - up to the end of the file + $EID = reportEncodeId( $SLOT, REPORT_RAW_ID_MAX ); $JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }"; }; }; - if( $DH == 0 ){ - //Ongoing Event goes next day - must catch up - $QS = "SELECT `id`, `ts`, `evt_type` FROM `events` WHERE `id` > {$BID} AND ( `evt_type`=53 OR `evt_type`=54 ) LIMIT 1"; + // Events by hours + if( $SLOT == REPORT_LEGACY_SLOT ){ + // Legacy day file: split by hour + $QS = "SELECT DISTINCT `ts`/3600 AS JUJA FROM `events`"; $NDD = $ZIZI->Query( $QS ); - if( count( $NDD ) ){ - $EID = intval( $NDD[0]['id'] ); - } else { - $EID = 1000000000;//Infinity + foreach( $NDD as $N ){ + $BTS = intval($N['JUJA'])*3600; + $DADA = date( "H:i", $BTS ); + $ETS = $BTS+3600; + $BID = 0; + $EID = 0; + $QS="SELECT `id` FROM `events` WHERE `ts`>({$BTS}-1) LIMIT 1"; + $KK = $ZIZI->Query( $QS ); + if( count( $KK ) ) $BID = $KK[0]['id']; + $QS="SELECT `id` FROM `events` WHERE `ts`<({$ETS}-1) ORDER BY `id` DESC LIMIT 1"; + $KK = $ZIZI->Query( $QS ); + if( count( $KK ) ) $EID = $KK[0]['id']; else $EID = $BID; + if( $BID && $EID ){ + $BID = reportEncodeId( $SLOT, $BID ); + $EID = reportEncodeId( $SLOT, $EID ); + $SIGA[] = array( 'k' => $BTS, 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" ); + }; }; - $JIGA[] = "{ text: '{$BTM}', leaf: true, bid: {$BID}, eid: {$EID} }"; - }; - if( count( $JIGA ) ){ - $NONO = "{ text: 'Sessions', leaf: false, expanded: true, children:[". implode( ",", $JIGA ) . "]}"; } else { - $NONO = "{ text: 'No Sessions', leaf: true }"; + // Hourly file: one node for the whole file + $KK = $ZIZI->Query( "SELECT MIN(`id`) AS `b`, MAX(`id`) AS `e`, MIN(`ts`) AS `t` FROM `events`" ); + if( count( $KK ) && intval( $KK[0]['b'] ) ){ + $BID = reportEncodeId( $SLOT, $KK[0]['b'] ); + $EID = reportEncodeId( $SLOT, $KK[0]['e'] ); + $DADA = sprintf( "%02d:00", $SLOT ); + $SIGA[] = array( 'k' => intval( $KK[0]['t'] ), 'n' => "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }" ); + }; }; }; - $QS = "SELECT DISTINCT `ts`/3600 AS JUJA FROM `events`"; - $NDD = $ZIZI->Query( $QS ); - if( count( $NDD ) ){ - $st_ignore = true; - $DH = 0; - $SIGA = array(); - foreach( $NDD as $N ){ - $BTS = intval($N['JUJA'])*3600; - $DADA = date( "H:i", $BTS ); - $ETS = $BTS+3600; - $BID = 0; - $EID = 0; - $QS="SELECT `id` FROM `events` WHERE `ts`>({$BTS}-1) LIMIT 1"; - $KK = $ZIZI->Query( $QS ); - if( count( $KK ) ) $BID = $KK[0]['id']; - $QS="SELECT `id` FROM `events` WHERE `ts`<({$ETS}-1) ORDER BY `id` DESC LIMIT 1"; - $KK = $ZIZI->Query( $QS ); - if( count( $KK ) ) $EID = $KK[0]['id']; else $EID = $BID; - if( $BID && $EID ){ - $SIGA[] = "{ text: '{$DADA}', leaf: true, bid: {$BID}, eid: {$EID} }"; - }; - }; - $EVEVE = "{ text: 'Events by Hours', leaf: false, expanded: true, children:[". implode( ",", $SIGA ) . "]}"; + if( count( $JIGA ) ){ + $NONO = "{ text: 'Sessions', leaf: false, expanded: true, children:[". implode( ",", $JIGA ) . "]}"; + } else { + $NONO = "{ text: 'No Sessions', leaf: true }"; + }; + if( count( $SIGA ) ){ + usort( $SIGA, function( $A, $B ){ return $A['k'] - $B['k']; } ); + $EVEVE = "{ text: 'Events by Hours', leaf: false, expanded: true, children:[". implode( ",", array_column( $SIGA, 'n' ) ) . "]}"; }; }; if( $NONO=='' ) $NONO = "{ text: 'No Sessions', leaf: true }"; diff --git a/lib/controller/getHistoryEvents.php b/lib/controller/getHistoryEvents.php index f5f22fa..e8dc028 100644 --- a/lib/controller/getHistoryEvents.php +++ b/lib/controller/getHistoryEvents.php @@ -15,14 +15,16 @@ foreach( $result as $R ) $NodeNames[$R['id']] = $R['name']; $DS = date("Y/m/d", $DTS ); //$QS = "SELECT `events`.*, `events_2_videos`.* FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) WHERE `events`.`id` >= {$BID} AND `events`.`id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC"; - $QS = "SELECT `events`.*, `events_2_videos`.`video_id`, `events_2_pictures`.`picture_id` FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) LEFT JOIN `events_2_pictures` ON( `events`.`id` = `events_2_pictures`.`evt_id` ) WHERE `events`.`id`>={$BID} AND `events`.`id`<={$EID} ORDER BY `events`.`ts` ASC, `events`.`ts_ms` ASC"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); + // BID/EID are global ids of one report file (see report_files.php) + list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID ); + $QS = "SELECT `events`.*, `events_2_videos`.`video_id`, `events_2_pictures`.`picture_id` FROM `events` LEFT JOIN `events_2_videos` ON( `events`.`id` = `events_2_videos`.`evt_id` ) LEFT JOIN `events_2_pictures` ON( `events`.`id` = `events_2_pictures`.`evt_id` ) WHERE `events`.`id`>={$RBID} AND `events`.`id`<={$REID} ORDER BY `events`.`ts` ASC, `events`.`ts_ms` ASC"; + $ZIZI = reportOpenSlot( $DS, $SLOT ); //$LREC = array_reverse( $ZIZI->Query( $QS ) ); - $LREC = $ZIZI->Query( $QS ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); $Data['log'] = array(); //date_default_timezone_set('America/New_York'); foreach( $LREC as $REC ){ - $CR['id'] = intval( $REC['id'] ); + $CR['id'] = reportEncodeId( $SLOT, $REC['id'] ); $CR['node_id'] = intval( $REC['node_id'] ); $CR['node_name'] = $NodeNames[$CR['node_id']]; $CR['rts'] = $DTS; diff --git a/lib/controller/getPictureInfo.php b/lib/controller/getPictureInfo.php index 1ecc9a9..c6072ca 100644 --- a/lib/controller/getPictureInfo.php +++ b/lib/controller/getPictureInfo.php @@ -6,9 +6,12 @@ if( $EID ){ $DS = date("Y/m/d", $DTS ); //$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}"; - $QS = "SELECT `pictures`.`media_stream_id`, `pictures`.`md5`, `pictures`.`ext` FROM `events_2_pictures` LEFT JOIN `pictures` ON( `pictures`.`id` = `events_2_pictures`.`picture_id` ) WHERE `events_2_pictures`.`evt_id`={$EID}"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); - $LREC = $ZIZI->Query( $QS ); + // ID is a global event id (see report_files.php) + $SLOT = reportSlotOf( $EID ); + $REID = reportRawId( $EID ); + $QS = "SELECT `pictures`.`media_stream_id`, `pictures`.`md5`, `pictures`.`ext` FROM `events_2_pictures` LEFT JOIN `pictures` ON( `pictures`.`id` = `events_2_pictures`.`picture_id` ) WHERE `events_2_pictures`.`evt_id`={$REID}"; + $ZIZI = reportOpenSlot( $DS, $SLOT ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); if( count( $LREC ) ){ $Pack = array(); $Pack['pictures'] = array(); diff --git a/lib/controller/getStatus.php b/lib/controller/getStatus.php index 6fa9674..8022996 100644 --- a/lib/controller/getStatus.php +++ b/lib/controller/getStatus.php @@ -22,18 +22,33 @@ $STR = $STATS->Query( $QS ); if( count( $STR ) ){ $DTS = sprintf("%04d/%02d/%02d", intval($STR[0]['year']), intval($STR[0]['month']), intval($STR[0]['day'])); - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DTS.'/report.db'); - $QS = "SELECT `id` FROM `events` WHERE `id` > {$LLID} LIMIT 1"; - $CH = $ZIZI->Query( $QS ); + // Newest report file of the newest day: last hourly report_HH.db (or legacy report.db) + // LSID is the global id of the last event the browser has (see report_files.php) + $RFILES = reportDayFiles( $DTS ); + $CH = array(); + if( count( $RFILES ) ){ + $HOURS = array_diff( array_keys( $RFILES ), array( REPORT_LEGACY_SLOT ) ); + $SLOT = count( $HOURS ) ? max( $HOURS ) : REPORT_LEGACY_SLOT; + $ZIZI = new SQLite_DB( $RFILES[$SLOT], SQLITE3_OPEN_READWRITE ); + $RLLID = reportRawId( $LLID ); + if( reportSlotOf( $LLID ) != $SLOT ){ + $RLLID = 0; // new file (next hour / day): everything in it is new + } else { + $MX = $ZIZI->Query( "SELECT MAX(`id`) AS `m` FROM `events`" ); + if( count( $MX ) && intval( $MX[0]['m'] ) < $RLLID ) $RLLID = 0; // same hour of another day + }; + $QS = "SELECT `id` FROM `events` WHERE `id` > {$RLLID} LIMIT 1"; + $CH = $ZIZI->Query( $QS ); + }; if( count( $CH ) ){ $QS = "SELECT * FROM nodes"; $result = $DATABASE->Query( $QS, false ); $NodeNames = array(); foreach( $result as $R ) $NodeNames[$R['id']] = $R['name']; - $QS = "SELECT `id`,`node_id`, `evt_type`, `ts`, `ts_ms`, `range_digital`, `azimuth`, `elevation`, `range`, `area`, `lrf_id` FROM `events` WHERE `id` > {$LLID} ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 32"; + $QS = "SELECT `id`,`node_id`, `evt_type`, `ts`, `ts_ms`, `range_digital`, `azimuth`, `elevation`, `range`, `area`, `lrf_id` FROM `events` WHERE `id` > {$RLLID} ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 32"; $LREC = $ZIZI->Query( $QS ); foreach( $LREC as $REC ){ - $CR['id'] = intval( $REC['id'] ); + $CR['id'] = reportEncodeId( $SLOT, $REC['id'] ); $CR['node_id'] = intval( $REC['node_id'] ); $CR['node_name'] = $NodeNames[$CR['node_id']]; $CR['ts'] = intval( $REC['ts'] ); diff --git a/lib/controller/getVideoInfo.php b/lib/controller/getVideoInfo.php index 41db143..65551b9 100644 --- a/lib/controller/getVideoInfo.php +++ b/lib/controller/getVideoInfo.php @@ -6,14 +6,20 @@ if( $EID ){ $DS = date("Y/m/d", $DTS ); //$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}"; - $QS = "SELECT `videos`.`id`, `videos`.`fps`,`videos`.`uts` as `ts`, `videos`.`md5`, `videos`.`ext`, `videos`.`media_stream_id`, `events_2_videos`.`frame` FROM `events_2_videos` LEFT JOIN `videos` ON( `videos`.`id` = `events_2_videos`.`video_id` ) WHERE `events_2_videos`.`evt_id`={$EID}"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); - $LREC = $ZIZI->Query( $QS ); + // ID is a global event id (see report_files.php); video ids are returned as global ids of the same file + $SLOT = reportSlotOf( $EID ); + $REID = reportRawId( $EID ); + $QS = "SELECT `videos`.`id`, `videos`.`fps`,`videos`.`uts` as `ts`, `videos`.`md5`, `videos`.`ext`, `videos`.`media_stream_id`, `events_2_videos`.`frame` FROM `events_2_videos` LEFT JOIN `videos` ON( `videos`.`id` = `events_2_videos`.`video_id` ) WHERE `events_2_videos`.`evt_id`={$REID}"; + $ZIZI = reportOpenSlot( $DS, $SLOT ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); if( count( $LREC ) ){ $Pack = array(); $Pack['ts'] = $DTS; $Pack['videos'] = array(); - foreach( $LREC as $Data ) $Pack['videos'][] = $Data; + foreach( $LREC as $Data ){ + $Data['id'] = reportEncodeId( $SLOT, $Data['id'] ); + $Pack['videos'][] = $Data; + }; echo json_encode( $Pack ); exit(); }; diff --git a/lib/controller/setPermanentBubbles.php b/lib/controller/setPermanentBubbles.php index ad61dad..4e74b67 100644 --- a/lib/controller/setPermanentBubbles.php +++ b/lib/controller/setPermanentBubbles.php @@ -76,9 +76,11 @@ }; if( $UID > 1 && $DTS ){ $DS = date("Y/m/d", $DTS ); - $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$BID} AND `id`<={$EID} ORDER BY `ts` ASC, `ts_ms` ASC"; - $ZIZI = new SQLite_DB( $SYSPath . '/lib/controller/data/reports/'.$DS.'/report.db'); - $LREC = $ZIZI->Query( $QS ); + // BID/EID are global ids of one report file (see report_files.php) + list( $SLOT, $RBID, $REID ) = reportResolveRange( $BID, $EID ); + $QS = "SELECT * FROM `events` WHERE ( `evt_type`=13 OR `evt_type`=14 ) AND `id`>={$RBID} AND `id`<={$REID} ORDER BY `ts` ASC, `ts_ms` ASC"; + $ZIZI = reportOpenSlot( $DS, $SLOT ); + $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array(); if( count( $LREC ) ){ foreach( $LREC as $REC ){ $bid = serchInBubbles( $REC ); diff --git a/lib/php/db/report_files.php b/lib/php/db/report_files.php new file mode 100644 index 0000000..92ce668 --- /dev/null +++ b/lib/php/db/report_files.php @@ -0,0 +1,74 @@ + path ), legacy report.db first, then hours ascending +function reportDayFiles( $DS ){ + $RV = array(); + $P = reportSlotPath( $DS, REPORT_LEGACY_SLOT ); + if( file_exists( $P ) ) $RV[REPORT_LEGACY_SLOT] = $P; + for( $H = 0; $H < 24; $H++ ){ + $P = reportSlotPath( $DS, $H ); + if( file_exists( $P ) ) $RV[$H] = $P; + }; + return $RV; +} + +// Opens the report file of a slot; NULL if it does not exist (never creates a file) +function reportOpenSlot( $DS, $slot ){ + if( $slot < 0 || $slot > REPORT_LEGACY_SLOT ) return NULL; + $P = reportSlotPath( $DS, $slot ); + if( !file_exists( $P ) ) return NULL; + return new SQLite_DB( $P, SQLITE3_OPEN_READWRITE ); +} + +function reportEncodeId( $slot, $id ){ + return intval( $slot ) * REPORT_ID_SLOT + intval( $id ); +} + +function reportSlotOf( $gid ){ + return intdiv( intval( $gid ), REPORT_ID_SLOT ); +} + +function reportRawId( $gid ){ + return intval( $gid ) % REPORT_ID_SLOT; +} + +/* + * Resolves a BID..EID range of global ids (always inside one report file) to + * array( slot, raw_bid, raw_eid ). If EID points past the file of BID (e.g. "until the end"), + * the range runs to the end of BID's file. + */ +function reportResolveRange( $BID, $EID ){ + $slot = reportSlotOf( $BID > 0 ? $BID : $EID ); + $rb = ( reportSlotOf( $BID ) == $slot ) ? reportRawId( $BID ) : 0; + $re = ( reportSlotOf( $EID ) == $slot ) ? reportRawId( $EID ) : REPORT_RAW_ID_MAX; + return array( $slot, $rb, $re ); +} +?> -- 2.39.5 From 036be22fa4859e2bb8669ae2dc8343c16f90411a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:55:16 +0000 Subject: [PATCH 2/2] Reports: show times in the host's local time zone PHP ignores the host time zone: without date.timezone in php.ini (the installer does not set it) it uses UTC, so session labels, event times, the hour nodes and the live log were shown in UTC while la_mojo names report folders/files in local time. - lib/php/host_timezone.php: sets PHP's default time zone from the host (/etc/localtime as maintained by timedatectl, then /etc/timezone, then TZ); loaded right after settings.php by ajax_asm, assembler, js_asm, soap_asm and ui_asm; added to files.list. - Calendar day key: getHistoryDates returns the host-local noon of each day and getHistoryDay uses it directly. The old "local midnight + current UTC offset" (applied twice) only worked east of UTC and could be off by a day across a DST change. - Video download file name uses the host-local time from getVideoInfo instead of the browser's time zone. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- files.list | 1 + lib/ajax_asm.php | 1 + lib/assembler.php | 1 + lib/controller/getHistoryDates.php | 6 ++-- lib/controller/getHistoryDay.php | 2 +- lib/controller/getVideoInfo.php | 1 + lib/javascript/jsapi_dynamic/mojo_reports.js | 4 ++- lib/js_asm.php | 1 + lib/php/host_timezone.php | 30 ++++++++++++++++++++ lib/soap_asm.php | 1 + lib/ui_asm.php | 1 + 11 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 lib/php/host_timezone.php diff --git a/files.list b/files.list index 6276e8c..b8855f7 100644 --- a/files.list +++ b/files.list @@ -5712,6 +5712,7 @@ ./lib/php/db/VS_Object_class.php ./lib/php/db/SQLite_Class.php ./lib/php/db/report_files.php +./lib/php/host_timezone.php ./lib/php/db/VS_Tree_class.php ./lib/php/db/language_class.php ./lib/php/db/external.php diff --git a/lib/ajax_asm.php b/lib/ajax_asm.php index 2c5e71a..99be3b7 100644 --- a/lib/ajax_asm.php +++ b/lib/ajax_asm.php @@ -1,6 +1,7 @@ 100 ) $CC = 100; $DD[] = '{"t": '.( $TS * 1000 ).',"v":'.$CC.'}'; //echo '[{"t": 1285891200000,"v": 20},{"t": 1285804800000,"v": 100},{"t": 1672249854000,"v": 50},{"t": 1672279854000,"v": 80}]'; diff --git a/lib/controller/getHistoryDay.php b/lib/controller/getHistoryDay.php index 6e179d6..854f55a 100644 --- a/lib/controller/getHistoryDay.php +++ b/lib/controller/getHistoryDay.php @@ -7,7 +7,7 @@ $DT = new DateTime("now", $TZ ); $DIDI = $TZ->getOffset( $DT ); $Data['tz_offset']=$DIDI; - $DTS += $DIDI; + // DTS is the day key from getHistoryDates (host local noon of the day) - no offset correction needed $Y = date("Y", $DTS ); $M = date("m", $DTS ); $D = date("d", $DTS ); diff --git a/lib/controller/getVideoInfo.php b/lib/controller/getVideoInfo.php index 65551b9..996a6c5 100644 --- a/lib/controller/getVideoInfo.php +++ b/lib/controller/getVideoInfo.php @@ -18,6 +18,7 @@ $Pack['videos'] = array(); foreach( $LREC as $Data ){ $Data['id'] = reportEncodeId( $SLOT, $Data['id'] ); + $Data['fname'] = date( "Y_m_d_H-i-s", intval( $Data['ts'] ) ); // download file name in host local time $Pack['videos'][] = $Data; }; echo json_encode( $Pack ); diff --git a/lib/javascript/jsapi_dynamic/mojo_reports.js b/lib/javascript/jsapi_dynamic/mojo_reports.js index 2e11cf2..4c71384 100644 --- a/lib/javascript/jsapi_dynamic/mojo_reports.js +++ b/lib/javascript/jsapi_dynamic/mojo_reports.js @@ -1047,6 +1047,7 @@ function loadEventData( record ){ videoNfo[data.videos[i].media_stream_id][1] = data.videos[i].md5; videoNfo[data.videos[i].media_stream_id][2] = data.videos[i].fps; videoNfo[data.videos[i].media_stream_id][3] = data.videos[i].ext; + videoNfo[data.videos[i].media_stream_id][4] = data.videos[i].fname; // host local time stamp for file name data.videos[i].frame -= 20; if( data.videos[i].frame < 0 ) data.videos[i].frame = 0; @@ -1898,7 +1899,8 @@ function showVideos(){ function downloadCurrentVideo( stid ){ var d = new Date( videoNfo[stid][0] * 1000 ); - var videoFileDownloadTarget = d.getFullYear().toString().padStart(4, '0')+'_'+(d.getMonth()+1).toString().padStart(2, '0')+'_'+d.getDate().toString().padStart(2, '0')+'_'+d.getHours().toString().padStart(2, '0')+'-'+d.getMinutes().toString().padStart(2, '0')+'-'+d.getSeconds().toString().padStart(2, '0'); + // File name in the host's local time (from the server); browser local time only as a fallback + var videoFileDownloadTarget = videoNfo[stid][4] ? videoNfo[stid][4] : d.getFullYear().toString().padStart(4, '0')+'_'+(d.getMonth()+1).toString().padStart(2, '0')+'_'+d.getDate().toString().padStart(2, '0')+'_'+d.getHours().toString().padStart(2, '0')+'-'+d.getMinutes().toString().padStart(2, '0')+'-'+d.getSeconds().toString().padStart(2, '0'); // TS, MD5, FPS, EXT downloadVideoFile( videoNfo[stid][0], videoNfo[stid][1], videoNfo[stid][2], videoFileDownloadTarget, videoNfo[stid][3] ); }; diff --git a/lib/js_asm.php b/lib/js_asm.php index 31ab682..99ec753 100644 --- a/lib/js_asm.php +++ b/lib/js_asm.php @@ -1,6 +1,7 @@ diff --git a/lib/soap_asm.php b/lib/soap_asm.php index bafadc5..da0f192 100644 --- a/lib/soap_asm.php +++ b/lib/soap_asm.php @@ -1,6 +1,7 @@