Plasma/Public Transport/CreateServiceProviders/ca: Difference between revisions

From KDE UserBase Wiki
(Created page with "*'''trim( string )''' (Elimina « » del principi i el final de la cadena donada). *'''stripTags( string )''' (Elimina totes les etiquetes de la cadena donada, és a di...")
(Created page with "*'''StopName''' ('''Obligatori per a suggeriments de parades'''. Serà el nom d'una parada/estació). *'''StopID''' (Serà l'identificador d'una parada/estació). *'''StopWeigh...")
Line 108: Line 108:
''Aquests elements d'informació només s'apliquen a suggeriments de parades:''
''Aquests elements d'informació només s'apliquen a suggeriments de parades:''


*'''StopName''' ('''Mandatory for stop suggestions''', The name of a stop / station)  
*'''StopName''' ('''Obligatori per a suggeriments de parades'''. Serà el nom d'una parada/estació).
*'''StopID''' (The ID of a stop / station)  
*'''StopID''' (Serà l'identificador d'una parada/estació).
*'''StopWeight''' (The weight of a stop suggestion)
*'''StopWeight''' (Serà el pes en rellevància per a un suggeriment de parada).


{{Info/ca|1=Més endavant hi haurà plantilles per a un fitxer XML i script. Fins llavors, podeu fer una ullada als proveïdors de serveis existents.}}
{{Info/ca|1=Més endavant hi haurà plantilles per a un fitxer XML i script. Fins llavors, podeu fer una ullada als proveïdors de serveis existents.}}

Revision as of 10:58, 14 March 2011

Other languages:

Crear un nou proveïdor de serveis

Els noms dels fitxers comencen amb el codi del país seguit d'un guió baix i un nom curt (i l'extensió, és clar). El nom del fitxer comença amb el codi de país o «international» o «unknown» seguit de «_» i un nom curt del proveïdor de serveis, per exemple, «de_db», «ch_sbb», «sk_atlas», «international_flightstats». El fitxer XML acaba amb «. xml».


El fitxer XML

Els enllaços als fitxers XML per al fitxer script que s'ha d'utilitzar i contindrà un «url pur», en aquest es pot inserir el nom de parada i altra informació.


El fitxer script

El fitxer script ha de contenir almenys una funció anomenada «parseTimetable», amb un argument. Tot el cos HTML anirà a l'script a través d'aquest argument. És llavors quan l'script analitza el document. Tot seguit us oferim una llista de funcions que criden al motor de dades PublicTransport per que s'analitzi un document:

  • parseTimetable( html ) (Usat per analitzar la sortida/arribada dels documents).
  • parseJourneys( html ) (Usat per analitzar els documents de viatge).
  • parsePossibleStops( html ) (Usat per analitzar els documents de suggeriment de parades).


Funcions auxiliars

