Advertisement
Sax

simula.py - colas

Sax
Dec 3rd, 2012
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.75 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. """
  4. TODO:
  5. 1) Quitar lo que no sirve
  6. 2) Escribir output
  7.  
  8. """
  9.  
  10. import sys
  11. import random
  12. from time import *
  13. from PySide import QtGui, QtCore
  14.  
  15. # Camiones, probabilidad, probabilidad acumulada.
  16. CAMIONES = [(0, 0.5, 0.5), (1, 0.25, 0.75), (2, 0.15, 0.9), (3, 0.1, 1.0)]
  17.  
  18. # Minutos, probabilidad, probabilidad acumulada.
  19. LLEGADAS = [(20, 0.02, 0.02), (25, 0.08, 0.1), (30, 0.12, 0.22),
  20.                  (35, 0.25, 0.47), (40, 0.2, 0.67), (45, 0.15, 0.82),
  21.                  (50, 0.1, 0.92), (55, 0.05, 0.97), (60, 0.03, 1.0)]
  22.  
  23.  
  24.  
  25. _3PERSONAS = [(20, 0.05, 0.05), (25, 0.1, 0.15), (30, 0.2, 0.35), (35, 0.25, 0.6),
  26.                      (40, 0.12, 0.72), (45, 0.1, 0.82), (50, 0.08, 0.9),
  27.                      (55, 0.06, 0.96), (60, 0.04, 1.0)]
  28.  
  29.  
  30. _4PERSONAS = [(15, 0.05, 0.05), (20, 0.15, 0.2), (25, 0.2, 0.4),
  31.                      (30, 0.2, 0.6), (35, 0.15, 0.75), (40, 0.12, 0.87),
  32.                      (45, 0.08, 0.95), (50, 0.04, 0.99), (55, 0.01, 1.0)]
  33.  
  34. _5PERSONAS = [(10, 0.1, 0.1), (15, 0.18, 0.28), (20, 0.22, 0.5),
  35.                      (25, 0.18, 0.68), (30, 0.1, 0.78), (35, 0.08, 0.86),
  36.                      (40, 0.06, 0.92), (45, 0.05, 0.97), (50, 0.03, 1.0)]
  37.  
  38. _6PERSONAS = [(5, 0.12, 0.12), (10, 0.15, 0.27), (15, 0.26, 0.53),
  39.                      (20, 0.15, 0.68), (25, 0.12, 0.8), (30, 0.08, 0.88),
  40.                      (35, 0.06, 0.94), (40, 0.04, 0.98), (45, 0.02, 1.0)]
  41.  
  42. tiempos_llegadas = []
  43. hora_llegada = []
  44. hora_inicio = []
  45. tiempo_servicio = []
  46. hora_fin = []
  47. ocio_personal = []
  48. tiempo_espera = []
  49. cola = []
  50. comieron = []
  51. cola_aux = []
  52. atendido = []
  53.  
  54. class MainWindow(QtGui.QMainWindow):
  55.  
  56.     def __init__(self, parent=None):
  57.         super(MainWindow, self).__init__(parent)
  58.        
  59.         self.initUI()
  60.  
  61.     def initUI(self):
  62.         """ Starts Window GUI. """
  63.  
  64.         self.statusBar().showMessage('Listo.')
  65.  
  66.         self.widget = MainWidget()
  67.         self.setCentralWidget(self.widget)
  68.  
  69.         self.setGeometry(300, 300, 1100, 700)
  70.         self.setWindowTitle('Simulador de Colas - Camiones')
  71.         self.setWindowIcon(QtGui.QIcon('icon.png'))
  72.         self.show()
  73.  
  74. class MainWidget(QtGui.QWidget):
  75.  
  76.     def __init__(self, parent=None):
  77.         super(MainWidget, self).__init__(parent)
  78.         self.initUI()
  79.  
  80.     def initUI(self):
  81.         """ Starts MainWidget GUI. """
  82.  
  83.         self.grid = QtGui.QGridLayout()
  84.         self.grid.setSpacing(10)
  85.  
  86.         self.valida = QtGui.QDoubleValidator()
  87.         self.valida_workers = QtGui.QIntValidator(1,6)
  88.  
  89.         self.groupbox = QtGui.QGroupBox("Opciones de Inicio")
  90.  
  91.         self.salario = QtGui.QLabel('Salario por hora')
  92.         self.salario_edit = QtGui.QLineEdit('25')
  93.         self.salario_edit.setValidator(self.valida)
  94.         self.salario_edit.setMaximumWidth(45)
  95.  
  96.         self.hora_extra = QtGui.QLabel('Hora extra')
  97.         self.hora_extra_edit = QtGui.QLineEdit('37.5')
  98.         self.hora_extra_edit.setValidator(self.valida)
  99.         self.hora_extra_edit.setMaximumWidth(45)
  100.  
  101.         self.costo_espera_camion = QtGui.QLabel('Costo de espera por trailer por hora')
  102.         self.costo_espera_camion_edit = QtGui.QLineEdit('100')
  103.         self.costo_espera_camion_edit.setValidator(self.valida)
  104.         self.costo_espera_camion_edit.setMaximumWidth(45)
  105.  
  106.         self.costo_opera_bodega = QtGui.QLabel('Costo de operar la bodega por hora')
  107.         self.costo_opera_bodega_edit = QtGui.QLineEdit('500')
  108.         self.costo_opera_bodega_edit.setValidator(self.valida)
  109.         self.costo_opera_bodega_edit.setMaximumWidth(45)
  110.  
  111.         self.hora_entrada = QtCore.QTime(11, 00)
  112.         self.hora_entrada_label = QtGui.QLabel('Hora de entrada')
  113.         self.hora_entrada_edit = QtGui.QTimeEdit()
  114.         self.hora_entrada_edit.setTime(self.hora_entrada)
  115.  
  116.         self.hora_salida = QtCore.QTime(19, 30)
  117.         self.hora_salida_label = QtGui.QLabel('Hora de salida')
  118.         self.hora_salida_edit = QtGui.QTimeEdit()
  119.         self.hora_salida_edit.setTime(self.hora_salida)
  120.  
  121.         self.empleados = QtGui.QLabel('No. de empleados')
  122.         self.empleados_edit = QtGui.QLineEdit('3')
  123.         self.empleados_edit.setValidator(self.valida_workers)
  124.         self.empleados_edit.setMaximumWidth(45)
  125.  
  126.         self.genera_button = QtGui.QPushButton('Simular')
  127.         self.genera_button.clicked.connect(imprime)
  128.         self.genera_button.setMaximumWidth(60)
  129.  
  130.         self.output = QtGui.QTextEdit()
  131.         self.output.setReadOnly(True)
  132.  
  133.         self.vbox = QtGui.QVBoxLayout()
  134.  
  135.         self.vbox.addWidget(self.salario)
  136.         self.vbox.addWidget(self.salario_edit)
  137.  
  138.         self.vbox.addWidget(self.hora_extra)
  139.         self.vbox.addWidget(self.hora_extra_edit)
  140.  
  141.         self.vbox.addWidget(self.costo_espera_camion)
  142.         self.vbox.addWidget(self.costo_espera_camion_edit)
  143.  
  144.         self.vbox.addWidget(self.costo_opera_bodega)
  145.         self.vbox.addWidget(self.costo_opera_bodega_edit)
  146.  
  147.         self.vbox.addWidget(self.hora_entrada_label)
  148.         self.vbox.addWidget(self.hora_entrada_edit)
  149.  
  150.         self.vbox.addWidget(self.hora_salida_label)
  151.         self.vbox.addWidget(self.hora_salida_edit)
  152.  
  153.         self.vbox.addWidget(self.empleados)
  154.         self.vbox.addWidget(self.empleados_edit)
  155.  
  156.         self.vbox.addWidget(self.genera_button)
  157.  
  158.         self.grid.addLayout(self.vbox, 0, 1)
  159.         self.grid.addWidget(self.output, 0, 3, 2, 5)
  160.        
  161.         self.grid.setColumnStretch(1,2)
  162.         self.grid.setColumnStretch(2,1)
  163.         self.grid.setColumnStretch(3,7)
  164.  
  165.         self.setLayout(self.grid)
  166.         self.show()
  167.  
  168. def get_x_numbers(x):
  169.     """ Regresa una lista de x numeros aleatorios """
  170.     numbers = []
  171.     for i in range(x):
  172.         numbers.append(random.random())
  173.  
  174.     return numbers
  175.  
  176. def get_camiones():
  177.     """ Genera los camiones iniciales """
  178.     if inicio <= CAMIONES[0][2]:
  179.         x = 0
  180.     elif inicio > CAMIONES[0][2] and inicio <= CAMIONES[1][2]:
  181.         x=1
  182.     elif inicio > CAMIONES[1][2] and inicio <= CAMIONES[2][2]:
  183.         x = 2
  184.     else:
  185.         x = 3
  186.     return x
  187.  
  188. def get_tiempo_llegadas(index):
  189.     """ Regresa los minutos que tardo el siguiente camion en llegar dependiendo
  190.    del numero aleatorio generado en numeros[index].
  191.  
  192.    La tupla tiene el formato: (Minutos, probabilidad, probabilidad acumulada).
  193.  
  194.    """
  195.  
  196.     if numeros[index] <= LLEGADAS[0][2]:
  197.         tiempo_llegadas = LLEGADAS[0][0]
  198.     elif numeros[index] > LLEGADAS[0][2] and numeros[index] <= LLEGADAS[1][2]:
  199.         tiempo_llegadas = LLEGADAS[1][0]
  200.     elif numeros[index] > LLEGADAS[1][2] and numeros[index] <= LLEGADAS[2][2]:
  201.         tiempo_llegadas = LLEGADAS[2][0]
  202.     elif numeros[index] > LLEGADAS[2][2] and numeros[index] <= LLEGADAS[3][2]:
  203.         tiempo_llegadas = LLEGADAS[3][0]
  204.     elif numeros[index] > LLEGADAS[3][2] and numeros[index] <= LLEGADAS[4][2]:
  205.         tiempo_llegadas = LLEGADAS[4][0]
  206.     elif numeros[index] > LLEGADAS[4][2] and numeros[index] <= LLEGADAS[5][2]:
  207.         tiempo_llegadas = LLEGADAS[5][0]
  208.     elif numeros[index] > LLEGADAS[5][2] and numeros[index] <= LLEGADAS[6][2]:
  209.         tiempo_llegadas = LLEGADAS[6][0]
  210.     elif numeros[index] > LLEGADAS[6][2] and numeros[index] <= LLEGADAS[7][2]:
  211.         tiempo_llegadas = LLEGADAS[7][0]
  212.     else:
  213.         tiempo_llegadas = LLEGADAS[8][0]
  214.  
  215.     return tiempo_llegadas
  216.    
  217.  
  218. def get_tiempo_servicio(index, personas):
  219.     """ Regresa los minutos que tardo el servicio dependiendo del numero
  220.    de personas y el aleatorio generado en numeros1[index].
  221.  
  222.    La tupla tiene el formato: (Minutos, probabilidad, probabilidad acumulada).
  223.  
  224.    """
  225.    
  226.     if personas == '3':
  227.         if numeros1[index] <= _3PERSONAS[0][2]:
  228.             tiempo_servicio = _3PERSONAS[0][0]
  229.         elif numeros1[index] > _3PERSONAS[0][2] and numeros1[index] <= _3PERSONAS[1][2]:
  230.             tiempo_servicio = _3PERSONAS[1][0]
  231.         elif numeros1[index] > _3PERSONAS[1][2] and numeros1[index] <= _3PERSONAS[2][2]:
  232.             tiempo_servicio = _3PERSONAS[2][0]
  233.         elif numeros1[index] > _3PERSONAS[2][2] and numeros1[index] <= _3PERSONAS[3][2]:
  234.             tiempo_servicio = _3PERSONAS[3][0]
  235.         elif numeros1[index] > _3PERSONAS[3][2] and numeros1[index] <= _3PERSONAS[4][2]:
  236.             tiempo_servicio = _3PERSONAS[4][0]
  237.         elif numeros1[index] > _3PERSONAS[4][2] and numeros1[index] <= _3PERSONAS[5][2]:
  238.             tiempo_servicio = _3PERSONAS[5][0]
  239.         elif numeros1[index] > _3PERSONAS[5][2] and numeros1[index] <= _3PERSONAS[6][2]:
  240.             tiempo_servicio = _3PERSONAS[6][0]
  241.         elif numeros1[index] > _3PERSONAS[6][2] and numeros1[index] <= _3PERSONAS[7][2]:
  242.             tiempo_servicio = _3PERSONAS[7][0]
  243.         else:
  244.             tiempo_servicio = _3PERSONAS[8][0]
  245.     elif personas == '4':
  246.         if numeros1[index] <= _4PERSONAS[0][2]:
  247.             tiempo_servicio = _4PERSONAS[0][0]
  248.         elif numeros1[index] > _4PERSONAS[0][2] and numeros1[index] <= _4PERSONAS[1][2]:
  249.             tiempo_servicio = _4PERSONAS[1][0]
  250.         elif numeros1[index] > _4PERSONAS[1][2] and numeros1[index] <= _4PERSONAS[2][2]:
  251.             tiempo_servicio = _4PERSONAS[2][0]
  252.         elif numeros1[index] > _4PERSONAS[2][2] and numeros1[index] <= _4PERSONAS[3][2]:
  253.             tiempo_servicio = _4PERSONAS[3][0]
  254.         elif numeros1[index] > _4PERSONAS[3][2] and numeros1[index] <= _4PERSONAS[4][2]:
  255.             tiempo_servicio = _4PERSONAS[4][0]
  256.         elif numeros1[index] > _4PERSONAS[4][2] and numeros1[index] <= _4PERSONAS[5][2]:
  257.             tiempo_servicio = _4PERSONAS[5][0]
  258.         elif numeros1[index] > _4PERSONAS[5][2] and numeros1[index] <= _4PERSONAS[6][2]:
  259.             tiempo_servicio = _4PERSONAS[6][0]
  260.         elif numeros1[index] > _4PERSONAS[6][2] and numeros1[index] <= _4PERSONAS[7][2]:
  261.             tiempo_servicio = _4PERSONAS[7][0]
  262.         else:
  263.             tiempo_servicio = _4PERSONAS[8][0]
  264.     elif personas == '5':
  265.         if numeros1[index] <= _5PERSONAS[0][2]:
  266.             tiempo_servicio = _5PERSONAS[0][0]
  267.         elif numeros1[index] > _5PERSONAS[0][2] and numeros1[index] <= _5PERSONAS[1][2]:
  268.             tiempo_servicio = _5PERSONAS[1][0]
  269.         elif numeros1[index] > _5PERSONAS[1][2] and numeros1[index] <= _5PERSONAS[2][2]:
  270.             tiempo_servicio = _5PERSONAS[2][0]
  271.         elif numeros1[index] > _5PERSONAS[2][2] and numeros1[index] <= _5PERSONAS[3][2]:
  272.             tiempo_servicio = _5PERSONAS[3][0]
  273.         elif numeros1[index] > _5PERSONAS[3][2] and numeros1[index] <= _5PERSONAS[4][2]:
  274.             tiempo_servicio = _5PERSONAS[4][0]
  275.         elif numeros1[index] > _5PERSONAS[4][2] and numeros1[index] <= _5PERSONAS[5][2]:
  276.             tiempo_servicio = _5PERSONAS[5][0]
  277.         elif numeros1[index] > _5PERSONAS[5][2] and numeros1[index] <= _5PERSONAS[6][2]:
  278.             tiempo_servicio = _5PERSONAS[6][0]
  279.         elif numeros1[index] > _5PERSONAS[6][2] and numeros1[index] <= _5PERSONAS[7][2]:
  280.             tiempo_servicio = _5PERSONAS[7][0]
  281.         else:
  282.             tiempo_servicio = _5PERSONAS[8][0]
  283.     elif personas == '6':
  284.         if numeros1[index] <= _6PERSONAS[0][2]:
  285.             tiempo_servicio = _6PERSONAS[0][0]
  286.         elif numeros1[index] > _6PERSONAS[0][2] and numeros1[index] <= _6PERSONAS[1][2]:
  287.             tiempo_servicio = _6PERSONAS[1][0]
  288.         elif numeros1[index] > _6PERSONAS[1][2] and numeros1[index] <= _6PERSONAS[2][2]:
  289.             tiempo_servicio = _6PERSONAS[2][0]
  290.         elif numeros1[index] > _6PERSONAS[2][2] and numeros1[index] <= _6PERSONAS[3][2]:
  291.             tiempo_servicio = _6PERSONAS[3][0]
  292.         elif numeros1[index] > _6PERSONAS[3][2] and numeros1[index] <= _6PERSONAS[4][2]:
  293.             tiempo_servicio = _6PERSONAS[4][0]
  294.         elif numeros1[index] > _6PERSONAS[4][2] and numeros1[index] <= _6PERSONAS[5][2]:
  295.             tiempo_servicio = _6PERSONAS[5][0]
  296.         elif numeros1[index] > _6PERSONAS[5][2] and numeros1[index] <= _6PERSONAS[6][2]:
  297.             tiempo_servicio = _6PERSONAS[6][0]
  298.         elif numeros1[index] > _6PERSONAS[6][2] and numeros1[index] <= _6PERSONAS[7][2]:
  299.             tiempo_servicio = _6PERSONAS[7][0]
  300.         else:
  301.             tiempo_servicio = _6PERSONAS[8][0]
  302.  
  303.     return tiempo_servicio
  304.  
  305. def imprime():
  306.     """ Imprimer la tabla con los resultados """
  307.     proceso()
  308.     ex.widget.output.setHtml("|| R ------------------|| T. Llegadas || Llegada || Inicio servicio || R -----------------|| T. Servicio || Fin servicio || Ocio Personal || T. Espera || Cola ||")
  309.     ex.widget.output.append("\n")
  310.     for i in range(len(numeros)-1):
  311.         ex.widget.output.append("|| " + str(numeros[i]) + " || "
  312.                                 + "------" + str(tiempos_llegadas[i]) + "------" + " || "
  313.                                 + hora_llegada[i].toString("hh:mm") + " || "
  314.                                 + hora_inicio[i].toString("hh:mm") + " || "
  315.                                 + str(numeros1[i]) + " || "
  316.                                 + "------" + str(tiempo_servicio[i]) + "------" + " ||"
  317.                                 + hora_fin[i].toString("hh:mm") + " || "
  318.                                 + "------" + str(ocio_personal[i]) + "------" + " || "
  319.                                 + "------" + str(tiempo_espera[i]) + "------" + " || "
  320.                                 + "------" + str(cola[i]) + "-----" + " || \n")
  321.     ex.widget.output.append('\nLa hora de la salida fue a las <b>' + salida_real.toString("hh:mm") + '</b>')
  322.     ex.widget.output.append('\nLos trabajadores hicieron <b>' + str(horas_extra) + ' minutos</b> extra.')
  323.     ex.widget.output.append('\nSu salario normal es <b>$' + str(pago) + '</b>.')
  324.     ex.widget.output.append('\nSu salario extra es <b>$' + str(pago_extra) + '</b>.')
  325.     ex.widget.output.append('\nSu salario total es <b>$' + str(pago_total) + '</b>.')
  326.     ex.widget.output.append('\nEl costo por todos los empleados es de <b>$' + str(costo_empleados) + '</b>.')
  327.     ex.widget.output.append('\nEl costo por tener esperando a los camiones fue de <b>$' + str(costo_espera) + '</b>.')
  328.     ex.widget.output.append('\nEl costo del almacen fue de <b>$' + str(costo_almacen) + '</b>.')
  329.     ex.widget.output.append('\nEl costo total fue de <b>$' + str(costo_total) + '</b> con <b>' + ex.widget.empleados_edit.text() + '</b> empleados.')
  330.  
  331. def cuenta_en_cola(index):
  332.     """ Cuenta cuantos camiones estan esperando """
  333.     weones = []
  334.  
  335.     for i in range(len(hora_fin)-1):
  336.         print "El len de hora_fin es " + str(len(hora_fin)-1)
  337.         if hora_llegada[index+1].__lt__(hora_fin[i]):
  338.             print "Si, la hora " + str(hora_llegada[index+1]) + "es menor a " + str(hora_fin[i])
  339.             weones.append(1)
  340.         else:
  341.             "No, no es menor"
  342.        
  343.     cuantos = sum(weones)
  344.  
  345.     return cuantos
  346.  
  347. def proceso():
  348.     """ El proceso de la simulacion """
  349.     global tiempos_llegadas
  350.     global hora_llegada
  351.     global hora_inicio
  352.     global tiempo_servicio
  353.     global hora_fin
  354.     global ocio_personal
  355.     global tiempo_espera
  356.     global cola
  357.     global comieron
  358.     global cola_aux
  359.     global atendido
  360.     global numeros
  361.     global numeros1
  362.     global inicio
  363.     global hora_salida
  364.  
  365.     numeros = get_x_numbers(20)
  366.     numeros1 = get_x_numbers(20)
  367.     inicio = random.uniform(0.5, 0.75)
  368.     hora_salida = ex.widget.hora_salida_edit.time()
  369.  
  370.     tiempos_llegadas = []
  371.     hora_llegada = []
  372.     hora_inicio = []
  373.     tiempo_servicio = []
  374.     hora_fin = []
  375.     ocio_personal = []
  376.     tiempo_espera = []
  377.     cola = []
  378.     comieron = []
  379.     cola_aux = []
  380.     atendido = []
  381.  
  382.     camiones_iniciales = get_camiones()
  383.  
  384.     #First run
  385.     if camiones_iniciales == 0:
  386.         tiempos_llegadas.append(0)
  387.         hora_llegada.append(0)
  388.         hora_inicio.append(0)
  389.         tiempo_servicio.append(0)
  390.         hora_fin.append(0)
  391.         ocio_personal.append(0)
  392.         tiempo_espera.append(0)
  393.         cola.append(0)
  394.         comieron.append(False)
  395.         atendido.append(True)
  396.     else:
  397.         tiempos_llegadas.append(0)
  398.         hora_llegada.append(ex.widget.hora_entrada_edit.time()) # Revisar toString
  399.         hora_inicio.append(ex.widget.hora_entrada_edit.time()) # Same
  400.         tiempo_servicio.append(
  401.             get_tiempo_servicio(0,ex.widget.empleados_edit.text()))
  402.         hora_fin.append(
  403.             ex.widget.hora_entrada_edit.time().addSecs(60 * tiempo_servicio[0]))
  404.         ocio_personal.append(0)
  405.         tiempo_espera.append(0)
  406.         cola.append(camiones_iniciales)
  407.         comieron.append(False)
  408.         atendido.append(True)
  409.  
  410.         cola_aux = list(cola)
  411.         print "Camiones iniciales son " + str(camiones_iniciales)
  412.  
  413.  
  414.     #Segundo Run
  415.     for index in range(len(numeros)-1):
  416.         print "Len de numeros es " + str(len(numeros)-1)
  417.         print "index es " + str(index)
  418.         #sleep(0.1)
  419.  
  420.         #Tier 1
  421.         #Tiempo entre llegadas
  422.         tiempos_llegadas.append(get_tiempo_llegadas(index))
  423.         print "el tiempo entre llegadas es de " + str(tiempos_llegadas[index+1])
  424.         #sleep(0.1)
  425.  
  426.         #Tiempo de Servicio
  427.         tiempo_servicio.append(get_tiempo_servicio(index, ex.widget.empleados_edit.text()))
  428.         print "el tiempo de servicio es " + str(tiempo_servicio[index+1])
  429.         #sleep(0.1)
  430.  
  431.        
  432.         #Ya comieron?
  433.         if comieron[index] is True:
  434.             comieron.append(True)
  435.         elif hora_fin[index].__ge__(hora_comida_inicia):
  436.             comieron.append(True)
  437.         else:
  438.             comieron.append(False)
  439.  
  440.         #Tier 2
  441.         #Hora de Llegada
  442.         hora_llegada.append(hora_llegada[index].addSecs(60 * tiempos_llegadas[index+1]))
  443.         print "la hora de llegada es " + str(hora_llegada[index+1])
  444.         #sleep(0.1)
  445.  
  446.         #Fue atendido?
  447.  
  448.         if hora_llegada[index+1].__le__(hora_salida):
  449.             #if hora_fin[index].__lt__(hora_salida):
  450.             atendido.append(True)
  451.             #else:
  452.                # atendido.append(False)
  453.         else:
  454.             atendido.append(False)
  455.  
  456.         if atendido[index+1] is False:
  457.             break
  458.  
  459.         #Tier 3
  460.         #Hora de Inicio de Servicio
  461.         if hora_fin[index].__lt__(hora_llegada[index+1]):
  462.             if comieron[index+1] is True:
  463.                 if comieron[index] is False:
  464.                     hora_inicio.append(hora_llegada[index+1].addSecs(60 * 30))
  465.                 else:
  466.                     hora_inicio.append(hora_llegada[index+1])
  467.             else:
  468.                 hora_inicio.append(hora_llegada[index+1])
  469.         elif comieron[index+1] is True:
  470.             if comieron[index] is False:
  471.                 hora_inicio.append(hora_fin[index].addSecs(60 * 30))
  472.             else:
  473.                 hora_inicio.append(hora_fin[index])
  474.         else:
  475.             hora_inicio.append(hora_fin[index])
  476.  
  477.         print "Hora de inicio de servicio es " + str(hora_inicio[index+1])
  478.  
  479.         #Tier 4
  480.         #Hora de Fin de Servicio
  481.         hora_fin.append(hora_inicio[index+1].addSecs(
  482.             60 * tiempo_servicio[index+1]))
  483.         print "la hora de fin de servicio es " + str(hora_fin[index+1])
  484.         #sleep(0.1)
  485.  
  486.         #Tier 5
  487.         #Tiempo de espera
  488.         yeah = hora_llegada[index+1].secsTo(hora_inicio[index+1])
  489.         print "yeah es " + str(yeah)
  490.         if yeah < 0:
  491.             yeah= (yeah + 86400) / 60
  492.         else:
  493.             yeah = yeah / 60
  494.            
  495.         tiempo_espera.append(yeah)
  496.         print "El tiempo de espera es " + str(tiempo_espera[index+1])
  497.         #sleep(0.1)
  498.  
  499.         #Tier 6
  500.         #Cola
  501.  
  502.         cola_aux.append(cuenta_en_cola(index))
  503.         print "Cola aux es " + str(cola_aux[index+1])
  504.  
  505.         cola.append(cola_aux[index+1])
  506.         print "La cola es de " + str(cola[index+1])
  507.  
  508.         #Tier 7
  509.         #Ocio del personal
  510.         lulz = hora_fin[index].secsTo(hora_inicio[index+1])
  511.         print "lulz es " + str(lulz)
  512.         if lulz < 0:
  513.             lulz = (lulz + 86400) / 60
  514.         else:
  515.             lulz = lulz / 60
  516.         ocio_personal.append(lulz)
  517.         print "El ocio es de " + str(ocio_personal[index+1])
  518.  
  519.     global salida_real
  520.     global horas_extra
  521.     global pago
  522.     global pago_extra
  523.     global pago_total
  524.     global costo_empleados
  525.     global costo_espera
  526.     global costo_almacen
  527.     global costo_total
  528.  
  529.     if hora_fin[len(hora_fin)-1].__gt__(hora_salida):
  530.         salida_real = hora_fin[len(hora_fin)-1]
  531.     else:
  532.         salida_real = hora_salida
  533.  
  534.     if len(numeros) > len(tiempos_llegadas):
  535.         while len(numeros) != len(tiempos_llegadas):
  536.             tiempos_llegadas.append(0)
  537.  
  538.     if len(numeros) > len(hora_llegada):
  539.         while len(numeros) != len(hora_llegada):
  540.             hora_llegada.append(QtCore.QTime(0,0))
  541.            
  542.     if len(numeros) > len(hora_inicio):
  543.         while len(numeros) != len(hora_inicio):
  544.             hora_inicio.append(QtCore.QTime(0,0))
  545.  
  546.     if len(numeros) > len(tiempo_servicio):
  547.         while len(numeros) != len(tiempo_servicio):
  548.             tiempo_servicio.append(0)
  549.  
  550.     if len(numeros) > len(hora_fin):
  551.         while len(numeros) != len(hora_fin):
  552.             hora_fin.append(QtCore.QTime(0,0))
  553.  
  554.     if len(numeros) > len(ocio_personal):
  555.         while len(numeros) != len(ocio_personal):
  556.             ocio_personal.append(0)
  557.  
  558.     if len(numeros) > len(tiempo_espera):
  559.         while len(numeros) != len(tiempo_espera):
  560.             tiempo_espera.append(0)
  561.  
  562.     if len(numeros) > len(cola):
  563.         while len(numeros) != len(cola):
  564.             cola.append(0)
  565.  
  566.     """
  567.    hora_fin.append(QtCore.QTime(0,0))
  568.    hora_inicio.append(QtCore.QTime(0,0))
  569.    tiempo_servicio.append(0)
  570.    ocio_personal.append(0)
  571.    tiempo_espera.append(0)
  572.    cola.append(0) """
  573.  
  574.     print len(numeros)
  575.     print len(tiempos_llegadas)
  576.     print len(hora_llegada)
  577.     print len(hora_inicio)
  578.     print len(numeros1)
  579.     print len(tiempo_servicio)
  580.     print len(hora_fin)
  581.     print len(ocio_personal)
  582.     print len(tiempo_espera)
  583.     print len(cola)
  584.    
  585.        
  586.     print "El ultimo camion se descargo a las " + str(salida_real)
  587.  
  588.     horas_extra = hora_salida.secsTo(salida_real) / 60
  589.     print "Los trabajadores jalaron extra %s minutos " % str(horas_extra)
  590.  
  591.     pago = float(ex.widget.salario_edit.text()) * 8
  592.     print "Su salario normal es " + str(pago)
  593.  
  594.     pago_extra = float(ex.widget.hora_extra_edit.text()) * (float(horas_extra) / 60)
  595.     print "Su salario extra es " + str(pago_extra)
  596.  
  597.     pago_total = pago + pago_extra
  598.     print "Su pago total es " +str(pago_total)
  599.  
  600.     costo_empleados = pago_total * float(ex.widget.empleados_edit.text())
  601.     print "Por todos los empleados el salario total es de " + str(costo_empleados)
  602.  
  603.     tiempo_total_espera = sum(tiempo_espera)
  604.     costo_espera = float(tiempo_total_espera) * float(ex.widget.costo_espera_camion_edit.text()) / 60
  605.     print "El costo total de tener esperando a los camiones fue de " + str(costo_espera)
  606.    
  607.     costo_almacen = float(ex.widget.costo_opera_bodega_edit.text()) *  (float(ex.widget.hora_entrada.secsTo(salida_real)) / 3600)
  608.     print "El costo del almacen fue de " + str(costo_almacen)
  609.  
  610.     costo_total = costo_empleados + costo_espera + costo_almacen
  611.     print "El costo total con %s personas fue de %f" % (ex.widget.empleados_edit.text(), costo_total)
  612.  
  613.     print "------------- Fin de la corrida -----------------------"
  614.  
  615. def main():
  616.     app = QtGui.QApplication(sys.argv)
  617.  
  618.     global ex
  619.     global hora_comida_inicia
  620.  
  621.     hora_comida_inicia = QtCore.QTime(15,0)
  622.    
  623.     ex = MainWindow()
  624.     sys.exit(app.exec_())    
  625.  
  626. if __name__ == '__main__':
  627.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement