Commit fa8630fa authored by O.V.B Sewmina's avatar O.V.B Sewmina

Merge branch 'master' into 'IT19242996'

Master

See merge request 2022-020/2022-020!32
parents 130463ad 3d3a5278
{ {
"python.analysis.extraPaths": [ "python.analysis.extraPaths": [
"./TravelTimePrediction/TrainData" "./TravelTimePrediction/TrainData",
] "./TravelTimePrediction"
} ]
\ No newline at end of file }
...@@ -196,6 +196,9 @@ weather =testingWeather.weather(city) #Get weather in travel area ...@@ -196,6 +196,9 @@ weather =testingWeather.weather(city) #Get weather in travel area
Distance =14.7 #Distance data come from seminas ----- data come from the Seminas data/member of route planning Distance =14.7 #Distance data come from seminas ----- data come from the Seminas data/member of route planning
#- ToDO
# callTimePrediction arguments should be dis, stops, hour, day
# Get Prediction USing this Method after Seminas Calling # Get Prediction USing this Method after Seminas Calling
def CallTimePrediction(distance,BuStops,TodayDate): def CallTimePrediction(distance,BuStops,TodayDate):
FnewDate = GetDateCode(TodayDate) FnewDate = GetDateCode(TodayDate)
...@@ -203,7 +206,7 @@ def CallTimePrediction(distance,BuStops,TodayDate): ...@@ -203,7 +206,7 @@ def CallTimePrediction(distance,BuStops,TodayDate):
CallTimePrediction(14.7,8,'Sunday')
# Get Train Data # Get Train Data
......
...@@ -217,7 +217,7 @@ class PathPlanner(): ...@@ -217,7 +217,7 @@ class PathPlanner():
#traveled_distance #traveled_distance
lastNode = self.start lastNode = self.start
for n in self.path[1:]: for n in self.path[1:]:
self.range = self.range+ distance(lastNode, n ) self.range += distance(lastNode, n )
lastNode = n lastNode = n
return self.range return self.range
...@@ -260,13 +260,35 @@ def main( val, start, destination): ...@@ -260,13 +260,35 @@ def main( val, start, destination):
path = planner.path path = planner.path
if path == False: if path == False:
print("No path Found", path) print("No path Found ")
return False return False
else: else:
print(path) print('path = ' ,path)
print('distance = ' , planner.get_traveled_distance()/10) dist = planner.get_traveled_distance()/10
print('distance = ' , dist)
fare = planner.get_fare(path) fare = planner.get_fare(path)
print('trip RS.' , fare) print('trip RS.' , fare)
main( 1, 1, 18) ####--------------- calling functions of travelTimePredictions (Shiwantha) ---------------
\ No newline at end of file
from datetime import datetime
# get current datetime
dateTime = datetime.now()
import sys
#adding Folder_2/subfolder to the system path
sys.path.insert(0, 'TravelTimePrediction')
#importing the hello
from TravelTimePredictionNN import CallTimePrediction
#dis, stops, hour, day
CallTimePrediction(dist,len(path),(dateTime.hour),(dateTime.strftime('%A')))
main( 1, 8, 18)
# from test import test
# test(map)
\ No newline at end of file
...@@ -44,7 +44,7 @@ route_8717 = { ...@@ -44,7 +44,7 @@ route_8717 = {
} }
map_test = { map_test = {
0: {'pos': (6.911034627182109, 79.84918916006576), 'connections': [1,16], 'name' : 'Kollupitiya','type': 0,'routeNo': 177, 'hValue': 1}, 0: {'pos': (6.911034627182109, 79.84918916006576), 'connections': [1,16], 'name' : 'Kollupitiya','type': 0,'routeNo': 177, 'hValue': 5},
1: {'pos': (6.911751932322411, 79.86194701315071), 'connections': [0,2], 'name' : 'Viharamahadevi Park', 'type': 0, 'routeNo': 177, 'hValue': 1}, 1: {'pos': (6.911751932322411, 79.86194701315071), 'connections': [0,2], 'name' : 'Viharamahadevi Park', 'type': 0, 'routeNo': 177, 'hValue': 1},
2: {'pos': (6.911385550864001, 79.87682791026592), 'connections': [1,3], 'name' : 'House Of Fashion', 'type': 0, 'routeNo': 177, 'hValue': 1}, 2: {'pos': (6.911385550864001, 79.87682791026592), 'connections': [1,3], 'name' : 'House Of Fashion', 'type': 0, 'routeNo': 177, 'hValue': 1},
3: {'pos': (6.911031363415147, 79.88498429384545), 'connections': [2,4], 'name' : 'Castle Street', 'type': 0, 'routeNo': 177, 'hValue': 1}, 3: {'pos': (6.911031363415147, 79.88498429384545), 'connections': [2,4], 'name' : 'Castle Street', 'type': 0, 'routeNo': 177, 'hValue': 1},
...@@ -73,18 +73,13 @@ class Map: ...@@ -73,18 +73,13 @@ class Map:
self.intersections = nx.get_node_attributes(G, "pos") self.intersections = nx.get_node_attributes(G, "pos")
self.routeNo = nx.get_node_attributes(G, "routeNo") self.routeNo = nx.get_node_attributes(G, "routeNo")
self.type = nx.get_node_attributes(G, "type") self.type = nx.get_node_attributes(G, "type")
self.name = nx.get_node_attributes(G, "name")
self.roads = [list(G[node]) for node in G.nodes()] self.roads = [list(G[node]) for node in G.nodes()]
def save(self, filename):
with open(filename, 'wb') as f:
pickle.dump(self._graph, f)
def load_map_graph(map_dict): def load_map_graph(map_dict):
G = nx.Graph() G = nx.Graph()
for node in map_dict.keys(): for node in map_dict.keys():
G.add_node(node, pos=map_dict[node]['pos'], type=map_dict[node]['type'],routeNo=map_dict[node]['routeNo']) G.add_node(node, pos=map_dict[node]['pos'], type=map_dict[node]['type'],routeNo=map_dict[node]['routeNo'],name=map_dict[node]['name'])
for node in map_dict.keys(): for node in map_dict.keys():
for con_node in map_dict[node]['connections']: for con_node in map_dict[node]['connections']:
G.add_edge(node, con_node) G.add_edge(node, con_node)
...@@ -93,22 +88,11 @@ def load_map_graph(map_dict): ...@@ -93,22 +88,11 @@ def load_map_graph(map_dict):
def load_map_b(map_dict): def load_map_b(map_dict):
# G = nx.Graph()
# for node in map_dict.keys():
# #nodeValue =
# if map_dict[node]['type'] != 1:
# continue
# else:
# G.add_node(node, pos=map_dict[node]['pos'], type=map_dict[node]['type'],routeNo=map_dict[node]['routeNo'])
G = nx.Graph() G = nx.Graph()
for node in map_dict.keys(): for node in map_dict.keys():
G.add_node(node, pos=map_dict[node]['pos'], type=map_dict[node]['type'],routeNo=map_dict[node]['routeNo']) G.add_node(node, pos=map_dict[node]['pos'], type=map_dict[node]['type'],routeNo=map_dict[node]['routeNo'])
# for node in map_dict.keys():
# for con_node in map_dict[node]['connections']:
# if map_dict[con_node]['type'] != 1:
# continue
# else:
# G.add_edge(node, con_node)
for node in map_dict.keys(): for node in map_dict.keys():
for con_node in map_dict[node]['connections']: for con_node in map_dict[node]['connections']:
if map_dict[node]['type'] != 1: if map_dict[node]['type'] != 1:
......
from helpers import load_map_test
MAP_ANSWERS = [ ANSWERS = [
(5, 34, [5, 16, 37, 12, 34]), (1,5, 34, [5, 16, 37, 12, 34]),
(5, 5, [5]), (1,5, 5, [5]),
(8, 24, [8, 14, 16, 37, 12, 17, 10, 24]) (1,8, 24, [8, 14, 16, 37, 12, 17, 10, 24])
] ]
def test(shortest_path_function): def test(shortest_path_function):
map = load_map_test() print('test started ---------------')
correct = 0 correct = 0
for start, goal, answer_path in MAP_ANSWERS: for map, start, goal, answer_path in ANSWERS:
path = shortest_path_function(map, start, goal).path path = shortest_path_function(map, start, goal).path
if path == answer_path: if path == answer_path:
correct += 1 correct += 1
...@@ -19,8 +18,8 @@ def test(shortest_path_function): ...@@ -19,8 +18,8 @@ def test(shortest_path_function):
"Correct: ", answer_path) "Correct: ", answer_path)
else: else:
print("Error Testing faild !!!" ) print("Error Testing faild !!!" )
if correct == len(MAP_ANSWERS): if correct == len(ANSWERS):
print("All tests pass ") print("All tests pass ")
else: else:
print("Only passed", correct, "/", len(MAP_ANSWERS), "test cases") print("Only passed", correct, "/", len(ANSWERS), "test cases")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment