Ejemplo n.º 1
0
def generate(db, count):
    print "Populating table: members"

    with open("firstnames_female.txt") as f:
        firstnames_female = f.readlines()
    with open("firstnames_male.txt") as f:
        firstnames_male = f.readlines()
    with open("lastnames.txt") as f:
        lastnames = f.readlines()
    with open("cities.txt") as f:
        cities = f.readlines()

    # At least one member per call should use a "samordningsnummer", and also about one in a hundred randomly
    # http://www.skatteverket.se/privat/sjalvservice/blanketterbroschyrer/broschyrer/info/707.4.39f16f103821c58f680007997.html
    samordning_index = int(random.random() * count)
    samordning_frequency = 0.01

    # At least one member per call should use extra letter after street number
    extra_address_letter_index = int(random.random() * count)

    # At least one member per call should use apartment number information in address
    apartment_number_index = int(random.random() * count)

    # At least one member per call should use extra info such as c/o or att: in address
    address_extra_info = int(random.random() * count)

    generated_ids = []
    for i in range(1, count+1):
        is_female = random.random() < 0.5

        member = Member()
        member.created_at = common.get_random_datetime(datetime.datetime(2013,1,1), datetime.datetime.now())
        member.updated_at = common.get_random_datetime(member.created_at, datetime.datetime.now())
        member.email = common.get_short_unique_string() + '@test.makerspace.se'
        if is_female:
            member.firstname = common.get_random_item(firstnames_female).strip()
        else:
            member.firstname = common.get_random_item(firstnames_male).strip()
        member.lastname = common.get_random_item(lastnames).strip()
        member.civicregno = make_civic_regno(is_female, i == samordning_index or random.random() < samordning_frequency)
        member.country = 'SE'
        member.phone = make_phone_number()
        member.address = make_address(i == extra_address_letter_index, i == apartment_number_index)
        member.city = common.get_random_item(cities).strip()
        # Apparently the connection between city and zip code is intellectual property in Sweden
        member.zipcode = "%03d%02d" % (int(random.random()*900)+100, int(random.random()*100))
        member.address2 = make_address2(i == address_extra_info, firstnames_female, lastnames)

        try:
            generated_ids.append(common.insert_into_table(db, 'members', member))
        except:
            print "Failed to populate members table"
            raise

    return generated_ids
Ejemplo n.º 2
0
def make_civic_regno(is_female, is_samordningsnummer):
    birthdatetime = common.get_random_datetime(datetime.datetime(1900,1,1), datetime.datetime(2010,1,1))
    birthdate = "%04d%02d%02d" % (birthdatetime.year, birthdatetime.month, birthdatetime.day + (60 if is_samordningsnummer else 0)) 
    short_birthdate = birthdate[-6:]
    birth_number = "%03d" % (int(random.random() * 500)*2 + (1 if not is_female else 0))

    checksum_string = short_birthdate + birth_number
    odd = False
    checksum = 0
    for i in range(0, len(checksum_string)):
        value = int(checksum_string[i])
        if not odd:
            value = value * 2
        checksum = checksum + (value % 10) + (value / 10)
        odd = not odd

    check_digit = (10 - (checksum % 10)) % 10
    return birthdate + '-' + birth_number + str(check_digit)
Ejemplo n.º 3
0
def make_civic_regno_naive(is_female, is_samordningsnummer):
    birthdatetime = common.get_random_datetime(datetime.datetime(1900, 1, 1),
                                               datetime.datetime(2010, 1, 1))
    birthdate = "%04d%02d%02d" % (birthdatetime.year, birthdatetime.month,
                                  birthdatetime.day +
                                  (60 if is_samordningsnummer else 0))
    short_birthdate = birthdate[-6:]
    birth_number = "%03d" % (int(random.random() * 500) * 2 +
                             (1 if not is_female else 0))

    checksum_string = short_birthdate + birth_number
    odd = False
    checksum = 0
    for i in range(len(checksum_string)):
        value = int(checksum_string[i])
        if not odd:
            value = value * 2
        checksum = checksum + (value % 10) + (value / 10)
        odd = not odd

    check_digit = (10 - (checksum % 10)) % 10
    return birthdate + '-' + birth_number + str(check_digit)
