From 5279c129209053024c8b7f8366254d80af5ccbc5 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Mon, 25 May 2015 11:32:47 +0200
Subject: [PATCH] --proximity / use_near_stops: Accept walking time in minutes

---
 Changelog                    |  7 +++++++
 bin/efa                      |  8 +++++---
 lib/Travel/Routing/DE/EFA.pm | 27 +++++++++++++++++++--------
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/Changelog b/Changelog
index 01c60d6..ffd89ef 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,10 @@
+git HEAD
+
+    * efa: Changed -p/--proximity default walking time from 8 to 10 minutes
+    * efa: The -p/--proximity option now takes an optional duration argument
+    * EFA: use_near_stops now accepts an integer (interpreted as walking time
+      in minutes) instead of a boolean value
+
 Travel::Routing::DE::VRR 2.09 - Fri Jan 09 2015
 
     * Travel::Routing::DE::EFA::Exception::Ambiguous: Add post_value accessor
diff --git a/bin/efa b/bin/efa
index 467c6cc..dd8019e 100755
--- a/bin/efa
+++ b/bin/efa
@@ -179,7 +179,7 @@ GetOptions(
 		max-change|m=i
 		num-connections|n=i
 		prefer|P=s
-		proximity|p
+		proximity|p:10
 		service|s=s
 		time|t=s
 		timeout=i
@@ -522,9 +522,11 @@ Prefer connections with less walking (at interchanges)
 
 =back
 
-=item B<-p>|B<--proximity>
+=item B<-p>|B<--proximity> [I<minutes>]
 
-Take stops close to the stop/start into account and possibly use them instead
+Take stops close to the stop/start into account.  By default, up to 10 minutes
+of walking to/from the route's first/last stop is considered acceptable. You
+can specify I<minutes> to use a custem value.
 
 =item B<-s>|B<--service> I<name>
 
diff --git a/lib/Travel/Routing/DE/EFA.pm b/lib/Travel/Routing/DE/EFA.pm
index 57791a0..fefc2bd 100644
--- a/lib/Travel/Routing/DE/EFA.pm
+++ b/lib/Travel/Routing/DE/EFA.pm
@@ -203,9 +203,16 @@ sub train_type {
 }
 
 sub use_near_stops {
-	my ( $self, $toggle ) = @_;
+	my ( $self, $duration ) = @_;
 
-	$self->{post}->{useProxFootSearch} = $toggle;
+	if ($duration) {
+		$self->{post}->{useProxFootSearch}  = 1;
+		$self->{post}->{trITArrMOTvalue100} = $duration;
+		$self->{post}->{trITDepMOTvalue100} = $duration;
+	}
+	else {
+		$self->{post}->{useProxFootSearch} = 0;
+	}
 
 	return;
 }
@@ -337,12 +344,12 @@ sub create_post {
 		sessionID                                          => 0,
 		text                                               => 1993,
 		trITArrMOT                                         => 100,
-		trITArrMOTvalue100                                 => 8,
+		trITArrMOTvalue100                                 => 10,
 		trITArrMOTvalue101                                 => 10,
 		trITArrMOTvalue104                                 => 10,
 		trITArrMOTvalue105                                 => 10,
 		trITDepMOT                                         => 100,
-		trITDepMOTvalue100                                 => 8,
+		trITDepMOTvalue100                                 => 10,
 		trITDepMOTvalue101                                 => 10,
 		trITDepMOTvalue104                                 => 10,
 		trITDepMOTvalue105                                 => 10,
@@ -380,7 +387,7 @@ sub create_post {
 		$self->select_interchange_by( $conf->{select_interchange_by} );
 	}
 	if ( $conf->{use_near_stops} ) {
-		$self->use_near_stops(1);
+		$self->use_near_stops( $conf->{use_near_stops} );
 	}
 	if ( $conf->{train_type} ) {
 		$self->train_type( $conf->{train_type} );
@@ -960,9 +967,13 @@ EFA server is used (usually 4 or 5).
 Prefer either fast connections (default), connections with low wait time or
 connections with little distance to walk
 
-=item B<use_near_stops> => B<0>|B<1>
+=item B<use_near_stops> => I<$int>
+
+If I<$int> is a true value: Take stops close to the stop/start into account and
+possibly use them instead. Up to I<$int> minutes of walking are considered
+acceptable.
 
-If true: Try using near stops instead of the specified origin/destination ones
+Otherwise: Do not take stops close to stop/start into account.
 
 =item B<train_type> => B<local>|B<ic>|B<ice>
 
@@ -1021,7 +1032,7 @@ The following methods act like the arguments to B<new>. See there.
 
 =item $efa->train_type(I<$type>)
 
-=item $efa->use_near_stops(I<$bool>)
+=item $efa->use_near_stops(I<$duration>)
 
 =item $efa->walk_speed(I<$speed>)
 
-- 
GitLab