Commit 91d1592a authored by Temujin's avatar Temujin

Merge branch 'master' into 'master'

Master

See merge request Omanko6969/csci30_project!1
parents b6b4a537 1498b5ff
family Chandelier
count 11
name Kyle
age 91
sex true
name Fe
age 73
sex false
name Daniel
age 77
sex true
name Alma
age 52
sex false
name Aaron
age 49
sex true
name Dane
age 33
sex true
name Juan
age 32
sex true
name Charles
age 17
sex true
name Joyce
age 11
sex false
name Floyd
age 4
sex true
name Patricia
age 2
sex false
links 10
child Kyle Fe
child Kyle Daniel
child Daniel Alma
child Daniel Aaron
child Alma Dane
child Alma Juan
child Juan Charles
child Juan Joyce
child Charles Floyd
child Charles Patricia
...@@ -333,6 +333,52 @@ class Person: ...@@ -333,6 +333,52 @@ class Person:
"""Return the name.""" """Return the name."""
return self.name return self.name
def openfile(filename): #Open Method
atree = FamilyTree()
fname = filename + ".ft"
readF = open(fname, "r")
familyname = readF.readline().split()[1]
count = int(readF.readline().split()[1])
for i in range(count):
name = readF.readline().split()[1]
age = int(readF.readline().split()[1])
sex = bool(readF.readline().split()[1])
person = Person(name, age, sex)
atree.insert_person(person)
links = int(readF.readline().split()[1])
for i in range(links):
line = readF.readline().split()
p1 = atree.get_person(line[1])
p2 = atree.get_person(line[2])
p2.set_parent(p1)
readF.close()
return atree
def savefile(filename, tree): #Save Method
fname = filename + ".ft"
saveF = open(fname, "w+")
saveF.write("family " + filename + "\n")
count = len(tree.family_tree)
saveF.write("count " + str(count) + "\n")
for i,x in tree.family_tree.items():
name = x.get_name()
age = str(x.get_age())
sex = str(x.get_sex())
saveF.write("name " + name + "\n")
saveF.write("age " + age + "\n")
saveF.write("sex " + sex + "\n")
links = count - 1
saveF.write("links " + str(links) + "\n")
for i,x in tree.family_tree.items():
if x is not tree.root:
parent = x.get_parent()
saveF.write("child " + parent.get_name() + " " + x.get_name() + "\n")
def main(): def main():
r"""For testing. r"""For testing.
...@@ -381,6 +427,18 @@ def main(): ...@@ -381,6 +427,18 @@ def main():
print("relationship {} is {}'s: {}".format(D, C, ftree.relationship(C, D))) print("relationship {} is {}'s: {}".format(D, C, ftree.relationship(C, D)))
print("relationship {} is {}'s: {}".format(C, D, ftree.relationship(D, C))) print("relationship {} is {}'s: {}".format(C, D, ftree.relationship(D, C)))
print("")
#test for opening and saving files
ntree = openfile("chandelier")
ntree.find_root()
ntree.precompute()
print("The root of the tree is {}.".format(ntree.root))
for key, node in ntree.family_tree.items():
print("{}: {}".format(node, node.get_generation()))
savefile("test", ntree)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment