-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dinos.py
64 lines (55 loc) · 1.78 KB
/
Dinos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import math
class Dino():
_registry = []
def __init__(self, name, leg_length, diet, stride_length, stance):
self.name = name
self.leg_length = float(leg_length)
self.diet = diet
self.stride_length = float(stride_length)
self.stance = stance
self._registry.append(self)
def speed_calc(self):
g = float(9.8)
speed = ((self.stride_length / self.leg_length) - 1) * math.sqrt(self.leg_length * g)
return speed
def __str__(self):
return self.name
@staticmethod
def pull_data():
dinos = {}
with open('dataset1.txt') as f1:
for line in f1.readlines()[1:]:
name, leg_length, diet = line.split(',')
dinos[name] = [leg_length, diet.strip('\n')]
with open('dataset2.txt') as f2:
for line in f2.readlines()[1:]:
name, stride_length, stance = line.split(',')
dinos[name].append(stride_length)
dinos[name].append(stance.strip('\n'))
return dinos
@classmethod
def constructor(cls,k,v):
dinospeed = {}
name = k
leg_length = v[0]
diet = v[1]
stride_length = v[2]
stance = v[3]
# v[0] =
return cls(name,leg_length,diet,stride_length,stance)
dinos = Dino.pull_data()
for k,v in dinos.items():
dinospeed = {}
dino = Dino.constructor(k,v)
# print (dino.name,dino.stance)
dino.speed = Dino.speed_calc(dino)
if dino.stance == 'bipedal':
dinospeed[dino.name] = dino.speed
for k, v in sorted(dinospeed.items(), key=lambda x: x[1], reverse=True):
print (k)
# Hadrosaurus
# Struthiomimus
# Velociraptor
# Tyrannosaurus Rex
for d in Dino._registry:
print ('Dino name: ',d)