Index: openacs-4/packages/logger/lib/entries.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/lib/entries.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/lib/entries.adp 4 Jan 2004 21:27:48 -0000 1.1 +++ openacs-4/packages/logger/lib/entries.adp 5 Jan 2004 21:49:35 -0000 1.2 @@ -6,6 +6,11 @@ + +
+ +
+
Index: openacs-4/packages/logger/lib/projection.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/lib/projection.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/lib/projection.adp 5 Jan 2004 21:49:35 -0000 1.1 @@ -0,0 +1,34 @@ + + + + + + + + + + + + + +
Dates + @progress_time_pct@% + +    @progress_days@/@total_days@ days + +    @progress_time_pct@% +
@variable.name@ + + @progress_value_pct@% + + + @progress_value_pct@% + + +    @total_value_pretty@/@projected_value_pretty@ @variable.unit@ + +    @progress_value_pct@% +
Index: openacs-4/packages/logger/lib/projection.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/lib/projection.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/lib/projection.tcl 5 Jan 2004 21:49:35 -0000 1.1 @@ -0,0 +1,71 @@ +# +# Displays current projection, and where we're at relative to it +# +# Expects: +# +# projection_id +# + +# Projection info +# TODO: Really should use the projection::get API +db_1row projection { + select p.name, + p.project_id, + p.variable_id, + p.value as projected_value, + to_char(start_time, 'YYYY-MM-DD HH24:MI:SS') as start_time_ansi, + to_char(end_time, 'YYYY-MM-DD HH24:MI:SS') as end_time_ansi + from logger_projections p + where p.projection_id = :projection_id +} + +logger::variable::get \ + -variable_id $variable_id \ + -array variable + + +# Get current budget consumption level, and latest timestamp within the range +set total_value 0 +set counter 0 +set time_stamp_ansi $start_time_ansi + +db_foreach select_values { + select e.value, + to_char(e.time_stamp, 'YYYY-MM-DD HH24:MI:SS') as time_stamp_ansi + from logger_entries e + where e.project_id = :project_id + and e.variable_id = :variable_id + and e.time_stamp + between to_date(:start_time_ansi, 'YYYY-MM-DD HH24:MI:SS') + and to_date(:end_time_ansi, 'YYYY-MM-DD HH24:MI:SS') + order by e.time_stamp +} { + incr counter + set total_value [expr $total_value + $value] +} + +# TODO: plus/minus one problem: logger_entry.time_stamp always has time part being midnight +# We should probably change all logic to use dates, not timestamps (and then we can use the projection API) + + +# Calculate percentage of time spent +set start_time_epoch [clock scan $start_time_ansi] +set end_time_epoch [clock scan $end_time_ansi] +set time_stamp_epoch [clock scan $time_stamp_ansi] + +set total_time [expr $end_time_epoch - $start_time_epoch] +set progress_time [expr $time_stamp_epoch - $start_time_epoch] + +set total_days [expr $total_time / (60*60*24) + 1] +set progress_days [expr $progress_time / (60*60*24)] + +set progress_time_pct [expr round($progress_time*100.0 / $total_time)] +set progress_time_pct_inverse [expr 100-$progress_time_pct] + +# Calculate percentage of value spent +set progress_value_pct [expr round($total_value*100.0 / $projected_value)] +set progress_value_pct_inverse [expr 100-$progress_value_pct] + +set total_value_pretty [lc_numeric $total_value] +set projected_value_pretty [lc_numeric $projected_value] +