Reports: read hourly report_HH.db files
#1
Merged
ClaudeAI
merged 2 commits from feature/hourly-report-db into master 2 hours ago
18 changed files with 246 additions and 85 deletions
-
2files.list
-
2lib/ajax_asm.php
-
1lib/assembler.php
-
8lib/controller/getBubbleAnalysis.php
-
7lib/controller/getFrames.php
-
6lib/controller/getHistoryDates.php
-
127lib/controller/getHistoryDay.php
-
10lib/controller/getHistoryEvents.php
-
9lib/controller/getPictureInfo.php
-
25lib/controller/getStatus.php
-
15lib/controller/getVideoInfo.php
-
8lib/controller/setPermanentBubbles.php
-
4lib/javascript/jsapi_dynamic/mojo_reports.js
-
1lib/js_asm.php
-
74lib/php/db/report_files.php
-
30lib/php/host_timezone.php
-
1lib/soap_asm.php
-
1lib/ui_asm.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 ); |
|||
} |
|||
?>
|
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
/* |
|||
* Use the host system's local time zone for all PHP date/time formatting. |
|||
* |
|||
* PHP does not follow the host time zone: without date.timezone in php.ini it uses UTC, so |
|||
* report days, session and event times were shown in UTC instead of the local time that |
|||
* la_mojo uses for report folders/files (data/reports/YYYY/MM/DD/report_HH.db). |
|||
* |
|||
* Source of the host zone, in order: |
|||
* /etc/localtime symlink (what timedatectl set-timezone maintains), /etc/timezone, TZ variable. |
|||
*/ |
|||
function hostTimezoneName(){ |
|||
$Candidates = array(); |
|||
$L = @readlink( '/etc/localtime' ); |
|||
if( $L !== false && ( $P = strpos( $L, 'zoneinfo/' ) ) !== false ){ |
|||
$Candidates[] = substr( $L, $P + 9 ); |
|||
}; |
|||
$T = @file_get_contents( '/etc/timezone' ); |
|||
if( $T !== false ) $Candidates[] = trim( $T ); |
|||
$E = getenv( 'TZ' ); |
|||
if( $E !== false ) $Candidates[] = ltrim( trim( $E ), ':' ); |
|||
foreach( $Candidates as $C ){ |
|||
if( $C !== '' && in_array( $C, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ) ) ) return $C; |
|||
}; |
|||
return NULL; |
|||
} |
|||
|
|||
$HOST_TZ = hostTimezoneName(); |
|||
if( $HOST_TZ !== NULL ) date_default_timezone_set( $HOST_TZ ); |
|||
?>
|
|||
@ -1,6 +1,7 @@ |
|||
<?php |
|||
|
|||
require_once('settings.php'); |
|||
require_once( __DIR__ . '/php/host_timezone.php'); // PHP must use the host's local time zone
|
|||
require_once('defines.php'); |
|||
|
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue