def pickle_demographics(self): cities = demographics.make_cities() age_gender = demographics.make_age_gender_dict() with open('./pickles/cities.pickle', 'wb') as output: pickle.dump(cities, output, pickle.HIGHEST_PROTOCOL) with open('./pickles/age_gender.pickle', 'wb') as output: pickle.dump(age_gender, output, pickle.HIGHEST_PROTOCOL)
def generate_age_gender(self): age_gender = demographics.make_age_gender_dict() g_a = age_gender[min([a for a in age_gender if a > np.random.random()])] g_a = age_gender[min(age_gender, key=lambda x: abs(x - random.random()))] a = np.random.random() c = [] for b in age_gender.keys(): if b > a: c.append(b) g_a = age_gender[min(c)] while True: dob = self.fake.date_time_this_century() # adjust the randomized date to yield the correct age start_age = (date.today() - date(dob.year, dob.month, dob.day)).days / 365. dob_year = dob.year - int(g_a[1] - int(start_age)) # since the year is adjusted, sometimes Feb 29th won't be a day # in the adjusted year try: # retg_aurn first letter of gender and dob return g_a[0][0], date(dob_year, dob.month, dob.day) except: pass
print_err(2) try: m = sys.argv[3] ## m = 'profiles/main_config.json' main = open(m, 'r').read() except: print_err(3) return num_cust, seed_num, main if __name__ == '__main__': # read and validate stdin num_cust, seed_num, main = validate() # from demographics module cities = demographics.make_cities() age_gender = demographics.make_age_gender_dict() fake = Faker() fake.seed(seed_num) headers = Headers() # turn all profiles into dicts to work with all_profiles = MainConfig(main).config for _ in range(num_cust): Customer()
print_err(2) try: m = sys.argv[3] ## m = 'profiles/main_config.json' main = open(m, 'r').read() except: print_err(3) return num_cust, seed_num, main if __name__ == '__main__': # read and validate stdin num_cust, seed_num, main = validate() # from demographics module cities = demographics.make_cities() age_gender = demographics.make_age_gender_dict() fake = Faker() Faker.seed(seed_num) headers = Headers() # turn all profiles into dicts to work with all_profiles = MainConfig(main).config for _ in range(num_cust): Customer()