generateicalendardata.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env php
  2. <?php
  3. use Sabre\VObject;
  4. if ($argc<2) {
  5. $cmd = $argv[0];
  6. fwrite(STDERR, <<<HI
  7. Fruux test data generator
  8. This script generates a lot of test data. This is used for profiling and stuff.
  9. Currently it just generates events in a single calendar.
  10. The iCalendar output goes to stdout. Other messages to stderr.
  11. {$cmd} [events]
  12. HI
  13. );
  14. die();
  15. }
  16. $events = 100;
  17. if (isset($argv[1])) $events = (int)$argv[1];
  18. include __DIR__ . '/../vendor/autoload.php';
  19. fwrite(STDERR, "Generating " . $events . " events\n");
  20. $currentDate = new DateTime('-' . round($events/2) . ' days');
  21. $calendar = VObject\Component::create('VCALENDAR');
  22. $calendar->version = '2.0';
  23. $calendar->calscale = 'GREGORIAN';
  24. $ii=0;
  25. while($ii < $events) {
  26. $ii++;
  27. $event = VObject\Component::create('VEVENT');
  28. $event->DTSTART = 'bla';
  29. $event->SUMMARY = 'Event #' . $ii;
  30. $event->UID = md5(microtime(true));
  31. $doctorRandom = mt_rand(1,1000);
  32. switch($doctorRandom) {
  33. // All-day event
  34. case 1 :
  35. $event->DTEND = 'bla';
  36. $dtStart = clone $currentDate;
  37. $dtEnd = clone $currentDate;
  38. $dtEnd->modify('+' . mt_rand(1,3) . ' days');
  39. $event->DTSTART->setDateTime($dtStart, VObject\Property\DateTime::DATE);
  40. $event->DTEND->setDateTime($dtEnd, VObject\Property\DateTime::DATE);
  41. break;
  42. case 2 :
  43. $event->RRULE = 'FREQ=DAILY;COUNT=' . mt_rand(1,10);
  44. // No break intentional
  45. default :
  46. $dtStart = clone $currentDate;
  47. $dtStart->setTime(mt_rand(1,23), mt_rand(0,59), mt_rand(0,59));
  48. $event->DTSTART->setDateTime($dtStart, VObject\Property\DateTime::UTC);
  49. $event->DURATION = 'PT'.mt_rand(1,3).'H';
  50. break;
  51. }
  52. $calendar->add($event);
  53. $currentDate->modify('+ ' . mt_rand(0,3) . ' days');
  54. }
  55. fwrite(STDERR, "Validating\n");
  56. $result = $calendar->validate();
  57. if ($result) {
  58. fwrite(STDERR, "Errors!\n");
  59. fwrite(STDERR, print_r($result,true));
  60. die(-1);
  61. }
  62. fwrite(STDERR, "Serializing this beast\n");
  63. echo $calendar->serialize();
  64. fwrite(STDERR, "done.\n");