Created
June 24, 2022 19:57
-
-
Save DiogoBerti/c8b2b0caffbf65da01b67bb4993f082c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from faker.factory import Factory | |
from random import randrange, randint | |
from datetime import timedelta, datetime | |
def main(): | |
# CONSTANTES... | |
start = datetime.strptime("1930-01-01", "%Y-%m-%d") | |
end = datetime.strptime("2001-01-01", "%Y-%m-%d") | |
# Opcoes | |
sexo = ["m","f"] | |
dias_semana = ["Segunda", "Terca", "Quarta", "Quinta", "Sexta"] | |
sp_zone = ["leste","oeste","sul","norte"] | |
tp_attend = ["vacina","clinica","medicação"] | |
species = ["felino","canino"] | |
# Faker para nomes.. | |
Faker = Factory.create | |
fake = Faker() | |
fake.seed(0) | |
# Arrays para preencher o arquivo. | |
persons = [] | |
pets = [] | |
atendimentos = [] | |
for n in range(1,600): | |
persons.append({ | |
"id_cliente": n, | |
"nascimento": random_date(start, end), | |
"num_pets": randrange(1,4), | |
"zona": sp_zone[randrange(len(sp_zone))], | |
"sexo": sexo[randrange(len(sexo))], | |
}) | |
dict_pet = { | |
"id_pet": randrange(n*10, 9500 ), | |
"nome_pet": fake.first_name_nonbinary(), | |
"especie": species[randrange(len(species))], | |
"sexo": sexo[randrange(len(sexo))], | |
"idade": randrange(0, 12) | |
} | |
pets.append(dict_pet) | |
dict_atend = { | |
"id_atendimento": n + 3, | |
"nome_cliente": fake.first_name_nonbinary(), | |
"pet": dict_pet.get("nome_pet"), | |
"dia_semana": dias_semana[randrange(len(dias_semana))], | |
"horario": f"{randrange(8,19):>02}", | |
"tipo_atendimento": tp_attend[randrange(len(tp_attend))], | |
"valor": f"{randint(5,300):.2f}" | |
} | |
atendimentos.append(dict_atend) | |
with open("persons.csv", "w") as person_file: | |
header = 0 | |
for item in persons: | |
if header == 0: | |
keys = [k for k in item.keys()] | |
person_file.writelines(f'{";".join(keys)}\n') | |
header = 1 | |
values = [str(v) for k,v in item.items()] | |
person_file.writelines(f'{";".join(values)}\n') | |
with open("pets.csv", "w") as pet_file: | |
header = 0 | |
for item in pets: | |
if header == 0: | |
keys = [k for k in item.keys()] | |
pet_file.writelines(f'{";".join(keys)}\n') | |
header = 1 | |
values = [str(v) for k,v in item.items()] | |
pet_file.writelines(f'{";".join(values)}\n') | |
with open("atendimentos.csv", "w") as attend_file: | |
header = 0 | |
for item in atendimentos: | |
if header == 0: | |
keys = [k for k in item.keys()] | |
attend_file.writelines(f'{";".join(keys)}\n') | |
header = 1 | |
values = [str(v) for k,v in item.items()] | |
attend_file.writelines(f'{";".join(values)}\n') | |
def random_date(start, end): | |
""" | |
Gera uma data aleatoria entre a data de inicio (start) e data fim (end). | |
""" | |
delta = end - start | |
int_delta = (delta.days * 24 * 60 * 60) + delta.seconds | |
random_second = randrange(int_delta) | |
return f"{start + timedelta(seconds=random_second):%Y-%m-%d}" | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment