-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab3.py
More file actions
224 lines (178 loc) · 7.32 KB
/
Lab3.py
File metadata and controls
224 lines (178 loc) · 7.32 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass, field
import re
from datetime import datetime
@dataclass
class PersonalInfo:
"""Collection of all personal data about employee"""
__name: str = "name surname"
first_name: str = field(default="first_name", init=False)
second_name: str = field(default="surname", init=False)
_address: str = "address"
_phone_number: str = "+1000000000"
email: str = "email@com"
_position: int = -1
_rank: str = "rank"
_salary: float = -1
id_counter = 0
def __post_init__(self):
self.id = PersonalInfo.id_counter
PersonalInfo.id_counter += 1
self.name = self.__name
if re.match("^\\+?[1-9][0-9]{7,14}$", self._phone_number) is None:
raise ValueError("Phone number is not valid!")
class Employee:
"""Container for all employees"""
def __init__(self, personal_info: PersonalInfo = None, projects=None):
self.personal_info = personal_info
if projects is None:
projects = []
self.projects: Project = projects
def calculate_salary(self):
return self.personal_info._salary
@dataclass
class Team:
""""Collection of info about members, connected to certain project"""
project_id: int
member_list: list = field(default_factory=lambda: [])
title: str = "Default title"
id_counter = 0
def __post_init__(self):
self.id = PersonalInfo.id_counter
PersonalInfo.id_counter += 1
class Developer(Employee):
"""Basis developer, that inherits from Employee"""
def __init__(self, personal_info: PersonalInfo = None, projects=[]):
try:
Employee.__init__(personal_info, projects)
except Exception as e:
raise ValueError("Developer instantiation error! " + str(e))
def assigned_projects(self):
""" Get all assigned project to developer."""
return self.projects
class AssignManagement:
"""Handles all assignments"""
def __init__(self, project, emp):
try:
self.project: Project = project
self.emp: Employee = emp
except Exception as e:
raise ValueError("Assignment error! " + str(e))
def assign(self):
"""Adds developer to specified project"""
try:
if self.project.limit <= len(self.project.team.member_list):
raise ValueError("Project developer limit is exceeded!")
if self.emp in self.project.team.member_list:
raise ValueError("Developer is already in the list!")
self.project.team.member_list.append(self.emp)
self.emp.projects.append(self.project)
except ValueError as e:
raise ValueError("Failed to add developer! " + str(e))
def unassign(self):
"""Removes developer from project"""
try:
self.project.team.member_list.remove(self.emp)
self.emp.projects.remove(self.project)
except ValueError:
raise ValueError("Developer was not found in the project!")
def assign_possibility(self):
"""Checks if developer can be added to the project"""
return not self.project.limit <= len(self.project.team.member_list)
class Project(metaclass=ABCMeta):
"""General Project factory"""
id_counter = 0
@abstractmethod
def __init__(self, title, start_date, task_list, team, limit):
try:
self.id: int = self.id_counter
Project.id_counter += 1
if team is None:
team = Team(self.id, [], str(title + "'s team"))
if task_list is None:
task_list = []
self.task_list: int = []
self.title: str = title
self.start_date: datetime = start_date
self.task_list: str = task_list
self.team: Team = team
self.limit: int = limit
except Exception as e:
raise ValueError("Project instantiation error! " + str(e))
@abstractmethod
def add_employee(self, emp: Employee):
"""Adds employee to project"""
pass
@abstractmethod
def remove_employee(self, emp: Employee):
"""Removes employee to project"""
pass
class Web(Project):
"""Web project subtype"""
def __init__(self, title="Title", start_date=None, task_list=None, team=None, limit=-1, domain="/", host_provider="host name"):
super().__init__(title, start_date, task_list, team, limit)
self.domain = domain
self.host_provider = host_provider
def add_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.assign()
def remove_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.unassign()
class Mobile(Project):
"""Mobile project subtype"""
def __init__(self, title="Title", start_date=None, task_list=None, team=None, limit=-1, is_crossplatform: bool = True):
super().__init__(title, start_date, task_list, team, limit)
self.is_crossplatform = is_crossplatform
def add_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.assign()
def remove_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.unassign()
class Embedded(Project):
"""Embedded project subtype"""
def __init__(self, title="Title", start_date=None, task_list=None, team=None, limit=-1, open_source: bool = True):
super().__init__(title, start_date, task_list, team, limit)
self.open_source = open_source
def add_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.assign()
def remove_employee(self, emp: Employee):
mgn = AssignManagement(self, emp)
mgn.unassign()
class SoftwareArchitect(Employee, metaclass=ABCMeta):
"""Software Architect factory"""
def fill_project(self, team: Team, project: Project):
"""Replaces projects' team with a new one"""
try:
if project not in self.projects:
raise ValueError(f"Architect has no access to '{project.title}'!")
map(lambda emp: emp.projects.append(project), project.team.member_list)
project.team = team
except ValueError as e:
raise ValueError(f"Filling project failed! {e}")
@abstractmethod
def create_project(self):
pass
class WebArchitect(SoftwareArchitect):
"""Web Architect subtype"""
def create_project(self, *args, **kwargs):
"""Creates Web project"""
project = Web(*args, **kwargs)
self.projects.append(project)
return project
class MobileArchitect(SoftwareArchitect):
"""Mobile Architect subtype"""
def create_project(self, *args, **kwargs):
"""Creates Mobile project"""
project = Mobile(*args, **kwargs)
self.projects.append(project)
return project
class EmbeddedArchitect(SoftwareArchitect):
"""Embedded Architect subtype"""
def create_project(self, *args, **kwargs):
"""Creates Embedded project"""
project = Embedded(*args, **kwargs)
self.projects.append(project)
return project