-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
269 lines (246 loc) · 9.75 KB
/
main.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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Display the Menu
def display_menu():
print(" XYZ COMPANY ".center(100))
print(" Main Menu ".center(100))
print("\t\t 1. Add a new project to existing projects")
print("\t\t 2. Remove a completed project from existing projects")
print("\t\t 3. Add new workers to available workers group")
print("\t\t 4. Update details on ongoing projects")
print("\t\t 5. Project Statistics")
print("\t\t 6. Exit")
# save data in a file
def save_data(data_list:list,available_workers:int):
with open("state.txt", "w") as file:
if data_list == []:
file.write(str(available_workers))
else:
for project in data_list:
file.write(",".join(project))
file.write("\n")
if available_workers == 0:
available_workers = tot_workers(data_list)
file.write(str(available_workers))
# read data in a file
def read_data(data_list:list=[],available_workers:int=0):
try:
with open("state.txt", "r") as file:
lines = file.readlines()
if len(lines) > 0:
available_workers = int(lines.pop())
for line in lines:
data_l = line.rstrip().split(',')
data_list.append(data_l)
return data_list,available_workers
else:
return data_list ,available_workers
except FileNotFoundError:
return data_list,available_workers
# Delete file contains
def delete_data():
with open("state.txt", "w") as file:
pass
# Add a new project to existing projects
def add_new_project(data_list:list) ->list:
print(" XYZ COMPANY ".center(100))
print(" Add a new project ".center(100))
project_code = input("Project code - ")
if project_code == "0":
return data_list
clients_name = input("Clients name - ")
start_date = input("Start date - ")
enter_expected_date = input("Expected end date - ")
num_of_workers = input("Number of workers - ")
while True:
project_status = input("Project status - ")
if project_status.lower() == "ongoing" or project_status.lower() == "on hold" or project_status.lower() == "completed":
break
else:
print("Invalid input.Try again.")
continue
project_list = [project_code,clients_name,start_date,enter_expected_date,num_of_workers,project_status]
user_input = input("Do you want to save the project (Yes/No)? ")
while True:
if user_input.lower() == "yes":
data_list.append(project_list)
break
elif user_input.lower() == "no":
break
else:
print("Invalid Input.Try again.")
continue
return data_list
#Calculate total workers
def tot_workers(data_list:list) ->int:
total_workers = 0
for project in data_list:
total_workers += int(project[4])
return total_workers
# show Project Statistics
def project_statistics(data_list:list,available_workers:int) ->list:
print(" XYZ COMPANY ".center(100))
print(" Project Statistics ".center(100))
print("Number of ongoing projects - ", num_of_ongoing_projects(data_list))
print("Number of completed projects - ",num_of_com_projects(data_list))
print("Number of on hold projects - ",num_of_on_hold_projects(data_list))
print("Number of available workers to assign - ", available_workers)
while True:
user_input = input("Do you want to add the project (Yes/No)? ")
if user_input.lower() == "yes":
return add_new_project(data_list)
elif user_input.lower() == "no":
return data_list
else:
print("Invalid input.Try again.")
continue
#Remove a completed project from existing projects
def remove_com_pro(data_list:list) ->list:
if data_list == []:
print("Data list is empty.")
return data_list
else:
while True:
project_code = input("Project Code - ")
for project in data_list:
if project_code == project[0]:
while True:
user_input = input("Do you want to remove the project (Yes/No)? ")
if user_input.lower() == "yes":
data_list.remove(project)
return data_list
elif user_input.lower() == "no":
return data_list
else:
print("Invalid input.Try again.")
continue
print("Project code is invalid.Re enter the project code.")
continue
#Update details on ongoing project
def update_project(data_list:list) ->list:
if data_list == []:
print("Data list is empty.")
return data_list
else:
while True:
project_code = input("Project Code - ")
if project_code == "0":
return data_list
for project in data_list:
if project_code == project[0]:
clients_name = input("Clients name - ")
start_date = input("Start date - ")
enter_expected_date = input("Expected end date - ")
num_of_workers = input("Number of workers - ")
while True:
project_status = input("Project status - ")
if project_status.lower() == "ongoing" or project_status.lower() == "on hold" or project_status.lower() == "completed":
break
else:
print("Invalid input.Try again.")
continue
while True:
user_input = input("Do you want to update the project details (Yes/No)? ")
if user_input.lower() == "yes":
project[1] = clients_name
project[2] = start_date
project[3] = enter_expected_date
project[4] = num_of_workers
project[5] = project_status
return data_list
elif user_input.lower() == "no":
return data_list
else:
print("Invalid input.Try again.")
continue
print("Project code is invalid.Re enter the project code.")
continue
#Add new workers to available workers group
def add_new_workers(a_workers:int) -> int:
while True:
try:
num_workers_add = int(input("number of workers to add - "))
break
except ValueError:
print("Invalid input.Enter the valid input(Integer Value).")
continue
while True:
user_input = input("Do you want to add (Yes/No)? ")
if user_input.lower() == "yes":
a_workers += num_workers_add
return a_workers
elif user_input.lower() == "no":
return a_workers
else:
print("Invalid input.Try again.")
continue
# calculate additionaly added workers
def cal_add_add_workers(data_list:list,available_workers:int) ->int:
if data_list == []:
return available_workers
else:
return available_workers - tot_workers(data_list)
# Calculate available workers
def cal_avail_workers(data_list:list,additionaly_added_workers:int) ->int:
if data_list == []:
return additionaly_added_workers
else:
return additionaly_added_workers + tot_workers(data_list)
#calculate Number of ongoing projects
def num_of_ongoing_projects(data_list:list) ->int:
num = 0
if data_list == []:
return 0
else:
for project in data_list:
if project[5] == "ongoing":
num += 1
return num
#calculate Number of completed projects
def num_of_com_projects(data_list:list) ->int:
num = 0
if data_list == []:
return 0
else:
for project in data_list:
if project[5] == "completed":
num += 1
return num
#calculate Number of on hold projects
def num_of_on_hold_projects(data_list:list) ->int:
num = 0
if data_list == []:
return 0
else:
for project in data_list:
if project[5] == "on hold":
num += 1
return num
#collect store data for using this program
data,available_workers = read_data()
additionaly_added_workers = cal_add_add_workers(data,available_workers)
#Loop the program
while True:
display_menu()
try:
user_choice = int(input("Your Choice: ".rjust(90)))
except ValueError:
print("Invalid input.Try again.")
continue
delete_data()
if user_choice == 1:
data = add_new_project(data)
elif user_choice == 2:
data = remove_com_pro(data)
elif user_choice == 3:
additionaly_added_workers = add_new_workers(additionaly_added_workers)
elif user_choice == 4:
data = update_project(data)
elif user_choice == 5:
available_workers = cal_avail_workers(data,additionaly_added_workers)
data = project_statistics(data,available_workers)
elif user_choice == 6:
available_workers = cal_avail_workers(data,additionaly_added_workers)
save_data(data,available_workers)
break
else:
print("Invalid input.Try again.")
continue