def search_airports(string): """ Search airport information using name, ICAO, or IATA by string input """ data = find_airport(string) header = ["ICAO", "IATA", "Name", "City", "Country Code"] print_table(data, header)
def flight_cli(flight_number, date): """ Get Flight Status by using flight number and optional argument date """ flight_stats = get_flight_status(flight_number, date) header = [ "Flight Number", "Status", "Airline", "Arrival Airport", "Arrival Time(UTC)", "Arrival Time(Local)", "Departure Airport", "Departure Time(UTC)", "Departure Time(Local)" ] print_table(flight_stats, header)
def lexical(filename, print_res=False): path_filename = os.path.dirname( os.path.realpath(__file__)) + '/tests/{}'.format(filename) stack = None with open(path_filename) as fs: while True: currentChar = fs.read(1) result = lexic_process(currentChar) if result != None: if print_res: print_table(result) stack = create_stack(result) break return stack
ns = [] x = a step = math.fabs(a - b) / n while x <= b: xs.append(x) x += step sums = taylor4sin(xs, ns) if fl_dfl: print "Default values:\n[a, b] = {}\nn = {}\nV = {}\neps = {}" \ .format([a, b], n, v, eps) if fl_w2f: file = open("values.txt", 'w') file.write(str(xs) + '\n') file.write(str(sums)) file.close() print "Lists were written into \"values.txt\"" if fl_pri: print "Range: {}\nNumber of tests: {}\nV = {}" \ .format([a, b], len(xs), v) titles = ["x", "f(x)", "n"] data = [xs, sums, ns] helper.print_table(data=helper.rotate_2D_list(data), titles_x=titles, \ column_width=10, vert_sep=True, horiz_sep=True)
differences.append(value) counter -= 1 differences_table.append(differences) return differences_table[:-1] def newton(x, xs, ys): diff_table = divided_differences(xs, ys) result = diff_table[0][0] omega = 1 for i in range(1, len(xs)): omega *= (x - xs[i - 1]) result += diff_table[i][0] * omega return result if __name__ == '__main__': xs = [0.0, 0.2, 0.5, 0.9, 1.4, 2.0, 2.7, 4.0] ys = [0.5403, 0.6831, 0.8216, 0.9185, 0.9697, 0.9909, 0.9977, 0.9998] #----------------Defining Table of Divided Differences--------------- table_headers = ['x_i', 'y_i'] table_values = [xs, ys] helper.print_table(table_headers, table_values, table_title='Newton', table_view='v')
def L(xi, x): return help_expr(x, xi) / help_expr(xi, xi) def lagrange(x, xs, ys): lst = [] for i in range(len(xs)): lst.append(L(xs[i], x) * ys[i]) return sum(lst) if __name__ == '__main__': interxs = list(helper.frange(-3, 3, 0.25)) interys = [lagrange(x, xs, ys) for x in interxs] table_headers = ['x', 'f(x)', 'L(x)'] table_values = [ interxs, # x helper.make_proportional(ys), # f(x) list(map(lambda y: round(y, 4), interys))] # L(x) helper.print_table( table_headers, table_values, table_title='Lagrange', table_view='v') #plot.plot(xs, ys, "o-") #plot.plot(interxs, interys) #plot.show()
import math import helper VAR = 3 EPS = 1e-5 xs = range(-5, 6) sums = [] ns = [] for x in xs: fx = VAR * x sum = fx i = 3 n = 0 while math.fabs(fx) > EPS: fx *= -((VAR * x)**2) / (i * (i - 1)) sum += fx i += 2 n += 1 sums.append(round(sum, 4)) ns.append(n) helper.print_table(table_headers=['x', 'f(x)', 'n'], table_values=[xs, sums, ns], table_title='Taylor sum') helper.save(value_list=[xs, sums], to='values.txt')
def lagrange(x, xs, ys): lst = [] for i in range(len(xs)): lst.append(L(xs[i], x) * ys[i]) return sum(lst) if __name__ == '__main__': interxs = list(helper.frange(-3, 3, 0.25)) interys = [lagrange(x, xs, ys) for x in interxs] table_headers = ['x', 'f(x)', 'L(x)'] table_values = [ interxs, # x helper.make_proportional(ys), # f(x) list(map(lambda y: round(y, 4), interys)) ] # L(x) helper.print_table(table_headers, table_values, table_title='Lagrange', table_view='v') #plot.plot(xs, ys, "o-") #plot.plot(interxs, interys) #plot.show()
(xs[j] - xs[i+j+1]) differences.append(value) counter -= 1 differences_table.append(differences) return differences_table[:-1] def newton(x, xs, ys): diff_table = divided_differences(xs, ys) result = diff_table[0][0] omega = 1 for i in range(1, len(xs)): omega *= (x - xs[i-1]) result += diff_table[i][0] * omega return result if __name__ == '__main__': xs = [0.0, 0.2, 0.5, 0.9, 1.4, 2.0, 2.7, 4.0] ys = [0.5403, 0.6831, 0.8216, 0.9185, 0.9697, 0.9909, 0.9977, 0.9998] #----------------Defining Table of Divided Differences--------------- table_headers = ['x_i', 'y_i'] table_values = [xs, ys] helper.print_table( table_headers, table_values, table_title='Newton', table_view='v')
def cli(ctx, arrivals, departures, date, delta, airline): """ Retrieve flights for a certain airport or between two airports which arrived/departed on the mentioned date within a given time interval. """ if ctx.invoked_subcommand is None: date_from, date_to = getTime(date, delta) src = get_airport(departures) if departures != None else None dest = get_airport(arrivals) if arrivals != None else None header3 = ["From Time", "To Time"] print_table([[date_from, date_to]], header3) header2 = [ "ICAO", "IATA", "Name of Airport", "City", "State", "Country" ] if src != None and dest == None: flights = get_flights(False, src[0][0], date_from, date_to) print_table(src, header2) click.echo( f"\nListing all departure flights from airport {src[0][2]}") elif src == None and dest != None: flights = get_flights(True, dest[0][0], date_from, date_to) print_table(dest, header2) click.echo( f"\nListing all arrival flights to airport {dest[0][2]}") elif src != None and dest != None: flights = get_flights(False, src[0][0], date_from, date_to) flights = get_filter(flights, dest[0][0], dest[0][1]) print_table(src, header2) print_table(dest, header2) click.echo( f"\nListing all flights from airport {src[0][2]} to airport {dest[0][2]}" ) else: click.echo("At least one arrival or departure airport required") sys.exit("Aborting!!!") if airline: flights = get_airlines(flights, airline) click.echo(f"via airline {airline}") header = [ "Flight Number", "Airline", "Status", "Scheduled Time(UTC)", "Scheduled Time(Local)", "Terminal", "Airport", "ICAO", "IATA" ] print_table(flights, header)
import math import helper VAR = 3 EPS = 1e-5 xs = range(-5, 6) sums = [] ns = [] for x in xs: fx = VAR * x sum = fx i = 3 n = 0 while math.fabs(fx) > EPS: fx *= -((VAR * x) ** 2) / (i * (i - 1)) sum += fx i += 2 n += 1 sums.append(round(sum, 4)) ns.append(n) helper.print_table(table_headers=['x', 'f(x)', 'n'], table_values=[xs, sums, ns], table_title='Taylor sum') helper.save(value_list=[xs, sums], to='values.txt')