Ejemplo n.º 4
0
def generate(db, report, count):
    print "Populating table: members"

    with open("firstnames_female.txt") as f:
        firstnames_female = f.readlines()
    with open("firstnames_male.txt") as f:
        firstnames_male = f.readlines()
    with open("lastnames.txt") as f:
        lastnames = f.readlines()
    with open("cities.txt") as f:
        cities = f.readlines()

    # At least one member per call should use a "samordningsnummer"
    # http://www.skatteverket.se/privat/sjalvservice/blanketterbroschyrer/broschyrer/info/707.4.39f16f103821c58f680007997.html
    samordning_index = random.randint(0, count - 1)

    # At least one member per call should use extra letter after street number
    extra_address_letter_index = random.randint(0, count - 1)

    # At least one member per call should use apartment number information in address
    apartment_number_index = random.randint(0, count - 1)

    # At least one member per call should use extra info such as c/o or att: in address
    address_extra_info_index = random.randint(0, count - 1)

    members = {}
    for i in xrange(count):
        is_female = common.chance(0.5)

        force_samordningsnummer = (i == samordning_index)
        force_extra_address_letter = (i == extra_address_letter_index)
        force_apartment_number = (i == apartment_number_index)
        force_extra_address_info = (i == address_extra_info_index)

        member = Member()
        member.created_at = common.get_random_datetime(
            datetime.datetime(2013, 1, 1), datetime.datetime.now())
        member.updated_at = common.get_random_datetime(member.created_at,
                                                       datetime.datetime.now())
        member.email = common.get_short_unique_string() + '@test.makerspace.se'
        if is_female:
            member.firstname = random.choice(firstnames_female).strip()
        else:
            member.firstname = random.choice(firstnames_male).strip()
        member.lastname = random.choice(lastnames).strip()
        member.civicregno = make_civic_regno(
            db, is_female, force_samordningsnummer or common.chance(0.01))
        member.country = 'SE'
        member.phone = make_phone_number()
        member.address = make_address(force_extra_address_letter,
                                      force_apartment_number)
        member.city = random.choice(cities).strip()
        # Apparently the connection between city and zip code is intellectual property in Sweden
        member.zipcode = "%03d%02d" % (int(random.random() * 900) + 100,
                                       int(random.random() * 100))
        member.address2 = make_address2(force_extra_address_info,
                                        firstnames_female, lastnames)

        try:
            member_id = common.insert_into_table(db, 'members', member)
        except:
            print "FAILED to insert members row"
            raise

        members[member_id] = member
        if force_samordningsnummer:
            report.append(("Samordningsnummer", member))
        if force_extra_address_letter:
            report.append(("Letter on street number", member))
        if force_apartment_number:
            report.append(("Address includes apartment number", member))
        if force_extra_address_info:
            report.append(("Extra address line", member))

    return members
Ejemplo n.º 5
0
def generate(db, report, members):
    print "Populating table: member_rfid"

    descriptions = ["Work tag", "Surgically implanted in hand", "Cell phone chip", "Sewn into wallet", "Of unknown extra-terrestrial origin"]

    # At least one member per call should have an inactive tag
    inactive_tag_index = random.randint(0, len(members)-1)

    # At least one member per call should have three rfid tags
    three_tag_index = random.randint(0, len(members)-1)

    # At least one member per call should lack tags completely
    no_tag_index = common.random_index_with_exclude(len(members), [inactive_tag_index, three_tag_index]) 

    # At least one member per call should have a full length rfid
    full_rfid_index = common.random_index_with_exclude(len(members), [no_tag_index])

    i = 0
    for member_id in members:
        member = members[member_id]

        force_three_tags = (i == three_tag_index)
        force_no_tag = (i == no_tag_index)
        force_full_rfid = (i == full_rfid_index)
        force_inactive_tag = (i == inactive_tag_index)

        if force_three_tags:
            number_of_ids = 3
        elif force_full_rfid:
            number_of_ids = 2
        elif force_no_tag or common.chance(0.1) and not force_inactive_tag:
            number_of_ids = 0
        else:
            number_of_ids = int(1 + 3*random.random()**5) # about 20% with two keys, 8% with three keys

        if number_of_ids > 0:
            for j in range(number_of_ids):
                has_description = j > 0 or common.chance(0.1)
                if force_full_rfid and j == 1 or common.chance(0.02):
                    rfid = make_unique_rfid(db, 16)
                else:
                    rfid = make_unique_rfid(db, 8)

                tag = MemberRFID()
                tag.created_at = common.get_random_datetime(member.created_at, datetime.datetime.now())
                tag.updated_at = common.get_random_datetime(tag.created_at, datetime.datetime.now())
                tag.member_id = member_id
                tag.active = common.chance(0.9) and not force_inactive_tag
                tag.tagid = rfid
                tag.description = None if not has_description else random.choice(descriptions)
                common.insert_into_table(db, 'member_rfid', tag)

        if force_three_tags:
            report.append(("Three RFID keys", member))
        if force_no_tag:
            report.append(("No RFID key", member))
        if force_full_rfid :
            report.append(("Full RFID", member))
        if force_inactive_tag :
            report.append(("Inactive RFID tag", member))

        i = i + 1
