Skrypty statystyk Listy Dyskusyjnej Mandragoratu Wandystanu https://wandystan.eu/statistics/doc/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

70 wiersze
2.3 KiB

  1. <?php
  2. /*
  3. * Generates dataset for statistics of posts by date and sender
  4. * Copyright (C) 2020 Polyna <https://wandystan.eu/B196>
  5. *
  6. * This file is part of LDMW statistical scripts.
  7. *
  8. * LDMW statistical scripts are free software: you can redistribute them
  9. * and/or modify them under the terms of the GNU Affero General Public
  10. * License as published by the Free Software Foundation, either version 3
  11. * of the License, or (at your option) any later version.
  12. *
  13. * LDMW statistical scripts are distributed in the hope that they will be
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with LDMW statistical scripts. If not, see
  20. * <https://www.gnu.org/licenses/>.
  21. */
  22. require_once 'common.php';
  23. // load document with month statistics
  24. try {
  25. $document = load_remote_dom_document('https://wandystan.groups.io/g/wandystan/months');
  26. } catch (Exception $e) {
  27. exit_error($e->getMessage());
  28. }
  29. $xpath = new DOMXPath($document);
  30. // find all months with non-zero number of posts
  31. $months = [];
  32. $rows = $xpath->query('//table/tbody/tr');
  33. foreach ($rows as $row) {
  34. $cols = $xpath->query('td', $row);
  35. $year = $cols[0]->nodeValue;
  36. for ($i = 1; $i < $cols->length; $i++) {
  37. if (
  38. $cols[$i]->firstChild->nodeType === XML_ELEMENT_NODE &&
  39. $cols[$i]->firstChild->tagName === 'a'
  40. ) {
  41. $months []= $year . '-' . str_pad($i, 2, '0', STR_PAD_LEFT);
  42. }
  43. }
  44. }
  45. // construct a linked data object corresponding to gathered data
  46. $ld = [
  47. '@context' => 'https://wandystan.eu/statistics/context.jsonld',
  48. '@type' => 'DataSet',
  49. 'title' => [
  50. 'en' => 'Posts by date and sender',
  51. 'pl' => 'Wiadomości wg daty i wysyłającego'
  52. ],
  53. 'description' => [
  54. 'en' => 'Statistics of number of posts sent by a given sender on a given date, grouped by period in which they were sent.',
  55. 'pl' => 'Statystyki liczby wiadomości wysłanych przez danego wysyłającego w danym dniu, pogrupowane wg okresu w jakim zostały wysłane.'
  56. ],
  57. 'publisher' => 'https://wandystan.eu/',
  58. 'structure' => 'structure/by-period',
  59. 'slices' => array_map(function ($month) { return "by-period/$month-01/P1M"; }, $months)
  60. ];
  61. header('Content-type: application/ld+json');
  62. print json_encode($ld);