Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
into tc_issue_98

# Conflicts:
#	transitclock/pom.xml

- Add headway information to synoptic view
- Add color of bus according to schAdh
- Needed to be tested in two directions route
- Merge develop and tc_issue_74
  • Loading branch information
vperez committed Sep 4, 2018
2 parents a9935d5 + ae1c74e commit 2cfae2a
Show file tree
Hide file tree
Showing 45 changed files with 3,585 additions and 88 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
*.jar
*.war
*.ear
*.log
/bin/
/.settings/
/.settings/
.DS_Store

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk: oraclejdk8
jdk: openjdk8
cache:
directories:
- "$HOME/.m2"
Expand All @@ -24,4 +24,4 @@ deploy:
on:
repo: TheTransitClock/transitime
tags: false
all_branches: true
branch: develop
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<module>transitclockApi</module>
<module>transitclockWebapp</module>
<module>transitclockQuickStart</module>
<module>transitclockTraccarClient</module>
<module>transitclockBarefootClient</module>
</modules>
<profiles>
<profile>
Expand All @@ -28,6 +30,8 @@
<module>transitclockApi</module>
<module>transitclockWebapp</module>
<module>transitclockQuickStart</module>
<module>transitclockTraccarClient</module>
<module>transitclockBarefootClient</module>
</modules>
</profile>
</profiles>
Expand Down
28 changes: 24 additions & 4 deletions transitclock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>transitclockCore</name>
<repositories>

<!-- Needed to fix problem with one-jar not working with AWS SDK. Was getting
<!-- Needed to fix problem with one-jar not working with AWS SDK. Was getting
error message "Fatal: Failed to load the internal config for AWS" -->
<repository>
<snapshots>
Expand All @@ -30,7 +30,21 @@
</pluginRepository>
</pluginRepositories>
<dependencies>

<dependency>
<groupId>TheTransitClock</groupId>
<artifactId>transitclockBarefootClient</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>TheTransitClock</groupId>
<artifactId>transitclockTraccarClient</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.esri.geometry</groupId>
<artifactId>esri-geometry-api</artifactId>
<version>1.1</version>
</dependency>
<!-- Needed to fix problem with one-jar not working with AWS SDK. Was getting
error message "Fatal: Failed to load the internal config for AWS" -->
<dependency>
Expand Down Expand Up @@ -244,6 +258,12 @@
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Logback log appender for AWS CloudWatch -->
<dependency>
<groupId>com.j256.cloudwatchlogbackappender</groupId>
<artifactId>cloudwatchlogbackappender</artifactId>
<version>1.11</version>
</dependency>
<!-- OLS regression algorithm -->
<dependency>
<groupId>com.github.haifengl</groupId>
Expand All @@ -258,8 +278,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package org.transitclock.avl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.transitclock.applications.Core;
import org.transitclock.db.structs.AvlReport;
import org.transitclock.utils.IntervalTimer;
import org.transitclock.utils.Time;

import com.esri.core.geometry.Point;

