Ejemplo n.º 1
0
 def debugPrint(verbosLevel, string, dictionary=None):
     if Logging.verbos >= verbosLevel:
         spacing = "  " * (verbosLevel - 1)
         BLUE_START = "\033[94m"
         COLOR_END = "\033[0m"
         prefix = "{}{}debug-{}: {}".format(spacing, BLUE_START,
                                            verbosLevel, COLOR_END)
         if dictionary:
             print("{}{}".format(prefix, string))
             for i, entry in enumerate(dictionary):
                 if type(dictionary) == type({}):
                     print("{}  {} --> {}".format(prefix, entry,
                                                  dictionary[entry]))
                 elif type(dictionary) == type([]):
                     print("{}  {}".format(prefix, entry))
         else:
             coloums = "( message, created )"
             values = "( \"{}\",\"{}\" )".format(
                 "{}".format(string), datetime.fromtimestamp(time.time()))
             sql = "INSERT INTO tvac.Debug {} VALUES {};".format(
                 coloums, values)
             # print(sql)
             try:
                 mysql = MySQlConnect()
                 mysql.cur.execute(sql)
                 mysql.conn.commit()
             except Exception as e:
                 pass
             for line in string.split("\n"):
                 print("{}{}".format(prefix, line))
Ejemplo n.º 2
0
    def logExpectedTemperatureData(data):
        '''
        data = {
             "expected_temp_values": expected_temp_values,
             "expected_time_values": expected_time_values,
             "Zone"                : self.args[0],
             "profileUUID"         : self.zoneProfile.profileUUID,
        '''
        expected_temp_values = data["expected_temp_values"]
        expected_time_values = data["expected_time_values"]
        zone = data["zone"]
        profile = data["profileUUID"]

        coloums = "( profile_I_ID, time, zone, temperature )"
        values = ""
        for i in range(len(expected_temp_values)):
            time = expected_time_values[i]
            time = datetime.fromtimestamp(time)

            temperature = expected_temp_values[i]
            values += "( \"{}\", \"{}\", {}, {} ),\n".format(
                profile, time.strftime('%Y-%m-%d %H:%M:%S'), int(zone[4:]),
                temperature)

        sql = "INSERT INTO tvac.Expected_Temperature {} VALUES {};".format(
            coloums, values[:-2])
        try:
            mysql = MySQlConnect()
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(1, "Error: {}".format(e))
Ejemplo n.º 3
0
    def saveProfile(self, json):
        try:
            name = json["name"]

            sql = "SELECT * FROM tvac.Thermal_Zone_Profile WHERE profile_name=\"{}\";".format(
                name)
            mysql = MySQlConnect()
            mysql.cur.execute(sql)
            mysql.conn.commit()

            results = mysql.cur.fetchall()
            if results:
                return "{'result':'Error, profile already exists'}"

            for zoneProfile in json['profiles']:
                result = self.saveZone(name, zoneProfile)
                if result != True:
                    return str(result)
            Logging.logEvent(
                "Event", "Profile", {
                    "message": "New Profile loaded: ({})".format(name),
                    "ProfileInstance": self.parent.getInstance()
                })
            return "{'result':'success'}"
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in loadProfile, zoneCollection: {}".format(str(e)))
            return str({'result': str(e)})
Ejemplo n.º 4
0
    def loadThermoCouples(self, profileName, zone):
        '''
        This is a helper medthod for LoadProfile, this will load thermocouples tied to this profile
        '''

        sql = "SELECT * FROM tvac.TC_Profile WHERE profile_name=\"{}\" AND zone=\"{}\";".format(
            profileName, zone)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in loadThermoCouples, zoneCollection: {}".format(
                    str(e)))
            if Logging.debug:
                raise e2

        results = mysql.cur.fetchall()
        TCs = []
        tcList = HardwareStatusInstance.getInstance().Thermocouples.tcList
        for result in results:
            TCs.append(int(result['thermocouple']))

        for tc in tcList:
            if tc.Thermocouple in TCs:
                tc.update({
                    "zone": "zone" + str(int(result['zone'])),
                    "userDefined": True
                })
        return TCs
