views.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:bid2charge 作者: soton-agents 项目源码 文件源码
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")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号