Search in sources :

Example 16 with Line

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;
            }
        }
    }
}
Also used : Line(im.tny.segvault.subway.Line) Network(im.tny.segvault.subway.Network) Intent(android.content.Intent)

Example 17 with Line

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;
}
Also used : Line(im.tny.segvault.subway.Line) Stop(im.tny.segvault.subway.Stop) Connection(im.tny.segvault.subway.Connection) HashSet(java.util.HashSet)

Example 18 with Line

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;
}
Also used : Line(im.tny.segvault.subway.Line) HashMap(java.util.HashMap) File(java.io.File) FileInputStream(java.io.FileInputStream) APIException(im.tny.segvault.disturbances.exception.APIException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Line (im.tny.segvault.subway.Line)18 Network (im.tny.segvault.subway.Network)8 Intent (android.content.Intent)5 Connection (im.tny.segvault.subway.Connection)5 SharedPreferences (android.content.SharedPreferences)4 Lobby (im.tny.segvault.subway.Lobby)4 Station (im.tny.segvault.subway.Station)4 Stop (im.tny.segvault.subway.Stop)4 ArrayList (java.util.ArrayList)4 View (android.view.View)3 FrameLayout (android.widget.FrameLayout)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 POI (im.tny.segvault.subway.POI)3 WorldPath (im.tny.segvault.subway.WorldPath)3 FileInputStream (java.io.FileInputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3