use of im.tny.segvault.subway.Line in project underlx by underlx.
the class MainActivity method onListFragmentInteraction.
@Override
public void onListFragmentInteraction(LineRecyclerViewAdapter.LineItem item) {
if (locService != null) {
for (Network network : locService.getNetworks()) {
Line line;
if ((line = network.getLine(item.id)) != null) {
Intent intent = new Intent(this, LineActivity.class);
intent.putExtra(LineActivity.EXTRA_LINE_ID, line.getId());
intent.putExtra(LineActivity.EXTRA_NETWORK_ID, network.getId());
startActivity(intent);
return;
}
}
}
}
use of im.tny.segvault.subway.Line in project underlx by underlx.
the class MainService method getLikelyNextExit.
public Stop getLikelyNextExit(List<Connection> path, double threshold) {
if (path.size() == 0) {
return null;
}
// get the line for the latest connection
Connection last = path.get(path.size() - 1);
Line line = null;
for (Line l : getAllLines()) {
if (l.edgeSet().contains(last)) {
line = l;
break;
}
}
if (line == null) {
return null;
}
Set<Stop> alreadyVisited = new HashSet<>();
for (Connection c : path) {
alreadyVisited.add(c.getSource());
alreadyVisited.add(c.getTarget());
}
// get all the stops till the end of the line, after the given connection
// (or in the case of circular lines, all stops of the line)
Stop maxStop = null;
double max = 0;
Set<Stop> stops = new HashSet<>();
while (stops.add(last.getSource())) {
Stop curStop = last.getTarget();
if (!alreadyVisited.contains(curStop)) {
double r = getLeaveTrainFactorForStop(curStop);
if (maxStop == null || r > max) {
maxStop = curStop;
max = r;
}
}
if (line.outDegreeOf(curStop) == 1) {
break;
}
for (Connection outedge : line.outgoingEdgesOf(curStop)) {
if (!stops.contains(outedge.getTarget())) {
last = outedge;
break;
}
}
}
if (max < threshold) {
// most relevant station is not relevant enough
return null;
}
return maxStop;
}
use of im.tny.segvault.subway.Line in project underlx by underlx.
the class StatsCache method readStats.
private HashMap<String, Stats> readStats() {
HashMap<String, Stats> info;
try {
FileInputStream fis = new FileInputStream(new File(context.getCacheDir(), STATS_CACHE_FILENAME));
ObjectInputStream is = new ObjectInputStream(fis);
info = (HashMap) is.readObject();
is.close();
fis.close();
Map<String, Line> lines = new HashMap<>();
for (Line l : mainService.getAllLines()) {
lines.put(l.getId(), l);
}
for (Stats stats : info.values()) {
if (!(stats instanceof Stats)) {
throw new Exception();
}
for (LineStats l : stats.weekLineStats.values()) {
if (!(l instanceof LineStats)) {
throw new Exception();
}
}
for (LineStats l : stats.monthLineStats.values()) {
if (!(l instanceof LineStats)) {
throw new Exception();
}
}
}
} catch (Exception e) {
// caching is best-effort
return null;
}
return info;
}
Aggregations