joewiz
10/23/2016 - 7:04 PM

Use XQuery tumbling windows to create groups of topics to be covered in class meetings

Use XQuery tumbling windows to create groups of topics to be covered in class meetings

<!-- $topics-per-week: 4 -->

<meeting-topics>Shang, Zhou, Qin, Han</meeting-topics>
<meeting-topics>Sui, Tang, Song, Yuan</meeting-topics>
<meeting-topics>Ming, Qing, Republic, Mao Zedong</meeting-topics>

<!-- $topics-per-meeting: 2 -->

<meeting-topics>Shang, Zhou</meeting-topics>
<meeting-topics>Qin, Han</meeting-topics>
<meeting-topics>Sui, Tang</meeting-topics>
<meeting-topics>Song, Yuan</meeting-topics>
<meeting-topics>Ming, Qing</meeting-topics>
<meeting-topics>Republic, Mao Zedong</meeting-topics>
xquery version "3.1";

(: Use tumbling windows to group topics into the number of class meetings for a section of a course.
   Our case in this example: 
   We have an intensive summer course that needs to cover 12 topics in 3 weeks. It has two sections.
   The first section meets once per week, so we need to cover 4 topics in each meeting.
   The query below tells us which topics should be covered at each meeting.
   For the second section, which meets twice per week, can cover 2 topics at each meeting.
   (Here, topics listed are the major Chinese dynasties, as sung at https://www.youtube.com/watch?v=xJis9TSw1rE.) 
   :)

let $all-topics := ('Shang', 'Zhou', 'Qin', 'Han', 'Sui', 'Tang', 'Song', 'Yuan', 'Ming', 'Qing', 'Republic', 'Mao Zedong')
let $topics-per-week := 4
for tumbling window $meeting-topics in $all-topics
    start at $starting-pos when true()
    only end at $ending-pos when $ending-pos - $starting-pos + 1 eq $topics-per-week
return <meeting-topics>{ string-join($meeting-topics, ', ') }</meeting-topics>