def generate_record(self): adoption = None if self.nested_count or chance.boolean(likelihood=70): immunizations = [] for i in range(0, self.nested_count or random.randint(0, 4)): immunizations.append({ 'type': chance.pickone( ['FIV', 'Panleukopenia', 'Rabies', 'Feline Leukemia']), 'date_administered': chance.date(minyear=2012).isoformat() }) adoption = { 'adopted_on': chance.date(minyear=2012).isoformat(), 'was_foster': chance.boolean(), 'immunizations': immunizations } return { 'id': self.id, 'name': fake.first_name(), 'pattern': chance.pickone(['Tabby', 'Tuxedo', 'Calico', 'Tortoiseshell']), 'age': random.randint(1, 15), 'adoption': adoption }
def generate_record(self): value_null = None value_integer = random.randint(-314159265359, 314159265359) value_integer_as_number = float( random.randint(-314159265359, 314159265359)) value_number = random.uniform(-314159265359, 314159265359) value_boolean = chance.boolean() value_date_time_string = chance.date(minyear=2012).isoformat() value_array = [] for i in range(random.randint(0, 1000)): value_array.append(random.randint(-314, 314)) value_object = { 'i': random.randint(-314159265359, 314159265359), 'n': random.uniform(-314159265359, 314159265359), 'b': chance.boolean() } return { 'every_type': chance.pickone([ value_null, value_integer, value_integer_as_number, value_number, value_boolean, value_date_time_string, value_array, value_object ]), 'number_which_only_comes_as_integer': value_integer }
def create_product(self, business, user): images_path = self.images_dir + self.images_dir_list[random.randint( 0, len(self.images_dir_list) - 1)] product = Product( name=chance.sentence(language='ru', words=4), price=random.randint(10000, 123456), description=chance.paragraph(sentences=5), user=user, ) with open(images_path, 'r') as f: image_file = File(f) product.image.save('picture.' + images_path.split('.')[-1:][0], image_file, True) product.save() organization_product = OrganizationProduct( product=product, is_featured=chance.boolean(), is_popular=chance.boolean(), is_service=chance.boolean(), organization=business, ) organization_product.save() self.stdout.write('Successfully created product (%s)' % (product.name, )) return product
def generate_record(self): record = CatStream.generate_record(self) if chance.boolean(likelihood=50): record['adoption'] = ['invalid', 'adoption'] elif chance.boolean(likelihood=50): record['age'] = 'very invalid age' elif record['adoption'] and chance.boolean(likelihood=50): record['adoption']['immunizations'] = { 'type': chance.pickone(['a', 'b', 'c']), 'date_administered': ['clearly', 'not', 'a', 'date'] } else: record['name'] = 22 / 7 return record
def range_query_data(input_collection, input_data): """Query a range of ages Arguments: input_collection {collection} -- mongoDB collection to connect to input_data {object} -- Random data to get a random age to query from """ greater_than_query = {"age": {"$gt": input_data["age"]}} less_than_query = {"age": {"$lt": input_data["age"]}} # Query either greater than or less than a random age query = greater_than_query if chance.boolean() else less_than_query input_collection.find(query)
def duplicate(self, force=False): if self.duplicates > 0 and \ len(self.records) > 0 and \ self.duplicates_written < self.duplicates and \ (force or chance.boolean(likelihood=30)): self.duplicates_written += 1 random_index = random.randint(0, len(self.records) - 1) record = self.records[random_index] self.duplicate_pks_used.append(record['id']) record_message = self.generate_record_message(record=record) record_message['sequence'] = self.sequence + self.duplicate_sequence_delta return record_message else: return False
def generate_record(self): value = None if self.changing_literal_type == 'integer': value = random.randint(-314159265359, 314159265359) elif self.changing_literal_type == 'number': value = chance.pickone([ random.uniform(-314159265359, 314159265359), float(random.randint(-314159265359, 314159265359)), random.randint(-314159265359, 314159265359) ]) elif self.changing_literal_type == 'boolean': value = chance.boolean() elif self.changing_literal_type == 'string': value = chance.date(minyear=2012).isoformat() elif self.changing_literal_type == 'date-time': value = chance.date(minyear=2012).isoformat() else: raise Exception('Unknown changing_literal_type: `{}`'.format( self.changing_literal_type)) return { 'id': self.id + self.starting_id, 'changing_literal_type': value, }