def import_flight(self): """Create a Flight object, read the raw log file and add meta data . TODO mange if device != Pixracer """ self.update_label_status("Loading in progress, please wait ...") self.update() logger.debug('import flight .......') self.imported_Flight = Flight() ulog_file_path = self.ui.label_file_log_1.text() ulog_device = self.ui.deviceComboBox.currentData() ulog_position = self.ui.positionComboBox.currentData() glider_name = self.ui.gliderModelLineEdit.text() manufacturer_name = self.ui.manufacturerLineEdit.text() modif = self.ui.gliderModifLineEdit.text() location = self.ui.locationLineEdit.text() size = self.ui.gliderSizeLineEdit.text() pilot = self.ui.pilotLineEdit.text() weight = self.ui.weightKgDoubleSpinBox.value() lab = self.ui.laboratoryLineEdit.text() self.imported_Flight.add_data_file(ulog_file_path, ulog_device, ulog_position) self.imported_Flight.add_info(manufacturer_name, glider_name, size, modif, pilot, weight, location, lab) self.imported_Flight.add_general_section() logger.debug("close import dialog") self.close()
def load_file(ulog_file_path, reload=True): """ Main function to load a Ulg file and create a Flight Object return : Flight object ( and saved or not in a pkl file) """ if reload_file: # print("Reading Ulog file : " + str(ulog_file_name)) mflight = Flight() mflight.add_data_file(ulog_file_path, Device.PIXRACER, Position.PILOT) mflight.add_info("Tulipe Glider", "Razor4", None, "Paul", 94.2, "Nice Place") mflight.add_general_section() logger.info("Writing : " + name_saved_file) with open(name_saved_file, "wb") as f: pickle.dump(mflight, f) else: logger.info("Reading : " + name_saved_file) with open(name_saved_file, "rb") as f: mflight = pickle.load(f) # Print Data for debug. logger.debug(mflight) df_data = mflight.data[0].list_available_data() logger.debug(df_data) # df_data.loc[df_data['parent']=='vehicle_local_position'] mdf = mflight.get_df_by_position(Position.PILOT)[0] logger.debug(mdf)
def fetch_html(self, date_item): dpport = self.options['dpport'] arport = self.options['arport'] dpdate = date_item[0].strftime("%d/%m/%Y") ardate = date_item[1].strftime("%d/%m/%Y") cmpid = self.options['cmpid'] b2cpin = self.options['b2cpin'] html = fetch_html(dpport, arport, dpdate, ardate, cmpid, b2cpin) rows = parse_html(html) print("{0} ~ {1}".format(dpdate, ardate)) print("=========" * 5) insert_rows = [] for row in rows: print("{company_code:4s} {cabin:1s} {ticket_price:>8s} ({stay_day_min:>3s} ~ {stay_day_max:>3s}) ({valid_date_from:>10s} ~ {valid_date_to:>10s}) ({valid_buy_ticket_date_from:>10s} ~ {valid_buy_ticket_date_to:>10s}) {flight_info_link_cond_code:>15s}".format( company_code=row['company_code'], cabin=row['cabin'], ticket_price=price_to_intenger(row['ticket_price']), stay_day_min=row['stay_day_min'], stay_day_max=row['stay_day_max'], valid_date_from=row['valid_date_from'], valid_date_to=row['valid_date_to'], valid_buy_ticket_date_from=row['valid_buy_ticket_date_from'], valid_buy_ticket_date_to=row['valid_buy_ticket_date_to'], flight_info_link_cond_code=row['flight_info_link_cond_code'] )) insert_rows.append(dict( departure_port=dpport, arrival_port=arport, company_code=row['company_code'], cabin=row['cabin'], ticket_price=price_to_intenger(row['ticket_price']), stay_day_min=row['stay_day_min'], stay_day_max=row['stay_day_max'], valid_date_from=string_to_datetime(row['valid_date_from']), valid_date_to=string_to_datetime(row['valid_date_to']), valid_buy_ticket_date_from=string_to_datetime(row['valid_buy_ticket_date_from']), valid_buy_ticket_date_to=string_to_datetime(row['valid_buy_ticket_date_to']), flight_info_link=row['flight_info_link'], flight_info_link_cond_code=row['flight_info_link_cond_code'] )) Flight.insert_many(insert_rows).execute() sleep(2) self.date_queue.task_done()
def load_flights(): """ Load flights from flights.csv """ for row in open("seed_data/flights.csv"): row = row.strip() origin, destination, carrier, quarter, time, avg_delay, \ duration, num_flights, num_delay, num_can_div, score = row.split(",") flight = Flight(origin=origin, destination=destination, carrier=carrier, quarter=int(quarter), time=int(time), num_flights=int(num_flights), num_delayed=int(num_delay), num_cancel_divert=int(num_can_div), duration=int(duration), avg_delay=int(avg_delay), score=float(score)) # Add each flight to the session db.session.add(flight) # Once we're done, commit all the flights to the database db.session.commit() return
def get_flight_id(flight_info_dict): """get flight id from db or newly added flight""" #search if flght is already saved in database search_flight_in_db = Flight.query.filter( Flight.departure_airport == flight_info_dict["departure_airport"], Flight.destination_airport == flight_info_dict["destination_airport"], Flight.carrier == flight_info_dict["carrier"], Flight.outbound_departure_time == flight_info_dict["outbound_departure_time"], Flight.outbound_arrival_time == flight_info_dict["outbound_arrival_time"], Flight.inbound_departure_time == flight_info_dict["inbound_departure_time"], Flight.inbound_arrival_time == flight_info_dict["inbound_arrival_time"], Flight.flight_price == flight_info_dict["flight_price"], Flight.outbound_carrier_id == flight_info_dict["outbound_carrier_id"], Flight.outbound_flight_number == flight_info_dict["outbound_flight_number"], Flight.inbound_carrier_id == flight_info_dict["inbound_carrier_id"], Flight.inbound_flight_number == flight_info_dict["inbound_flight_number"]).first() #if flight not in database, save it if not search_flight_in_db: flight = Flight( departure_airport=flight_info_dict["departure_airport"], destination_airport=flight_info_dict["destination_airport"], carrier=flight_info_dict["carrier"], outbound_departure_time=flight_info_dict[ "outbound_departure_time"], outbound_arrival_time=flight_info_dict["outbound_arrival_time"], inbound_departure_time=flight_info_dict["inbound_departure_time"], inbound_arrival_time=flight_info_dict["inbound_arrival_time"], flight_price=flight_info_dict["flight_price"], outbound_carrier_id=flight_info_dict["outbound_carrier_id"], outbound_flight_number=flight_info_dict["outbound_flight_number"], inbound_carrier_id=flight_info_dict["inbound_carrier_id"], inbound_flight_number=flight_info_dict["inbound_flight_number"]) db.session.add(flight) db.session.commit() #get id for the newly added flight if not search_flight_in_db: current_flight_id = Flight.query.order_by( Flight.flight_id.desc()).first().flight_id #print "flight not in db", current_flight_id #get id for the already existed flight else: current_flight_id = search_flight_in_db.flight_id #print "flight in db", current_flight_id return current_flight_id
def create_flight(air_field_id, destination, date_time_departure, date_time_arrival): new_flight = Flight( air_field=air_field_id, destination=destination, date_time_departure=datetime.strptime(date_time_departure, "%Y-%m-%d %H:%M:%S"), date_time_arrival=datetime.strptime(date_time_arrival, "%Y-%m-%d %H:%M:%S")) db.session.add(new_flight) db.session.commit() return new_flight.id
class import_log_diaglog(QDialog): def __init__(self, parent=None): super(import_log_diaglog, self).__init__(parent) self.ui = Ui_Dialog_import_log() self.ui.setupUi(self) self.flight = None populate_combo_box(self.ui.positionComboBox, Position) populate_combo_box(self.ui.positionComboBox_2, Position) populate_combo_box(self.ui.deviceComboBox, Device) populate_combo_box(self.ui.deviceComboBox_2, Device) populate_combo_box(self.ui.deviceComboBox_video_device, VideoDevice) self.ui.positionComboBox.setCurrentIndex( self.ui.positionComboBox.findText( Position.PILOT.name)) # to have pilot as default position self.ui.deviceComboBox.setCurrentIndex( self.ui.deviceComboBox.findText( Device.PIXRACER.name)) # to have pixracer as default position #set up button self.ui.button_debug.clicked.connect(self.debug_) self.ui.button_import.clicked.connect(self.import_flight) self.ui.pushButton_import_file_log1.clicked.connect(self.browse_path) self.check_valid() #set up line edit: self.ui.gliderModelLineEdit.textChanged.connect(self.check_valid) self.imported_Flight = None def debug_(self): """Quickly populate all flied for rapid debug """ logger.debug("Populate with dummy values") file_name = "/home/fred/Ozone/paralogger/paralogger/samples/log_6_2019-11-6-13-32-36_flight_1.ulg" self.ui.label_file_log_1.setText(file_name) self.ui.gliderModelLineEdit.setText("Macpi4") self.ui.manufacturerLineEdit.setText("Exemple_gliders_ltd") self.ui.locationLineEdit.setText("niceplace") self.ui.gliderSizeLineEdit.setText("24") self.ui.pilotLineEdit.setText("Arnold") self.ui.weightKgDoubleSpinBox.setValue(95) self.ui.laboratoryLineEdit.setText("GoodLab") def update_label_status(self, str_message): self.ui.label_status.setText(str_message) QGuiApplication.processEvents() # would be better to use a progressbar def browse_path(self): filename = QFileDialog.getOpenFileName(self, 'Open pickler File', "", 'Logs Files (*.*)') if isinstance(filename, tuple): filename = filename[0] if filename: self.ui.label_file_log_1.setText(filename) def import_flight(self): """Create a Flight object, read the raw log file and add meta data . TODO mange if device != Pixracer """ self.update_label_status("Loading in progress, please wait ...") self.update() logger.debug('import flight .......') self.imported_Flight = Flight() ulog_file_path = self.ui.label_file_log_1.text() ulog_device = self.ui.deviceComboBox.currentData() ulog_position = self.ui.positionComboBox.currentData() glider_name = self.ui.gliderModelLineEdit.text() manufacturer_name = self.ui.manufacturerLineEdit.text() modif = self.ui.gliderModifLineEdit.text() location = self.ui.locationLineEdit.text() size = self.ui.gliderSizeLineEdit.text() pilot = self.ui.pilotLineEdit.text() weight = self.ui.weightKgDoubleSpinBox.value() lab = self.ui.laboratoryLineEdit.text() self.imported_Flight.add_data_file(ulog_file_path, ulog_device, ulog_position) self.imported_Flight.add_info(manufacturer_name, glider_name, size, modif, pilot, weight, location, lab) self.imported_Flight.add_general_section() logger.debug("close import dialog") self.close() def check_valid(self): """Check if the required field and ok to enble the import. """ check_list = [] item_to_check = [self.ui.gliderModelLineEdit, self.ui.label_file_log_1] for item in item_to_check: check_list.append(len(item.text()) < 1) if not any(check_list): self.ui.button_import.setEnabled(True) self.ui.label_status.setText("Field with * are mandatory (OK)") else: self.ui.button_import.setEnabled(False)
#%% PARAMETERS cwd = os.path.dirname(os.path.abspath(__file__)) log_name = "log_23_2019-9-29-15-15-10_heli_slow.ulg" ulog_file_path = os.path.join(cwd, "samples", log_name) Reload_file = True gravity = 9.80665 # m·s-2 name_saved_file = "mflight_plot.pkl" #%% Prepare file logger.info(" --- Start ----") if Reload_file: # print("Reading Ulog file : " + str(ulog_file_name)) mflight = Flight() mflight.add_data_file(ulog_file_path, Device.PIXRACER, Position.PILOT) mflight.add_info("Tulipe Glider", "Razor4", None, "Paul", 94.2, "Nice Place") logger.info("Writing : " + name_saved_file) with open(name_saved_file, "wb") as f: pickle.dump(mflight, f) else: logger.info("Reading : " + name_saved_file) with open(name_saved_file, "rb") as f: mflight = pickle.load(f)
import urllib2