def get_stat(self): current_store = data_store_manager.get_current_store() metrage_matin = current_store.metrage_matin metrage_soir = current_store.metrage_soir arret_time_matin = current_store.arret_time_matin imprevu_arret_time_matin = current_store.imprevu_arret_time_matin arret_time_soir = current_store.arret_time_soir imprevu_arret_time_soir = current_store.imprevu_arret_time_soir if self.moment == "matin": result = metrage_matin arret_time = arret_time_matin imprevu_arret_time = imprevu_arret_time_matin elif self.moment == "soir": result = metrage_soir arret_time = arret_time_soir imprevu_arret_time = imprevu_arret_time_soir else: result = metrage_matin + metrage_soir arret_time = arret_time_matin + arret_time_soir imprevu_arret_time = imprevu_arret_time_matin + imprevu_arret_time_soir self.metre_value = result self.arret_time = arret_time self.imprevu_arret_time = imprevu_arret_time self.percent = get_ratio_prod(self.moment)
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
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")
def draw_chart_and_vertical_grid(self, p): debut, fin, ech = self.get_drawing_info() extra_drawing = 10 # Sur combien de pixels supplémentaires on trace à gauche et à droite t = debut + (self.drag_offset - extra_drawing) * ech i = -extra_drawing while i <= self.get_chart_width() + extra_drawing: if abs(timestamp_au_debut_de_hour(t) - t) < ech: self.draw_principale_x_axis(p, i, t) diff = 2 * ech for min in (15, 30, 45): current_diff = timestamp_au_debut_de_hour(t, min) - t if abs(current_diff) < diff: diff = current_diff if -ech / 2 <= diff < ech / 2: self.draw_secondaire_x_axis(p, i) speed = data_store_manager.get_current_store().get_speed( t, t + ech) self.draw_speed(p, i, speed) t += ech i += 1
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)
def create_master_stat(): back_ground_master_stat = MondonWidget() back_ground_master_stat.set_background_color(color_blanc) back_ground_master_stat.set_border(color=color_bleu_dune, size=1) hbox_master_stat = QHBoxLayout(back_ground_master_stat) current_store = data_store_manager.get_current_store() date = timestamp_to_date_little(timestamp_at_day_ago(current_store.day_ago)) label_date = QLabel(date) label_date.setStyleSheet(black_16_label_stylesheet) time_imprevu = current_store.imprevu_arret_time_matin + current_store.imprevu_arret_time_soir imprevu_time_str = str(timedelta(seconds=round(time_imprevu))) text_imprevu_time = ("{time} d'arrêt imprévu".format(time=imprevu_time_str)) label_imprevu_time = QLabel(text_imprevu_time) imprevu_time_label_stylesheet = red_16_bold_label_stylesheet if time_imprevu > 0 \ else green_16_bold_label_stylesheet label_imprevu_time.setStyleSheet(imprevu_time_label_stylesheet) metrage_total = current_store.metrage_matin + current_store.metrage_soir label_metrage_total = QLabel("{}m".format(affiche_entier(metrage_total))) label_metrage_total.setStyleSheet(black_16_label_stylesheet) percent = get_ratio_prod("total") label_percent = QLabel("{}%".format(percent)) if percent < 25: percent_stylesheet = red_16_bold_label_stylesheet elif percent < 50: percent_stylesheet = orange_16_bold_label_stylesheet else: percent_stylesheet = green_16_bold_label_stylesheet label_percent.setStyleSheet(percent_stylesheet) hbox_master_stat.addWidget(label_date, alignment=Qt.AlignLeft) hbox_master_stat.addWidget(label_percent) hbox_master_stat.addWidget(label_metrage_total) hbox_master_stat.addWidget(label_imprevu_time, alignment=Qt.AlignRight) return back_ground_master_stat
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