def get_fees_for_splitted_booking(booking_split, fees, bkg, portion=1): # initialize fee fields for fee_name in set(fee_names.values()): booking_split[fee_name] = '' # try to get fee info from booking comments, as some booking_fee data is not available via api # remove this if you can get all bookings_fee info in future if bkg['comments']: cmt = bkg['comments'] # .encode('ascii', 'ignore').decode('utf-8') # b = False for fee_name in fee_names.keys(): fee_info = re.search('{}(.*)'.format(fee_name.replace('_', ' ').lower()), cmt.lower()) if fee_info and len(fee_info.groups()) > 0: fee_initial = re.search('[0-9]+\.[0-9]*', fee_info.group(1)) if fee_initial: # b = True booking_split[fee_names[fee_name]] = to_float(to_float(fee_initial.group(0)) * portion) # for debugging # if not b: # print(cmt.encode('ascii', 'ignore')) # get fee info if fees: for fee in fees: booking_split[fee['name']] = to_float(fee['price'] * portion)
def add_booking_data(booking_split, booking, proportion=1): exceptions = ['start_at', 'end_at', 'id'] prices = [ 'initial_price', 'initial_rental_price', 'charge_damage_deposit_on_arrival', 'channel_price', 'vat', 'city_tax', 'cleaning_fee', 'discount', 'final_rental_price', 'rental_min_price', 'rental_max_price', 'final_price', 'payment_left_to_collect', 'damage_deposit', 'paid_amount' ] for key, val in booking.items(): if key not in exceptions: if key in prices and is_payment_splittable(key) and is_number(val): booking_split[key] = to_float(val * proportion) else: booking_split[key] = val
def get_bookings_fee(bookings_fee): my_bfees = [] for fee in bookings_fee: my_bfee = { 'id': fee['id'], 'updated_at': to_datetime(fee['updated_at']), 'created_at': to_datetime(fee['created_at']), 'booking_id': to_int(fee['links']['booking']), 'included_in_price': fee['included_in_price'], 'price': to_float(fee['price']), 'required': fee['required'], 'times_booked': int(fee['times_booked']), 'name': get_fee_name(fee) } my_bfees.append(my_bfee) return my_bfees
def get_rentals(rentals): my_rentals = [] for r in rentals: my_rentals.append({ 'id': r['id'], 'rental_type': r['rental_type'], 'created_at': to_datetime(r['created_at']), 'updated_at': to_datetime(r['updated_at']), 'published_at': to_datetime(r['published_at']), 'name': r['name'], 'address1': r['address1'], 'address2': r['address2'], 'currency': r['currency'], 'bedrooms_count': to_int(r['bedrooms_count']), 'bathrooms_count': to_int(r['bathrooms_count']), 'sleeps': to_int(r['sleeps']), 'sleeps_max': to_int(r['sleeps_max']), 'city': r['city'], 'country_code': r['country_code'], 'contact_name': r['contact_name'], 'zip': r['zip'], 'notes': r['notes'], 'base_rate': to_float(r['base_rate']), 'base_rate_kind': r['base_rate_kind'], 'downpayment': to_float(r['downpayment']), 'initial_price': to_float(r['initial_price']), 'final_price': to_float(r['final_price']), 'damage_deposit': to_float(r['damage_deposit']), 'min_price': to_float(r['min_price']), 'max_price': to_float(r['max_price']), 'absolute_min_price': to_float(r['absolute_min_price']) }) return my_rentals
def get_bookings(bookings): my_bookings = [] t_ren = time.time() sources = advanced_request('source', params={ 'from': '20111101', 'fields': 'id,name' }) logging.info('Obtained Sources data in {} sec'.format(time.time() - t_ren)) t_ren = time.time() comments = advanced_request('booking_comment', params={ 'from': '20111101', 'fields': 'id,content' }) logging.info('Obtained Comments data in {} sec'.format(time.time() - t_ren)) t_ren = time.time() accounts = request_data(Cfg.get('bks_accounts_base_url'), params={'fields': 'id,business_name'}) logging.info('Obtained Accounts data in {} sec'.format(time.time() - t_ren)) for b in bookings: if b['status'] == 'Canceled': if (to_datetime(b['start_at']).date() - to_datetime(b['canceled_at']).date() ).days > Cfg.get('btx_payed_status_interval'): continue my_booking = { 'id': int(b['id']), 'client_id': to_int(b['links']['client']), 'rental_id': to_int(b['links']['rental']), 'start_at': to_datetime(b['start_at']), 'end_at': to_datetime(b['end_at']), 'created_at': to_datetime(b['created_at']), 'canceled_at': to_datetime(b['canceled_at']), 'balance_due_at': to_datetime(b['balance_due_at']), 'tentative_expires_at': to_datetime(b['tentative_expires_at']), 'updated_at': to_datetime(b['updated_at']), 'contract_updated_at': to_datetime(b['contract_updated_at']), 'status': b['status'], 'reference': b['reference'], 'booked': b['booked'], 'unavailable': b['unavailable'], 'initial_price': to_float(b['initial_price']), 'initial_rental_price': to_float(b['initial_rental_price']), 'channel_price': to_float(b['channel_price']), 'discount': b['discount'], 'final_rental_price': to_float(b['final_rental_price']), 'final_price': to_float(b['final_price']), 'paid_amount': to_float(b['paid_amount']), 'currency': b['currency'], 'notes': b['notes'], 'damage_deposit': to_float(b['damage_deposit']), 'charge_damage_deposit_on_arrival': to_float(b['charge_damage_deposit_on_arrival']), 'adults': to_int(b['adults']), 'children': to_int(b['children']), 'bookings_payments_count': to_int(b['bookings_payments_count']), 'review_requests_count': to_int(b['review_requests_count']), 'locked': b['locked'], 'cancelation_reason': b['cancelation_reason'], 'expected_checkin_time': b['expected_checkin_time'], 'expected_checkout_time': b['expected_checkout_time'], 'payment_url': b['payment_url'], 'rental_payback_to_owner': to_float(b['rental_payback_to_owner']), 'final_payback_to_owner': to_float(b['final_payback_to_owner']), 'commission': to_float(b['commission']), 'door_key_code': b['door_key_code'], 'payment_left_to_collect': to_float(b['payment_left_to_collect']), 'owned_by_app': b['owned_by_app'], 'account_id': to_int(b['links']['account']), 'probability_win': None, 'source': b['links']['source'] if b['links']['source'] else 'Praguestars.com' } if my_booking['source']: source = find_dict_in_list(sources, 'id', my_booking['source']) if source: my_booking['source'] = source['name'] if my_booking['start_at']: days_interval = (my_booking['start_at'] - datetime.now()).days my_booking['probability_win'] = to_int( Cfg.get_interval_prob(days_interval)) # get comments comment_str = '' for comment_id in b['links']['booking_comments']: comment = find_dict_in_list(comments, 'id', comment_id) if comment: comment_str += comment['content'] + '\n' my_booking['comments'] = comment_str my_bookings.append(my_booking) # get account name for b in my_bookings: for a in accounts['accounts']: if len(a) > 0 and a['id'] == b['account_id']: b['account'] = a['business_name'] return my_bookings
''' Echelle Diagram ''' # theo = pd.read_csv('') # Theoretical Frequencies filename = '/media/bmr135/SAMSUNG/AIMS-interp-testing2/M147_MS_272' # Original Frequencies filename1 = '/media/bmr135/SAMSUNG/AIMS-interp-testing2/Interp_Freqs_MS/M1.47.X0.740.Z0.0057-atm-0272' # Interpolated Frequencies freqfile = open(filename) freqfile.readline() # skip head mode_temp = [] l, nn, fre = [], [], [] for line in freqfile: line = line.strip() columns = line.split() n = int(columns[1]) freq = utilities.to_float(columns[2]) mode_temp.append((n,int(columns[0]),freq,utilities.to_float(columns[4]))) # CLES l.append(int(columns[0])) nn.append(n) fre.append(freq) freqfile1 = open(filename1) freqfile1.readline() # skip head dnu = float(freqfile1.readline()) mode_temp1 = [] for line in freqfile1: line = line.strip() columns = line.split() n = int(columns[0]) freq1 = utilities.to_float(columns[2]) mode_temp1.append((n,int(columns[1]),freq1)) # ,utilities.to_float(columns[4]))) # CLES