Ejemplo n.º 5
0
 def logPressureData(self):
     coloums = "( profile_I_ID, guage, pressure, time )"
     values = "( \"{}\",{},{},\"{}\" ),\n".format(
         self.zoneProfiles.profileUUID, self.gauges.get_cryopump_address(),
         self.gauges.get_cryopump_pressure(),
         datetime.datetime.fromtimestamp(time.time()))
     values += "( \"{}\",{},{},\"{}\" ),\n".format(
         self.zoneProfiles.profileUUID, self.gauges.get_chamber_address(),
         self.gauges.get_chamber_pressure(),
         datetime.datetime.fromtimestamp(time.time()))
     values += "( \"{}\",{},{},\"{}\" )".format(
         self.zoneProfiles.profileUUID, self.gauges.get_roughpump_address(),
         self.gauges.get_roughpump_pressure(),
         datetime.datetime.fromtimestamp(time.time()))
     sql = "INSERT INTO tvac.Pressure {} VALUES {};".format(coloums, values)
     mysql = MySQlConnect()
     try:
         mysql.cur.execute(sql)
         mysql.conn.commit()
     except Exception as e:
         print(sql)
         Logging.debugPrint(
             1, "Error in logPressureData, PfeifferGaugeUpdater: {}".format(
                 str(e)))
         if Logging.debug:
             raise e
Ejemplo n.º 6
0
    def loadThermalProfiles(self, profileName, zone):
        '''
        This is a helper medthod for LoadProfile, this will load thermal profiles
        '''
        sql = "SELECT * FROM tvac.Thermal_Profile WHERE profile_name=\"{}\" AND zone=\"{}\";".format(
            profileName, zone)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in loadThermoProfiles, zoneCollection: {}".format(
                    str(e)))
            if Logging.debug:
                raise e

        results = mysql.cur.fetchall()
        thermalprofiles = []
        for result in results:
            TP = {}
            TP['thermalsetpoint'] = int(result['set_point'])
            TP['tempgoal'] = float(result['temp_goal'])
            TP['soakduration'] = int(result['soak_time'])
            TP['ramp'] = int(result['ramp_time'])
            thermalprofiles.append(TP)

        return thermalprofiles
Ejemplo n.º 7
0
def releaseHoldThread():
    ProfileInstance.getInstance().inHold = False
    sql = "UPDATE System_Status SET in_hold=0;"
    mysql = MySQlConnect()
    try:
        mysql.cur.execute(sql)
        mysql.conn.commit()
    except Exception as e:
        Logging.debugPrint(3, "sql: {}".format(sql))
        Logging.debugPrint(
            1, "Error in ThreadCollection, holdThread: {}".format(str(e)))
        if Logging.debug:
            raise e
Ejemplo n.º 8
0
 def holdThread(self, data=None):
     Logging.debugPrint(3, "Holding Zones")
     ProfileInstance.getInstance().inHold = True
     sql = "UPDATE System_Status SET in_hold=1;"
     mysql = MySQlConnect()
     try:
         mysql.cur.execute(sql)
         mysql.conn.commit()
     except Exception as e:
         Logging.debugPrint(3, "sql: {}".format(sql))
         Logging.debugPrint(
             1, "Error in ThreadCollection, holdThread: {}".format(str(e)))
         if Logging.debug:
             raise e
Ejemplo n.º 9
0
    def updateDBwithEndTime(self):
        sql = "update tvac.Profile_Instance set endTime=\"{}\" where endTime is null;".format(
            datetime.datetime.fromtimestamp(time.time()))

        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(
                1,
                "Error in updateDBwithEndTime, Duty Cycle control: {}".format(
                    str(e)))
            if Logging.debug:
                raise e
Ejemplo n.º 10
0
    def updateThermalStartTime(self, thermalStartTime):
        '''
        This is a helper function that is called either when a profile begins the
        thermal section (when it is in a vacuum) or when the the server is restarted. 
        '''
        # This loop is to hold the program here until the temperature vaules have been loaded
        if os.name == 'posix':
            userName = os.environ['LOGNAME']
        else:
            userName = "******"

        tmpStr = ""
        for zone in self.zoneDict:
            if self.zoneDict[zone].activeZoneProfile:
                if "root" in userName:
                    while True:
                        currentTemp = self.zoneDict[zone].getTemp(
                            self.zoneDict[zone].average)
                        Logging.debugPrint(
                            4,
                            "Zone Col.: currentTemp: {}".format(currentTemp))
                        if not math.isnan(
                                currentTemp) and int(currentTemp) != 0:
                            break
                        time.sleep(.5)
                else:
                    currentTemp = self.zoneDict[zone].getTemp(
                        self.zoneDict[zone].average)

                tmpStr += "{}_Temp = {},".format(zone, currentTemp)

        tmpStr = tmpStr[:-1]
        sql = "UPDATE tvac.Profile_Instance set thermal_Start_Time=\"{}\",{} where thermal_Start_Time is null;".format(
            datetime.datetime.fromtimestamp(thermalStartTime), tmpStr)
        print(sql)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(
                1,
                "Error in updateDBwithEndTime, Duty Cycle control: {}".format(
                    str(e)))
            if Logging.debug:
                raise e
