-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDADSA1 Assessment 1 Task 3.py
671 lines (573 loc) · 31.4 KB
/
DADSA1 Assessment 1 Task 3.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# -*- coding: utf-8 -*-
"""
DADSA Assignment one TASK 3
Created on Wed Dec 30 18:41:50 2020 NEW VERSION
@author: benjamin Ell-Jones
"""
import csv
#Class to store Shop data
class Item:
def __init__(self, itemName, itemPrice,itemStores):
self.itemNumber = 0 # stores item number
self.itemName = itemName# stores item name
self.itemPrice = itemPrice # stores item price
self.itemStores = itemStores# stores the shops that item can be bought from
def getItemNumber(self):
return self.itemNumber
def getItemName(self):
return self.itemName
def getItemPrice(self):
return self.itemPrice
def getItemStores(self):
return self.itemStores
def setItemNumber(self, itemNumber):
self.itemNumber = itemNumber
#Class to store shopping list data
class ShoppingLists:
def __init__(self,houseName,week, itemList):
self.houseName = houseName # stores house name
self.itemList = itemList # stores items shopping list
self.minimalCombinations = [] # stores the shops the house needs to visit to forfill order
self.week = week# stores what week this houses is in
self.needToBuyShopA = []# stores what items this house needs from shop A
self.needToBuyShopAQuantities = []# stores what quantity of items this house needs from shop A
self.needToBuyShopB = []# stores what items this house needs from shop B
self.needToBuyShopBQuantities = []# stores what quantity of items this house needs from shop B
self.needToBuyShopC = []# stores what items this house needs from shop C
self.needToBuyShopCQuantities = []# stores what quantity of items this house needs from shop C
self.needToBuyShopD = []# stores what items this house needs from shop D CHEAP STORE
self.needToBuyShopDQuantities = []# stores what quantity of items this house needs from shop D CHEAP STORE
self.ammountShopsSceduled = 0# stores the ammount of shops that this house requires
self.addedToDelivery = False# keeps track of if the house has been added to the delivery schedule
def getHouseName(self):
return self.houseName
def getItemList(self):
return self.itemList
def getWeek(self):
return self.week
def getMinimalCombinations(self):
return self.minimalCombinations
def getAmmountShopsSceduled(self):
return self.ammountShopsSceduled
def addAmmountShopsSceduled(self, ammount):
self.ammountShopsSceduled = self.ammountShopsSceduled + ammount
def getAddedToDelivery(self):
return self.addedToDelivery
def addAddedToDelivery(self, addedToDelivery):
self.addedToDelivery = addedToDelivery
def getNeedToBuyShopAQuantities(self):
return self.needToBuyShopAQuantities
def getNeedToBuyShopBQuantities(self):
return self.needToBuyShopBQuantities
def getNeedToBuyShopCQuantities(self):
return self.needToBuyShopCQuantities
def getNeedToBuyShopDQuantities(self):
return self.needToBuyShopDQuantities
def getNeedToBuyShopA(self):
return self.needToBuyShopA
def getNeedToBuyShopB(self):
return self.needToBuyShopB
def getNeedToBuyShopC(self):
return self.needToBuyShopC
def getNeedToBuyShopD(self):
return self.needToBuyShopD
def setItemList(self, itemList):
self.itemList.append(itemList)
def setStoreCombinations(self, storeCombinations):
self.minimalCombinations = storeCombinations
def setNeedToBuyShopA(self, needToBuyShopA):
self.needToBuyShopA.append(needToBuyShopA)
def setNeedToBuyShopB(self, needToBuyShopB):
self.needToBuyShopB.append(needToBuyShopB)
def setNeedToBuyShopC(self, needToBuyShopC):
self.needToBuyShopC.append(needToBuyShopC)
def setNeedToBuyShopD(self, needToBuyShopD):
self.needToBuyShopD.append(needToBuyShopD)
def replaceNeedToBuyShopA(self, needToBuyShopA):
self.needToBuyShopA = needToBuyShopA
def replaceNeedToBuyShopB(self, needToBuyShopB):
self.needToBuyShopB = needToBuyShopB
def replaceNeedToBuyShopC(self, needToBuyShopC):
self.needToBuyShopC = needToBuyShopC
def replaceNeedToBuyShopD(self, needToBuyShopD):
self.needToBuyShopD = needToBuyShopD
def setNeedToBuyShopAQuantities(self, needToBuyShopAQuantities):
self.needToBuyShopAQuantities.append(needToBuyShopAQuantities)
def setNeedToBuyShopBQuantities(self, needToBuyShopBQuantities):
self.needToBuyShopBQuantities.append(needToBuyShopBQuantities)
def setNeedToBuyShopCQuantities(self, needToBuyShopCQuantities):
self.needToBuyShopCQuantities.append(needToBuyShopCQuantities)
def setNeedToBuyShopDQuantities(self, needToBuyShopDQuantities):
self.needToBuyShopDQuantities.append(needToBuyShopDQuantities)
def replaceMinimalCombinations(self, minimalCombinations):
self.minimalCombinations = minimalCombinations
def replaceNeedToBuyShopAQuantities(self, needToBuyShopAQuantities):
self.needToBuyShopAQuantities = needToBuyShopAQuantities
def replaceNeedToBuyShopBQuantities(self, needToBuyShopBQuantities):
self.needToBuyShopBQuantities = needToBuyShopBQuantities
def replaceNeedToBuyShopCQuantities(self, needToBuyShopCQuantities):
self.needToBuyShopCQuantities = needToBuyShopCQuantities
def replaceNeedToBuyShopDQuantities(self, needToBuyShopDQuantities):
self.needToBuyShopDQuantities = needToBuyShopDQuantities
class Catagories:
def __init__(self,catagoryName ,itemList):
self.catagoryName = catagoryName# catagory name
self.itemList = itemList# Items in catagory
def getCatagoryName(self):
return self.catagoryName
def getItemList(self):
return self.itemList
def setCatagoryName(self, catagoryName):
self.catagoryName = catagoryName
def setItemList(self, itemList):
self.itemList = itemList
class Delivery():
def __init__(self, day, week):
self.day = day# stores day
self.week = week# stores week
self.deliverySchedule = []# houses that will need to be deliverd to on this particular day in week
def getDayDelivery(self):
return self.day
def getWeekDelivery(self):
return self.week
def getdeliverySchedule(self):
return self.deliverySchedule
def setDayDelivery(self, day):
self.day = day
def setDeliverySchedule(self, deliverySchedule):
self.deliverySchedule.append(deliverySchedule)
class ShoppingSchedule():
def __init__(self,day,week):
self.day = day # stores day
self.week = week # stores week
self.ShopToBuyFrom = "" # stores the shop that this day will be used to buy from
self.ShoppingToBuy = [] # this stores the shopping that needs to be bought on this day
self.ShoppingQuantities = []# this stores the shopping quantitys that needs to be bought on this day
def getDayShoppingSchedule(self):
return self.day
def getWeekShoppingSchedule(self):
return self.week
def getShopToBuyFrom(self):
return self.ShopToBuyFrom
def getShopingToBuy(self):
return self.ShoppingToBuy
def getShoppingQuantities(self):
return self.ShoppingQuantities
def setDayShoppingSchedule(self, day):
self.day = day
def setShopToBuyFrom(self, ShopToBuyFrom):
self.ShopToBuyFrom = ShopToBuyFrom
def setShopingToBuy(self, ShoppingToBuy):
self.ShoppingToBuy.append(ShoppingToBuy)
def setShoppingQuantities(self, ShoppingQuantities):
self.ShoppingQuantities.append(ShoppingQuantities)
shopObjects = [] # Stores a list of shop objects
houseObjects = [] # stores a list of shopping list objects
catagoryObjects = [] # stores a list of catagory objects
shoppingScheduleObjects = []# stores shopping schedule objects (days)
deliveryObjects = []# stores delivery schedule objects (days)
countHouseNamesWeeks = [] # Stores a list of house names obtained by running inputCSVHouseNames() the result of that function is stored in here
#gets all shops and item data
def inputCSVShopList():
with open('DATA CWK SHOPPING DATA WEEK 7 FILE A.csv', 'r') as csv_file1:
csv_reader1 = csv.reader(csv_file1)
next(csv_reader1)
for row1 in csv_reader1:
itemNumber = 0
shopList = []
itemNumber = itemNumber + 1
tempShopStorageA = row1[3]
tempShopStorageB = row1[4]
tempShopStorageC = row1[5]
tempShopStorageD = row1[6]
if(tempShopStorageA == 'Y'):
shopList.append(tempShopStorageA)
elif(tempShopStorageA == ''):
shopList.append('N')
else:
print("Error StoreA Input")
if(tempShopStorageB == 'Y'):
shopList.append(tempShopStorageB)
elif(tempShopStorageB == ''):
shopList.append('N')
else:
print("Error StoreB Input")
if(tempShopStorageC == 'Y'):
shopList.append(tempShopStorageC)
elif(tempShopStorageC == ''):
shopList.append('N')
else:
print("Error StoreC Input")
if(tempShopStorageD == 'Y'):
shopList.append(tempShopStorageD)
elif(tempShopStorageD == ''):
shopList.append('N')
else:
print("Error StoreD Input")
shopObjects.append(Item(row1[1],row1[2],shopList))
# Gets each house holds name
def inputCSVHouseNames():
with open('DATA CWK SHOPPING DATA WEEK 7 FILE B.csv', 'r') as csv_file2:
csv_reader2 = csv.reader(csv_file2)
gotFirstLine = False # if set true python has obtained the first line from the csv file
output = [] # Stores the output of this func to be returned
for line2 in csv_reader2:
if (gotFirstLine == False): # if the first line of the csv file has not been obtained do:
countColumn = []
countInrange = 0
for i in range(0,31): # for each column
countInrange = countInrange + 1
countColumn.append(line2[countInrange]) # Add obtained data from field in csv file to a tempary storage array
output = countColumn # store contence in output
gotFirstLine = True # One the first line from csv has been obtained set to true
return output
# Gets each house holds shopping list
def inputCSVShoppingList(countHouseNamesWeeks):
count = 1
weekCounter = 1
for i in range(0,31): # for each house name in countHouseNamesWeeks
count = count + 1
tempStorageItemQuantity = []
if (count > 16): # if hits 16 houses sets week counter to week 2
weekCounter = 2 # add week
with open('DATA CWK SHOPPING DATA WEEK 7 FILE B.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # dont include row one of csv
next(csv_reader) # dont include row two of csv
if(count == 32):
break
else:
for line in csv_reader:
tempStorageItemQuantity.append(line[count])# append column to tempStorageItemQuantity
houseObjects.append(ShoppingLists(countHouseNamesWeeks[i],weekCounter, tempStorageItemQuantity)) # create object and add data
#this function splits an items name into a selection of key words, those key words are analised and then the item is catagorised and stored in a list(category)
def categorySort():
print("Category Sort")
itemNumber = -1
splitElementCount = -1
splitItemName = []
categoryTempStoreage = { "Bread" : [], "Milk" : [], "Cheese" : [], "Tomatoes" : [], "Carrots" : [],
"Potatoes" : [], "Rice" : [], "Butter" : [], "Spread" : [],"Eggs" : [],"Apples" : [],"Onions" : [],
"Oranges" : [],"Kiwi" : [], "Kitchen" : [], "Toilet" : [], "Tea" : [], "Coffee" : [],"NoSubstatutes" : []}
categoryTempStoreageKey = ["Bread", "Milk", "Cheese", "Tomatoes", "Carrots",
"Potatoes", "Rice", "Butter", "Spread", "Eggs", "Apples", "Onions",
"Oranges", "Kiwi", "Kitchen", "Toilet", "Tea", "Coffee","NoSubstatutes"]
categoryTempStoreageLower = ["bread", "milk", "cheese", "tomatoes", "carrots",
"potatoes", "rice", "butter", "spread", "eggs", "apples", "onions",
"oranges", "kiwi", "kitchen", "toilet", "tea", "coffee","NoSubstatutes"]
for i in shopObjects: # for each item
itemNumber = itemNumber + 1
itemName = shopObjects[itemNumber].getItemName() # Gets an items name
splitItemName = itemName.split(' ') #Splits the item name into keywords
foundCatagory = False
for x in splitItemName: #For each keyword
splitElementCount = splitElementCount + 1
# This next section of code tries to match one of those key words to a catagory.
#for example if an item has bread as a keyword it's item number will be added to the bread category
catagoryTmpStoreKeyCount = -1
for i in categoryTempStoreageKey:
catagoryTmpStoreKeyCount = catagoryTmpStoreKeyCount + 1
if (splitItemName[splitElementCount] == categoryTempStoreageKey[catagoryTmpStoreKeyCount] or splitItemName[splitElementCount] == categoryTempStoreageLower[catagoryTmpStoreKeyCount]):
#categoryTempStoreage[categoryTempStoreageKey[catagoryTmpStoreKeyCount]].append(itemNumber)
#this next line is for testing
categoryTempStoreage[categoryTempStoreageKey[catagoryTmpStoreKeyCount]].append(shopObjects[itemNumber].getItemName())
foundCatagory = True
if(foundCatagory == False):# If in no catagory put in NoSubstatutes
categoryTempStoreage["NoSubstatutes"].append(shopObjects[itemNumber].getItemName())
splitElementCount = -1
countClassInput = -1
for i in categoryTempStoreageKey:
countClassInput = countClassInput + 1
catagoryObjects.append(Catagories(categoryTempStoreageKey[countClassInput], categoryTempStoreage[categoryTempStoreageKey[countClassInput]]))
#Gives all items in the shopObjects = [] array Item Numbers
def giveItemNumber():
itemNumber = -1
for i in shopObjects:
itemNumber = itemNumber + 1
shopObjects[itemNumber].setItemNumber(itemNumber)
#removes blank spaces in lists and replaces them with 0
# This function does scale
def RemoveBlank(aList):
count = -1
for x in aList: #for each element in array
count = count + 1
if (aList[count] == ''): # if element equals nothing
aList[count] = 0 # replace with 0
return aList
# Implements the RemoveBlank Method
#Personal Note: ellipsis caused here
def replace():
countHouseObjects = -1
tempHouseList = []
for i in houseObjects: # for each object in houseObjects
countHouseObjects = countHouseObjects + 1
tempHouseList = RemoveBlank(houseObjects[countHouseObjects].getItemList()) # remove the blank spots in a list in itemStores(array) in houseObjects and store in temp variable
houseObjects[countHouseObjects].setItemList(tempHouseList) # update list in itemStores(array) in houseObjects using data from tempHouseList variable
tempHouseList = [] # clear the list for the next set of data
# Checks to see what stores a spesific item is in.
def inStore(item):
inShops = ""
tempStoreShopList = shopObjects[item].getItemStores()
if (tempStoreShopList[3] == 'Y'):# if in store D
return "D" # return store that is in I.E store D
elif (tempStoreShopList[0] == 'Y'):
return"A"
elif (tempStoreShopList[1] == 'Y'):
return "B"
elif (tempStoreShopList[2] == 'Y'):
return "C"
else:
print("Error Item not in any stores")
# Will combine output of inStore so, for house A1 you may have A,B,A,A,B,A,B,B,A and this function will reduce it to A,B
def minimumStores(StoreShopChoice): # This function finds out what shops each house hold will need to visit
StoreStoreAmmountA = 0
StoreStoreAmmountB = 0
StoreStoreAmmountC = 0
StoreStoreAmmountD = 0
count = 0
logicalChoice = []
for i in StoreShopChoice: #for each of the shops that have been flag as need to visit
if(StoreShopChoice[count] == 'D'):# if required to go to store D
StoreStoreAmmountD = StoreStoreAmmountD + 1 # ADD one to store D counter
elif(StoreShopChoice[count] == 'A'):
StoreStoreAmmountA = StoreStoreAmmountA + 1
elif(StoreShopChoice[count] == 'B'):
StoreStoreAmmountB = StoreStoreAmmountB + 1
elif(StoreShopChoice[count] == 'C'):
StoreStoreAmmountC = StoreStoreAmmountC + 1
count = count + 1
if(StoreStoreAmmountD >= 1):# if store D counter is greater than one then we definately are required to go to store D
logicalChoice.append('D')# Append store D to minimum stores list
if(StoreStoreAmmountA >= 1):
logicalChoice.append('A')
if(StoreStoreAmmountB >= 1):
logicalChoice.append('B')
if(StoreStoreAmmountC >= 1):
logicalChoice.append('C')
return logicalChoice # return minimum stores list for a given house
#Main Data proccessing function, uses minimumStores and inStore functionss
def proccess():
mainCounter = -1
itemListCounter = -1
tempProccessed = []
combination = []
for i in houseObjects:# for all houses
mainCounter = mainCounter + 1
tempItemListStorage = houseObjects[mainCounter].getItemList() # item required items list
tempItemListStorage.pop()# Pops the strange ellipsis
for i in tempItemListStorage:# for each item
itemListCounter = itemListCounter + 1
if (int(tempItemListStorage[itemListCounter]) > 0): # if need to buy item I.E the quantity is greater than 0
canBeFoundInStore = inStore(itemListCounter) # get the store the item can be bought from
tempProccessed.append(canBeFoundInStore)# append store to list
itemName = shopObjects[itemListCounter].getItemName() # get the items name
if(canBeFoundInStore == "D"): # if it can be found in store D
houseObjects[mainCounter].setNeedToBuyShopD(itemName) # add item to the list if items needed to buy from shop D
houseObjects[mainCounter].setNeedToBuyShopDQuantities(tempItemListStorage[itemListCounter])# add quantity to the list if items needed to buy from shop D
# each of these if statements is the same as for shop D but obviously appends to there diffrent respective item lists
elif (canBeFoundInStore == "A"):
houseObjects[mainCounter].setNeedToBuyShopA(itemName)
houseObjects[mainCounter].setNeedToBuyShopAQuantities(tempItemListStorage[itemListCounter])
elif(canBeFoundInStore == "B"):
houseObjects[mainCounter].setNeedToBuyShopB(itemName)
houseObjects[mainCounter].setNeedToBuyShopBQuantities(tempItemListStorage[itemListCounter])
elif(canBeFoundInStore == "C"):
houseObjects[mainCounter].setNeedToBuyShopC(itemName)
houseObjects[mainCounter].setNeedToBuyShopCQuantities(tempItemListStorage[itemListCounter])
else:
print("Error 1: in proccess")
combination = minimumStores(tempProccessed)# find minimum combination
houseObjects[mainCounter].setStoreCombinations(combination)# set a houses minimum store combinations
tempProccessed = []# reset list
itemListCounter = -1
combination = []
#This function finds out if a houses minimum combination is already in combinations.
def matchCombinations(combinations, minimumCombos):
combinationCount = -1
for n in combinations:# for all combinations
combinationCount = combinationCount + 1
combinationShopCount = -1
match = 0
for x in combinations[combinationCount]:# for each shop in combination
combinationShopCount = combinationShopCount + 1
if (len(combinations[combinationCount]) > len(minimumCombos) or len(combinations[combinationCount]) < len(minimumCombos)):# if the size of the two lists dont match skip to next itteration
continue
minimumCombosCount = -1
for z in minimumCombos:
minimumCombosCount = minimumCombosCount + 1
if (minimumCombos[minimumCombosCount] == combinations[combinationCount][combinationShopCount]):# if a shop is in both minimum combination and combination
match = match + 1 # increment how many matches there have been
if(match == len(combinations[combinationCount])):# if both shops match
return True # return true
return False # if it goes through all combinations and does not find a match return false
#finds shops that will need to be visited by all houses
def commonShopCombinations(getWeek):
shoppingCountWeekOne = -1
combinations = []
for i in houseObjects:# for all houses
shoppingCountWeekOne = shoppingCountWeekOne + 1
if (houseObjects[shoppingCountWeekOne].getWeek() == getWeek):
minimumCombos = houseObjects[shoppingCountWeekOne].getMinimalCombinations()# get minimum combinations
if(len(combinations) == 0):# if there are no shopping combinations in combination list
combinations.append(minimumCombos)# add first combination
else:
matchCondition = False
matchCondition = matchCombinations(combinations, minimumCombos)# find a match
if(matchCondition == True):# the moment it finds a match end iterate the loop by 1
continue
if(matchCondition == False):# if it never finds a match add to combinations
combinations.append(minimumCombos)
continue
return combinations
#Adds days to scedule/Generates raw schedule with no deliverys or shopping trips
def addDays():
dayCount = 0
weekCount = 1
for i in range(0,8):
dayCount = dayCount + 1
if(dayCount == 5):
dayCount = 1
weekCount = weekCount + 1
shoppingScheduleObjects.append(ShoppingSchedule(dayCount,weekCount))#Adds days
deliveryObjects.append(Delivery(dayCount,weekCount))#Adds days
# adds shops to the shopping scedule
def shoppingSceduleAddShops(week, combinations):
biggestLen = 0
listOfShops = []
currentComboCount = -1
#this for loop finds the biggest combination of all the given combinations
for i in combinations:
currentComboCount = currentComboCount + 1
if (biggestLen == 0):
biggestLen = len(combinations[currentComboCount])
listOfShops = combinations[currentComboCount]
elif(biggestLen < len(combinations[currentComboCount])):
biggestLen = len(combinations[currentComboCount])
listOfShops = combinations[currentComboCount]
#this loop adds the shops to the shopping schedule
listOfshopCount = -1
for z in listOfShops: # for each shop
listOfshopCount = listOfshopCount + 1
shoppingScheduleCount = -1
for b in shoppingScheduleObjects:# for each day in shopping list
shoppingScheduleCount = shoppingScheduleCount + 1
if(shoppingScheduleObjects[shoppingScheduleCount].getWeekShoppingSchedule() == week):# only append to the shopping list in the week spesified
if(shoppingScheduleObjects[shoppingScheduleCount].getShopToBuyFrom() == ""):# if the shop to buy field is blank then
shoppingScheduleObjects[shoppingScheduleCount].setShopToBuyFrom(listOfShops[listOfshopCount])#set Shop
break
# pulls shopping list from specified shop for a given house
def getShoppingFromShop(shop, houseCount):
if (shop == "A"):
return houseObjects[houseCount].getNeedToBuyShopA()
elif (shop == "B"):
return houseObjects[houseCount].getNeedToBuyShopB()
elif (shop == "C"):
return houseObjects[houseCount].getNeedToBuyShopC()
elif (shop == "D"):
return houseObjects[houseCount].getNeedToBuyShopD()
else:
print("Error no shop selected in 'getShoppingFromShop' function")
# pulls shopping list (Quantities) from specified shop for a given house
def getShoppingFromShopQuantities(shop, houseCount):
if (shop == "A"):
return houseObjects[houseCount].getNeedToBuyShopAQuantities()
elif (shop == "B"):
return houseObjects[houseCount].getNeedToBuyShopBQuantities()
elif (shop == "C"):
return houseObjects[houseCount].getNeedToBuyShopCQuantities()
elif (shop == "D"):
return houseObjects[houseCount].getNeedToBuyShopDQuantities()
else:
print("Error no shop selected in 'getShoppingFromShop' function")
#creates shopping list using all data gathered
def shoppingSceduleShoppingSort(week):
houseObjectsCount = -1
for i in houseObjects:# for each house
houseObjectsCount = houseObjectsCount + 1
shoppingScheduleObjectsCount = -1
if (houseObjects[houseObjectsCount].getWeek() == week):# if the house is in the week spesified
for x in shoppingScheduleObjects:# for each day in shopping scedule
shoppingScheduleObjectsCount = shoppingScheduleObjectsCount + 1
if (shoppingScheduleObjects[shoppingScheduleObjectsCount].getWeekShoppingSchedule() == week):# if shoppng scedule day is in the week spesified
minimumComboCount = -1
for i in houseObjects[houseObjectsCount].getMinimalCombinations():
minimumComboCount = minimumComboCount + 1
# (code bellow this) if shop required for each house match the shopping schedule shop then add both the items and item quantity to it
if (houseObjects[houseObjectsCount].getMinimalCombinations()[minimumComboCount] == shoppingScheduleObjects[shoppingScheduleObjectsCount].getShopToBuyFrom()):
shoppingScheduleObjects[shoppingScheduleObjectsCount].setShopingToBuy(getShoppingFromShop(houseObjects[houseObjectsCount].getMinimalCombinations()[minimumComboCount], houseObjectsCount))
shoppingScheduleObjects[shoppingScheduleObjectsCount].setShoppingQuantities(getShoppingFromShopQuantities(houseObjects[houseObjectsCount].getMinimalCombinations()[minimumComboCount], houseObjectsCount))
houseObjects[houseObjectsCount].addAmmountShopsSceduled(1)#increment every time a shop is added to delivery scedule
#if the length of the variable in the class houseObjects is equal to the length of the mimimum combinations for that house and house has not yet been added to the delivery scedule
if (houseObjects[houseObjectsCount].getAmmountShopsSceduled() == len(houseObjects[houseObjectsCount].getMinimalCombinations()) and houseObjects[houseObjectsCount].getAddedToDelivery() == False):
houseObjects[houseObjectsCount].addAddedToDelivery(True)# set to true to indicate it has been added to the delivery scedule
deliveryObjects[shoppingScheduleObjectsCount].setDeliverySchedule(houseObjects[houseObjectsCount].getHouseName())# add house to delivery scedule
#outputs Shopping scedule
def outputScedule():
shoppingSceduleCount = -1
print("Shopping Scedule")
for i in shoppingScheduleObjects:
shoppingSceduleCount = shoppingSceduleCount + 1
shopToBuyFrom = shoppingScheduleObjects[shoppingSceduleCount].getShopToBuyFrom()
if(shopToBuyFrom != ""):
print("===============================================")
print("Week: " + str(shoppingScheduleObjects[shoppingSceduleCount].getWeekShoppingSchedule()))
print("Day " + str(shoppingScheduleObjects[shoppingSceduleCount].getDayShoppingSchedule()))
print("Shop to buy from: " + shopToBuyFrom)
print("Items to buy: ")
shopping = []
shoppingAmmount = []
shopping = shopping + shoppingScheduleObjects[shoppingSceduleCount].getShopingToBuy()
shoppingAmmount = shoppingAmmount + shoppingScheduleObjects[shoppingSceduleCount].getShoppingQuantities()
shoppingCount = -1
for i in shopping:
shoppingCount = shoppingCount + 1
print("Item: " + str(shopping[shoppingCount]))
print("Ammount: " + str(shoppingAmmount[shoppingCount]))
print(" ")
print(" ")
print("===============================================")
input("Press enter for shopping day next: ")
print(" ")
#outputs delivery schedule
def outputDelivery():
deliveryObjectsCount = -1
print("Delivery Scedule")
for i in deliveryObjects:
deliveryObjectsCount = deliveryObjectsCount + 1
houseToDeliverTo = deliveryObjects[deliveryObjectsCount].getdeliverySchedule()
if (len(houseToDeliverTo) > 0):
print("===============================================")
print("Week: " + str(deliveryObjects[deliveryObjectsCount].getWeekDelivery()))
print("Day " + str(deliveryObjects[deliveryObjectsCount].getDayDelivery()))
print("Houses to deliver to: ")
print(houseToDeliverTo)
print("===============================================")
input("Press enter for next delivery day: ")
print(" ")
#runs all other functions
def main():
print("DADSA Assignment one TASK 3") #Prints project title
print(" ")
# ==================== this section of function calls handles data intake and sorting ===================================
inputCSVShopList()
countHouseNamesWeeks = inputCSVHouseNames()
countHouseNamesWeeks.pop(0)# removes ellipsis
inputCSVShoppingList(countHouseNamesWeeks)
categorySort()
giveItemNumber()
replace()
proccess()
#===========================Section End============================
# ===================this next section of function calls deals with schedule creation =======================
addDays()
shoppingSceduleAddShops(1,commonShopCombinations(1))# run for week 1
shoppingSceduleAddShops(2,commonShopCombinations(2))# run for week 2
shoppingSceduleShoppingSort(1)# run for week 1
shoppingSceduleShoppingSort(2)# run for week 2
#==============Section End===================
#================= outputs results ======================
outputScedule()
outputDelivery()
#==============Section End================
input("Press enter to close program ")
main()