Skip to content

Instantly share code, notes, and snippets.

@seryh
Created June 29, 2016 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seryh/84031fb71a4818e57773b18ebf37a2cc to your computer and use it in GitHub Desktop.
Save seryh/84031fb71a4818e57773b18ebf37a2cc to your computer and use it in GitHub Desktop.
(ns iway.utils)
(def ^:const TYPE-PLACES {0 :RENT
1 :SUBURB
2 :AIRPORT
3 :STATION
4 :NEAR
5 :LOCALITY
6 :OTHER
7 :MKAD
8 :KAD
9 :CENTRE
10 :HOTEL})
(defn parse-int [s]
(Integer/parseInt (re-find #"\A-?\d+" s)))
(defmulti get-iway-type-route (fn ([start-id finish-id]
[(class start-id) (class finish-id)])))
(defmethod get-iway-type-route [String String] [start-id finish-id]
(get-iway-type-route (parse-int start-id) (parse-int finish-id)))
(defmethod get-iway-type-route [Long Long] [start-id finish-id]
(get-iway-type-route (int start-id) (int finish-id)))
(defmethod get-iway-type-route [Integer Integer] [start-id finish-id]
(let [SUBURBS [:NEAR :LOCALITY :MKAD :KAD :CENTRE]
HOTELS [:HOTEL :OTHER]
get-label (fn [place-id]
(let [place (TYPE-PLACES place-id)]
(cond
(some #(= place %) SUBURBS) :SUBURB
(some #(= place %) HOTELS) :HOTEL
:else place)))
start-label (name (get-label start-id))
finish-label (name (get-label finish-id))]
(keyword (str start-label "-" finish-label))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment