def main():

    file_path = lambda x: os.path.join(DATA_PATH, x)
    fem_data = parse_data(file_path('dist.female.first'))
    male_data = parse_data(file_path('dist.male.first'))
    last_data = parse_data(file_path('dist.all.last'))

    # Create Objects
    fem_wc = WeightedChoice(fem_data);
    male_wc = WeightedChoice(male_data);
    last_wc = WeightedChoice(last_data);

    # Generate Female Names
    output_fem = generate_names(fem_wc, last_wc, NUM_FEM, False)

    # Generate Male Names
    output_male = generate_names(male_wc, last_wc, NUM_MALE, False)

    output = output_fem + output_male

    # Generate a result containing: employee_id, employee name, document
    employee_id = 0
    doc_id = 0
    result = []
    for employee in output:
        employee_id = employee_id + 1
        for doc in range(0, random.randint(DOCS_MIN, DOCS_MAX)):
            doc_id = doc_id + 1
            result.append((employee_id, employee, '%s%s' % (DOC_PREFIX, doc_id)))

    # Randomly shuffle the output
    shuffle(result)

    print result
Ejemplo n.º 2
0
def main():

    file_path = lambda x: os.path.join(DATA_PATH, x)
    fem_data = parse_data(file_path('dist.female.first'))
    male_data = parse_data(file_path('dist.male.first'))
    last_data = parse_data(file_path('dist.all.last'))

    # Create Objects
    fem_wc = WeightedChoice(fem_data)
    male_wc = WeightedChoice(male_data)
    last_wc = WeightedChoice(last_data)

    # Generate Female Names
    output_fem = generate_names(fem_wc, last_wc, NUM_FEM, False)

    # Generate Male Names
    output_male = generate_names(male_wc, last_wc, NUM_MALE, False)

    output = output_fem + output_male

    # Generate a result containing: employee_id, employee name, document
    employee_id = 0
    doc_id = 0
    result = []
    for employee in output:
        employee_id = employee_id + 1
        for doc in range(0, random.randint(DOCS_MIN, DOCS_MAX)):
            doc_id = doc_id + 1
            result.append(
                (employee_id, employee, '%s%s' % (DOC_PREFIX, doc_id)))

    # Randomly shuffle the output
    shuffle(result)
def main():
    parser = OptionParser()
    parser.add_option("-u", "--unique", action="store_true", dest="unique", default=False, help="Generate unique names (within a given sex)")
    parser.add_option("-m", "--male", action="store", type="int", dest="num_male", default=0, help="Number of male names")
    parser.add_option("-f", "--female", action="store", type="int", dest="num_fem", default=0, help="Number of female names")
    parser.add_option("-r", "--random", action="store", type="int", dest="num_rand", default=0, help="Number of random names, regardless of sex.")
    parser.add_option("-i", "--invert", action="store_true", dest="invert", default=False, help="Print last name first")
    parser.add_option("--ucfirst", action="store_true", dest="ucfirst", default=False, help="Print names upper case first instead of all caps.")
    (options, args) = parser.parse_args()

    if len(sys.argv) == 1:
        parser.error("No arguments")
    elif len(args) != 0:
        parser.error("Wrong number of arguments")
    else:
        # Parse data
        #file_path = lambda x: os.path.join(os.path.split(__file__)[0], '..', 'data', x)
        file_path = lambda x: os.path.join(DATA_PATH, x)
        fem_data = parse_data(file_path('dist.female.first'))
        male_data = parse_data(file_path('dist.male.first'))
        last_data = parse_data(file_path('dist.all.last'))

        # Create Objects
        fem_wc = WeightedChoice(fem_data);
        male_wc = WeightedChoice(male_data);
        last_wc = WeightedChoice(last_data);

        if options.num_rand > 0:
            for i in range(options.num_rand):
                if choice('mf') == 'm':
                    options.num_male = options.num_male + 1
                else:
                    options.num_fem = options.num_fem + 1
        
        # Generate Female Names
        if options.num_fem > 0:
            output_fem = generate_names(fem_wc, last_wc, options.num_fem, options.unique, options.invert, options.ucfirst)
        else:
            output_fem = []

        # Generate Male Names
        if options.num_male > 0:
            output_male = generate_names(male_wc, last_wc, options.num_male, options.unique, options.invert, options.ucfirst)
        else:
            output_male = []

        # Randomly shuffle the output so male and female names are mixed
        output = output_fem + output_male
        shuffle(output)

        for name in output:
            print name
    def handle(self, *args, **options):
        from storybase_user.utils import is_admin

        if name_generator is None:
            raise CommandError("To use this management command, you need to "
                    "install the name_generator package from "
                    "https://github.com/macropin/random-name-generator")
       
        interactive = options.get('interactive')

        if interactive:
            confirm = raw_input("""You have requested to anonymize all user data. 
This action CANNOT BE REVERSED.
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel """)
        else:
            confirm = 'yes'

        if confirm == 'yes':
            file_path = lambda x: os.path.join(options['name_data_dir'], x)
            first_data = name_generator.parse_data(file_path('dist.female.first')) + name_generator.parse_data(file_path('dist.male.first'))
            last_data = name_generator.parse_data(file_path('dist.all.last'))
            first_wc = WeightedChoice(first_data)
            last_wc = WeightedChoice(last_data)

            users = User.objects.all()
            names = name_generator.generate_names(first_wc, last_wc, users.count(), True)

            for i, user in enumerate(users):
                if options['skip_admins'] and is_admin(user):
                    # Skip admin user
                    self.stderr.write("Skipping admin user %s\n" % (user.username))
                    continue

                (fname, lname) = [n.title() for n in names[i].split(' ')]
                username = "******" % (fname.lower(), lname.lower())
                email = "*****@*****.**" % (fname.lower(), lname.lower())
                password = User.objects.make_random_password()

                user.username = username
                user.first_name = fname
                user.last_name = lname
                user.set_password(password)
                user.email = email
                user.save()
        else:
            self.stderr.write("User anonymization cancelled\n")
