Forum OpenACS Q&A: Response to Clickstream solutions

Collapse
Posted by Jeff Davis on
For completeness sake here are the other two:
cs-data.tcl
# $Id: cs-data.tcl,v 3.1 2000/04/10 15:17:24 jsalz Exp $
# File:        cs-data.tcl
# Date:        6 Apr 2000
# Author:      jsalz@mit.edu
# Description: Returns clickstreaming data for a particular chunk.
# Inputs:      chunk_start

set_the_usual_form_variables

proc_doc cs_data_write_chunk { time chunk_start } { Write all lines in the chunk beginning with $chunk_start from the log file for $time. } {
    set filename [cs_log_file $time]
    if { ![file exists $filename] } {
	return
    }
    set file [open $filename "r"]

    set out ""
    while { [gets $file line] >= 0 } {
	set time [string range $line 0 [expr { [string first "	" $line] - 1 }]]
	if { $time >= $chunk_start && $time < $chunk_start + 3600 } {
	    append out $line
	    append out "
"
	    if { [string length $out] >= 8192 } {
		ns_write $out
		set out ""
	    }
	}
    }
    ns_write $out

    close $file
}

ReturnHeaders "text/plain"

# Note that we need to look in two log files - the one we'd expect, plus the next one (in case
# any requests weren't logged until the next chunk, i.e., the request was issued at 10:59:59 but
# the request wasn't written to the log until 11:00:01).
foreach time [list $chunk_start [expr { $chunk_start + 3600 }]] {
    cs_data_write_chunk $time $chunk_start
}
cs-one-day.tcl

# /SYSTEM/cs-one-day.tcl
#
# returns compressed log file
#
# richardl@arsdigita.com, jsalz@mit.edu 5 June 2000
#
# $Id: cs-one-day.tcl,v 3.4 2000/06/26 17:21:02 iwashima Exp $

set host_ip [ns_conn peeraddr]
set hosts_approved [ad_parameter_all_values_as_list Approved_ip cs/logging]
if {[lsearch -exact $hosts_approved $host_ip] == -1} {
    ns_log "Notice" "$host_ip not in $hosts_approved ... not approved IP to access clickstreaming log"
    # The person isn't allowed in here
    ad_return_complaint 1 "Your IP $host_ip is not on the allowed list of IPs to see this page."
    return
}

ad_page_variables {
    start_time
}

ns_log Notice "starting downloads...[cs_archive_file $start_time]"

ns_returnfile 200 application/x-gzip-compressed [cs_archive_file $start_time]