def main(): """ :return: """ running = True print(copyr) jasons = [] for root, dirs, files in os.walk("."): path = root.split(os.sep) for file in files: if file.endswith(".json"): temp = os.path.join(root, file) jasons.append(temp) pickPattern = re.compile(r"(\d+|none)(?=\s*)") print("#########################################") for ndx in range(len(jasons)): # if runningTests[key]._status not in (1, 3): # continue print( "#############Use {} to link to###########\n{}\n#########################################" .format(ndx, jasons[ndx])) runningTests = {} runningTestNum = 0 while True: temp = pickPattern.search( input( "Use the link number to load that file. Use 'None' to start from scratch: " )) while not temp: temp = pickPattern.search( input( "Use the link number to report result for that. Use 'None' to start from scratch: " )) if temp.group(0) == "none": print("Loading...") Objects.cases = [1, 2] organ = Objects.BatchTestingOrganizer() break elif int(temp.group(0)) >= len(jasons): print("{} did not appear to be in the the active tests.".format( int(temp.group(0)))) continue else: print("Loading...") filename = jasons[int(temp.group(0))] data = open(filename, 'rb') restore = json.load(data) data.close() organ = Objects.BatchTestingOrganizer(restore=restore) for item in organ.individualStore._testing: runningTests[runningTestNum] = organ.individualStore._testing[ item] runningTestNum += 1 for item in organ.batchStore._testing: runningTests[runningTestNum] = organ.batchStore._testing[item] runningTestNum += 1 break #cases with positives first then totoal pop our null is 50/50 #and becomes negligable after we have a lot of samples copyrightPattern = re.compile(r"(show c)\s*") warrantyPattern = re.compile(r"(show w)\s*") exitPattern = re.compile(r"(exit|quit)\s*") #exit command propPattern = re.compile( r"(?<=prop:)\s*\d*\.\d+\s*") #find batch size based on proportion addPattern = re.compile( r"(?<=add pop:)\s*\d+\s+\d+\s*" ) #add cases to population with positives first then negatives newCasePattern = re.compile( r"(?<=add patient)\s*" ) #add cases to population with positives first then negatives popPattern = re.compile(r"population\s*") batchPattern = re.compile(r"batch size\s*") resultsPattern = re.compile(r"(?<=test results)\s*") nextTestPattern = re.compile(r"get next(?=\s*)") posNegPattern = re.compile(r"(\+|-)(?=\s*)") digitPattern = re.compile(r"(\d+|oops)(?=\s*)") savePattern = re.compile(r"(save)(?=\s*)") clearPattern = re.compile(r"(clear)(?=\s*)") print("Loading Done") while running: try: action = input("what action should we take? ") #print(action) if exitPattern.search(action.lower()): #print("Shutting down program...") filename = ".\SavedStates\BatchOrganizer_Date_{}.json".format( datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) saved = organ.shutdown() with open(filename, 'w+') as f: json.dump(saved, f, indent=4) print("Save successful in {}".format(filename)) running = False break if propPattern.search(action.lower()): number = propPattern.search(action.lower()).group(0) number = float(number) batchSizeOptimizer( number ) #just run for the print probably will fix this later continue if addPattern.search(action.lower()): #print(addPattern.search(action.lower())) numbers = addPattern.search(action.lower()).group(0) pos, neg = [int(x) for x in numbers.split()] Objects.cases[0] += pos Objects.cases[1] += neg + pos batchSizeOptimizer((Objects.cases[0] / Objects.cases[1])) continue if popPattern.search(action.lower()): print( "Positive cases: \t{}\nTotal tests:\t\t{}\nPositive percentage: \t{:.4f}%" .format(Objects.cases[0], Objects.cases[1], 100. * Objects.cases[0] / Objects.cases[1])) continue if batchPattern.search(action.lower()): batchSizeOptimizer((Objects.cases[0] / Objects.cases[1])) continue if newCasePattern.search(action.lower()): organ.newID(input("Enter new Accession Number: ")) continue if resultsPattern.search(action.lower()): print("#########################################") for key in runningTests: #if runningTests[key]._status not in (1, 3): #continue print( "Use {} to link to\n{}\n#########################################" .format(key, runningTests[key])) temp = digitPattern.search( input( "Use the link number to report result for that. Use 'oops' to go back: " )) while not temp: temp = digitPattern.search( input( "Use the link number to report result for that. Use 'oops' to go back: " )) if temp.group(0) == "oops": continue if int(temp.group(0)) not in runningTests: print("{} did not appear to be in the the active tests.". format(int(temp.group(0)))) tested = runningTests.pop(int(temp.group(0))) result = "" while not result: a = input("result (+ or -): ") if posNegPattern.search(a): result = posNegPattern.search(a).group(0) result = (result == "+") organ.results(tested, result) continue if nextTestPattern.search(action.lower()): next = organ.getNextTest() if next: runningTests[runningTestNum] = next runningTestNum += 1 continue if warrantyPattern.search(action.lower()): print(warranty) continue if copyrightPattern.search(action.lower()): print( "Tell 'em Thomas sent ya' and that he expect that ya'll won't keep him waitin' next time.\n" "also any redistribution must contain the all copyright information." ) continue if savePattern.search(action.lower()): #print("Saving program state...") filename = ".\SavedStates\BatchOrganizer_Date_{}.json".format( datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) saved = organ.saveAndRun() with open(filename, 'w+') as f: json.dump(saved, f, indent=4) print("Save successful in {}".format(filename)) continue if clearPattern.search(action.lower()): clearScreen() continue except Exception as e: print("Unexpected error:", repr(e)) continue print("Thank you, good bye.")