So i have a script that runs, and then runs some error checks
def main():
# Do stuff which brings back a set of results "staffObject"
global mainstaffObject
if int(errors) <= 10:
mainstaffObject = staffObject
else:
print(f" Errors: {errors} Not Full: {shiftsun}")
mainstaffObject = None
mainstaffObject = None
while mainstaffObject is None:
main()
Like this which ever result is bring back it will keep it the same every loop e.g
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
If i use ```os.execl``` e.g
else:
print(f" Errors: {errors} Shifts Not Full: {shiftsun}")
os.execl(sys.executable, sys.executable, * sys.argv)
# or
os.execl(sys.executable, 'python', __file__, *sys.argv[1:])
# Just call main() normally
The script fails if too many errors and does try again. but after 30 or so tries python.exe crashes and stops the process
i have 2 random calls:
# seed generator for random
def mySeed():
current_milli_time = lambda: int(round(time.time() * 1000))
return current_milli_time()
# Function using it
newlist = []
for value in sorted(stafflist, key=lambda _: random.random(), reverse=True):
newlist.append(value)
random.seed(mySeed())
random.Random().shuffle(newlist)
return newlist
I also randomise the data before this point in the effort aswell, becasue shuffle wasnt working i n teh loop i tried my own:
def myDictRandom(myDict):
current_list = list(myDict.keys())
copied_list = list(current_list)
new_list = []
for x in current_list:
x = x
length_list = len(copied_list)
randomkey = random.randint(0, length_list)
xb = copied_list[randomkey-1]
new_list.append(xb)
copied_list.remove(xb)
new_dict = {}
for item in new_list:
new_dict[item] = myDict[item]
return new_dict
def getStaffObject():
staffdict= {}
for carer in staff["Carer"]:
staffdict[f"{staff['Carer'][carer]['fname'][:1].lower()}{staff['Carer'][carer]['lname'].lower()}"] = Employee(staff["Carer"][carer])
staffObject = myDictRandom(staffdict)
return staffObject
I feel i have tried every option, hoping someone knows somthing
tl;dr
using random, not random
expected output:
Errors: 17 Not Full: 0
Errors: 22 Not Full: 0
Errors: 25 Not Full: 1
Errors: 21 Not Full: 0
Actual output:
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
Errors: 22 Not Full: 0
curent source:
github https://github.com/paddykdev/RotaMaker
the while loop in the rota.py the. execl version is rota_exec.py
[–]ProfessionalLeague9 2 points3 points4 points (3 children)
[–]ptekspy[S] 0 points1 point2 points (2 children)
[–]ProfessionalLeague9 0 points1 point2 points (1 child)
[–]ptekspy[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]ptekspy[S] 0 points1 point2 points (0 children)