Example #1
0
        public RoutesMoveHackList GetRoutes(string source, string destination, string departure_time = null)
        {
            var routes = new  RoutesMoveHackList();

            source      = source + " Delhi India";
            destination = destination + " Delhi India";
            if (departure_time == null)
            {
                departure_time = ToEpoch(DateTime.UtcNow).ToString();
            }
            routes.Routes = new List <RoutesMoveHack>();

            var bus = true;

            AddRoutes(routes);
            foreach (var ro in routes.Routes[0].Steps)
            {
                if (ro.Type == "METRO")
                {
                    bus = false;
                }
            }
            if (!bus)
            {
                //   AddRoutes(urlGet, routes);
            }

            return(routes);
        }
Example #2
0
        private static void AddRoutes(RoutesMoveHackList routes)
        {
            var path        = new List <LocalTrainStation>();
            var path1       = new List <LocalTrainStation>();
            var source      = routes.ToString();
            var destination = routes.ToString();
            //Connect to neo4j
            GraphClient graphClient = null;
            var         time        = "";

            if (string.IsNullOrEmpty(time))
            {
                time = DateTime.Now.ToString("hh:mm tt");
            }
            var now = DateTime.Parse(time).TimeOfDay;;

            try
            {
                graphClient = new GraphDb().GetClient();
                if (!graphClient.IsConnected)
                {
                    graphClient.Connect();
                }
            }
            catch (Exception e)
            {
                graphClient = new GraphDb().GetClient();
                graphClient.Connect();
            }
            //Neo4j Query
            var data =
                "MATCH (start:Stations) , (end:Stations ) MATCH p = allShortestPaths((start) -[r:route *]->(end)) where start.Station =~ '(?i){0}' and end.Station =~ '(?i){1}' and  not start = end and  all(m2 in relationships(p) where  m2.time > 0) RETURN extract(n in nodes(p) | n.Station) as Names, reduce(sum = 0, nn IN relationships(p) | sum + nn.time) as sum order by sum limit 5";
            string query = String.Format(data,
                                         source, destination);
            var result =
                ((IRawGraphClient)graphClient).ExecuteGetCypherResults <PathReturn>(new CypherQuery(query, null,
                                                                                                    Neo4jClient.Cypher.CypherResultMode.Projection));

            routes.Routes.AddRange((List <RoutesMoveHack>)result);
        }