diff --git a/GUIS/straw/C02/CO2GUI.py b/GUIS/straw/C02/CO2GUI.py index ca592794..2abb7b3b 100644 --- a/GUIS/straw/C02/CO2GUI.py +++ b/GUIS/straw/C02/CO2GUI.py @@ -6,10 +6,10 @@ import pyautogui import time -import datetime import os import csv import sys +from datetime import datetime from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * @@ -22,7 +22,6 @@ # import modules from removeStraw import * -from masterUpload import * from checkstraw import * sys.path.insert( @@ -129,13 +128,11 @@ def saveWorkers(self): previousWorkers = [] activeWorkers = [] exists = os.path.exists( - self.workerDirectory + datetime.datetime.now().strftime("%Y-%m-%d") + ".csv" + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv" ) if exists: with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "r", ) as previous: today = csv.reader(previous) @@ -155,9 +152,7 @@ def saveWorkers(self): if prev != self.justLogOut: activeWorkers.append(prev) with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "a+", ) as workers: if exists: @@ -417,34 +412,6 @@ def saveData(self): QMessageBox.about(self, "Save", "Data saved successfully!") - def uploadData(self): - QMessageBox.about(self, "Upload", "Now attempting data upload.") - - uploadWorker = self.sessionWorkers[0] - uploader = getUploader(self.stationID)("prod") - passed = True - - for straw in self.straws: - if straw != "_______": - try: - uploader.beginUpload( - straw, uploadWorker, self.epoxyBatch, self.palletNum - ) - except UploadFailedError as error: - passed = False - lastMessage = error.message - - if passed: - QMessageBox.about(self, "Upload", "All data uploaded successfully!") - else: - QMessageBox.warning( - self, - "Upload Error", - "Some Uploads Failed\n\n" - + lastMessage - + "\n\nCheck 'errors.txt' for a complete list", - ) - def resetGUI(self): self.palletID = "" self.palletNum = "" diff --git a/GUIS/straw/Laser/LazerGUI.py b/GUIS/straw/Laser/LazerGUI.py index b42a01e1..bc37b10f 100644 --- a/GUIS/straw/Laser/LazerGUI.py +++ b/GUIS/straw/Laser/LazerGUI.py @@ -27,11 +27,11 @@ import csv import sys import threading -import datetime import win32gui import win32con # import pyperclip +from datetime import datetime from pathlib import Path from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -60,7 +60,6 @@ sys.path.insert(0, os.path.dirname(__file__) + "..\\") from removeStraw import * from checkstraw import * -from masterUpload import * ##**GLOBAL VARIABLES**## @@ -304,7 +303,7 @@ def getTempHumid(self): found = False filename = "" for entry in D: - if entry.startswith("464_" + datetime.datetime.now().strftime("%Y-%m-%d")): + if entry.startswith("464_" + datetime.now().strftime("%Y-%m-%d")): filename = entry found = True @@ -363,9 +362,7 @@ def saveDummy(self): time.sleep(1) # print(MAIN_DIR) pyautogui.typewrite( - MAIN_DIR - + "Dummy Files\\" - + datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S") + MAIN_DIR + "Dummy Files\\" + datetime.now().strftime("%Y-%m-%d_%H_%M_%S") ) time.sleep(0.5) pyautogui.press("enter") @@ -666,13 +663,11 @@ def saveWorkers(self): previousWorkers = [] activeWorkers = [] exists = os.path.exists( - self.workerDirectory + datetime.datetime.now().strftime("%Y-%m-%d") + ".csv" + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv" ) if exists: with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "r", ) as previous: today = csv.reader(previous) @@ -692,9 +687,7 @@ def saveWorkers(self): if prev != self.justLogOut: activeWorkers.append(prev) with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "a+", ) as workers: if exists: @@ -764,9 +757,7 @@ def saveData(self): "a", ) as palletWrite: palletWrite.write("\n") - palletWrite.write( - datetime.datetime.now().strftime("%Y-%m-%d_%H:%M") + "," - ) + palletWrite.write(datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") palletWrite.write("lasr,") for straw in self.straws: palletWrite.write(straw) @@ -781,9 +772,7 @@ def saveData(self): "a", ) as palletWrite: palletWrite.write("\n") - palletWrite.write( - datetime.datetime.now().strftime("%Y-%m-%d_%H:%M") + "," - ) + palletWrite.write(datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") palletWrite.write("leng,") for straw in self.straws: palletWrite.write(straw) @@ -797,7 +786,7 @@ def saveData(self): with open(self.laserDirectory + self.palletNum + ".csv", "w+") as file: header = "Timestamp, Pallet ID, Cut Type (0-4) or (2-6), Cut Temperature [C], Cut Humidity, workers ***NEWLINE***: Straw Names (24) ***NEWLINE***: Cut Lengths mm (24) ***NEWLINE***: Comments (optional)***\n" file.write(header) - file.write(datetime.datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") + file.write(datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") file.write(self.palletID + ",") file.write(self.cutType + ",") file.write(self.cutTemperature + ",") @@ -828,42 +817,6 @@ def saveData(self): # self.uploadData() self.resetGUI() - def uploadData(self): - uploadWorker = self.sessionWorkers[0] - - t = datetime.datetime.now() - t.strftime("%Y-%m-%d %H:%M") - - lastMessage = "" - - uploader = getUploader("leng")("prod") - - for index, straw in enumerate(self.straws): - print("trying to upload" + straw) - try: - if straw != "_______": - uploader.beginUpload( - straw, - uploadWorker, - t, - self.cutTemperature, - self.cutHumidity, - self.cutLengths[index], - 0, - self.palletNum, - ) - except UploadFailedError as error: - lastMessage = error.message - - if lastMessage != "": - QMessageBox.warning( - self, - "Upload Error", - "Some Uploads Failed\nOne example error message:\n\n" - + lastMessage - + "\n\nCheck 'errors.txt' for a complete list", - ) - def editPallet(self): rem = removeStraw(self.sessionWorkers) rem.palletDirectory = self.palletDirectory diff --git a/GUIS/straw/Leak/LeakTestGUI.py b/GUIS/straw/Leak/LeakTestGUI.py index 33e83340..4e7e3b5f 100644 --- a/GUIS/straw/Leak/LeakTestGUI.py +++ b/GUIS/straw/Leak/LeakTestGUI.py @@ -48,14 +48,8 @@ 0, str(Path(Path(__file__).resolve().parent.parent.parent.parent / "Data")) ) from workers.credentials.credentials import Credentials - from remove import Ui_DialogBox -# move up one directory -sys.path.insert(0, os.path.dirname(__file__) + "..\\") -from masterUpload import * - - import threading @@ -1437,35 +1431,6 @@ def getCPALS(self): return - def strawUpload(self, chamber): - ROW = int(chamber / 5) - COL = chamber % 5 - - strawname = self.Choosenames[ROW][COL][:7] - # strawname = strawname.upper() - - uploadWorker = self.getWorker() - - leakrate = self.leak_rate[chamber] - uncertainty = self.leak_rate_err[chamber] - currenttime = datetime.datetime.now().strftime("%m-%d-%Y %H:%M:%S") - (_, cpal) = FindCPAL(strawname) - - uploader = getUploader(self.stationID)("prod") - - try: - uploader.beginUpload( - strawname, - uploadWorker, - leakrate, - uncertainty, - currenttime, - chamber, - cpal, - ) - except UploadFailedError as error: - self.FailedUpload.emit(strawname, error.message) - def editPallet(self): if self.checkCredentials(): self.getCPALS() diff --git a/GUIS/straw/Resistance/resistanceGUI.py b/GUIS/straw/Resistance/resistanceGUI.py index 4d1f7ad1..ecc3a1aa 100644 --- a/GUIS/straw/Resistance/resistanceGUI.py +++ b/GUIS/straw/Resistance/resistanceGUI.py @@ -52,7 +52,6 @@ sys.path.insert(0, os.path.dirname(__file__) + "..\\") # import modules -from masterUpload import * from removeStraw import * sys.path.insert( @@ -871,46 +870,6 @@ def save(self): QMessageBox.about(self, "Save", "Data saved successfully!") - def uploadData(self): - QMessageBox.about(self, "Upload", "Now attempting data upload.") - - temp, humid = self.getTempHumid() - # temp, humid = 0, 0 - uploadWorker = self.sessionWorkers[0] - uploader = getUploader(self.stationID)("prod") - passed = True - - for straw_index, straw in enumerate(self.strawIDs): - if straw == None: - continue # Don't execute the code below - for measure_index in range(4): - try: - uploader.beginUpload( - straw, - uploadWorker, - temp, - humid, - self.measurements[straw_index][measure_index], - self.meas_type_labels_apprev[measure_index], - straw_index + 1, - self.palletNumber, - ) - - except UploadFailedError as error: - passed = False - last_message = error.message - - if passed: - QMessageBox.about(self, "Upload", "All data uploaded successfully!") - else: - QMessageBox.warning( - self, - "Upload Error", - "Some Uploads Failed\n\n" - + last_message - + "\n\nCheck 'errors.txt' for a complete list", - ) - def saveReset(self): if self.measureByHand_counter < 2: message = "There are some failed measurements. Would you like to try measuring by hand?" diff --git a/GUIS/straw/Silver Epoxy/SilverGUI.py b/GUIS/straw/Silver Epoxy/SilverGUI.py index 842ac71b..c0ae4cf6 100644 --- a/GUIS/straw/Silver Epoxy/SilverGUI.py +++ b/GUIS/straw/Silver Epoxy/SilverGUI.py @@ -9,8 +9,8 @@ import os import csv import sys -import datetime import threading +from datetime import datetime from pathlib import Path from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -26,7 +26,6 @@ from remove import Ui_Dialogw from removeStraw import * -from masterUpload import * from checkstraw import * sys.path.insert( @@ -129,13 +128,11 @@ def saveWorkers(self): previousWorkers = [] activeWorkers = [] exists = os.path.exists( - self.workerDirectory + datetime.datetime.now().strftime("%Y-%m-%d") + ".csv" + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv" ) if exists: with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "r", ) as previous: today = csv.reader(previous) @@ -155,9 +152,7 @@ def saveWorkers(self): if prev != self.justLogOut: activeWorkers.append(prev) with open( - self.workerDirectory - + datetime.datetime.now().strftime("%Y-%m-%d") - + ".csv", + self.workerDirectory + datetime.now().strftime("%Y-%m-%d") + ".csv", "a+", ) as workers: if exists: @@ -233,7 +228,7 @@ def initialData(self): or not int(self.epoxyBatch[3:5]) in range(1, 13) or not int(self.epoxyBatch[5:7]) in range(1, 32) or not int(self.epoxyBatch[7:9]) - in range(17, (datetime.datetime.now().year - 2000) + 1) + in range(17, (datetime.now().year - 2000) + 1) or not self.epoxyBatch[-2:].isnumeric() ): valid[2] = False @@ -330,9 +325,7 @@ def saveData(self): "a", ) as palletWrite: palletWrite.write("\n") - palletWrite.write( - datetime.datetime.now().strftime("%Y-%m-%d_%H:%M") + ",silv," - ) + palletWrite.write(datetime.now().strftime("%Y-%m-%d_%H:%M") + ",silv,") for straw in self.straws: palletWrite.write(straw) @@ -345,7 +338,7 @@ def saveData(self): with open(self.silverDirectory + self.palletNum + ".csv", "w+") as file: header = "Timestamp, Pallet ID, Epoxy Batch #, Endpiece Insertion time (H:M:S), Workers ***NEWLINE***: Comments (optional)\n" file.write(header) - file.write(datetime.datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") + file.write(datetime.now().strftime("%Y-%m-%d_%H:%M") + ",") file.write(self.palletID + "," + self.epoxyBatch + ",") file.write( str(self.ui.hour_disp.intValue()) @@ -406,33 +399,6 @@ def getStraws(self): if entry % 2 == 0: self.straws.append(pallet[row][entry]) - def uploadData(self): - lastMessage = "" - - self.getStraws() - - uploadWorker = self.sessionWorkers[0] - - uploader = getUploader(self.stationID)("prod") - - for straw in self.straws: - if straw != "_______": - try: - uploader.beginUpload( - straw, uploadWorker, self.epoxyBatch, self.palletNum - ) - except UploadFailedError as error: - lastMessage = error.message - - if lastMessage != "": - QMessageBox.warning( - self, - "Upload Error", - "Some Uploads Failed\nOne example error message:\n\n" - + lastMessage - + "\n\nCheck 'errors.txt' for a complete list", - ) - def resetGUI(self): self.palletID = "" self.palletNum = "" diff --git a/GUIS/straw/Verification/makeLeakRateFile.py b/GUIS/straw/Verification/makeLeakRateFile.py index 62c625ec..f641a64b 100644 --- a/GUIS/straw/Verification/makeLeakRateFile.py +++ b/GUIS/straw/Verification/makeLeakRateFile.py @@ -4,15 +4,15 @@ dataList = [] leaktest_result_path = ( os.path.dirname(__file__) - + "/../../../Data/Leak test data/Leak Test Results/Leak Test Results.csv" + + "../../../Data/Leak test data/Leak Test Results/Leak Test Results.csv" ) leaktest_result_old_path = ( os.path.dirname(__file__) - + "/../../../Data/Leak test data/Leak test results old/Leak Test Results.csv" + + "../../../Data/Leak test data/Leak test results old/Leak Test Results.csv" ) leaktest_old_result_old_path = ( os.path.dirname(__file__) - + "/../../../Data/Leak test data/Leak test results old/Old Leak Test Results.csv" + + "../../../Data/Leak test data/Leak test results old/Old Leak Test Results.csv" ) pathlist = [ diff --git a/GUIS/straw/Verification/rejectFind.py b/GUIS/straw/Verification/rejectFind.py index 8f09694f..3ddac366 100644 --- a/GUIS/straw/Verification/rejectFind.py +++ b/GUIS/straw/Verification/rejectFind.py @@ -4,15 +4,18 @@ def main(): strawID = input("\nscan straw id: ") usable = open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\StorageRejected_Usable.csv", + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Straw storage\\StorageRejected_Usable.csv", "r", ) recut = open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\StorageRejected_Recut.csv", + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Straw storage\\StorageRejected_Recut.csv", "r", ) practice = open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\StorageRejected_Practice.csv", + os.path.dirname(__file__) + + "..\\..\\Data\\Straw storage\\StorageRejected_Practice.csv", "r", ) diff --git a/GUIS/straw/Verification/sortStorageByData.py b/GUIS/straw/Verification/sortStorageByData.py index e3575f4c..9a1a1fa8 100644 --- a/GUIS/straw/Verification/sortStorageByData.py +++ b/GUIS/straw/Verification/sortStorageByData.py @@ -3,7 +3,8 @@ straws = list() with open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\StorageRejected.csv", "r" + os.path.dirname(__file__) + "..\\..\\..\\Data\\Straw storage\\StorageRejected.csv", + "r", ) as f: reader = csv.DictReader(f) headers = reader.fieldnames @@ -11,7 +12,9 @@ straws.append(straw) straws = sorted(straws, key=lambda row: row["timestamp"]) with open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\SortedStorageRejected.csv", "w" + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Straw storage\\StorageStorageRejected.csv", + "w", ) as f: writer = csv.DictWriter(f, headers) for line in straws: diff --git a/GUIS/straw/Verification/tempHumid.py b/GUIS/straw/Verification/tempHumid.py index 52632409..3586e647 100644 --- a/GUIS/straw/Verification/tempHumid.py +++ b/GUIS/straw/Verification/tempHumid.py @@ -19,7 +19,7 @@ def tempConversion(temp, current_scale, desired_scale): def getTempHumid(temp_scale="C"): directory = ( - "\\\\MU2E-CART1\\Users\\Public\\Database Backup\\temp_humid_data\\464_main\\" + os.path.dirname(__file__) + "..\\..\\..\\Data\\temp_humid_data\\464_main\\" ) D = os.listdir(directory) filename = "" diff --git a/GUIS/straw/Verification/verifyStorageStraw.py b/GUIS/straw/Verification/verifyStorageStraw.py index 94aea7b4..0d213200 100644 --- a/GUIS/straw/Verification/verifyStorageStraw.py +++ b/GUIS/straw/Verification/verifyStorageStraw.py @@ -87,7 +87,7 @@ def getAllStraws(self): # Function based on positioncheck.py def checkLaserCutData(self, straw, pos): - path = r"\\\\MU2E-CART1\\Database Backup\\Laser cut data" + path = os.path.dirname(__file__) + "..\\..\\..\\Data\\Laser cut data" for pal in os.listdir(path): with open(path + "\\" + pal) as csvf: reader = csv.reader(csvf) @@ -114,7 +114,9 @@ def printMu2e(self): # Given strawID, returns ((float) ii, (float) oo, (bool) pass_fail) def checkResistanceData(self, strawID): strawID = strawID.upper() - resistance_dir = "\\\\MU2E-CART1\\Database Backup\\Resistance Testing" + resistance_dir = ( + os.path.dirname(__file__) + "..\\..\\..\\Data\\Resistance Testing" + ) res_data = { "inside-inside": float(), "inside-outside": float(), @@ -179,7 +181,8 @@ def checkLeakData(self, strawID): if not data_found: leak_dir = ( - "\\\\MU2E-CART1\\Database Backup\\Leak test data\\Leak Test Results" + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Leak test data\\Leak Test Results" ) for file_name in os.listdir(leak_dir): @@ -226,7 +229,8 @@ def checkLeakData(self, strawID): # Record findings in leak_ratefile.csv with open( - "\\\\MU2E-CART1\\Database Backup\\Leak test data\\Leak Test Results\\Leak Test Results.csv", + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Leak test data\\Leak Test Results\\Leak Test Results.csv", "a", ) as leak_rate_file: leak_rate_file.write("\n") # Newline @@ -252,7 +256,8 @@ def checkLeakData(self, strawID): else: # There's something funky with the plot with open( - "\\\\MU2E-CART1\\Database Backup\\Straw storage\\BenRecalculateLeakTest.txt", + os.path.dirname(__file__) + + "..\\..\\..\\Data\\Straw storage\\BenRecalculateLeakTest.txt", "a", ) as f: f.write("\n" + self.strawID)