def setDB(): relationshipType = ["Child"] personName = [["Ana", "Arias", "65"], ["Carlos", "Soto", "67"], ["Maria", "Soto", "25"], ["Juan", "Soto", "30"], ["Carla", "Soto", "32"], ["Ivan", "Soto", "8"], ["Pedro", "Castro", "7"]] relationsAna = [3, 4, 5] relationsCarlos = [3, 4, 5] relationsJuan = [6] relationsCarla = [7] for x in relationshipType: relationship = Relationships() relationship.name = x db.session.add(relationship) db.session.commit() for x in personName: newPerson = Person() newPerson.name = x[0] newPerson.lastName = x[1] newPerson.age = x[2] db.session.add(newPerson) db.session.commit() for x in relationsAna: newRelative = Relative() newRelative.personID = Person.query.filter_by(name="Ana").first().id newRelative.relativeID = x newRelative.relationshipID = 1 db.session.add(newRelative) db.session.commit() for x in relationsCarlos: newRelative = Relative() newRelative.personID = Person.query.filter_by(name="Carlos").first().id newRelative.relativeID = x newRelative.relationshipID = 1 db.session.add(newRelative) db.session.commit() for x in relationsJuan: newRelative = Relative() newRelative.personID = Person.query.filter_by(name="Juan").first().id newRelative.relativeID = x newRelative.relationshipID = 1 db.session.add(newRelative) db.session.commit() for x in relationsCarla: newRelative = Relative() newRelative.personID = Person.query.filter_by(name="Carla").first().id newRelative.relativeID = x newRelative.relationshipID = 1 db.session.add(newRelative) db.session.commit()
def get_acs_person_data(filepath, year): # set up personal logger logger = Logger() current_path = os.getcwd() logger.define_issue_log(os.path.join(current_path, 'files/issues.log')) dictionary_of_people = dict() with open(filepath) as csvfile: file_reader = csv.reader(csvfile) line = next(file_reader) class Column(Enum): SERIALNO = line.index('SERIALNO') ST = line.index('ST') PUMA = line.index('PUMA') AGEP = line.index('AGEP') SCHL = line.index('SCHL') MAR = line.index('MAR') HICOV = line.index('HICOV') RACBLK = line.index('RACBLK') # 0 = not black; 1 = black DIS = line.index('DIS') # 1 = disabled; 2 = not disabled MIL = line.index('MIL') # 1-3 = veteran WAOB = line.index('WAOB') # 1-2 = non-immigrant NWAB = line.index('NWAB') # 1 = temp work absence; 2 = no try: i = 0 while True: acs_row = next(file_reader) serial_number = acs_row[Column.SERIALNO.value] person = Person(serial_number) state = acs_row[Column.ST.value] person.state = state # TODO make an enum of state names and use it here person.puma = state + acs_row[Column.PUMA.value] + year person.age = acs_row[Column.AGEP.value] person.education = acs_row[Column.SCHL.value] if acs_row[Column.MAR.value] == '3': person.divorced = True else: person.divorced = False if acs_row[Column.HICOV.value] == '1': person.insured = True else: person.insured = False if acs_row[Column.RACBLK.value] == '1': person.black = True else: person.black = False if acs_row[Column.DIS.value] == '1': person.disabled = True else: person.disabled = False mil = acs_row[Column.MIL.value] if mil == '1' or mil == '2' or mil == '3': person.veteran = True else: person.veteran = False if acs_row[Column.WAOB.value] == '1' or acs_row[ Column.WAOB.value] == '2': person.immigrant = False else: person.immigrant = True nwab = acs_row[Column.NWAB.value] if nwab == '1': person.unemployed = True elif nwab == '2' or nwab == 'b': person.unemployed = False else: person.unemployed = 'NA' id = serial_number + state + year dictionary_of_people[id] = person # i += 1 # logger.log('Setting up person #', format(i, ',d'), erase=True) except StopIteration: pass logger.log('Created', format(len(dictionary_of_people), ',d'), 'people from', filepath) return dictionary_of_people