From: Maxious Date: Tue, 23 Aug 2011 10:45:57 +0000 Subject: Add test of protobuf GTFS-realtime conversion to PHP X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=1e2c95dada70cdbb68b896e6729ef07c135be735 --- Add test of protobuf GTFS-realtime conversion to PHP --- --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -47,52 +47,29 @@ } $serviceAlertCause = Array( -UNKNOWN_CAUSE -OTHER_CAUSE -TECHNICAL_PROBLEM -STRIKE -DEMONSTRATION -ACCIDENT -HOLIDAY -WEATHER -MAINTENANCE -CONSTRUCTION -POLICE_ACTIVITY -MEDICAL_EMERGENCY - -Unknown cause -Other cause (not represented by any of these options) -Technical problem -Strike -Demonstration -Accident -Holiday -Weather -Maintenance -Construction -Police activity -Medical emergency +"UNKNOWN_CAUSE" => "Unknown cause", +"OTHER_CAUSE" => "Other cause", +"TECHNICAL_PROBLEM" => "Technical problem", +"STRIKE" => "Strike", +"DEMONSTRATION" => "Demonstration", +"ACCIDENT" => "Accident", +"HOLIDAY" => "Holiday", +"WEATHER" => "Weather", +"MAINTENANCE" => "Maintenance", +"CONSTRUCTION" => "Construction", +"POLICE_ACTIVITY" => "Police activity", +"MEDICAL_EMERGENCY" => "Medical emergency" ); $serviceAlertEffect = Array( -NO_SERVICE -REDUCED_SERVICE -SIGNIFICANT_DELAYS -DETOUR -ADDITIONAL_SERVICE -MODIFIED_SERVICE -OTHER_EFFECT -UNKNOWN_EFFECT -STOP_MOVED - -No service -Reduced service -Significant delays (insignificant delays should only be provided through Trip updates). -Detour -Additional service -Modified service -Stop moved -Other effect (not represented by any of these options) -Unknown effect); +"NO_SERVICE" => "No service", +"REDUCED_SERVICE" => "Reduced service", +"SIGNIFICANT_DELAYS" => "Significant delays", +"DETOUR" => "Detour", +"ADDITIONAL_SERVICE" => "Additional service", +"MODIFIED_SERVICE" => "Modified service", +"OTHER_EFFECT" => "Other effect", +"UNKNOWN_EFFECT" => "Unknown effect", +"STOP_MOVED" => "Stop moved"); function getServiceAlerts($filter_class, $filter_id) { /* --- /dev/null +++ b/lib/Protobuf-PHP/test.php @@ -1,1 +1,65 @@ +setGtfsRealtimeVersion(1); +$fh->setTimestamp(time()); +$fm->setHeader($fh); +$fe = new transit_realtime\FeedEntity(); + $fe->setId("1234"); + $alert = new transit_realtime\Alert(); + $tr = new transit_realtime\TimeRange(); + $tr->setStart(000); + $tr->setEnd(001); + $alert-> addActivePeriod($tr); + $es = new transit_realtime\EntitySelector(); + $es->setAgencyId("0"); + $es->setStopId("0"); + $es->setRouteId("0"); + $td = new transit_realtime\TripDescriptor(); + $td->setTripId("0"); + $es->setTrip($td); + $alert-> addInformedEntity($es); + $alert->setCause(constant("transit_realtime\Alert\Cause::"."UNKNOWN_CAUSE")); + $alert->setEffect(constant("transit_realtime\Alert\Effect::"."UNKNOWN_EFFECT")); + $tsUrl = new transit_realtime\TranslatedString(); + $tUrl = new transit_realtime\TranslatedString\Translation(); + $tUrl->setText("http"); + $tUrl->setLanguage("en"); + $tsUrl->addTranslation($tUrl); + $alert->setUrl($tsUrl); + $tsHeaderText= new transit_realtime\TranslatedString(); + $tHeaderText = new transit_realtime\TranslatedString\Translation(); + $tHeaderText->setText("http"); + $tHeaderText->setLanguage("en"); + $tsHeaderText->addTranslation($tHeaderText); + $alert->setHeaderText($tsHeaderText); + $tsDescriptionText= new transit_realtime\TranslatedString(); + $tDescriptionText = new transit_realtime\TranslatedString\Translation(); + $tDescriptionText->setText("http"); + $tDescriptionText->setLanguage("en"); + $tsDescriptionText->addTranslation($tDescriptionText); + $alert->setDescriptionText($tsDescriptionText); + $fe->setAlert($alert); +$fm->addEntity($fe); +//var_dump($fm); + +//$codec = new DrSlump\Protobuf\Codec\Binary(); +//echo $codec->encode($fm); + +$codec = new DrSlump\Protobuf\Codec\Json(); +echo $codec->encode($fm); + +?>