7.2 Query Functions
How to use a query to filter a list of files for subsequent bout analysis.
(require "../query.rkt") | package: base |
procedure
(query-table? table) → boolean?
table : any/c
Example:
( ;; header row ( "header0" "header1" "header2") ;; list of rows ( ("row0-cell0" "row0-cell1" "row0-cell2") ("row1-cell0" "row1-cell1" "row1-cell2")))
procedure
(predicate? pred) → boolean?
pred : any/c
(predicate? '( "Group" ("Control"))) -> #t (predicate? '( "Name" ("Rat02" "Rat04" "Rat06"))) -> #t
procedure
(predicate-list? pred-list) → boolean?
pred-list : any/c
(predicate-list? '( ("Group" ("Control")) ("Name" ("Rat02" "Rat04" "Rat06")) ) ) -> #t
procedure
(table-headers table) → (non-empty-listof string?)
table : query-table?
(table-headers my-table) -> ("Name" "Group" "Weight" "Intake")
procedure
(table-rows table) → list?
table : query-table?
(table-rows my-table) -> ( ("Rat01" "Control" "320" "42") ("Rat02" "Control" "300" "41") ("Rat03" "Control" "310" "40") ("Rat04" "Drug" "250" "36") ("Rat05" "Drug" "255" "37") ("Rat06" "Drug" "253" "38") )
procedure
(table-row-ref table row-index) → list?
table : query-table? row-index : nonnegative-integer?
(table-row-ref my-table 3) -> ("Rat03" "Control" "310" "40")
procedure
(table-row-cell table #:row row #:column-heading column-heading) → any/c table : query-table? row : list column-heading : string?
(table-row-cell my-table #:row (table-row-ref my-table 3) #:column-heading "Group") -> "Control"
procedure
(table-filter table predicate-list) → query-table?
table : query-table? predicate-list : predicate-list?
a new table is returned, with the same headers list as the original table
predicate-list is list of predicates: (<column-heading> match-term1 [match-term2 ...]) <column-heading> should be in _column-headings hash table
each predicate starts with name of column, followed by variable number of terms as potential matches for that column.
Within a predicate, matches are OR’d.
Between predicates, matches are AND’d.
( (column-headingA (match1 match2)) (column-headingB (match3 match4)) )
(and (or (equal? column-headingA match1) (equal? column-headingA match2)) (or (equal? column-headingB match3) (equal? column-headingB match4)))
an example:
;; find rows where column 1 is Control, and column 0 is Rat03 (table-filter my-table '(("Group" ("Control")) ("Name"( "Rat03"))) ) -> ( ("Name" "Group" "Weight" "Intake") ( ("Rat03" "Control" "310" "40"))) ;; find rows where column 0 is Rat04 or Rat05 (table-filter my-table '(("Name" ("Rat04" "Rat05")))) -> ( ("Name" "Group" "Weight" "Intake") ( ("Rat04" "Drug" "250" "36") ("Rat05" "Drug" "255" "37")))
procedure
(table-search table search-string) → query-table?
table : query-table? search-string : string?
procedure
(table-filter-search table predicate-list search-string) → query-table? table : query-table? predicate-list : predicate-list? search-string : string?
procedure
(format-filter predicate-list search-string) → string? predicate-list : predicate-list? search-string : string?
procedure
(table-column-values table column-heading) → (listof string?)
table : query-table? column-heading : string?
procedure
(table-sort table column-heading [direction]) → query-table?
table : query-table? column-heading : string? direction : (or/c 'ascending 'descending) = 'ascending