Ejemplo n.º 11
0
    def returnActiveProfile(self):
        '''
        A helper function that will look in the DB to see if there is any half finished profile instances
        Returns the profile profile_name and Profile ID if there is, False, False if not
        '''
        sql = "SELECT profile_name, profile_Start_Time, thermal_Start_Time, first_Soak_Start_Time FROM tvac.Profile_Instance WHERE endTime IS NULL;"
        try:
            mysql = MySQlConnect()
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            return (False, e)

        result = mysql.cur.fetchone()
        if not result:
            return False
        return result
Ejemplo n.º 12
0
    def addProfileInstancetoBD(self):
        '''
        This is a helper function of runProfile that adds the new profile Instance to the DB
        '''

        coloums = "( profile_name, profile_I_ID, profile_Start_Time )"
        values = "( \"{}\",\"{}\", \"{}\" )".format(
            self.zoneProfiles.profileName, self.zoneProfiles.profileUUID,
            datetime.datetime.fromtimestamp(time.time()))
        sql = "INSERT INTO tvac.Profile_Instance {} VALUES {};".format(
            coloums, values)
        # print(sql)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            return e

        return True
Ejemplo n.º 13
0
    def getStatusFromDB(self):
        sql = "SELECT * FROM tvac.System_Status;"
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in profileInstance, getStatus: {}".format(str(e)))
            if Logging.debug:
                raise e

        results = mysql.cur.fetchone()
        self.inHold = True if results["in_hold"] else False
        self.inPause = True if results["in_pause"] else False
        self.inRamp = True if results["in_ramp"] else False
        self.recordData = True if results["record_data"] else False
        self.vacuumWanted = True if results["vacuum_wanted"] else False
        self.currentSetpoint = results["setpoint"]
Ejemplo n.º 14
0
    def logLiveTemperatureData(data):
        '''
        data = {
            "time":		TCs['time'],
            "tcList":	TCs['tcList'],
            "ProfileUUID": ProfileUUID,
        }
        TCs is a list of dicitations ordered like this....
        {
        'Thermocouple': tc_num,
        'time': tc_time_offset,
        'temp': tc_tempK,
        'working': tc_working,
        'alarm': tc_alarm
        }
        '''
        testList = [7, 9, 10, 11, 12, 91, 92, 100, 105, 110, 115, 120]

        time = data["time"]
        profile = data["profileUUID"]
        coloums = "( profile_I_ID, time, thermocouple, temperature )"
        values = ""

        for tc in data['tcList']:
            thermocouple = tc["Thermocouple"]
            temperature = tc["temp"]
            if math.isnan(tc["temp"]):
                continue
            values += "( \"{}\", \"{}\", {}, {} ),\n".format(
                profile, time.strftime('%Y-%m-%d %H:%M:%S'), thermocouple,
                temperature)
        sql = "INSERT INTO tvac.Real_Temperature {} VALUES {};".format(
            coloums, values[:-2])

        sql.replace("nan", "NULL")
        try:
            mysql = MySQlConnect()
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(1, "Error: {}".format(e))
Ejemplo n.º 15
0
    def createExpectedValues(self, setPoints, startTime=None):
        '''
        This is a helper function that given a list of setpoints
        containing a GoalTemp, RampTime and SoakTime. It will 
        generate a list time values and matching temputure values
        '''
        Logging.logEvent(
            "Debug", "Status Update", {
                "message":
                "DCCS: Creating Expected temperature values: {}".format(
                    self.name),
                "level":
                2
            })
        intervalTime = self.parent.updatePeriod
        # if given a startTime, use that, otherwise, use current
        Logging.debugPrint(
            1, "DCCS: thermalStartTime: {}".format(
                self.parent.zoneProfiles.thermalStartTime))
        if startTime:
            Logging.debugPrint(
                3, "DCCS: Starttime is: {}\t current: {}".format(
                    startTime, time.time()))
            if "datetime.datetime" in str(type(startTime)):
                startTime = time.mktime(startTime.timetuple())
            currentTime = int(startTime)
        else:
            currentTime = int(time.time())

        sql = "SELECT zone{}_Temp FROM tvac.Profile_Instance where endTime is null;".format(
            self.zoneProfile.zone)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in loadThermoProfiles, zoneCollection: {}".format(
                    str(e)))
            if Logging.debug:
                raise e

        result = mysql.cur.fetchone()
        print("result: {}".format(result))
        currentTemp = result["zone{}_Temp".format(self.zoneProfile.zone)]
        currentTemp = float(currentTemp)
        print("currentTemp: {}".format(currentTemp))

        expected_temp_values = []
        expected_time_values = []
        self.parent.setpoint_start_time = []
        for setPoint in setPoints:
            # get values out from setpoint
            goalTemp = setPoint.tempGoal
            rampTime = setPoint.ramp
            soakTime = setPoint.soakduration
            currentTime2 = time.time()
            # skip ramp section if rampTime == 0
            if rampTime:
                TempDelta = goalTemp - currentTemp
                numberOfJumps = rampTime / intervalTime
                intervalTemp = TempDelta / numberOfJumps
                rampEndTime = currentTime + rampTime

                # Debug prints
                debugStatus = {
                    "goal temperature": goalTemp,
                    "Time at Start of Setpoint": currentTime,
                    "Ramp Duration": rampTime,
                    "Delta temp per Update": intervalTemp,
                    "Update Time": self.parent.updatePeriod,
                    "TempDelta Total": TempDelta,
                }
                Logging.logEvent(
                    "Debug", "Data Dump", {
                        "message":
                        "DCCS: Setpoint {}: Ramp Status".format(
                            setPoint.thermalsetpoint),
                        "level":
                        3,
                        "dict":
                        debugStatus
                    })

                # setting all values all for ramp
                notUsed = 0
                for i, tempSetPoint in enumerate(
                        range(currentTime, rampEndTime, intervalTime)):
                    if tempSetPoint > currentTime2:
                        x = tempSetPoint
                        y = currentTemp + ((i) * intervalTemp)
                        expected_time_values.append(tempSetPoint)
                        expected_temp_values.append(y)
                    else:
                        notUsed += 1
            else:
                rampEndTime = currentTime
            self.parent.setpoint_start_time.append([currentTime, 0])

            # Debug prints
            debugStatus = {
                "Soak Duration": soakTime,
                "goal temperature": goalTemp,
            }
            Logging.logEvent(
                "Debug", "Data Dump", {
                    "message":
                    "DCCS: Setpoint {}: Soak Status".format(
                        setPoint.thermalsetpoint),
                    "level":
                    3,
                    "dict":
                    debugStatus
                })

            #Setting all soak values
            self.parent.setpoint_start_time[-1][1] = rampEndTime
            for tempSetPoint in range(rampEndTime, rampEndTime + soakTime,
                                      intervalTime):
                if tempSetPoint > currentTime2:
                    x = tempSetPoint
                    y = goalTemp
                    expected_time_values.append(tempSetPoint)
                    expected_temp_values.append(y)
            currentTime = rampEndTime + soakTime
            currentTemp = goalTemp
        # end of for loop, end generating outputs

    # print("Logging all data")
    # Logging.logEvent("Event","Expected Temp Update",
    # {"expected_temp_values": expected_temp_values,
    #  "expected_time_values": expected_time_values,
    #  "zone"                : self.args[0],
    #  "profileUUID"         : self.zoneProfile.profileUUID,
    #  "ProfileInstance"     : ProfileInstance.getInstance()
    # })

        return expected_temp_values, expected_time_values