public class BarefootPlaybackModule extends PlaybackModule {
private static final Logger logger =
LoggerFactory.getLogger(PlaybackModule.class);

public BarefootPlaybackModule(String agencyId) {
super(agencyId);

}

@Override
public void run() {

IntervalTimer timer = new IntervalTimer();
// Keep running as long as not trying to access in the future.

while (dbReadBeginTime < System.currentTimeMillis() && (playbackEndTimeStr.getValue().length()==0 || dbReadBeginTime<parsePlaybackEndTime(playbackEndTimeStr.getValue()))) {
List<AvlReport> avlReports = getBatchOfAvlReportsFromDb();

// Process the AVL Reports read in.
long last_avl_time=-1;
for (AvlReport avlReport : avlReports) {
logger.info("Processing avlReport={}", avlReport);

// Update the Core SystemTime to use this AVL time
Core.getInstance().setSystemTime(avlReport.getTime());

DateFormat estFormat = new SimpleDateFormat("yyyyMMddHHmmss");
TimeZone estTime = TimeZone.getTimeZone("EST");
estFormat.setTimeZone(estTime);

TimeZone gmtTime = TimeZone.getTimeZone("GMT");
DateFormat gmtFormat = new SimpleDateFormat("yyyyMMddHHmmss");
gmtFormat.setTimeZone(gmtTime);

String estDate=estFormat.format(avlReport.getTime());
String gmtDate=gmtFormat.format(avlReport.getTime());


if(playbackRealtime.getValue()==true)
{
if(last_avl_time>-1)
{
try {
// only sleep if values less than 10 minutes. This is to allow it skip days/hours of missing data.
if((avlReport.getTime()-last_avl_time)<600000)
{
Thread.sleep(avlReport.getTime()-last_avl_time);
}
last_avl_time=avlReport.getTime();
} catch (InterruptedException e) {
e.printStackTrace();
}
}else
{
last_avl_time=avlReport.getTime();
}
}
// Send avl to barefoot server.
sendUpdate(avlReport);

}
}
// logging here as the rest is database access dependent.
logger.info("Processed AVL from playbackStartTimeStr:{} to playbackEndTimeStr:{} in {} secs.",playbackStartTimeStr,playbackEndTimeStr, Time.secondsStr(timer.elapsedMsec()));


// Wait for database queue to be emptied before exiting.
while(Core.getInstance().getDbLogger().queueSize()>0)
{
try {
Thread.sleep(10000);
} catch (InterruptedException e) {

}
}


logger.info("Read in AVL in playback mode all the way up to current " +
"time so done. Exiting.");

System.exit(0);
}
public void sendUpdate(AvlReport avlReport) {
try {
JSONObject report = new JSONObject();

InetAddress host = InetAddress.getLocalHost();

int port = 1234;

report.put("id", avlReport.getVehicleId());

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");

report.put("time", df.format(avlReport.getDate()));

Point point = new Point();
point.setX(avlReport.getLon());
point.setY(avlReport.getLat());

report.put("point", "POINT(" + avlReport.getLon() + " " + avlReport.getLat() + ")");
// report.put("point", GeometryEngine.geometryToGeoJson(point));

sendBareFootSample(host, port, report);

} catch (Exception e) {
logger.error("Problem when sending samples to barefoot.", e);
}
}

private void sendBareFootSample(InetAddress host, int port, JSONObject sample) throws Exception {
int trials = 120;
int timeout = 500;
Socket client = null;
// TODO Will need to leave socket open.
while (client == null || !client.isConnected()) {
try {
client = new Socket(host, port);
} catch (IOException e) {
Thread.sleep(timeout);

if (trials == 0) {
logger.error(e.getMessage());
client.close();
throw new IOException();
} else {
trials -= 1;
}
}
}
PrintWriter writer = new PrintWriter(client.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
writer.println(sample.toString());
writer.flush();

String code = reader.readLine();
if (!code.equals("SUCCESS")) {
throw new Exception("Barefoot server did not respond with SUCCESS. Code="+code);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.transitclock.avl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Collection;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.transitclock.db.structs.AvlReport;

import com.esri.core.geometry.Point;

public class NextBusBarefootAvlModule extends NextBusAvlModule {
private static final Logger logger = LoggerFactory
.getLogger(NextBusBarefootAvlModule.class);
public NextBusBarefootAvlModule(String agencyId) {
super(agencyId);
}

@Override
protected void processAvlReports(Collection<AvlReport> avlReports) {
forwardAvlReports(avlReports);
}


protected void forwardAvlReports(Collection<AvlReport> avlReportsReadIn) {
for(AvlReport avlReport:avlReportsReadIn)
{
sendUpdate(avlReport);
}
}

public void sendUpdate(AvlReport avlReport) {
try {
JSONObject report = new JSONObject();

InetAddress host = InetAddress.getLocalHost();

int port = 1234;

report.put("id", avlReport.getVehicleId());

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");

report.put("time", df.format(avlReport.getDate()));

Point point = new Point();
point.setX(avlReport.getLon());
point.setY(avlReport.getLat());

report.put("point", "POINT(" + avlReport.getLon() + " " + avlReport.getLat() + ")");
// report.put("point", GeometryEngine.geometryToGeoJson(point));

sendBareFootSample(host, port, report);

} catch (Exception e) {
logger.error("Problem when sending samples to barefoot.", e);
}
}

private void sendBareFootSample(InetAddress host, int port, JSONObject sample) throws Exception {
int trials = 120;
int timeout = 500;
Socket client = null;
// TODO Will need to leave socket open.
while (client == null || !client.isConnected()) {
try {
client = new Socket(host, port);
} catch (IOException e) {
Thread.sleep(timeout);

if (trials == 0) {
logger.error(e.getMessage());
client.close();
throw new IOException();
} else {
trials -= 1;
}
}
}
PrintWriter writer = new PrintWriter(client.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
writer.println(sample.toString());
writer.flush();

String code = reader.readLine();
if (!code.equals("SUCCESS")) {
throw new Exception("Barefoot server did not respond with SUCCESS. Code="+code);
}
}
}
Loading

0 comments on commit 2cfae2a

Please sign in to comment.