Example #1
0
 def is_vendredi(ts_day):
     """
     Test si un ts correspond à un vendredi
     :return: True si le ts correspond a un vendredi sinon False
     """
     day = timestamp_to_day(ts_day)
     return day == "vendredi"
Example #2
0
 def is_weekend(ts_day):
     """
     Test si un ts correspond à un jour du weekend (samedi ou dimanche)
     :return: True si le ts correspond a un samedi ou dimanche sinon False
     """
     day = timestamp_to_day(ts_day)
     return day == "samedi" or day == "dimanche"
Example #3
0
 def is_vendredi(ts):
     """
     Test si le jour d'un timestamp est vendredi
     :param ts: L etimestamp a tester
     :return: True si on est vendredi
     """
     return timestamp_to_day(ts) == "vendredi"
Example #4
0
 def get_start_and_end(self, ts):
     vendredi = timestamp_to_day(ts) == "vendredi"
     start = DEBUT_PROD_MATIN
     mid = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
     end = FIN_PROD_SOIR_VENDREDI if vendredi else FIN_PROD_SOIR
     if self.moment == "matin":
         end = mid
     if self.moment == "soir":
         start = mid
     return start, end
Example #5
0
    def get_arret(self):
        """
        S'occupe de créer une liste de models Arret pour le moment de la journée courante
        :return:
        """
        # Récupere le store courant
        store = data_store_manager.get_current_store()
        # Stock la liste des arrets trier par ordre croissant (par rapport au start)
        arrets = store.arrets
        # Récupere le dictionnaire des arrets
        dic_arret = store.dic_arret
        # Récupere le timestamp du jours actuel
        ts = timestamp_at_day_ago(self.day_ago)

        # Check si on est un vendredi
        # Dans ce cas les équipes travail 7h (6h-13h,13h-21h)
        vendredi = timestamp_to_day(ts) == "vendredi"
        start = DEBUT_PROD_MATIN
        mid = FIN_PROD_MATIN_VENDREDI if vendredi else DEBUT_PROD_SOIR
        end = FIN_PROD_SOIR_VENDREDI if vendredi else FIN_PROD_SOIR

        # Definit les bornes de sélection des arret en fonction du moment de la journée (matin ou soir)
        if self.moment == "matin":
            end = mid
        if self.moment == "soir":
            start = mid
        start_ts = timestamp_at_time(ts, hours=start)
        end_ts = timestamp_at_time(ts, hours=end)

        # Initialise la liste d'arret
        list_arret = []
        # Parcours la liste des arret
        for arret in arrets:
            start_arret = arret[0]
            end_arret = arret[1]
            # Si le debut de l'arret est compris dans les bornes de selection
            if end_ts >= start_arret >= start_ts:
                # Et si la fin de l'arret est bien definit
                if end_arret > 0:
                    # On ajoute a la liste des arrets l'models Arret stocké dans le dictionnaire
                    list_arret.append(dic_arret[start_arret])
            # Sinon on continue la boucle
            else:
                continue
        self.list_arret = list_arret
    def draw_speed(self, p):
        def get_speed():
            speeds = data_store_manager.get_current_store().data
            i = 0
            current_sum = 0
            new_data = []
            for speed in speeds:
                if i < 90:
                    value = speed[1]
                    current_sum += value
                else:
                    i = 0
                    new_data.append(round(current_sum / 90))
                    current_sum = 0
                i += 1
            new_data.append(round(current_sum / 90))
            return new_data

        speeds = get_speed()
        i = 0
        for speed in speeds:
            speed = speed if speed < 190 else 190
            color = color_vert if speed > VITESSE_LIMITE_ASSIMILATION_ARRET else color_rouge
            draw_rectangle(p, self.X_CHART + i,
                           self.H_CHART - speed + self.Y_CHART, 1, speed + 1,
                           color)
            i += 1
        current_store = data_store_manager.get_current_store()
        vendredi = timestamp_to_day(timestamp_at_day_ago(
            current_store.day_ago)) == "vendredi"
        if vendredi:
            draw_rectangle(p, self.X_CHART + (40 * 14), self.Y_CHART, 40 * 2,
                           self.H_CHART, color_gris_moyen)
            draw_text(p,
                      self.X_CHART + (40 * 14),
                      self.Y_CHART,
                      40 * 2,
                      self.H_CHART,
                      color_gris_fonce,
                      align="C",
                      font_size=10,
                      text="Vendredi")
