commit bd365b6aa86483bd77d7586fccfbae8d1c61b353
parent ead3c4304e8b9f7efb94884560e6e0a4c79bb203
Author: Kebigon <git@kebigon.xyz>
Date: Mon, 16 Mar 2020 21:42:39 +0900
Convert travel distance to the nearest station into walk time
Diffstat:
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/main/java/xyz/kebigon/housesearch/browser/suumo/SuumoBrowser.java b/src/main/java/xyz/kebigon/housesearch/browser/suumo/SuumoBrowser.java
@@ -60,9 +60,22 @@ public class SuumoBrowser extends Browser
final String stationField = getField(posting, "沿線・駅");
final int walkTimeToStationSubstringIndex = stationField.indexOf("徒歩");
- final Integer walkTimeToStation = walkTimeToStationSubstringIndex != -1
- ? Integer.parseInt(stationField.substring(walkTimeToStationSubstringIndex + 2, stationField.indexOf("分", walkTimeToStationSubstringIndex)))
- : null;
+ Integer walkTimeToStation = null;
+ if (walkTimeToStationSubstringIndex != -1)
+ walkTimeToStation = Integer
+ .parseInt(stationField.substring(walkTimeToStationSubstringIndex + 2, stationField.indexOf("分", walkTimeToStationSubstringIndex)));
+ else
+ {
+ final int carIndex = stationField.indexOf("車");
+ final int kmIndex = stationField.indexOf("km");
+
+ if (carIndex != -1 && kmIndex != -1)
+ {
+ final double distanceToStation = Double.parseDouble(stationField.substring(carIndex + 1, kmIndex));
+ // I'll take 1.43 m/s = 11.7 min/km as average walking speed
+ walkTimeToStation = (int) (distanceToStation * 11.7d);
+ }
+ }
final int stationOpenBracketIndex = stationField.indexOf('「');
final int stationCloseBracketIndex = stationField.indexOf('」');