package im.tny.segvault.disturbances;

import android.content.Context;

import java.util.Date;

import im.tny.segvault.s2ls.routing.NeutralWeighter;
import im.tny.segvault.subway.Connection;
import im.tny.segvault.subway.Network;
import im.tny.segvault.subway.Transfer;

/**
 * Created by gabriel on 4/27/17.
 */

public class DisturbanceAwareWeighter extends NeutralWeighter {
    private Context context;


    public DisturbanceAwareWeighter(Context context) {
        this.context = context;
    }

    @Override
    public double getEdgeWeight(Network network, Connection connection) {
        double weight = super.getEdgeWeight(network, connection);
        // make transferring to lines with disturbances much "heavier"
        LineStatusCache.Status s = Coordinator.get(context).getLineStatusCache().getLineStatus(connection.getTarget().getLine().getId());
        if (connection instanceof Transfer || isSource(connection.getSource())) {
            if (!isTarget(connection.getTarget()) && s != null &&
                    (s.down || connection.getTarget().getLine().isExceptionallyClosed(new Date()))) {
                // TODO adjust this according to disturbance severity, if possible
                weight += 100000;
                if(connection.getTarget().getLine().isExceptionallyClosed(new Date())) {
                    weight += 100000;
                }
            }
        }
        return weight;
    }
}

@@ -654,79 +654,9 @@
 n);%0A
-        // make transferring to lines with disturbances much %22heavier%22
 %0A
+
     
@@ -933,19 +933,115 @@
  != null
- &&
+%0A                    // make transferring to closed lines or lines with disturbances much %22heavier%22
 %0A       
@@ -1052,16 +1052,19 @@
         
+ &&
  (s.down
@@ -1066,16 +1066,36 @@
 .down %7C%7C
+%0A                   
  connect
@@ -1153,17 +1153,288 @@
  Date())
-)
+ %7C%7C%0A                    // make transferring through closed stations much %22heavier%22%0A                    connection.getTarget().getStation().isAlwaysClosed() %7C%7C%0A                    connection.getTarget().getStation().isExceptionallyClosed(network, new Date()))%0A            
 ) %7B%0A    
@@ -1538,32 +1538,32 @@
 ight += 100000;%0A
-
                 
@@ -1564,16 +1564,17 @@
       if
+ 
 (connect

Stop route planner from suggesting line changes through closed stations