-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.py
More file actions
98 lines (83 loc) · 3.69 KB
/
session.py
File metadata and controls
98 lines (83 loc) · 3.69 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
''' ====================================================================
Session: A class to represent a instance of a climbing session.
A climbing session consists of:
A unique climbing date
1 or more climb instances
Methods:
__init__ - Constructor for the class
updateSessionType() - Updates session type information for
climbs if necessary. Each session can have multiple
climb types.
updateSessionGradeCount() - Updated the count of successful
climbs for each grade
addClimb() - Add a climb type to session
getSessionType() - Returns type of session. Can have more
than one type per session (example: "BS").
B = Bouldering
S = Summer
W = Winter
getSessionVSum() - Returns the VSum for the session (if
Bouldering occured in session)
getSessionGradeCount() - Provides a count/distrobution of
all grades
getSessionDistance(unit) - Return the sum of the lengths
of all successful climbs in a session
getSessionDate - Returns the date of the session
===================================================================='''
class Session():
climbs = []
sessionType = ""
totalDistance = 0
vSum = 0
sessionGradeCount = {}
# Constructor method for the Session class.
def __init__(self, date):
self.date = date
self.sessionGradeCount = {}
self.vSum = 0
self.totalDistance = 0
self.climbs = []
self.sessionType = ""
# Update session type information (sessionType) by appending it to string
# Climb types are: B, TR, Trad, SP, MI, WI
def updateSessionType(self, climb):
if climb.climbType not in self.sessionType:
self.sessionType += climb.climbType
# Winter climbs - look at winter grades to determine winter sessions
if "WI" in climb.grade and "WI" not in self.sessionType:
self.sessionType += "WI"
if "MI" in climb.grade and "MI" not in self.sessionType:
self.sessionType += "MI"
# Update session grade count dictionary (sessionGradeCount)
def updateSessionGradeCount(self, climb):
if climb.grade in self.sessionGradeCount:
self.sessionGradeCount[climb.grade] += 1
else:
self.sessionGradeCount[climb.grade] = 1
# Add a climb to this session
def addClimb(self, climb):
self.climbs.append(climb)
self.totalDistance += climb.getTotalLength()
self.updateSessionType(climb)
self.updateSessionGradeCount(climb)
# Add a climb to this session
def addBoulder(self, climb):
self.updateSessionType(climb)
self.vSum += climb.getVSum()
''' Returns the session type (sessionType).
A session can consist of more than one type of climb '''
def getSessionType(self):
return self.sessionType
''' Returns a dictionary (sessionGradeCount) containing
counts of successful climbs for each grade in a session '''
def getSessionGradeCount(self):
return self.sessionGradeCount
''' Returns the VSum (vSum) for the session '''
def getSessionVSum(self):
return self.vSum
''' Return the total distance (totalDistance) for the session '''
def getSessionDistance(self):
return self.totalDistance
''' Return the date of the session '''
def getSessionDate(self):
return self.date