Example #7
0
def get_ratio_prod(moment):
    from production.stores.data_store_manager import data_store_manager
    current_store = data_store_manager.get_current_store()
    # Récupere le ts actuel
    ts_actuel = timestamp_now()

    # Calcul de la production maximum
    vendredi = timestamp_to_day(timestamp_at_day_ago(
        current_store.day_ago)) == "vendredi"
    if moment == "soir":
        debut_prod = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
    else:
        debut_prod = DEBUT_PROD_MATIN
    if moment == "matin":
        fin_prod = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
    else:
        fin_prod = FIN_PROD_SOIR_VENDREDI if vendredi else FIN_PROD_SOIR
    if ts_actuel < timestamp_at_time(current_store.start, hours=fin_prod):
        total_s = (ts_actuel -
                   timestamp_at_time(current_store.start, hours=debut_prod))
    else:
        total_s = 3600 * (fin_prod - debut_prod)
    max_prod = VITESSE_MOYENNE_MAXI * total_s / 60

    # Calcul le métrage total de la période
    metrage_total = 0
    if moment == "total":
        metrage_total = current_store.metrage_matin + current_store.metrage_soir
    if moment == "matin":
        metrage_total = current_store.metrage_matin
    if moment == "soir":
        metrage_total = current_store.metrage_soir

    # Calcul ratio
    if max_prod > 0 and metrage_total >= 0:
        ratio = metrage_total / max_prod * 100
        if ratio > 100:
            ratio = 100
    else:
        ratio = 0
    return round(ratio, 1)
Example #8
0
    def create_bloc_arret(moment):
        vbox = QVBoxLayout()
        current_store = data_store_manager.get_current_store()
        arrets = current_store.arrets
        vendredi = timestamp_to_day(timestamp_at_day_ago(current_store.day_ago)) == "vendredi"
        if moment == "matin":
            start_hour = DEBUT_PROD_MATIN
            end_hour = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
        else:
            start_hour = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
            end_hour = FIN_PROD_SOIR_VENDREDI if vendredi else FIN_PROD_SOIR
        start_ts = timestamp_at_time(timestamp_at_day_ago(current_store.day_ago), hours=start_hour)
        end_ts = timestamp_at_time(timestamp_at_day_ago(current_store.day_ago), hours=end_hour)
        # Trie les arrets par ordre chronologique
        arrets = sorted(arrets, key=lambda arret: arret[0])
        limit_imprevu = 0

        def count_valid_arret(arrets, limit_imprevu):
            count = 0
            for arret in arrets:
                start_arret = arret[0]
                end_arret = arret[1]
                type = arret[2][0].type if arret[2] else "non renseigné"
                if (start_ts <= start_arret <= end_ts and end_arret - start_arret >= 1800)\
                        or (start_ts <= start_arret <= end_ts and type == "Imprévu"
                            and end_arret - start_arret >= limit_imprevu):
                    count += 1
            return count > 10

        while count_valid_arret(arrets, limit_imprevu):
            limit_imprevu += 10

        for arret in arrets:
            container_arret = QVBoxLayout()
            container_arret.setSpacing(0)
            start_arret = arret[0]
            end_arret = arret[1]
            type = arret[2][0].type if arret[2] else "non renseigné"
            if (start_ts <= start_arret <= end_ts and end_arret - start_arret >= 1800) \
                    or (start_ts <= start_arret <= end_ts and type == "Imprévu"
                        and end_arret - start_arret >= limit_imprevu):
                start = str(timestamp_to_hour_little(start_arret))
                duree = str(timedelta(seconds=round(end_arret - start_arret)))
                text_arret = "Arrêt {type} à {start}, durée {duree}".format(type=type, start=start, duree=duree)
                if type == "Imprévu" or type == "non renseigné":
                    stylesheet = red_12_bold_label_stylesheet
                else:
                    stylesheet = blue_12_bold_label_stylesheet
                title_arret = QLabel(text_arret)
                title_arret.setStyleSheet(stylesheet)
                container_arret.addWidget(title_arret, alignment=Qt.AlignTop)

                def add_label_to_container(vbox, label):
                    label.setStyleSheet(black_12_label_stylesheet)
                    label.setWordWrap(True)
                    vbox.addWidget(label, alignment=Qt.AlignTop)
                    vbox.addLayout(container_arret)

                if arret[2]:
                    if type == "Imprévu":
                        for raison in arret[2]:
                            if raison.type == "Nettoyage" or raison.type == "Prévu":
                                continue
                            add_label_to_container(container_arret, QLabel(raison.raison))
                    else:
                        add_label_to_container(container_arret, QLabel(arret[2][0].raison))
                else:
                    add_label_to_container(container_arret, QLabel(""))
                vbox.addLayout(container_arret)
        vbox.addStretch(1)
        return vbox