Browse Source
Reports: read hourly report_HH.db files
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
pull/1/head
Failed to extract signature
11 changed files with 201 additions and 81 deletions
-
1files.list
-
1lib/ajax_asm.php
-
8lib/controller/getBubbleAnalysis.php
-
7lib/controller/getFrames.php
-
125lib/controller/getHistoryDay.php
-
10lib/controller/getHistoryEvents.php
-
9lib/controller/getPictureInfo.php
-
25lib/controller/getStatus.php
-
14lib/controller/getVideoInfo.php
-
8lib/controller/setPermanentBubbles.php
-
74lib/php/db/report_files.php
@ -0,0 +1,74 @@ |
|||
<?php |
|||
/* |
|||
* Report database files of a day folder. |
|||
* |
|||
* la_mojo writes one report database per local hour into the day folder: |
|||
* data/reports/YYYY/MM/DD/report_HH.db (HH = 00..23) |
|||
* Days recorded before that change have a single data/reports/YYYY/MM/DD/report.db |
|||
* (the "legacy" file); a day during the upgrade can have both. |
|||
* |
|||
* Row ids (events, pictures, videos) are AUTOINCREMENT per file, so ids sent to the browser |
|||
* carry the file ("slot") they belong to: |
|||
* global id = slot * REPORT_ID_SLOT + rowid slot: 0..23 = hour file, 24 = legacy report.db |
|||
* The browser treats ids as opaque values and sends them back unchanged; controllers decode them |
|||
* with reportSlotOf() / reportRawId(). The largest id (24 * 10^7 + 9999999) fits a 32-bit int. |
|||
*/ |
|||
define('REPORT_ID_SLOT', 10000000); |
|||
define('REPORT_LEGACY_SLOT', 24); |
|||
define('REPORT_RAW_ID_MAX', REPORT_ID_SLOT - 1); |
|||
|
|||
function reportDayDir( $DS ){ |
|||
global $SYSPath; |
|||
return $SYSPath . '/lib/controller/data/reports/' . $DS; |
|||
} |
|||
|
|||
// Path of the report file of a slot (does not check existence)
|
|||
function reportSlotPath( $DS, $slot ){ |
|||
if( $slot == REPORT_LEGACY_SLOT ) return reportDayDir( $DS ) . '/report.db'; |
|||
return reportDayDir( $DS ) . sprintf( '/report_%02d.db', $slot ); |
|||
} |
|||
|
|||
// Existing report files of a day: array( slot => 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 ); |
|||
} |
|||
?>
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue