Navitia: New Brazil provider, covering São Paulo, Rio de Janeiro, Belo Horizonte and Porto Allegre.

This commit is contained in:
Torsten Grote 2017-12-05 12:31:07 -02:00 committed by Andreas Schildbach
parent 82c6761097
commit d32131cfa7
3 changed files with 156 additions and 0 deletions

View file

@ -0,0 +1,67 @@
/*
* Copyright the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.schildbach.pte;
import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Style;
import de.schildbach.pte.dto.Style.Shape;
/**
* @author Torsten Grote
*/
public class BrazilProvider extends AbstractNavitiaProvider {
private static final String API_REGION = "br";
public BrazilProvider(final String authorization) {
super(NetworkId.BRAZIL, authorization);
setTimeZone("America/Sao_Paulo");
}
@Override
public String region() {
return API_REGION;
}
@Override
protected Style getLineStyle(final String network, final Product product, final String code, final String color) {
final Style defaultStyle = Standard.STYLES.get(product);
int bc = defaultStyle.backgroundColor;
int fc = defaultStyle.foregroundColor;
if (color != null) {
bc = Style.parseColor(color);
fc = computeForegroundColor(color);
}
switch (product) {
case SUBURBAN_TRAIN: {
return new Style(Shape.CIRCLE, bc, fc);
}
case SUBWAY: {
return new Style(Shape.CIRCLE, bc, fc);
}
case TRAM: {
return new Style(Shape.RECT, bc, fc);
}
case BUS: {
return new Style(Shape.RECT, bc, fc);
}
default:
return new Style(bc, fc);
}
}
}

View file

@ -92,4 +92,7 @@ public enum NetworkId {
// Nicaragua
NICARAGUA,
// Brazil
BRAZIL,
}

View file

@ -0,0 +1,86 @@
/*
* Copyright the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.schildbach.pte.live;
import de.schildbach.pte.BrazilProvider;
import de.schildbach.pte.dto.Point;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* @author Torsten Grote
*/
public class BrazilProviderLiveTest extends AbstractNavitiaProviderLiveTest {
public BrazilProviderLiveTest() {
super(new BrazilProvider(secretProperty("navitia.authorization")));
}
@Test
public void nearbyStationsAddress() throws Exception {
// Sao Paulo
nearbyStationsAddress(-23547900, -46635200);
}
@Test
public void nearbyStationsAddress2() throws Exception {
// Rio de Janeiro
nearbyStationsAddress(-22905300, -43179500);
}
@Test
public void nearbyStationsStation() throws Exception {
nearbyStationsStation("stop_point:OIO:SP:18255914");
}
@Test
public void nearbyStationsInvalidStation() throws Exception {
nearbyStationsInvalidStation("stop_point:OIO:SPX:18255914");
}
@Test
public void queryDeparturesEquivsFalse() throws Exception {
queryDeparturesEquivsFalse("stop_point:OSA:SP:800016608");
}
@Test
public void queryDeparturesInvalidStation() throws Exception {
queryDeparturesInvalidStation("stop_point:OWX:SP:6911");
}
@Test
public void suggestLocations() throws Exception {
suggestLocationsFromName("Republica");
}
@Test
public void queryTripStations() throws Exception {
queryTrip("Benjamim Constant", "Avenida Paulista");
}
@Test
public void queryMoreTrips() throws Exception {
queryMoreTrips("Republica", "Avenida Paulista");
}
@Test
public void getArea() throws Exception {
final Point[] polygon = provider.getArea();
assertTrue(polygon.length > 0);
}
}