#This script will parse the aircraft characteristic .xlxs file in to a suitable PSOA RuleML code# #Copyright (C) 2018 Theodoros Mitsikas, Sofia Almpani #Licensed under the Non-Profit Open Software License 3.0 (NPOSL-3.0). #You should have received a copy of the Non-Profit Open Software License 3.0 #along with this program. If not, see https://opensource.org/licenses/NPOSL-3.0. import xlrd # available in pip workbook = xlrd.open_workbook('FAA-Aircraft-Char-Database-v2-201801.xlsx') sheet1= workbook.sheet_by_name('Aircraft') with open('aircraft_db.psoa', 'w') as fl: # erases previous files print("File aircraft_db.psoa written, overwriting older versions") counter = 0 unique_aircrafr_counter = set() for i in range (5,1351): if sheet1.cell(i, 19).value == xlrd.empty_cell.value or sheet1.cell(i, 19).value == 'tbd' or sheet1.cell(i, 16).value == xlrd.empty_cell.value or sheet1.cell(i, 9).value == xlrd.empty_cell.value or sheet1.cell(i, 16).value == 'tbd' or sheet1.cell(i, 8).value == xlrd.empty_cell.value: continue else: icaoDesignation = sheet1.cell(i, 19).value if len(icaoDesignation) > 4: print("Manual corrections required for the aircraft \"" + icaoDesignation + "\" found at line " + str(i + 1) + " of the excel file") if icaoDesignation != icaoDesignation.replace('*', '_'): print("Please do a manual review of aicraft " + icaoDesignation + " found at line " + str(i + 1) + " of the excel file.", end="") icaoDesignation = icaoDesignation.replace('*', '_') print(" It was changed to " + icaoDesignation + " automatically") mtow = sheet1.cell(i, 16).value mtom = float(mtow) * 0.45359237 # pounds to kilograms wingspan = sheet1.cell(i, 9).value appspeed = sheet1.cell(i, 8).value with open('aircraft_db.psoa', 'a') as fl: fl.write(":"+ icaoDesignation.lower() + "#:Aircraft(:mtom->" + str(round(mtom, 2))) fl.write("\n\t\t\t:mtow->" + str(mtow)) fl.write("\n\t\t\t:wingspan->" + str(wingspan)) fl.write("\n\t\t\t:appSpeed->" + str(appspeed)) # Temp workaround for notequal of naf absense in PSOA RuleML if icaoDesignation == 'A388': fl.write("\n\t\t\t:specialCase->:A380)") elif icaoDesignation == 'A225': fl.write("\n\t\t\t:specialCase->:A225)") elif icaoDesignation == 'B752' or icaoDesignation == 'B753': fl.write("\n\t\t\t:specialCase->:B757)") else: fl.write("\n\t\t\t:specialCase->:No)") fl.write("\n\n") counter += 1 unique_aircrafr_counter.update([icaoDesignation]) print("Total of " + str(counter) + " aircraft written") print("The database contains a total of " + str(len(unique_aircrafr_counter)) + " different aircraft")