Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CSCI30_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Temujin
CSCI30_Project
Commits
fc4afe66
Commit
fc4afe66
authored
Dec 10, 2019
by
Temujin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed relationship func. commandline added
parent
9b822ba9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
103 deletions
+159
-103
family_tree.py
family_tree.py
+113
-103
test.ft
test.ft
+46
-0
No files found.
family_tree.py
View file @
fc4afe66
...
...
@@ -197,12 +197,12 @@ class FamilyTree:
elif
furthest
==
2
:
return
self
.
TERM
(
"nibling"
,
d1
,
d2
,
p2
.
sex
)
else
:
return
self
.
GREAT
(
furthest
)
+
"grand"
+
self
.
TERM
(
"nibling"
,
d1
,
d2
,
p2
.
sex
)
return
self
.
GREAT
(
furthest
-
2
)
+
"grand"
+
self
.
TERM
(
"nibling"
,
d1
,
d2
,
p2
.
sex
)
elif
nearest
==
0
:
if
furthest
==
1
:
return
self
.
TERM
(
"child"
,
d1
,
d2
,
p2
.
sex
)
else
:
return
self
.
GREAT
(
furthest
)
+
"grand"
+
self
.
TERM
(
"child"
,
d1
,
d2
,
p2
.
sex
)
return
self
.
GREAT
(
furthest
-
2
)
+
"grand"
+
self
.
TERM
(
"child"
,
d1
,
d2
,
p2
.
sex
)
def
ORDINAL
(
self
,
n
):
"""Return the index in the ordinal table."""
...
...
@@ -328,7 +328,9 @@ class Person:
"""Return the name."""
return
self
.
name
def
openfile
(
filename
):
#Open Method
def
openfile
(
filename
):
"""Open a .ft file."""
atree
=
FamilyTree
()
fname
=
filename
+
".ft"
readF
=
open
(
fname
,
"r"
)
...
...
@@ -356,14 +358,16 @@ def openfile(filename): #Open Method
atree
.
precompute
()
return
atree
def
savefile
(
filename
,
tree
):
#Save Method
def
savefile
(
filename
,
tree
):
"""Save the tree to a file."""
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
():
for
i
,
x
in
tree
.
family_tree
.
items
():
name
=
x
.
get_name
()
age
=
str
(
x
.
get_age
())
sex
=
str
(
x
.
get_sex
())
...
...
@@ -374,12 +378,14 @@ def savefile(filename, tree): #Save Method
links
=
count
-
1
saveF
.
write
(
"links "
+
str
(
links
)
+
"
\n
"
)
for
i
,
x
in
tree
.
family_tree
.
items
():
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
commandLine
():
"""Open command line."""
tree
=
FamilyTree
()
while
True
:
cmd
=
input
()
.
split
()
...
...
@@ -418,7 +424,7 @@ def commandLine():
print
(
"Error: no such person "
+
cmd
[
1
])
elif
cmd
[
0
]
==
"edit-name"
:
try
:
if
tree
.
family_tree
.
get
(
cmd
[
2
])
==
None
:
if
tree
.
family_tree
.
get
(
cmd
[
2
])
is
None
:
tree
.
get_person
(
cmd
[
1
])
.
set_name
(
cmd
[
2
])
tree
.
family_tree
[
cmd
[
2
]]
=
tree
.
family_tree
[
cmd
[
1
]]
del
tree
.
family_tree
[
cmd
[
1
]]
...
...
@@ -464,9 +470,9 @@ def commandLine():
else
:
print
(
"Error: no such command"
)
def
main
():
r"""For testing.
A
/
\
B C
...
...
@@ -502,18 +508,21 @@ def main():
print
(
"The lca of {} and {} is {}"
.
format
(
A
,
B
,
ftree
.
find_lca
(
"A"
,
"B"
)))
# parent/child
print
(
"relationship {} is {}'s: {}"
.
format
(
B
,
A
,
ftree
.
relationship
(
A
,
B
)))
print
(
"relationship {} is {}'s: {}"
.
format
(
A
,
B
,
ftree
.
relationship
(
B
,
A
)))
print
(
"{} is {}'s: {}"
.
format
(
B
,
A
,
ftree
.
relationship
(
A
,
B
)))
print
(
"{} is {}'s: {}"
.
format
(
A
,
B
,
ftree
.
relationship
(
B
,
A
)))
# grandparent/granchild
print
(
""
)
# sibling
print
(
"
relationship
{} is {}'s: {}"
.
format
(
B
,
C
,
ftree
.
relationship
(
C
,
B
)))
print
(
"
relationship
{} is {}'s: {}"
.
format
(
C
,
B
,
ftree
.
relationship
(
B
,
C
)))
print
(
"{} is {}'s: {}"
.
format
(
B
,
C
,
ftree
.
relationship
(
C
,
B
)))
print
(
"{} is {}'s: {}"
.
format
(
C
,
B
,
ftree
.
relationship
(
B
,
C
)))
# nibling
print
(
"
relationship
{} is {}'s: {}"
.
format
(
D
,
C
,
ftree
.
relationship
(
C
,
D
)))
print
(
"
relationship
{} is {}'s: {}"
.
format
(
C
,
D
,
ftree
.
relationship
(
D
,
C
)))
print
(
"{} is {}'s: {}"
.
format
(
D
,
C
,
ftree
.
relationship
(
C
,
D
)))
print
(
"{} is {}'s: {}"
.
format
(
C
,
D
,
ftree
.
relationship
(
D
,
C
)))
print
(
""
)
print
(
"{} is {}'s: {}"
.
format
(
A
,
D
,
ftree
.
relationship
(
D
,
A
)))
print
(
"{} is {}'s: {}"
.
format
(
D
,
A
,
ftree
.
relationship
(
A
,
D
)))
#test for opening and saving files
#
test for opening and saving files
ntree
=
openfile
(
"chandelier"
)
ntree
.
find_root
()
...
...
@@ -524,5 +533,6 @@ def main():
savefile
(
"test"
,
ntree
)
if
__name__
==
"__main__"
:
main
()
test.ft
0 → 100644
View file @
fc4afe66
family test
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment