Created
April 20, 2022 15:28
-
-
Save mjlassila/43a06a40d1877633c29129a2004bdaae to your computer and use it in GitHub Desktop.
Convert DSpace Simplestats statistics to analysis-friendly CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare option output:method "csv"; | |
declare option output:csv "header=yes, separator=comma"; | |
declare function local:to-datestamp($raw_date){ | |
let $parts:=tokenize($raw_date," / ") | |
return $parts[2] || '-' || $parts[1] || '-1' | |
}; | |
declare function local:not-total($string) { | |
let $status:= not($string eq "Total") and not($string eq "/ The entire DSpace") | |
return $status | |
}; | |
let $range:=//th[local:not-total(.) and not(@class)] | |
let $datestamps:= | |
for $date in $range | |
return local:to-datestamp($date) | |
let $items:= | |
<items>{for $item in //tr[position()>1] | |
let $handle:=data($item/td/a/@href) | |
let $counts:= | |
for $count in $item/td[position()>1] | |
count $c | |
where $datestamps[$c] | |
return | |
<stat date="{$datestamps[$c]}" count="{$count}"/> | |
return | |
<item> | |
<handle>{$handle}</handle> | |
{$counts} | |
</item> | |
}</items> | |
let $csv:= | |
<csv>{ | |
for $item in $items/item | |
let $stats:=$item/stat | |
for $stat in $stats | |
return | |
<entry> | |
<handle>{data($item/handle)}</handle> | |
<date>{data($stat/@date)}</date> | |
<count>{data($stat/@count)}</count> | |
</entry> | |
}</csv> | |
return $csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment