def main(): """main part""" temphumi = DHT22_AM2302(19) # BCM 19 = PIN 35 temp_cpu = CPU() measurements = {DS_TEMP1: Measurements(3), \ DS_TEMPCPU: Measurements(3), \ DS_TEMP2: Measurements(3), \ DS_HUMI: Measurements(3)} rrd_template = DS_TEMP1 + ":" + \ DS_TEMPCPU + ":" + \ DS_TEMP2 + ":" + \ DS_HUMI while (True): _temp, _humi = temphumi.read() measurements[DS_TEMP1].append(_temp) measurements[DS_HUMI].append(_humi) measurements[DS_TEMPCPU].append(temp_cpu.read()) measurements[DS_TEMP2].append(0) # empty, for later useage rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) print strftime("%H:%M:%S", localtime()), rrd_data rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data) sleep(35)
def main(): """main part""" sq = SensorQueueClient_write("../../configs/weatherqueue.ini") qvalue_temp = SensorValue("ID_06", "TempKinderzimmer", SensorValue_Data.Types.Temp, "°C") qvalue_humi = SensorValue("ID_07", "HumiKinderzimmer", SensorValue_Data.Types.Humi, "% rF") sq.register(qvalue_temp) sq.register(qvalue_humi) temphumi = DHT22_AM2302(19, qvalue_temp, qvalue_humi) # BCM 19 = PIN 35 temp_cpu = CPU() measurements = {DS_TEMP1: Measurements(3), \ DS_TEMPCPU: Measurements(3), \ DS_TEMP2: Measurements(3), \ DS_HUMI: Measurements(3)} udp = Sender(CREDENTIALS) while (True): _temp, _humi = temphumi.read() measurements[DS_TEMP1].append(_temp) measurements[DS_HUMI].append(_humi) measurements[DS_TEMPCPU].append(temp_cpu.read_temperature()) measurements[DS_TEMP2].append(0) # empty, for later useage rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) # Log(rrd_data) udp.send(rrd_data) sleep(35)
def __init__(self, company, gender, clothing, H, frontView=None, backView=None, bentArmsView=None): self.mes = Measurements(H, frontView, bentArmsView, backView) self.company = company self.gender = gender self.clothing = clothing self.errorCalc = 0 self.rating = '' self.Fit = []
def main(): """main part""" sq = SensorQueueClient_write("../../configs/weatherqueue.ini") qvalue_temp = SensorValue("ID_06", "TempKinderzimmer", SensorValue_Data.Types.Temp, "°C") qvalue_humi = SensorValue("ID_07", "HumiKinderzimmer", SensorValue_Data.Types.Humi, "% rF") sq.register(qvalue_temp) sq.register(qvalue_humi) temphumi = DHT22_AM2302(19, qvalue_temp, qvalue_humi) # BCM 19 = PIN 35 temp_cpu = CPU() measurements = {DS_TEMP1: Measurements(3), \ DS_TEMPCPU: Measurements(3), \ DS_TEMP2: Measurements(3), \ DS_HUMI: Measurements(3)} rrd_template = DS_TEMP1 + ":" + \ DS_TEMPCPU + ":" + \ DS_TEMP2 + ":" + \ DS_HUMI while (True): _temp, _humi = temphumi.read() measurements[DS_TEMP1].append(_temp) measurements[DS_HUMI].append(_humi) measurements[DS_TEMPCPU].append(temp_cpu.read_temperature()) measurements[DS_TEMP2].append(0) # empty, for later useage rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) # print(strftime("%H:%M:%S", localtime()), rrd_data) # rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data) # python rrdtool seems not to work here; the pi needs a proper reinstall. # as a workaround, i just call the os for rrd update # rrd = "/usr/bin/rrdtool update {} --template {} {}".format(RRDFILE, rrd_template, rrd_data) rrd = [ "/usr/bin/rrdtool", "update", RRDFILE, "--template", rrd_template, rrd_data ] print(rrd) subprocess.call(rrd) sleep(35)
def run(self): self.__running = True self.measurements = Measurements(maxlen=20) set_brightness = self.set_brightness() while self.__running: self.measurements.append(sensor.lux_calced) # full brightness between 6 am and 10 pm or # if manually switched on if self.schedule_on() or self.switched_on(): set_brightness(Sensor.MAX) else: set_brightness(int(self.measurements.avg())) time.sleep(0.02) set_brightness(Sensor.MAX) # set max brightness on exit
def start(front, bent, back, shirt): error = 6 inches = 76 + error #m = Measurements(inches, front, bent, back) m = Measurements(inches, frontView=front) ''' print(m.shoulder_width) print(m.right_shoulder_elbow) print(m.right_elbow_wrist) print(m.left_shoulder_elbow ) print(m.left_elbow_wrist ) print(m.right_shoulder_wrist ) print(m.left_shoulder_wrist ) print(m.shoulder_hip) print(m.right_hip_ankle ) print(m.left_hip_ankle ) print(m.right_hip_knee ) print(m.left_hip_knee ) print(m.hip_ankle_max ) print(m.chest_point) ''' #shirt_height = 29.875 shirt_height = 26.125 shoulder_length = 18.875 sleeve_length = 32.5 print("image height ", shirt_height / m.inchesPerPixel) print("image width ", (m.calc.getDistance(m.points[1][0], m.points[3][0]) + (1.5 / m.inchesPerPixel)) * 2) Original_Image = Image.open(bent).convert('RGBA') Original_Image_Copy = Original_Image.copy() original_height, original_width = Original_Image.size image_ratio = original_height / original_width shirt_image = Image.open(shirt).convert('RGBA') shirt_image_copy = shirt_image.copy() shirt_image_copy = shirt_image_copy.resize( (int(shirt_height / (image_ratio * m.inchesPerPixel)), int(shirt_height / m.inchesPerPixel))) _, width = shirt_image_copy.size coordinate_x = m.points[1][0] - width / 2 - (2.5 / m.inchesPerPixel) coordinate_y = m.points[1][1] + (3 / m.inchesPerPixel) # paste image giving dimensions Original_Image_Copy.paste(shirt_image_copy, (int(coordinate_x), int(coordinate_y)), shirt_image_copy) # save the image Original_Image_Copy.save( 'C:/Classnotes/Dress-Virtual-Trialroom/output_maybe_success.png', format='png') # img = cv2.imread('output_maybe_success.png') # imgplot = plt.imshow(img) # plt.show() img = cv2.imread( 'C:/Classnotes/Dress-Virtual-Trialroom/output_maybe_success.png') path = 'C:/Classnotes/Dress-Virtual-Trialroom/' cv2.imwrite(os.path.join(path, 'static/waka.jpg'), img) print("File saved") cv2.waitKey(0)
def main(): """main part""" temp1 = DS1820("/sys/bus/w1/devices/28-000006d62eb1/w1_slave") temp2 = DS1820("/sys/bus/w1/devices/28-000006dd6ac1/w1_slave") temp4 = DS1820("/sys/bus/w1/devices/28-000006de535b/w1_slave") temphumi = DHT22_AM2302(21) # BCM 21 = PIN 40 tempcpu = CPU() heatcontrol = Schedules.Control(Schedules.ScheduleHeat(), heatlamp) lightcontrol = Schedules.Control(Schedules.ScheduleLight(), lightlamp) measurements = {DS_TEMP1: Measurements(), \ DS_TEMP2: Measurements(), \ DS_TEMP3: Measurements(), \ DS_TEMP4: Measurements(), \ DS_TEMPCPU: Measurements(), \ DS_HUMI: Measurements()} rrd_template = DS_TEMP1 + ":" + \ DS_TEMP2 + ":" + \ DS_TEMP3 + ":" + \ DS_TEMP4 + ":" + \ DS_TEMPCPU + ":" + \ DS_HUMI + ":" + \ DS_HEATING + ":" + \ DS_LIGHTING while (True): measurements[DS_TEMP1].append(temp1.read()) measurements[DS_TEMP2].append(temp2.read()) measurements[DS_TEMP4].append(temp4.read()) _temp3, _humi = temphumi.read() measurements[DS_TEMP3].append(_temp3) measurements[DS_HUMI].append(_humi) measurements[DS_TEMPCPU].append(tempcpu.read()) heatcontrol.control(measurements[DS_TEMP3].avg()) lightcontrol.control(measurements[DS_TEMP3].avg()) rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_TEMP3].last()) + \ ":{:.2f}".format(measurements[DS_TEMP4].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) + \ ":{:}".format(heatlamp.status()) + \ ":{:}".format(lightlamp.status()) print strftime("%H:%M:%S", localtime()), rrd_data rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data) sleep(35)
def main(): """main part""" temp_fridge = DS1820("/sys/bus/w1/devices/28-000006dc8d42/w1_slave") temp_cpu = CPU() temphumi = DHT22_AM2302(21) # BCM 21 = PIN 40 measurements = {DS_TEMP1: Measurements(3), \ DS_TEMPCPU: Measurements(3), \ DS_TEMP2: Measurements(3), \ DS_HUMI: Measurements(3)} rrd_template = DS_TEMP1 + ":" + \ DS_TEMPCPU + ":" + \ DS_TEMP2 + ":" + \ DS_HUMI + ":" + \ DS_ON + ":" + \ DS_OPEN while (True): measurements[DS_TEMP1].append(temp_fridge.read_temperature()) measurements[DS_TEMPCPU].append(temp_cpu.read()) _temp, _humi = temphumi.read() measurements[DS_TEMP2].append(_temp) measurements[DS_HUMI].append(_humi) if (measurements[DS_TEMP2].avg() > 5.2): fridge.on() if (measurements[DS_TEMP2].avg() < 5.0): fridge.off() # if (temp > 6): fridge.on() # else if (temp > 5): # fridge_on_time(60,90) # für 60 sekunden einschalten; 90 Sekunden mindestens aus # else if (temp < 5.0): # fridge.off() # class fridge_... derived from class Heating # threading: https://docs.python.org/2/library/threading.html # multi inheritance: https://docs.python.org/2/tutorial/classes.html#multiple-inheritance # class DerivedClassName(Base1, Base2, Base3): # fridge_on_time: # thread: # with lock: # timing = active # __on() # sleep(60) # __off() # sleep(90) # with lock: # timing = non_active # in on(), off() # ... # if (active): pass rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) + \ ":{:}".format(fridge.status()) + \ ":{:}".format(reedcontact.status_stretched()) print strftime("%H:%M:%S", localtime()), rrd_data rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data) writeMonitoringData(rrd_data) sleep(35)
class Control(threading.Thread): """controls brightness of display""" DELAYTOLIGHTOFF = 15 def __init__(self): threading.Thread.__init__(self) self.timestamp = datetime.now() self.__switchedon = False self.__running = False @staticmethod def set_brightness(): lastvalue = 0 def set_value(brightness): nonlocal lastvalue if brightness != lastvalue: lastvalue = brightness command = "sudo bash -c \"echo \\\"{}\\\" > {}\"" command = command.format(brightness, CONFIG.CONTROLBRIGHTNESS) subprocess.call(command, shell=True) return set_value def switch_on(self): self.__switchedon = True self.timestamp = datetime.now() + timedelta( seconds=self.DELAYTOLIGHTOFF) def switched_on(self): if datetime.now() > self.timestamp: self.__switchedon = False return self.__switchedon def prettybright(self): """no need to set display to full brightness if it is already very bright""" return self.measurements.avg() > Sensor.MAX - 5 @staticmethod def schedule_on(): """full brightness from 6 am to 10 pm""" return 6 <= datetime.now().hour < 22 def run(self): self.__running = True self.measurements = Measurements(maxlen=20) set_brightness = self.set_brightness() while self.__running: self.measurements.append(sensor.lux_calced) # full brightness between 6 am and 10 pm or # if manually switched on if self.schedule_on() or self.switched_on(): set_brightness(Sensor.MAX) else: set_brightness(int(self.measurements.avg())) time.sleep(0.02) set_brightness(Sensor.MAX) # set max brightness on exit def stop(self): self.__running = False
def main(): """main part""" qvalue_tempbox = SensorValueLock("ID_08", "TempDonutBox", SensorValue.Types.Temp, u'°C', Lock()) qvalue_humi = SensorValueLock("ID_09", "HumiDonut", SensorValue.Types.Humi, u'% rF', Lock()) qvalue_tempoutdoor = SensorValueLock("ID_12", "TempDonutOutDoor", SensorValue.Types.Temp, u'°C', Lock()) qvalue_heatlamp = SensorValueLock("ID_10", "SwitchHeatlamp", SensorValue.Types.Switch, u'Heizung:', Lock()) qvalue_lightlamp = SensorValueLock("ID_11", "SwitchLightlamp", SensorValue.Types.Switch, u'Beleuchtung:', Lock()) sq.register(qvalue_tempbox) sq.register(qvalue_humi) sq.register(qvalue_tempoutdoor) sq.register(qvalue_heatlamp) sq.register(qvalue_lightlamp) sq.start() temp1 = DS1820("/sys/bus/w1/devices/28-000006d62eb1/w1_slave", qvalue_tempoutdoor) temp2 = DS1820("/sys/bus/w1/devices/28-000006dd6ac1/w1_slave") temp4 = DS1820("/sys/bus/w1/devices/28-000006de535b/w1_slave") temphumi = DHT22_AM2302(21, qvalue_tempbox, qvalue_humi) # BCM 21 = PIN 40 tempcpu = CPU() heatcontrol = Schedules.Control(Schedules.ScheduleHeat(), heatlamp, qvalue_heatlamp) lightcontrol = Schedules.Control(Schedules.ScheduleLight(), lightlamp, qvalue_lightlamp) measurements = {DS_TEMP1: Measurements(), \ DS_TEMP2: Measurements(), \ DS_TEMP3: Measurements(), \ DS_TEMP4: Measurements(), \ DS_TEMPCPU: Measurements(), \ DS_HUMI: Measurements()} rrd_template = DS_TEMP1 + ":" + \ DS_TEMP2 + ":" + \ DS_TEMP3 + ":" + \ DS_TEMP4 + ":" + \ DS_TEMPCPU + ":" + \ DS_HUMI + ":" + \ DS_HEATING + ":" + \ DS_LIGHTING while (True): measurements[DS_TEMP1].append(temp1.read_temperature()) measurements[DS_TEMP2].append(temp2.read_temperature()) measurements[DS_TEMP4].append(temp4.read_temperature()) _temp3, _humi = temphumi.read() measurements[DS_TEMP3].append(_temp3) measurements[DS_HUMI].append(_humi) measurements[DS_TEMPCPU].append(tempcpu.read()) heatcontrol.control(measurements[DS_TEMP3].avg()) lightcontrol.control(measurements[DS_TEMP3].avg()) rrd_data = "N:{:.2f}".format(measurements[DS_TEMP1].last()) + \ ":{:.2f}".format(measurements[DS_TEMP2].last()) + \ ":{:.2f}".format(measurements[DS_TEMP3].last()) + \ ":{:.2f}".format(measurements[DS_TEMP4].last()) + \ ":{:.2f}".format(measurements[DS_TEMPCPU].last()) + \ ":{:.2f}".format(measurements[DS_HUMI].last()) + \ ":{:}".format(heatlamp.status()) + \ ":{:}".format(lightlamp.status()) print strftime("%H:%M:%S", localtime()), rrd_data rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data) sleep(35)
from Measurements import Measurements from PIL import Image import cv2 import os # import matplotlib.pyplot as plt import matplotlib.pyplot as plt import matplotlib.image as mpimg front = "/content/UIFit/backend/tucked1.jpg" bent = "/content/UIFit/backend/tucked2.jpg" back = "/content/UIFit/backend/tucked3.jpg" error = 6 inches = 76+error #m = Measurements(inches, front, bent, back) m = Measurements(inches, frontView=front) ''' print(m.shoulder_width) print(m.right_shoulder_elbow) print(m.right_elbow_wrist) print(m.left_shoulder_elbow ) print(m.left_elbow_wrist ) print(m.right_shoulder_wrist ) print(m.left_shoulder_wrist ) print(m.shoulder_hip) print(m.right_hip_ankle ) print(m.left_hip_ankle ) print(m.right_hip_knee ) print(m.left_hip_knee ) print(m.hip_ankle_max ) print(m.chest_point)
class Analysis: def __init__(self, company, gender, clothing, H, frontView=None, backView=None, bentArmsView=None): self.mes = Measurements(H, frontView, bentArmsView, backView) self.company = company self.gender = gender self.clothing = clothing self.errorCalc = 0 self.rating = '' self.Fit = [] def calcShortSleeveSuccess(self): U_shirtlen = self.mes.getShoulderHip() U_shoulderWidth = self.mes.getShoulderWidth() U_rightSleeve = self.mes.getRightShoulderElbow() U_leftSleeve = self.mes.getLeftShoulderElbow() I_shirtlen = 24.875 I_shoulderWidth = 18.75 I_sleeveRatio = 5 shirtLenError = abs(U_shirtlen - I_shirtlen) / I_shirtlen shoulderWidthError = abs(U_shoulderWidth - I_shoulderWidth) / I_shoulderWidth if shirtLenError < 0.1: self.Fit.append('Length of shirt is good') elif shirtLenError < 0.2: self.Fit.append('Length of shirt is decent') else: self.Fit.append('Length of shirt is bad') if shoulderWidthError < 0.1: self.Fit.append('Shoulders are well-fitted') elif shoulderWidthError < 0.2: self.Fit.append('Shoulders have a decent fit') else: self.Fit.append('Shoulders are not well-fitted') # rightSleeveError = I_sleeveRatio / U_rightSleeve # print(rightSleeveError) # leftSleeveError = I_sleeveRatio / U_leftSleeve # print(leftSleeveError) self.errorCalc = shirtLenError + shoulderWidthError def calcLongSleeveSuccess(self): U_shirtlen = self.mes.getShoulderHip() U_shoulderWidth = self.mes.getShoulderWidth() U_rightArm = self.mes.getRightShoulderElbow() + self.mes.getRightElbowWrist() U_leftArm = self.mes.getLeftShoulderElbow() + self.mes.getLeftElbowWrist() I_shirtlen = 24.875 I_shoulderWidth = 18.75 I_LongSleeve = 32.5 shirtLenError = abs(U_shirtlen - I_shirtlen) / I_shirtlen shoulderWidthError = (abs(U_shoulderWidth - I_shoulderWidth)) / I_shoulderWidth longSleeveError = (abs(max(U_rightArm, U_leftArm) - I_LongSleeve)) / I_LongSleeve self.errorCalc = shirtLenError + shoulderWidthError + longSleeveError def calcJeansSuccess(self): U_rightJean = self.mes.getRightHipAnkle() U_leftJean = self.mes.getLeftHipAnkle() U_hipWidth = self.mes.getHipWidth() I_hipWidth = 31 I_jeanLen = 10 jeanError = (abs(max(U_rightJean, U_leftJean) - I_jeanLen)) / I_jeanLen HipError = (abs(U_hipWidth - I_hipWidth)) / I_hipWidth print(jeanError) print(HipError) self.errorCalc = jeanError + HipError def getCalcError(self): if self.errorCalc < 0.1: return 'Well-Fitted' elif self.errorCalc < 0.15: return 'Fitted' elif self.errorCalc < 0.2: return 'Adequate' elif self.errorCalc < 0.35: return 'Loose' else: return 'Very Loose' def getFit(self): return self.Fit