Index: src/statrep.c ================================================================== --- src/statrep.c +++ src/statrep.c @@ -54,14 +54,24 @@ ** ** Returns one of: 'c', 'w', 'g', 't', 'e', representing the type of ** filter it applies, or '*' if no filter is applied (i.e. if "all" is ** used). */ +/* + * XXX: From timeline.c -- a header would be a better place... + */ +double symbolic_name_to_mtime(const char *); +#define ONE_SECOND (1.0/86400.0) static int stats_report_init_view(){ const char *zType = PD("type","*"); /* analog to /timeline?y=... */ + const char *zAfter = P("a"); /* analog to /timeline?a=... */ + const char *zBefore = P("b"); /* analog to /timeline?b=... */ const char *zRealType = NULL; /* normalized form of zType */ int rc = 0; /* result code */ + double rBefore, rAfter; /* Boundary times */ + Blob sql; + assert( !statsReportType && "Must not be called more than once." ); switch( (zType && *zType) ? *zType : 0 ){ case 'c': case 'C': zRealType = "ci"; @@ -89,21 +99,47 @@ break; default: rc = '*'; break; } + assert(0 != rc); + + rBefore = symbolic_name_to_mtime(zBefore); + rAfter = symbolic_name_to_mtime(zAfter); + + blob_zero(&sql); + if(zRealType){ statsReportTimelineYFlag = zRealType; - db_multi_exec("CREATE TEMP VIEW v_reports AS " + blob_append_sql(&sql, "CREATE TEMP VIEW v_reports AS " "SELECT * FROM event WHERE type GLOB %Q", zRealType); }else{ statsReportTimelineYFlag = "a"; - db_multi_exec("CREATE TEMP VIEW v_reports AS " - "SELECT * FROM event"); + blob_append_sql(&sql, "CREATE TEMP VIEW v_reports AS " + "SELECT * FROM event WHERE 1"); + } + + if( rAfter>0.0 ){ + if( rBefore>0.0 ){ + blob_append_sql(&sql, + " AND mtime>=%.17g AND mtime<=%.17g", + rAfter-ONE_SECOND, rBefore+ONE_SECOND); + }else{ + blob_append_sql(&sql, + " AND mtime>=%.17g", + rAfter-ONE_SECOND); + } + }else if( rBefore>0.0 ){ + blob_append_sql(&sql, + " AND mtime<=%.17g", + rBefore+ONE_SECOND); } + + db_multi_exec("%s", blob_sql_text(&sql)); + return statsReportType = rc; } /* ** Returns a string suitable (for a given value of suitable) for @@ -662,10 +698,12 @@ ** view=REPORT_NAME Valid values: bymonth, byyear, byuser ** user=NAME Restricts statistics to the given user ** type=TYPE Restricts the report to a specific event type: ** ci (check-in), w (wiki), t (ticket), g (tag) ** Defaulting to all event types. +** a=TIMEORTAG Limit report to after this event +** b=TIMEORTAG Limit report to before this event ** ** The view-specific query parameters include: ** ** view=byweek: **