Ejemplo n.º 6
0
def generate(db, report, members):
    print "Populating table: member_rfid"

    descriptions = [
        "Work tag", "Surgically implanted in hand", "Cell phone chip",
        "Sewn into wallet", "Of unknown extra-terrestrial origin"
    ]

    # At least one member per call should have an inactive tag
    inactive_tag_index = random.randint(0, len(members) - 1)

    # At least one member per call should have three rfid tags
    three_tag_index = random.randint(0, len(members) - 1)

    # At least one member per call should lack tags completely
    no_tag_index = common.random_index_with_exclude(
        len(members), [inactive_tag_index, three_tag_index])

    # At least one member per call should have a full length rfid
    full_rfid_index = common.random_index_with_exclude(len(members),
                                                       [no_tag_index])

    i = 0
    for member_id in members:
        member = members[member_id]

        force_three_tags = (i == three_tag_index)
        force_no_tag = (i == no_tag_index)
        force_full_rfid = (i == full_rfid_index)
        force_inactive_tag = (i == inactive_tag_index)

        if force_three_tags:
            number_of_ids = 3
        elif force_full_rfid:
            number_of_ids = 2
        elif force_no_tag or common.chance(0.1) and not force_inactive_tag:
            number_of_ids = 0
        else:
            number_of_ids = int(
                1 + 3 * random.random()**5
            )  # about 20% with two keys, 8% with three keys

        if number_of_ids > 0:
            for j in range(number_of_ids):
                has_description = j > 0 or common.chance(0.1)
                if force_full_rfid and j == 1 or common.chance(0.02):
                    rfid = make_unique_rfid(db, 16)
                else:
                    rfid = make_unique_rfid(db, 8)

                tag = MemberRFID()
                tag.created_at = common.get_random_datetime(
                    member.created_at, datetime.datetime.now())
                tag.updated_at = common.get_random_datetime(
                    tag.created_at, datetime.datetime.now())
                tag.member_id = member_id
                tag.active = common.chance(0.9) and not force_inactive_tag
                tag.tagid = rfid
                tag.description = None if not has_description else random.choice(
                    descriptions)
                common.insert_into_table(db, 'member_rfid', tag)

        if force_three_tags:
            report.append(("Three RFID keys", member))
        if force_no_tag:
            report.append(("No RFID key", member))
        if force_full_rfid:
            report.append(("Full RFID", member))
        if force_inactive_tag:
            report.append(("Inactive RFID tag", member))

        i = i + 1
Ejemplo n.º 7
0
def generate(db, report, count):
    print "Populating table: members"

    with open("firstnames_female.txt") as f:
        firstnames_female = f.readlines()
    with open("firstnames_male.txt") as f:
        firstnames_male = f.readlines()
    with open("lastnames.txt") as f:
        lastnames = f.readlines()
    with open("cities.txt") as f:
        cities = f.readlines()

    # At least one member per call should use a "samordningsnummer"
    # http://www.skatteverket.se/privat/sjalvservice/blanketterbroschyrer/broschyrer/info/707.4.39f16f103821c58f680007997.html
    samordning_index = random.randint(0, count-1)

    # At least one member per call should use extra letter after street number
    extra_address_letter_index = random.randint(0, count-1)

    # At least one member per call should use apartment number information in address
    apartment_number_index = random.randint(0, count-1)

    # At least one member per call should use extra info such as c/o or att: in address
    address_extra_info_index = random.randint(0, count-1)

    members = {}
    for i in xrange(count):
        is_female = common.chance(0.5)

        force_samordningsnummer = (i == samordning_index)
        force_extra_address_letter = (i == extra_address_letter_index)
        force_apartment_number = (i == apartment_number_index)
        force_extra_address_info = (i == address_extra_info_index)

        member = Member()
        member.created_at = common.get_random_datetime(datetime.datetime(2013,1,1), datetime.datetime.now())
        member.updated_at = common.get_random_datetime(member.created_at, datetime.datetime.now())
        member.email = common.get_short_unique_string() + '@test.makerspace.se'
        if is_female:
            member.firstname = random.choice(firstnames_female).strip()
        else:
            member.firstname = random.choice(firstnames_male).strip()
        member.lastname = random.choice(lastnames).strip()
        member.civicregno = make_civic_regno(db, is_female, force_samordningsnummer or common.chance(0.01))
        member.country = 'SE'
        member.phone = make_phone_number()
        member.address = make_address(force_extra_address_letter, force_apartment_number)
        member.city = random.choice(cities).strip()
        # Apparently the connection between city and zip code is intellectual property in Sweden
        member.zipcode = "%03d%02d" % (int(random.random()*900)+100, int(random.random()*100))
        member.address2 = make_address2(force_extra_address_info, firstnames_female, lastnames)

        try:
            member_id = common.insert_into_table(db, 'members', member)
        except:
            print "FAILED to insert members row"
            raise

        members[member_id] = member
        if force_samordningsnummer:
            report.append(("Samordningsnummer", member))
        if force_extra_address_letter:
            report.append(("Letter on street number", member))
        if force_apartment_number:
            report.append(("Address includes apartment number", member))
        if force_extra_address_info:
            report.append(("Extra address line", member))

    return members