|
- <?php
- /*
- * Generates dataset for statistics of posts by date and sender
- * Copyright (C) 2020 Polyna <https://wandystan.eu/B196>
- *
- * This file is part of LDMW statistical scripts.
- *
- * LDMW statistical scripts are free software: you can redistribute them
- * and/or modify them under the terms of the GNU Affero General Public
- * License as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * LDMW statistical scripts are distributed in the hope that they will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with LDMW statistical scripts. If not, see
- * <https://www.gnu.org/licenses/>.
- */
- require_once 'common.php';
-
- // load document with month statistics
- try {
- $document = load_remote_dom_document('https://wandystan.groups.io/g/wandystan/months');
- } catch (Exception $e) {
- exit_error($e->getMessage());
- }
-
- $xpath = new DOMXPath($document);
-
- // find all months with non-zero number of posts
- $months = [];
- $rows = $xpath->query('//table/tbody/tr');
-
- foreach ($rows as $row) {
- $cols = $xpath->query('td', $row);
- $year = $cols[0]->nodeValue;
-
- for ($i = 1; $i < $cols->length; $i++) {
- if (
- $cols[$i]->firstChild->nodeType === XML_ELEMENT_NODE &&
- $cols[$i]->firstChild->tagName === 'a'
- ) {
- $months []= $year . '-' . str_pad($i, 2, '0', STR_PAD_LEFT);
- }
- }
- }
-
- // construct a linked data object corresponding to gathered data
- $ld = [
- '@context' => 'https://wandystan.eu/statistics/context.jsonld',
- '@type' => 'DataSet',
- 'title' => [
- 'en' => 'Posts by date and sender',
- 'pl' => 'Wiadomości wg daty i wysyłającego'
- ],
- 'description' => [
- 'en' => 'Statistics of number of posts sent by a given sender on a given date, grouped by period in which they were sent.',
- 'pl' => 'Statystyki liczby wiadomości wysłanych przez danego wysyłającego w danym dniu, pogrupowane wg okresu w jakim zostały wysłane.'
- ],
- 'publisher' => 'https://wandystan.eu/',
- 'structure' => 'structure/by-period',
- 'slices' => array_map(function ($month) { return "by-period/$month-01/P1M"; }, $months)
- ];
-
- header('Content-type: application/ld+json');
- print json_encode($ld);
|