def structure_records_total_counts(): data_thesis = database.database("Thesis") global records_total_counts, max_num #get location clusters location_clusters = data_thesis.get_data("SELECT `features_plain_gobig`.`listing_id`, `location_cluster`, `cluster` FROM `features_plain_gobig` INNER JOIN `listing_clusters_big_all` ON `features_plain_gobig`.`listing_id` = `listing_clusters_big_all`.`listing_id` WHERE location_cluster != -1") #trying go big for now #make structure for the pulled data #`listing_id`, `location_cluster`, `cluster` # # #structure for the final datastructure #location_cluster : { listing_cluster: { year: {day: percentage occupied}}} for year in ["2013", "2014", "2015", "2016"]: records_averages_full_year["ENQUIRY"][year] = {} records_averages_full_year["CANCELLED"][year] = {} for entry in location_clusters: #if the location cluster if entry[1] not in records_total_counts["ENQUIRY"]: for filename in ["ENQUIRY", "CANCELLED"]: records_total_counts[filename][entry[1]] = {} records_averages[filename][entry[1]] = {} for year in ["2013", "2014", "2015", "2016"]: records_averages_full_year[filename][year][entry[1]] = {} #if the listing_cluster if entry[2] not in records_total_counts["ENQUIRY"][entry[1]].keys(): for filename in ["ENQUIRY", "CANCELLED"]: records_total_counts[filename][entry[1]][entry[2]] = time.default_date_structure() records_averages[filename][entry[1]][entry[2]] = time.default_date_structure() for year in ["2013", "2014", "2015", "2016"]: records_averages_full_year[filename][year][entry[1]][entry[2]] = {} data_thesis.destroy_connection()
def main(): global all_prices_calendar, valid_listings all_data = get_data() #make structure and only do it for listing_ids that have data thesis_data = database.database("Thesis") pot_listings = thesis_data.get_data( "SELECT `listing_id` FROM listing_clusters_plain") valid_listings = [entry[0] for entry in pot_listings] thesis_data.destroy_connection() for listing_id in valid_listings: all_prices_calendar[listing_id] = time.default_date_structure() #fill structure: for item in all_data: process_entry(item) #get default_rate data: #just id, rate all_data = get_data(False) for entry in all_data: listing_id = entry[0] if listing_id not in all_prices_calendar.keys(): #need to get like this: #listing_id`,`date_start`, `date_end`, `rate` all_prices_calendar[listing_id] = time.default_date_structure() to_process = [ listing_id, datetime.date(2014, 1, 1), datetime.date(2016, 1, 29), entry[1] ] is_none = process_entry(to_process) if is_none is True: del all_prices_calendar[listing_id] #fill the ends of the dates and really make sure there are no 0's or None for listing_id, default_date_dict in all_prices_calendar.iteritems(): fill_nones(listing_id, datetime.date(2016, 1, 29)) #save it with open("data/price_dict.json", 'w') as jsonFile: json.dump(all_prices_calendar, jsonFile) print "Finished!!! "
def main(): global all_prices_calendar, valid_listings all_data = get_data() #make structure and only do it for listing_ids that have data thesis_data = database.database("Thesis") pot_listings = thesis_data.get_data("SELECT `listing_id` FROM listing_clusters_plain") valid_listings = [entry[0] for entry in pot_listings] thesis_data.destroy_connection() for listing_id in valid_listings: all_prices_calendar[listing_id] = time.default_date_structure() #fill structure: for item in all_data: process_entry(item) #get default_rate data: #just id, rate all_data = get_data(False) for entry in all_data: listing_id = entry[0] if listing_id not in all_prices_calendar.keys(): #need to get like this: #listing_id`,`date_start`, `date_end`, `rate` all_prices_calendar[listing_id] = time.default_date_structure() to_process = [listing_id, datetime.date(2014, 1, 1), datetime.date(2016, 1, 29), entry[1]] is_none = process_entry(to_process) if is_none is True: del all_prices_calendar[listing_id] #fill the ends of the dates and really make sure there are no 0's or None for listing_id, default_date_dict in all_prices_calendar.iteritems(): fill_nones(listing_id, datetime.date(2016, 1, 29)) #save it with open("data/price_dict.json", 'w') as jsonFile: json.dump(all_prices_calendar, jsonFile) print "Finished!!! "
def main(): global full_reservation_data all_data = get_data() #get valid_listings and make reservation structure thesis_data = database.database("Thesis") valid_listings = thesis_data.get_data("SELECT `listing_id` FROM listing_clusters_plain") full_reservation_data = {entry[0]: time.default_date_structure() for entry in valid_listings} for entry in all_data: if entry[0] in full_reservation_data.keys(): process_data(entry) with open("data/monte_carlo_reservation_dict.json", 'w') as outFile: json.dump(full_reservation_data, outFile) thesis_data.destroy_connection()
def main(): global full_reservation_data all_data = get_data() #get valid_listings and make reservation structure thesis_data = database.database("Thesis") valid_listings = thesis_data.get_data( "SELECT `listing_id` FROM listing_clusters_plain") full_reservation_data = { entry[0]: time.default_date_structure() for entry in valid_listings } for entry in all_data: if entry[0] in full_reservation_data.keys(): process_data(entry) with open("data/monte_carlo_reservation_dict.json", 'w') as outFile: json.dump(full_reservation_data, outFile) thesis_data.destroy_connection()