Ejemplo n.º 16
0
    def saveZone(self, name, zoneProfile):
        '''
        This is a helper functiont for saveProfile. It saves the data needed for each zone into the DB
        '''
        average = zoneProfile["average"]
        zone = zoneProfile["zone"]
        heatError = zoneProfile["maxTemp"]
        minTemp = zoneProfile["minTemp"]
        maxSlope = zoneProfile["maxSlope"]

        coloums = "( profile_name, zone, average, max_heat_error, min_heat_error, max_heat_per_min )"
        values = "( \"{}\",{},\"{}\",{},{},{} )".format(
            name, zone, average, heatError, minTemp, maxSlope)
        sql = "INSERT INTO tvac.Thermal_Zone_Profile {} VALUES {};".format(
            coloums, values)
        mysql = MySQlConnect()
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in saveZone, zoneCollection: {}".format(str(e)))
            raise e

        coloums = "( profile_name, zone, set_point, temp_goal, ramp_time, soak_time )"
        values = ""
        for profile in zoneProfile["thermalprofiles"]:
            setpoint = profile["thermalsetpoint"]
            tempgoal = profile["tempgoal"]
            rampTime = profile["ramp"]
            soakTime = profile["soakduration"]

            values += "( \"{}\", {}, {}, {}, {}, {} ),\n".format(
                name, zone, setpoint, tempgoal, rampTime, soakTime)
        sql = "INSERT INTO tvac.Thermal_Profile {} VALUES {};".format(
            coloums, values[:-2])
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in saveZone, zoneCollection: {}".format(str(e)))
            raise e

        # Saving the TC as well
        coloums = "( profile_name, zone, thermocouple )"
        values = ""
        for tc in zoneProfile["thermocouples"]:
            values += "( \"{}\", {}, {} ),\n".format(name, zone, tc)
        sql = "INSERT INTO tvac.TC_Profile {} VALUES {};".format(
            coloums, values[:-2])
        try:
            mysql.cur.execute(sql)
            mysql.conn.commit()
        except Exception as e:
            Logging.debugPrint(3, "sql: {}".format(sql))
            Logging.debugPrint(
                1, "Error in saveZone, zoneCollection: {}".format(str(e)))
            raise e

        return True
Ejemplo n.º 17
0
    def load_profile(self,
                     profileName,
                     profileStartTime=None,
                     thermalStartTime=None,
                     firstSoakStartTime=None):
        '''
        This will take a profile loaded in the DB and put it in RAM
        If this is a pre exisiting profile we are loading after reboot, a startTime will be given
        this is the startTime of the profileInstance that was/will be ran by the ThreadCollection
        '''
        if thermalStartTime:
            Logging.debugPrint(
                2, "Loading profile {}:\tpst: {}\ttst: {}\tfsst: {}".format(
                    profileName, profileStartTime,
                    time.mktime(thermalStartTime.timetuple()),
                    firstSoakStartTime))
        else:
            Logging.debugPrint(2, "No thermalStartTime")
        try:
            sql = "SELECT zone, average, min_heat_error, max_heat_error, max_heat_per_min FROM tvac.Thermal_Zone_Profile WHERE profile_name=\"{}\";".format(
                profileName)
            mysql = MySQlConnect()
            try:
                mysql.cur.execute(sql)
                mysql.conn.commit()
            except Exception as e:
                Logging.debugPrint(3, "sql: {}".format(sql))
                Logging.debugPrint(
                    1,
                    "Error in loadProfile, zoneCollection: {}".format(str(e)))
                if Logging.debug:
                    raise e

            results = mysql.cur.fetchall()
            if not results:
                return "{'Error':'No profile loaded under that name.'}"

            # Collect this from the database..somehow if startTime not none
            self.profileUUID = uuid.uuid4()
            self.profileName = profileName
            self.profileStartTime = profileStartTime
            self.thermalStartTime = thermalStartTime
            self.firstSoakStartTime = firstSoakStartTime

            Logging.debugPrint(2, "Loaded profile: {}".format(profileName))

            for result in results:
                zoneProfile = {}
                zoneName = "zone" + str(result['zone'])
                # TODO: This is where I fix the bug where each zone has it's own ID and gets a new one on reload
                zoneProfile['profileuuid'] = self.profileUUID
                zoneProfile['zone'] = result['zone']
                zoneProfile['zoneuuid'] = uuid.uuid4()
                zoneProfile['average'] = result['average']
                zoneProfile['max_heat_error'] = result['max_heat_error']
                zoneProfile['min_heat_error'] = result['min_heat_error']
                zoneProfile['max_heat_per_min'] = result['max_heat_per_min']
                try:
                    zoneProfile['thermalprofiles'] = self.loadThermalProfiles(
                        profileName, result['zone'])
                except Exception as e:
                    raise e

                try:
                    zoneProfile["thermocouples"] = self.loadThermoCouples(
                        profileName, result['zone'])
                except Exception as e:
                    raise e

                # After you have all the data on the zone, add it to the instance
                Logging.debugPrint(
                    3, "Loaded Profile Data Zone {}: ".format(
                        zoneProfile['zone']), zoneProfile)
                self.zoneDict[zoneName].update(zoneProfile)
                self.zoneDict[zoneName].activeZoneProfile = True

            # TODO: This needs to be fixed
            self.parent.getInstance().vacuumWanted = True

            return "{'result':'success'}"
        except Exception as e:
            return {'result': '{}'.format(str(e))}