Jump to content

How to implement the backend of a journey planner ?

I am planning to make an app for the metro system in my city.
I am stumped as to how to implement the backend if I know the source and destination.

I basically want to make a clean user-friendly app that gives the info shown in the photo(From Official website)
http://www.delhimetrorail.com/metro-fares.aspx

Any Sort of help is appreciated. I am completely stumped 

Planner.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

You could do a headless browser that submitted and used "GET" requests to the official website (so you get like JSON or HTML or something). Then, take what's on the website, scrape off the good information, and display it in your app.

Want to know which mobo to get?

Spoiler

Choose whatever you need. Any more, you're wasting your money. Any less, and you don't get the features you need.

 

Only you know what you need to do with your computer, so nobody's really qualified to answer this question except for you.

 

chEcK iNsidE sPoilEr fOr a tREat!

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for the suggestion and that's my backup plan. But I would really like to build a proper backend. It's a college project and I want to learn how to use databases and other backend services (Which I know very little about ). It's more about learning to do something rather than getting the app done. :):) 
 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, mrmayurs4 said:

Thanks for the suggestion and that's my backup plan. But I would really like to build a proper backend. It's a college project and I want to learn how to use databases and other backend services (Which I know very little about ). It's more about learning to do something rather than getting the app done. :):) 
 

At work we use node. Look into servers.io it's built on express and makes making rest apis pretty simple.

 

I use it at work when making simple services though for our main product with use express.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Without knowing the relation of the data, and the set of data itself I can't give you a great suggestion.

 

The naive solution would be to make a doubly-linked list. You shouldn't take the below as gospel, speed times will be awful - worse than O(n); but the naive solution will get you started. There are gaps in solution, and logic, but it should help.

 

data TransitLine
  = Central
  | Northern
  | District
  | Circle

-- Some go north/south, but for simplicity we'll assume they're the same
data Direction
  = East
  | West

type GetNextStation
  = Direction -> Maybe Station

data Station
  = Station
      { name          :: Text
      , lines         :: [TransitLine]
      , nextStation   :: GetNextStation
      , intersections :: [Station]
      }

mkStation :: Text -> [TransitLine] -> GetNextStation -> ]Station] -> Station
mkStation
  -- construct the station
  = undefined

nextStationOnLine ::  Direction -> TransitLine -> Station -> Maybe Station
nextStationOnLine direction station
  -- run nextStation function with direction 
  = undefined

stationList :: [Station]
stationList
  = [ mkStation
    , ...
    ]

-- return "can't find path" or the list of stations and the line
shortestPathBetween :: Station -> Station -> Either String [(TransitLine, Station)]
shortestPathBetween
  -- implement dijkstra shortest path
  = undefined

The above is Haskell, if the syntax doesn't make sense I can explain it further.

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for the reply

On 2/18/2018 at 4:00 AM, vorticalbox said:

At work we use node. Look into servers.io it's built on express and makes making rest apis pretty simple.

 

I use it at work when making simple services though for our main product with use express.

Thanks for the reply, but I really don't know anything about node or express, it would be nice if you could point me to some resource or example with similar sort of implementation. If need be I am ready to learn node.js . I am currently using w3schools  to learn the basics of node.js but don't want to sink too much time unless its the final solution. 

Link to comment
Share on other sites

Link to post
Share on other sites

22 hours ago, nuc said:

Without knowing the relation of the data, and the set of data itself I can't give you a great suggestion.

 

The naive solution would be to make a doubly-linked list. You shouldn't take the below as gospel, speed times will be awful - worse than O(n); but the naive solution will get you started. There are gaps in solution, and logic, but it should help.

 


data TransitLine
  = Central
  | Northern
  | District
  | Circle

-- Some go north/south, but for simplicity we'll assume they're the same
data Direction
  = East
  | West

type GetNextStation
  = Direction -> Maybe Station

data Station
  = Station
      { name          :: Text
      , lines         :: [TransitLine]
      , nextStation   :: GetNextStation
      , intersections :: [Station]
      }

mkStation :: Text -> [TransitLine] -> GetNextStation -> ]Station] -> Station
mkStation
  -- construct the station
  = undefined

nextStationOnLine ::  Direction -> TransitLine -> Station -> Maybe Station
nextStationOnLine direction station
  -- run nextStation function with direction 
  = undefined

stationList :: [Station]
stationList
  = [ mkStation
    , ...
    ]

-- return "can't find path" or the list of stations and the line
shortestPathBetween :: Station -> Station -> Either String [(TransitLine, Station)]
shortestPathBetween
  -- implement dijkstra shortest path
  = undefined

The above is Haskell, if the syntax doesn't make sense I can explain it further.

I don't know Haskell but will look it to it and get back to you, My question is how am I supposed to implement the algorithm above on a server provided the information available is here and the official journey planner, lets forget about cost and time I just want to go from source station to destination station, all that's needed is the list of stations and interchanges the user will have to take.

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, mrmayurs4 said:

Thanks for the reply

Thanks for the reply, but I really don't know anything about node or express, it would be nice if you could point me to some resource or example with similar sort of implementation. If need be I am ready to learn node.js . I am currently using w3schools  to learn the basics of node.js but don't want to sink too much time unless its the final solution. 

I like http://serverjs.io for making rest applications. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, mrmayurs4 said:

I don't know Haskell but will look it to it and get back to you, My question is how am I supposed to implement the algorithm above on a server provided the information available is here and the official journey planner, lets forget about cost and time I just want to go from source station to destination station, all that's needed is the list of stations and interchanges the user will have to take.

Above was modelling a potential data representation solution - Haskell is just my current choice/employed language, and I feel it's clear and concise enough for most people to understand data structures (other language features <<>~, >>=, <|>, etc, probably not).

Your endpoint would fill out the shortestPathBetween function; this function would return all stations along the path - if you wish to group them, that's up to you as well. If you need more assistance, you'd want to send a POST request to your handler with a body like:

{
	"from": "Nawada",
	"to": "Jor Bagh",
	"time": "2018-02-19T20:00:00Z"
}

and would ideally return a structure similar to:

{
	"from": "Nawada",
	"to": "Jor Bagh",
	"time": "2018-02-19T20:00:00Z",
	"stations":
		[ { line: "Blue", station: "Nawada" }
		, ...
		, { line: "Yellow", station: "Jor Bagh" }
		]
}

 

You don't need to use Haskell by any means, but the concept of an n-linked list is the same.

 

Adding in time would change the results, as we'd need to record average time between all stations. Least jumps wouldn't always be the shortest path.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×