Ejemplo n.º 5
0
def main():
    parser = OptionParser()
    parser.add_option("-u",
                      "--unique",
                      action="store_true",
                      dest="unique",
                      default=False,
                      help="Generate unique names (within a given sex)")
    parser.add_option("-m",
                      "--male",
                      action="store",
                      type="int",
                      dest="num_male",
                      default=0,
                      help="Number of male names")
    parser.add_option("-f",
                      "--female",
                      action="store",
                      type="int",
                      dest="num_fem",
                      default=0,
                      help="Number of female names")
    (options, args) = parser.parse_args()

    if len(sys.argv) == 1:
        parser.error("No arguments")
    elif len(args) != 0:
        parser.error("Wrong number of arguments")
    else:
        # Parse data
        # file_path = lambda x: os.path.join(os.path.split(__file__)[0], '..', 'data', x)
        file_path = lambda x: os.path.join(DATA_PATH, x)
        fem_data = parse_data(file_path('dist.female.first'))
        male_data = parse_data(file_path('dist.male.first'))
        last_data = parse_data(file_path('dist.all.last'))

        # Create Objects
        fem_wc = WeightedChoice(fem_data)
        male_wc = WeightedChoice(male_data)
        last_wc = WeightedChoice(last_data)

        i = 3
        j = 3
        flag = 0

        output_male_wash = []
        output_fem_wash = []
        # Generate Female Names

        if options.num_fem > 0:
            output_fem = generate_names(fem_wc, last_wc, options.num_fem,
                                        options.unique)
            shuffle(output_fem)
            output_fem_wash = list(set(output_fem))
            print('female:' + str(len(output_fem_wash)))

        # Generate Male Names
        if options.num_male > 0:
            output_male = generate_names(male_wc, last_wc, options.num_male,
                                         options.unique)
            shuffle(output_male)
            output_male_wash = list(set(output_male))
            print('male:' + str(len(output_male_wash)))

        # Randomly shuffle the output so male and female names are mixed

        dic = {}
        dic['male_name'] = []
        dic['female_name'] = []
        for name in output_fem_wash:
            dic['female_name'].append(name)
        for name in output_male_wash:
            dic['male_name'].append(name)
        json_data = json.dumps(dic)
        f = open('name_text.json', 'w')
        f.write(json_data)
        f.close()
Ejemplo n.º 6
0
# coding: utf-8

# In[1]:

from species_generator import generate_species, search_species, convert_format
from name_generator import generate_names, convert_name, standard_formats
import pandas as pd
import random

# In[2]:

frame_columns = ["PatientName", "Attendings", "IPCStaff", "Pathogen"]

patient_info = pd.DataFrame(columns=frame_columns)  #init a blank table
num_patients = 100
patient_names = generate_names(100, "f l")  #create the set of patient names
attendings_names = generate_names(30, "f m l")  #attending full names
ipc_names = generate_names(20, "f m l")  #ipc member full names

for patient in patient_names:
    patient = convert_name(patient, "f l", 'l, f')
    #pick a random attending and random name format
    curr_attending = convert_name(random.choice(attendings_names), "f m l",
                                  "mix")
    #do the same for a random number of staff
    curr_staff = random.choices(ipc_names, k=random.randint(1, 5))
    for i in range(len(curr_staff)):
        curr_staff[i] = convert_name(curr_staff[i], "f m l", "mix")
    curr_staff = ";".join(curr_staff)
    #generate a random pathogen
    curr_pathogen = ";".join(
Ejemplo n.º 7
0
def analysis_vector():
    ATT_NAMES = generate_names()
    size_trend_analysis(OUT_NAME, ATT_NAMES)
Ejemplo n.º 8
0
def get_test_content():
    ATT_NAMES = generate_names()
    print("genrating names")
    print(ATT_NAMES)
    print("preparing sets")
    my_set = SampleSet(CTN, FILEPATH_SAMPLE, FILEPATH_MAP, BOUNDARY_ALL)