query-36c07f661548df099e2568b78a48e73b

rq turtle/ttl

using https://cs.wikipedia.org/wiki/Algoritmus_pro_v%C3%BDpo%C4%8Det_dne_v_t%C3%BDdnu#Zeller%C5%AFv_algoritmus SELECT (?q AS ?Date) (SUM(?mon) AS ?Mon) (SUM(?tue) AS ?Tue) (SUM(?wed) AS ?Wed) (SUM(?thu) AS ?Thu) (SUM(?fri) AS ?Fri) (SUM(?sat) AS ?Sat) (SUM(?sun) AS ?Sun) (COUNT(?start_time) AS ?Tot) WHERE { { ?disaster wdt:P31/wdt:P279 wd:Q3839081 ; p:P580 ?start_time_stm . ?start_time_stm ps:P580 ?start_time . ?start_time_stm psv:P580 ?start_time_node . ?start_time_node wikibase:timePrecision ?tp . FILTER(?tp=11) } UNION # to cover both "point in time" and "start time" events { ?disaster wdt:P31/wdt:P279 wd:Q3839081 ; p:P585 ?start_time_stm . ?start_time_stm ps:P585 ?start_time . ?start_time_stm psv:P585 ?start_time_node . ?start_time_node wikibase:timePrecision ?tp . FILTER(?tp=11) } BIND( DAY( ?start_time ) AS ?q ) . BIND( MONTH( ?start_time ) + IF( MONTH( ?start_time ) < 3, 12, 0 ) AS ?m ) . BIND( YEAR( ?start_time ) - IF( MONTH( ?start_time ) < 3, 1, 0 ) AS ?_year ) . BIND( ?_year - FLOOR( ?_year / 100 ) * 100 AS ?K ) . # modulo BIND( FLOOR( YEAR( ?start_time ) / 100 ) AS ?J ) . BIND( ?q + FLOOR( 13 * ( ?m + 1 ) / 5 ) + ?K + FLOOR( ?K / 4 ) + FLOOR( ?J / 4 ) - 2 * ?J AS ?_h ) . BIND( ?_h - FLOOR( ?_h / 7 ) * 7 AS ?weekday) . # modulo, 0 is Saturday BIND(IF(?weekday=2,1,0) AS ?mon) BIND(IF(?weekday=3,1,0) AS ?tue) BIND(IF(?weekday=4,1,0) AS ?wed) BIND(IF(?weekday=5,1,0) AS ?thu) BIND(IF(?weekday=6,1,0) AS ?fri) BIND(IF(?weekday=0,1,0) AS ?sat) BIND(IF(?weekday=1,1,0) AS ?sun) } GROUP BY ?q ORDER BY ?Date

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
# using https://cs.wikipedia.org/wiki/Algoritmus_pro_v%C3%BDpo%C4%8Det_dne_v_t%C3%BDdnu#Zeller%C5%AFv_algoritmus
SELECT (?q AS ?Date) (SUM(?mon) AS ?Mon) (SUM(?tue) AS ?Tue) (SUM(?wed) AS ?Wed) (SUM(?thu) AS ?Thu) (SUM(?fri) AS ?Fri) (SUM(?sat) AS ?Sat) (SUM(?sun) AS ?Sun)  (COUNT(?start_time) AS ?Tot)  WHERE {
 { 
  ?disaster wdt:P31/wdt:P279* wd:Q3839081 ;
            p:P580 ?start_time_stm .
  ?start_time_stm ps:P580 ?start_time .
  ?start_time_stm psv:P580 ?start_time_node .
  ?start_time_node wikibase:timePrecision ?tp . FILTER(?tp=11) 
 }
 UNION # to cover both "point in time" and "start time" events
 {
  ?disaster wdt:P31/wdt:P279* wd:Q3839081 ;
            p:P585 ?start_time_stm .
  ?start_time_stm ps:P585 ?start_time .
  ?start_time_stm psv:P585 ?start_time_node .
  ?start_time_node wikibase:timePrecision ?tp . FILTER(?tp=11) 
 }
  BIND( DAY( ?start_time ) AS ?q ) .
  BIND( MONTH( ?start_time ) + IF( MONTH( ?start_time ) < 3, 12, 0 ) AS ?m ) .
  BIND( YEAR( ?start_time ) - IF( MONTH( ?start_time ) < 3, 1, 0 ) AS ?_year ) .
  BIND( ?_year - FLOOR( ?_year / 100 ) * 100 AS ?K ) . # modulo
  BIND( FLOOR( YEAR( ?start_time ) / 100 ) AS ?J ) .
  BIND( ?q + FLOOR( 13 * ( ?m + 1 ) / 5 ) + ?K + FLOOR( ?K / 4 ) + FLOOR( ?J / 4 ) - 2 * ?J AS ?_h ) .
  BIND( ?_h - FLOOR( ?_h / 7 ) * 7 AS ?weekday) . # modulo, 0 is Saturday
  BIND(IF(?weekday=2,1,0) AS ?mon)
  BIND(IF(?weekday=3,1,0) AS ?tue)
  BIND(IF(?weekday=4,1,0) AS ?wed)
  BIND(IF(?weekday=5,1,0) AS ?thu)
  BIND(IF(?weekday=6,1,0) AS ?fri)
  BIND(IF(?weekday=0,1,0) AS ?sat)
  BIND(IF(?weekday=1,1,0) AS ?sun)
}
GROUP BY ?q
ORDER BY ?Date

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v21("?Date") v25("?Fri") v11("?J") v10("?K") v21("?Mon") v26("?Sat") v27("?Sun") v24("?Thu") v28("?Tot") v22("?Tue") v23("?Wed") v12("?_h") v9("?_year") v3("?disaster") v18("?fri"):::projected v8("?m") v14("?mon"):::projected v7("?q"):::projected v19("?sat"):::projected v5("?start_time"):::projected v6("?start_time_node") v4("?start_time_stm") v20("?sun"):::projected v17("?thu"):::projected v2("?tp") v15("?tue"):::projected v16("?wed"):::projected v13("?weekday") a1((" ")) a2((" ")) c4(["wd:Q3839081"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f0[["?tp = '11^^xsd:integer'"]] f0 --> v2 v3 --"p:direct/P31"--> a2 a2 --"p:direct/P279"--> c4 v3 --"p:P585"--> v4 v4 --"p:statement/P585"--> v5 v4 --"p:statement/value/P585"--> v6 v6 --"wikibase:timePrecision"--> v2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; f1[["?tp = '11^^xsd:integer'"]] f1 --> v2 v3 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c4 v3 --"p:P580"--> v4 v4 --"p:statement/P580"--> v5 v4 --"p:statement/value/P580"--> v6 v6 --"wikibase:timePrecision"--> v2 end union0r <== or ==> union0l end bind2[/"day-from-dateTime(?start_time)"/] v5 --o bind2 bind2 --as--o v7 bind3[/"month-from-dateTime(?start_time) + if(month-from-dateTime(?start_time) < '3^^xsd:integer','12^^xsd:integer','0^^xsd:integer')"/] v5 --o bind3 bind3 --as--o v8 bind4[/"year-from-dateTime(?start_time) - if(month-from-dateTime(?start_time) < '3^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v5 --o bind4 bind4 --as--o v9 bind5[/"?_year - numeric-floor(?_year / '100^^xsd:integer') * '100^^xsd:integer'"/] v9 --o bind5 bind5 --as--o v10 bind6[/"numeric-floor(year-from-dateTime(?start_time) / '100^^xsd:integer')"/] v5 --o bind6 bind6 --as--o v11 bind7[/"?q + numeric-floor('13^^xsd:integer' * ?m + '1^^xsd:integer' / '5^^xsd:integer') + ?K + numeric-floor(?K / '4^^xsd:integer') + numeric-floor(?J / '4^^xsd:integer') - '2^^xsd:integer' * ?J"/] v7 --o bind7 v8 --o bind7 v10 --o bind7 v11 --o bind7 bind7 --as--o v12 bind8[/"?_h - numeric-floor(?_h / '7^^xsd:integer') * '7^^xsd:integer'"/] v12 --o bind8 bind8 --as--o v13 bind9[/"if(?weekday = '2^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind9 bind9 --as--o v14 bind10[/"if(?weekday = '3^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind10 bind10 --as--o v15 bind11[/"if(?weekday = '4^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind11 bind11 --as--o v16 bind12[/"if(?weekday = '5^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind12 bind12 --as--o v17 bind13[/"if(?weekday = '6^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind13 bind13 --as--o v18 bind14[/"if(?weekday = '0^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind14 bind14 --as--o v19 bind15[/"if(?weekday = '1^^xsd:integer','1^^xsd:integer','0^^xsd:integer')"/] v13 --o bind15 bind15 --as--o v20 bind24[/"?q"/] v7 --o bind24 bind24 --as--o v21 bind25[/"sum(?mon)"/] v14 --o bind25 bind25 --as--o v21 bind26[/"sum(?tue)"/] v15 --o bind26 bind26 --as--o v22 bind27[/"sum(?wed)"/] v16 --o bind27 bind27 --as--o v23 bind28[/"sum(?thu)"/] v17 --o bind28 bind28 --as--o v24 bind29[/"sum(?fri)"/] v18 --o bind29 bind29 --as--o v25 bind30[/"sum(?sat)"/] v19 --o bind30 bind30 --as--o v26 bind31[/"sum(?sun)"/] v20 --o bind31 bind31 --as--o v27 bind32[/"count(?start_time)"/] v5 --o bind32 bind32 --as--o v28