Advertisement
Sax

weafail2

Sax
Feb 20th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import threading
  3.  
  4. class mf(threading.Thread):
  5.  
  6.     def __init__(self, p):
  7.         self._p = p[:]
  8.         threading.Thread.__init__(self)
  9.  
  10. class trapecio(mf):
  11.  
  12.     def evaluate(self,x):
  13.         if x<=self._p[0]:
  14.             return 0
  15.         elif self._p[0] < x <= self._p[1]:
  16.             return (x - self._p[0])/(self._p[1] - self._p[0])
  17.         elif self._p[1] < x <= self._p[2]:
  18.             return 1
  19.         elif self._p[2] < x <= self._p[3]:
  20.             return 1 - (x - self._p[2])/(self._p[3] - self._p[2])
  21.         else:
  22.             return 0
  23.  
  24. morning = trapecio([5, 7, 9, 11])
  25. noon = trapecio([11, 14, 16, 17])
  26. night = trapecio([17, 19, 21,23])
  27.  
  28.  
  29. tiempos = [0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90,
  30.            1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60, 1.70, 1.80, 1.90,
  31.            2.00, 2.10, 2.20, 2.30, 2.40, 2.50, 2.60, 2.70, 2.80, 2.90,
  32.            3.00, 3.10, 3.20, 3.30, 3.40, 3.50, 3.60, 3.70, 3.80, 3.90,
  33.            4.00, 4.10, 4.20, 4.30, 4.40, 4.50, 4.60, 4.70, 4.80, 4.90,
  34.            5.00, 5.10, 5.20, 5.30, 5.40, 5.50, 5.60, 5.70, 5.80, 5.90,
  35.            6.00, 6.10, 6.20, 6.30, 6.40, 6.50, 6.60, 6.70, 6.80, 6.90,
  36.            7.00, 7.10, 7.20, 7.30, 7.40, 7.50, 7.60, 7.70, 7.80, 7.90,
  37.            8.00, 8.10, 8.20, 8.30, 8.40, 8.50, 8.60, 8.70, 8.80, 8.90,
  38.            9.00, 9.10, 9.20, 9.30, 9.40, 9.50, 9.60, 9.70, 9.80, 9.90,
  39.            10.00, 10.10, 10.20, 10.30, 10.40, 10.50, 10.60, 10.70, 10.80, 10.90,
  40.            11.00, 11.10, 11.20, 11.30, 11.40, 11.50, 11.60, 11.70, 11.80, 11.90,
  41.            12.00, 12.10, 12.20, 12.30, 12.40, 12.50, 12.60, 12.70, 12.80, 12.90,
  42.            13.00, 13.10, 13.20, 13.30, 13.40, 13.50, 13.60, 13.70, 13.80, 13.90,
  43.            14.00, 14.10, 14.20, 14.30, 14.40, 14.50, 14.60, 14.70, 14.80, 14.90,
  44.            15.00, 15.10, 15.20, 15.30, 15.40, 15.50, 15.60, 15.70, 15.80, 15.90,
  45.            16.00, 16.10, 16.20, 16.30, 16.40, 16.50, 16.60, 16.70, 16.80, 16.90,
  46.            17.00, 17.10, 17.20, 17.30, 17.40, 17.50, 17.60, 17.70, 17.80, 17.90,
  47.            18.00, 18.10, 18.20, 18.30, 18.40, 18.50, 18.60, 18.70, 18.80, 18.90,
  48.            19.00, 19.10, 19.20, 19.30, 19.40, 19.50, 19.60, 19.70, 19.80, 19.90,
  49.            20.00, 20.10, 20.20, 20.30, 20.40, 20.50, 20.60, 20.70, 20.80, 20.90,
  50.            21.00, 21.10, 21.20, 21.30, 21.40, 21.50, 21.60, 21.70, 21.80, 21.90,
  51.            22.00, 22.10, 22.20, 22.30, 22.40, 22.50, 22.60, 22.70, 22.80, 22.90,
  52.            23.00, 23.10, 23.20, 23.30, 23.40, 23.50, 23.60, 23.70, 23.80, 23.90]
  53.  
  54. for item in tiempos:
  55.     time.sleep(6.0)
  56.     hora = item
  57.     morning_ratio = morning.evaluate(float(hora))
  58.     noon_ratio = noon.evaluate(float(hora))
  59.     night_ratio = night.evaluate(float(hora))
  60.  
  61.     if morning_ratio > noon_ratio:
  62.         eval_ratio = morning_ratio
  63.     elif noon_ratio > night_ratio:
  64.         eval_ratio = noon_ratio
  65.     else:
  66.         eval_ratio = night_ratio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement