def run(self): try: yield 'Loading dataframe...' self.data_frame = df_fileloader.load_agenda(self.frontur) yield 'Selecting airport' self.data_frame = em.select_airport(self.data_frame, self.airport) if self.aliases: yield 'Substituting values' em.substitute_values(self.data_frame, self.aliases) yield 'Merging plane data' self.data_frame = em.add_plane_data(self.data_frame, self.planes) yield 'Formatting days' self.data_frame = em.format_dates(self.data_frame) yield 'Selecting days' self.data_frame = em.select_days(self.data_frame, self.available_days) self.fully_loaded = True yield 'Finished.' import io buf = io.StringIO() self.data_frame.info(buf=buf) yield buf.getvalue() except Exception as err: yield str(err) finally: self.execution_end = True
def add_plane_data( data_frame: pandas.DataFrame, file_path: str, target_col: str = const.DF_PLANE_COL_NAME) -> pandas.DataFrame: """Merges DataFrame with information about the flight planes Args: data_frame (pandas.DataFrame): Source DataFrame file_path (str): Source file path target_col (str): Target column to merge Returns: pandas.DataFrame: Source DataFrame with aditional information """ planes = df_fileloader.load_agenda(file_path) data_frame[target_col] = data_frame[target_col].astype(str) planes[target_col] = planes[target_col].astype(str) data_frame = pandas.merge(data_frame, planes, how='outer', on=[target_col], indicator=True) unmatched = data_frame.query('_merge == "left_only"').groupby( [target_col]).size().reset_index(name='count') if not unmatched.empty: err_msg = 'There\'s missing information about the following planes:' for index, row in unmatched.iterrows(): err_msg += '\n {} with {} ocurrences.'.format( row[target_col], row['count']) utility.eprint(err_msg) return return data_frame.query('_merge == "both"').drop(columns=['_merge'])
def run(self): try: yield 'Dataframe load' self.data_frame = df_fileloader.load_agenda(self.filename) yield 'Calculating results... (this may take a few minutes)' self.data_frame = df_solver(self.data_frame, no_groups=True, parameters=self.solver_parameters) yield 'Finished' import io buf = io.StringIO() self.data_frame.info(buf=buf) yield buf.getvalue() self.fully_loaded = True except Exception as err: yield str(err) finally: self.execution_end = True
def solver(infile: str, outfile: str): """ ·______ ______ ______ __ __ ______ __ __ ______ /\ ___\ /\ == \ /\ __ \ /\ "-.\ \ /\__ _\ /\ \/\ \ /\ == \ \ \ __\ \ \ __< \ \ \/\ \ \ \ \-. \ \/_/\ \/ \ \ \_\ \ \ \ __< ·\ \_\ \ \_\ \_\ \ \_____\ \ \_\\\\"\_\ \ \_\ \ \_____\ \ \_\ \_\\ ··\/_/ \/_/ /_/ \/_____/ \/_/ \/_/ \/_/ \/_____/ \/_/ /_/ Program that selects the optimum amount of flights of an airport to interview. \f Args: infile (str): Path to file with FronTur flights outfile (str): Output path with selected FronTur flights """ data_frame = df_fileloader.load_agenda(infile) import pandas import json with open(const.REQ_INTERVIEWS_FILE_PATH) as jfile: data = json.load(jfile) data_frame = df_solver(data_frame, no_groups=True, parameters={ 'workday_time': pandas.Timedelta(hours=8).seconds, 'rest_time': pandas.Timedelta(minutes=10).seconds, 'execution_time_limit': pandas.Timedelta(minutes=15).seconds, 'country_kwargs': { 'plane_kwargs': { 'seats_used': 0.8, 'poll_success': 0.6, 'poll_time': pandas.Timedelta(seconds=30).seconds }, 'interviews': data } }) if outfile: df_fileloader.save_agenda(outfile, data_frame)
def process(infile: str, airport: str, days: str, planes: str, substitutions: str, outfile: str): """ ·______ ______ ______ __ __ ______ __ __ ______ /\ ___\ /\ == \ /\ __ \ /\ "-.\ \ /\__ _\ /\ \/\ \ /\ == \ \ \ __\ \ \ __< \ \ \/\ \ \ \ \-. \ \/_/\ \/ \ \ \_\ \ \ \ __< ·\ \_\ \ \_\ \_\ \ \_____\ \ \_\\\\"\_\ \ \_\ \ \_____\ \ \_\ \_\\ ··\/_/ \/_/ /_/ \/_____/ \/_/ \/_/ \/_/ \/_____/ \/_/ /_/ Program that processes various information from a file with concrete information about flights of an airport. \f Args: infile (str): Path to file with FronTur flights outfile (str): Output path with parsed FronTur flights airport (str): Target airport string identifier code days (str): Path to json file with correct parameters of the assigned interview days planes (str): Path to file with the neccesary information of the planes substitutions (str): Optional json file with value conversions """ data_frame = df_fileloader.load_agenda(infile) data_frame = em.select_airport(data_frame, airport) if substitutions != '.': em.substitute_values(data_frame, substitutions) data_frame = em.add_plane_data(data_frame, const.PLANES_DATA_FILE_PATH) data_frame = em.format_dates(data_frame) data_frame = em.select_days(data_frame, days) print(data_frame, '\n-------------\n', data_frame.groupby(['Destino']).sum(), '\n-------------\n', data_frame.groupby(['Pais']).sum()) if outfile: df_fileloader.save_agenda(outfile, data_frame)
def test_load_csv_agenda(mock_method, ext, tmpdir): file = tmpdir.join('filename.' + ext) actual = utility_fileloader.load_agenda(file.strpath) assert actual == 'csv'