/// <summary> /// post scenario to the central server /// </summary> /// <param name="scenario">Scenario object</param> public void PostScenario(Scenario scenario) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "scenario/", "PUT", request => { ScenarioPost scenarioPost = new ScenarioPost(); scenarioPost.customers = new List <int>(); scenarioPost.tag = "updated"; if (scenario.tag != null) { scenarioPost.tag = scenario.tag + "_" + (scenario.version + 1); } foreach (Customer customer in scenario.customers) { if (customer.selected) { scenarioPost.customers.Add(customer.id); } } // post a scenario object string postData = JsonConvert.SerializeObject(scenarioPost); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { resultstr = " Submit Scenario : " + getServerResponse(request.responseCode); Debug.Log("Status Code: " + request.responseCode + " " + " " + request.downloadHandler.text); })); }
/// <summary> /// posts a set of vehicles and customers the central service and it returns /// an AI plan result /// </summary> /// <param name="plan">current PLan</param> public void PostPlanToAI(Plan plan) { StartCoroutine(SessionLib.FullWebRequest(GetCentralServiceEndpoint() + "ai/opsplan/", "POST", request => { // setup planner AI object OpsPlanAIRun test = new OpsPlanAIRun(); test.input = JsonConvert.SerializeObject(plan); test.output = ""; string postData = JsonConvert.SerializeObject(test); Debug.Log("planner AI send data : " + postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { resultstr = " Return AI Plan : " + getServerResponse(request.responseCode); string convertResults = request.downloadHandler.text.Replace("True", "true"); convertResults = convertResults.Replace("False", "false"); OpsPlanAIRun aiResults = JsonConvert.DeserializeObject <OpsPlanAIRun>(convertResults); // convert python True to true string formatted = aiResults.output.Replace("True", "true"); aiPlannerResultQueuePlan = JsonConvert.DeserializeObject <Plan>(formatted); })); }
/// <summary> /// gets the full plan representation by id /// </summary> /// <param name="id">plan id</param> public void GetPlan(int id) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "plan/" + id + "/", "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); Plan result = JsonConvert.DeserializeObject <Plan>(request.downloadHandler.text); planqueue.Add(result); })); }
/// <summary> /// gets the current scenario of the team and session /// </summary> public void GetScenario() { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "scenario/", "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); Scenario scenarioData = JsonConvert.DeserializeObject <Scenario>(request.downloadHandler.text); scenarioqueue.Add(scenarioData); })); }
/// <summary> /// gets the current market id /// </summary> public void GetMarket() { StartCoroutine(SessionLib.FullWebRequest(GetCentralServiceEndpoint() + "exper/session/", "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); Session postData = JsonConvert.DeserializeObject <Session>(request.downloadHandler.text); market = postData.market; })); }
/// <summary> /// posts a vehicle to store on the central data server /// </summary> /// <param name="vehicle"></param> public void PostVehicle(Vehicle vehicle) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "vehicle/", "POST", request => { string postData = JsonConvert.SerializeObject(vehicle); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { resultstr = " Submit Vehicle : " + getServerResponse(request.responseCode); Debug.Log("Status Code: " + request.responseCode + " " + " " + request.downloadHandler.text); })); }
/// <summary> /// gets short plan representations of information by name and id /// </summary> public void GetShortPlans() { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "planshort/", "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); PlanShortResultMessage results = JsonConvert.DeserializeObject <PlanShortResultMessage>(request.downloadHandler.text); foreach (PlanShort result in results.results) { planshortqueue.Add(result); } })); }
/// <summary> /// gets the vehicles of the team and session /// </summary> public void GetVehicles() { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "vehicle/", "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); VehiclesResultMessage postData = JsonConvert.DeserializeObject <VehiclesResultMessage>(request.downloadHandler.text); foreach (Vehicle result in postData.results) { vehiclequeue.Add(result); } })); }
/// <summary> /// gets the designer AI vehicles based on current evaluation metrics /// </summary> /// <param name="range">range in miles</param> /// <param name="cost">cost</param> /// <param name="capacity">capacity in lb</param> public void GetAIVehicles(float range, float cost, float capacity) { StartCoroutine(SessionLib.FullWebRequest(GetCentralServiceEndpoint() + "ai/designer1/?range=" + range + "&cost=" + cost + "&payload=" + capacity, "GET", request => { request.redirectLimit = 0; request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); VehiclesResultMessage postData = JsonConvert.DeserializeObject <VehiclesResultMessage>(request.downloadHandler.text); aiDesignerQueue.Clear(); foreach (Vehicle result in postData.results) { aiDesignerQueue.Add(result.config, new double[] { result.range, result.cost, result.payload }); } })); }
/// <summary> /// posts a plan to the central server /// </summary> /// <param name="plan"></param> public void PostPlan(Plan plan) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "plan/", "Post", request => { // create a post plan object PlanPost planPost = new PlanPost(); planPost.tag = plan.tag; planPost.scenario = plan.scenario.id; planPost.paths = new List <PlanVehicleDeliveryPost>(); foreach (VehicleDelivery p in plan.paths) { if (p.customers.Count > 0) { PlanVehicleDeliveryPost planpath = new PlanVehicleDeliveryPost(); planpath.vehicle = p.vehicle.id; planpath.warehouse = p.warehouse.id; planpath.customers = new List <int>(); planpath.leavetime = 0; planpath.returntime = p.customers[p.customers.Count - 1].deliverytime; foreach (CustomerDelivery customerpath in p.customers) { planpath.customers.Add(customerpath.id); } planPost.paths.Add(planpath); } } string postData = JsonConvert.SerializeObject(planPost); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); resultstr = " Submit Plan : " + getServerResponse(request.responseCode); })); }
/// <summary> /// posts a vehicle to the evaluation service /// </summary> /// <param name="vehicle"></param> public void PostEvaluation(Vehicle vehicle) { StartCoroutine(SessionLib.FullWebRequest(GetCentralServiceEndpoint() + "ai/uavdesign2traj/", "POST", request => { EvaluationInput input = new EvaluationInput(); input.config = vehicle.config; string postData = JsonConvert.SerializeObject(input); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); uavEvaluation = JsonConvert.DeserializeObject <EvaluationOutput>(request.downloadHandler.text); resultstr = " Evaluation : " + getServerResponse(request.responseCode); // currently the trajectory is offset by the below x and z values float yoffset = 1035.0f; float zoffset = 2000.0f; Vector3 lastPosition = new Vector3(0, 0, 0); foreach (Trajectory trajectory in uavEvaluation.trajectory) { trajectory.position[1] = trajectory.position[1] - yoffset; trajectory.position[2] = trajectory.position[2] - zoffset; Vector3 nextPosition = new Vector3( (float)trajectory.position[0], (float)trajectory.position[1], (float)trajectory.position[2]); } })); }
/// <summary> /// posts a log message to the server /// </summary> /// <param name="logstr">log message to write to the central data logs</param> /// <param name="type">the type of log message</param> public void PostLog(string logstr, string type) { StartCoroutine(SessionLib.FullWebRequest(GetCentralDatastoreEndpoint() + "datalog/", "POST", request => { // create the log statement DataLog log = new DataLog(); log.team = GetTeamName(); log.user = GetUserName(); log.action = type + ";" + logstr; string postData = JsonConvert.SerializeObject(log); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); Debug.Log("Status Code: " + request.responseCode + " " + " " + request.downloadHandler.text); })); }
/// <summary> /// Get Dronebot results /// </summary> /// <param name="question">question to ask dronebot</param> public void GetDronebotVehicles(string question) { StartCoroutine(SessionLib.FullWebRequest(GetCentralServiceEndpoint() + "ai/dronebot/", "POST", request => { // create the log statement DroneBotObject obj = new DroneBotObject(); obj.input = question; obj.output = ""; string postData = JsonConvert.SerializeObject(obj); Debug.Log(postData); request.redirectLimit = 0; byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(postData); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); }, request => { Debug.Log(request.downloadHandler.text); DroneBotObject postData = JsonConvert.DeserializeObject <DroneBotObject>(request.downloadHandler.text); dronebotqueue = postData.output; })); }