nsmcp::ServerHistory method options (protected)

 <instance of nsmcp::ServerHistory[i]> options arguments

Defined in /usr/local/ns/tcl/nsmcp/lib/stats-tools.tcl

Parameters:
arguments (required)

Testcases:
No testcase defined.
Source code:
if {[lindex $arguments 1] ne "object"} {
    error "Expected arguments object"
}
set options {limit 12 cursor 0}
foreach {key type value} [lindex $arguments 2] {
    if {$key eq "period"} {
        if {$type ne "string" || $value ne "previous-hour"} {
            error "period must be previous-hour"
        }
    } elseif {$key ni {lastMinutes from to limit cursor} || $type ne "number" || ![string is entier -strict $value]} {
        error "Supply integer time and paging options, or period previous-hour"
    }
    dict set options $key $value
}
set explicit [expr {[dict exists $options from] || [dict exists $options to]}]
set relative [expr {[dict exists $options lastMinutes] + [dict exists $options period]}]
if {$relative > 1 || ($explicit && $relative)} {
    error "Use lastMinutes, period, or paired from/to"
}
if {$explicit && (![dict exists $options from] || ![dict exists $options to])} {
    error "Supply both from and to"
}
if {!$explicit && [dict get $options cursor] != 0} {
    error "Paging requires the returned explicit from/to bounds"
}
set now [clock seconds]
if {[dict exists $options period]} {
    set end [expr {($now / 3600) * 3600}]
    dict set options from [expr {$end - 3600}]
    dict set options to $end
    dict unset options period
} elseif {!$explicit} {
    set minutes 10
    if {[dict exists $options lastMinutes]} {
        set minutes [dict get $options lastMinutes]
        dict unset options lastMinutes
    }
    if {$minutes < 1 || $minutes > 1440} {
        error "lastMinutes must be 1..1440"
    }
    set end [expr {($now / 60) * 60}]
    dict set options from [expr {$end - $minutes * 60}]
    dict set options to $end
}
dict with options {}
if {$from < 0 || $to <= $from || $to > $now || $to - $from > 86400
    || $limit < 1 || $limit > 100 || $cursor < 0
    || ($cursor != 0 && ($cursor < $from * 1000000 || $cursor >= $to * 1000000))} {
    error "Expected a past window up to 24 hours, limit 1..100 and a cursor within the window"
}
return $options
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: