def getShortestPath(request):
# Task List as a dict object
taskList = json.loads(request.POST["taskList"])
# Build the list of task descriptions (semicolon separated). E.g: "B;D;E"
taskSelectionString = ";".join("{0}{1}".format(t["description"], "") for t in taskList)
# Get the Shortest Path for the specified tasks - String of semicolon separated task descritpions. E.g: "D;B;E"
shortestPath = ShortestPath.objects.filter(task_selection = taskSelectionString)[0]
# Build the actual list of Task objects forming the shortest path. E.g: [<Task: D>, <Task: B>, <Task: E>]
shortestPathTasks = shortestPath.getShortestPathTasks()
# Serialize and return the list of tasks as JSON
json_serializer = serializers.get_serializer("json")()
shortestPathJson = json_serializer.serialize(shortestPathTasks)
logger = logging.getLogger("console_logger")
return HttpResponse(json.dumps({"shortestPath": shortestPathJson,
"totalCost": shortestPath.total_cost,
"totalReward": shortestPath.total_reward}),
content_type="application_json")
评论列表
文章目录