-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessingClasses.py
90 lines (60 loc) · 2.36 KB
/
ProcessingClasses.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
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
#------------------------------------------#
# Title: Processing Classes
# Desc: A Module for processing Classes
# Change Log: (Who, When, What)
# DBiesinger, 2030-Jan-01, Created File
# DBiesinger, 2030-Jan-02, Extended functionality to add tracks
#------------------------------------------#
if __name__ == '__main__':
raise Exception('This file is not meant to ran by itself')
import DataClasses as DC
class DataProcessor:
"""Processing the data in the application"""
@staticmethod
def add_CD(CDInfo, table):
"""function to add CD info in CDinfo to the inventory table.
Args:
CDInfo (tuple): Holds information (ID, CD Title, CD Artist) to be added to inventory.
table (list of dict): 2D data structure (list of dicts) that holds the data during runtime.
Returns:
None.
"""
cdId, title, artist = CDInfo
try:
cdId = int(cdId)
except ValueError:
print('ID must be an Integer!')
row = DC.CD(cdId, title, artist)
table.append(row)
table.sort(key=lambda i: i.cd_id)
@staticmethod
def select_cd(table: list, cd_idx: int) -> DC.CD:
"""selects a CD object out of table that has the ID cd_idx
Args:
table (list): Inventory list of CD objects.
cd_idx (int): id of CD object to return
Raises:
Exception: If id is not in list.
Returns:
row (DC.CD): CD object that matches cd_idx
"""
# TODO add code as required
for row in table:
if row.cd_id == cd_idx:
return row
raise Exception('This CD track does not exist.')
@staticmethod
def add_track(track_info: tuple, cd: DC.CD) -> None:
"""adds a Track object with attributes in track_info to cd
Args:
track_info (tuple): Tuple containing track info (position, title, Length).
cd (DC.CD): cd object the track gets added to.
Raises:
Exception: raised in case position is not an integer.
Returns:
None
"""
# TODO add code as required
position, title, length = track_info
track = DC.Track(position, title, length)
cd.add_track(track)