You've already forked OpenUxAS-SoI
mirror of
https://github.com/AdaCore/OpenUxAS-SoI.git
synced 2026-02-12 13:04:49 -08:00
91 lines
6.1 KiB
Plaintext
91 lines
6.1 KiB
Plaintext
file << "#! /usr/bin/env python" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "import xml.dom.minidom" << std::endl;
|
|
file << "from xml.dom.minidom import Node" << std::endl;
|
|
file << "import pandas as pd" << std::endl;
|
|
file << "import glob" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "def get_a_document(filename):" << std::endl;
|
|
file << " return xml.dom.minidom.parse(filename)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "def ProcessMissionCommand(missionCommand):" << std::endl;
|
|
file << "\tisGoodMessage = True" << std::endl;
|
|
file << "\ttry:" << std::endl;
|
|
file << "\t\tfirstWaypoint = 0" << std::endl;
|
|
file << "\t\telements = missionCommand.getElementsByTagName('FirstWaypoint')" << std::endl;
|
|
file << "\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\tfirstWaypoint = int(elements[0].firstChild.data)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\t\tcommandID = 0" << std::endl;
|
|
file << "\t\telements = missionCommand.getElementsByTagName('CommandID')" << std::endl;
|
|
file << "\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\tcommandID = int(elements[0].firstChild.data)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\t\tvehicleID = 0" << std::endl;
|
|
file << "\t\telements = missionCommand.getElementsByTagName('VehicleID')" << std::endl;
|
|
file << "\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\tvehicleID = int(elements[0].firstChild.data)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\t\tstatus = 'Cancelled'" << std::endl;
|
|
file << "\t\telements = missionCommand.getElementsByTagName('Status')" << std::endl;
|
|
file << "\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\tstatus = str(elements[0].firstChild.data)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\t\twaypointList = []" << std::endl;
|
|
file << "\t\telements = missionCommand.getElementsByTagName('WaypointList')" << std::endl;
|
|
file << "\t\tif elements:" << std::endl;
|
|
file << "\t\t\telementWaypoints = elements[0].getElementsByTagName('Waypoint')" << std::endl;
|
|
file << "\t\t\tfor elementWaypoint in elementWaypoints:" << std::endl;
|
|
file << "\t\t\t\tnumber = -1" << std::endl;
|
|
file << "\t\t\t\telements1 = elementWaypoint.getElementsByTagName('Number')" << std::endl;
|
|
file << "\t\t\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\t\t\tnumber = int(elements1[0].firstChild.data)" << std::endl;
|
|
file << "\t\t\t\taltitude = -1" << std::endl;
|
|
file << "\t\t\t\telements1 = elementWaypoint.getElementsByTagName('Altitude')" << std::endl;
|
|
file << "\t\t\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\t\t\taltitude = float(elements1[0].firstChild.data)" << std::endl;
|
|
file << "\t\t\t\tlatitude = 0" << std::endl;
|
|
file << "\t\t\t\telements1 = elementWaypoint.getElementsByTagName('Latitude')" << std::endl;
|
|
file << "\t\t\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\t\t\tlatitude = float(elements1[0].firstChild.data)" << std::endl;
|
|
file << "\t\t\t\telements1 = elementWaypoint.getElementsByTagName('Longitude')" << std::endl;
|
|
file << "\t\t\t\tlongitude = 0" << std::endl;
|
|
file << "\t\t\t\tif elements and elements[0].firstChild and elements[0].firstChild.nodeType == Node.TEXT_NODE:" << std::endl;
|
|
file << "\t\t\t\t\tlongitude = float(elements1[0].firstChild.data)" << std::endl;
|
|
file << "\t\t\t\twaypointList.append([number,latitude,longitude,altitude])" << std::endl;
|
|
file << "\t\t\t\t# print('# 5a status[' + str(waypointList) + ']')" << std::endl;
|
|
file << "\t\twaypointListPd = pd.DataFrame(data = waypointList,columns=['number','latitude','longitude','altitude'])" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\texcept StandardError:" << std::endl;
|
|
file << "\t\tprint('### Error encountered while processing the MissionCommand ###')" << std::endl;
|
|
file << "\t\tisGoodMessage = False" << std::endl;
|
|
file << "\texcept:" << std::endl;
|
|
file << "\t\tprint('### Error encountered while processing the MissionCommand ###Unexpected error:', sys.exc_info()[0])" << std::endl;
|
|
file << "\t\tisGoodMessage = False" << std::endl;
|
|
file << "\tif isGoodMessage:" << std::endl;
|
|
file << "\t\treturn [vehicleID,firstWaypoint,commandID,status,waypointListPd]" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "def ProcessAutomationResponseFile(filename):" << std::endl;
|
|
file << "\tdoc2 = get_a_document(filename)" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "\toriginalResponse = doc2.getElementsByTagName('OriginalResponse')" << std::endl;
|
|
file << "\tautomationResponse = originalResponse[0].getElementsByTagName('AutomationResponse')" << std::endl;
|
|
file << "\tmissionCommandList = automationResponse[0].getElementsByTagName('MissionCommandList')" << std::endl;
|
|
file << "\tmissionCommands = missionCommandList[0].getElementsByTagName('MissionCommand')" << std::endl;
|
|
file << "\tmissionCommandArray = []" << std::endl;
|
|
file << "\tfor missionCommand in missionCommands:" << std::endl;
|
|
file << "\t\tmissionCommandArray.append(ProcessMissionCommand(missionCommand))" << std::endl;
|
|
file << "\treturn missionCommandArray " << std::endl;
|
|
file << "" << std::endl;
|
|
file << "def main():" << std::endl;
|
|
file << "\tmissionCommandArray = []" << std::endl;
|
|
file << "\tfor AutomationResponseFile in glob.glob('UniqueAutomationResponse*'):" << std::endl;
|
|
file << "\t\tprint('loading [' + AutomationResponseFile + ']')" << std::endl;
|
|
file << "\t\tmissionCommandArray = ProcessAutomationResponseFile(AutomationResponseFile)" << std::endl;
|
|
file << "\tmissionCommandArrayPd = pd.DataFrame(data = missionCommandArray,columns=['vehicleID','firstWaypoint','commandID','status','waypointListPd'])" << std::endl;
|
|
file << "\tprint('saving [MissionCommands.pkl]')" << std::endl;
|
|
file << "\tmissionCommandArrayPd.to_pickle('MissionCommands.pkl')" << std::endl;
|
|
file << "" << std::endl;
|
|
file << "if __name__ == '__main__':" << std::endl;
|
|
file << " main()" << std::endl;
|