def percent_by_gender(gender): """ Get the percentage of the specified gender in the whole community """ count_all = 0 count_choice = 0 if gender == 'female' or gender == 'male': count_all = Person.select().count() count_choice = Person.select().where(Person.gender == gender).count() click.echo('Percent of {}: {:.1f}%'.format( gender, count_choice * 100 / count_all)) else: click.echo('Wrong gender, try again!')
def people_by_dob_range(): """ Provide the date range and get all the people within this range """ flag_change = '' flag_found = False date1 = click.prompt("Provide the first date (YYYY-MM-DD)", value_proc=get_date) date2 = click.prompt("Provide the second date (YYYY-MM-DD)", value_proc=get_date) if date1 > date2: flag_change = date2 date2 = date1 date1 = flag_change persons = Person.select() for person in persons: dob = Dob.select().join(Person).where(Person.id == person.id).get() name = Name.select().join(Person).where(Person.id == person.id).get() dt = datetime.strptime(dob.date, "%Y-%m-%dT%H:%M:%S.%fZ") dob_new = date(dt.year, dt.month, dt.day) if date1 <= dob_new <= date2: result = name.first + ' ' + name.last + ' - ' + str(dob_new) click.echo(result) flag_found = True if not flag_found: click.echo("No results!")