Aquest és un objecte d'ajuda anomenat «helper», que pot ser utilitzat per l'script. Té les següents funcions:

  • trim( string ) (Elimina « » del principi i el final de la cadena donada).
  • stripTags( string ) (Elimina totes les etiquetes de la cadena donada, és a dir, elimina <...> o </...>).
  • camelCase( string ) (El primer caràcter de cada paraula serà en majúscula, totes les altres en minúscules).
  • extractBlock( string, beginString, endString ) (Retorna la cadena entre la primera aparició de beginString i la primera aparició de endString, o una cadena buida si beginString o endString no s'ha pogut trobar a la cadena. Per exemple, extractBlock("<b>Bold Text</b>", "<b>", "</b>") returna "Bold Text").
  • matchTime( string, formatString ) (Cerca una cadena d'hora en el format donat, per exemple, «hh:mm» retorna una llista amb dos nombres enters, l'hora i els minuts).
  • formatTime( hour, minute, formatString ) (Dona format a l'hora donada amb el formatString determinat).
  • duration( sTime1, sTime2, formatString ) (Torna la durada en minuts de sTime1 a sTime2, que són cadenes d'hora en el formatString determinat).
  • addMinsToTime( sTime, minsToAdd, formatString ) (Analitza l'hora amb el formatString determinat, afegeix minuts amb minsToAdd i especifica altra vegada el format utilitzant formatString).
  • splitSkipEmptyParts( string, separator ) (Divideix la cadena donada utilitzant el separador indicat, mentre que omet les parts buides).


Afegir sortides analitzades per al conjunt de resultats

Aquest és un objecte anomenat «timetableData» donat a l'script. Per afegir una sortida analitzada al conjunt de resultats feu alguna cosa com això:

// Add departure
 timetableData.clear();
 timetableData.set( 'TransportLine', 'N6' );
 timetableData.set( 'TypeOfVehicle', 'STR' );
 timetableData.set( 'Target', 'Bremen Hbf' );
 timetableData.set( 'DepartureHour', 1 );
 timetableData.set( 'DepartureMinute', 30 );
 result.addData( timetableData );

Això afegeix un punt de sortida de la línia de tramvia «N6», sortint a les 01:30 amb la destinació «Hbf Bremen».


Tipus d'Informació

Aquí teniu una llista de tots els tipus d'informació que es pot afegir a l'objecte timetableData per a sortida, arribada i viatge:

  • DepartureDate (The date of the departure)
  • DepartureHour (Mandatory for departures/arrivals/journeys, the hour of the departure)
  • DepartureMinute (Mandatory for departures/arrivals/journeys, the minute of the departure)
  • TransportLine (Mandatory for departures/arrivals, The name of the public transport line, e.g. "4", "6S", "S 5", "RB 24122")
  • Target (Mandatory for departures/arrivals, The target of a journey / of a public transport line)
  • TypeOfVehicle (The type of vehicle)
  • FlightNumber (Same as TransportLine, used for flights)
  • Platform (The platform at which the vehicle departs/arrives)
  • Delay (The delay of a public transport vehicle)
  • DelayReason (The reason of a delay)
  • JourneyNews (Can contain delay / delay reason / other news)
  • JourneyNewsOther (Other news (not delay / delay reason))
  • JourneyNewsLink (Contains a link to an html page with journey news. The url of the accessor is prepended, if a relative path has been matched (starting with "/"))
  • DepartureHourPrognosis (The prognosis for the departure hour, which is the departure hour plus the delay)
  • DepartureMinutePrognosis (The prognosis for the departure minute, which is the departure minute plus the delay)
  • Operator (The company that is responsible for the journey)
  • DepartureAMorPM (Used to match the string "am" or "pm" for the departure time)
  • DepartureAMorPMPrognosis (Used to match the string "am" or "pm" for the prognosis departure time)
  • ArrivalAMorPM (Used to match the string "am" or "pm" for the arrival time)
  • Status (The current status of the departure/arrival. Currently only used for planes)
  • DepartureYear (The year of the departure, to be used when the year is separated from the date)
  • RouteStops (A list of stops of the departure/arrival to its destination stop or a list of stops of the journey from its start to its destination stop. If RouteStops and RouteTimes are both set, they should contain the same number of elements. And elements with equal indices should be associated (the times at which the vehicle is at the stops). For journeys RouteTimesDeparture and RouteTimesArrival should be used instead of RouteTimes)
  • RouteTimes (A list of times of the departure/arrival to its destination stop. If RouteStops and RouteTimes are both set, they should contain the same number of elements. And elements with equal indices should be associated (the times at which the vehicle is at the stops))
  • RouteTimesDeparture (A list of departure times of the journey. If RouteStops and RouteTimesDeparture are both set, the latter should contain one elements less (because the last stop has no departure, only an arrival time). Elements with equal indices should be associated (the times at which the vehicle departs from the stops))
  • RouteTimesArrival (A list of arrival times of the journey. If RouteStops and RouteTimesArrival are both set, the latter should contain one elements less (because the first stop has no arrival, only a departure time). Elements with equal indices should be associated (the times at which the vehicle arrives at the stops))
  • RouteExactStops (The number of exact route stops. The route stop list isn't complete from the last exact route stop)
  • RouteTypesOfVehicles (The types of vehicles used for each "sub-journey" of a journey)
  • RouteTransportLines (The transport lines used for each "sub-journey" of a journey)
  • RoutePlatformsDeparture (The platforms of departures used for each "sub-journey" of a journey)
  • RoutePlatformsArrival (The platforms of arrivals used for each "sub-journey" of a journey)
  • RouteTimesDepartureDelay (A list of delays in minutes for each departure time of a route (RouteTimesDeparture))
  • RouteTimesArrivalDelay (A list of delays in minutes for each arrival time of a route (RouteTimesArrival))

Aquests elements d'informació només s'apliquen als viatges:

  • Duration (The duration of a journey)
  • StartStopName (The name of the starting stop of a journey)
  • StartStopID (The ID of the starting stop of a journey)
  • TargetStopName (The name of the target stop of a journey)
  • TargetStopID (The ID of the target stop of a journey)
  • ArrivalDate (The date of the arrival)
  • ArrivalHour (Mandatory for journeys, The hour of the arrival)
  • ArrivalMinute (Mandatory for journeys, The minute of the arrival)
  • Changes (The number of changes between different vehicles in a journey)
  • TypesOfVehicleInJourney (A list of vehicle types used in a journey)
  • Pricing (Information about the pricing of a journey)

Aquests elements d'informació només s'apliquen a suggeriments de parades:

  • StopName (Obligatori per a suggeriments de parades. Serà el nom d'una parada/estació).
  • StopID (Serà l'identificador d'una parada/estació).
  • StopWeight (Serà el pes en rellevància per a un suggeriment de parada).

Informació

Més endavant hi haurà plantilles per a un fitxer XML i script. Fins llavors, podeu fer una ullada als proveïdors de serveis existents.