def save_plan_prod(self):
     if not self.plan_prod.new_plan:
         self.update_plan_prod_on_database(plan_prod=self.plan_prod)
     else:
         code_bobines_selected = get_code_bobine_selected(
             self.plan_prod.bobines_filles_selected)
         code_data_reglages = self.plan_prod.data_reglages.get_data_reglage_code(
         )
         Database.create_plan_prod(
             p_id=self.plan_prod.p_id,
             bobine_papier=self.plan_prod.bobine_papier_selected.code,
             code_bobines_selected=code_bobines_selected,
             refente=self.plan_prod.refente_selected.code,
             start=self.plan_prod.start,
             longueur=self.plan_prod.longueur,
             tours=self.plan_prod.tours,
             bobine_poly=self.plan_prod.bobine_poly_selected.code,
             code_data_reglages=code_data_reglages,
             encrier_1=self.plan_prod.encrier_1.color,
             encrier_2=self.plan_prod.encrier_2.color,
             encrier_3=self.plan_prod.encrier_3.color)
         self.plan_prod.new_plan = False
         from gestion.stores.plan_prod_store import plan_prod_store
         plan_prod_store.plans_prods.append(self.plan_prod)
     self.update_plans_prods()
     self.SETTINGS_CHANGED_SIGNAL.emit()
Beispiel #2
0
 def add_raison_on_database(self):
     Database.create_raison_arret(
         _id=self.id,
         start_arret=self.start,
         type_arret=self.type,
         raison_arret=self.raison,
         primaire=self.primaire)
 def add_data(self):
     try:
         ts = timestamp_at_day_ago(self.day_ago)
         self.update_raison_from_database()
         if self.data and self.day_ago > 0:
             pass
         else:
             new_data = Database.get_speeds(self.start * 1000,
                                            self.end * 1000)
             if not new_data:
                 return False, []
             self.data = clean_data_per_second(data=new_data,
                                               start=self.start,
                                               end=self.end)
             if self.day_ago > 0:
                 metrage = Database.get_metrages_for_one_day(start_time=ts)
                 metrage = metrage[0]
                 if not metrage:
                     metrage = self.get_live_stat(self.data, ts)
             else:
                 metrage = self.get_live_stat(self.data, ts)
             self.metrage_matin = round(metrage[0])
             self.metrage_soir = round(metrage[1])
         return True, self.update_arret()
     except:
         return False, []
 def save_event(self, event):
     Database.create_event_prod(start=event.start,
                                end=event.end,
                                p_type=event.type_event,
                                info=event.info,
                                ensemble=event.ensemble)
     from gestion.stores.event_store import event_store
     event_store.update()
     self.SETTINGS_CHANGED_SIGNAL.emit()
Beispiel #5
0
 def save_on_base_de_donnee(self):
     Database.save_dechet(id=self.id,
                          arret_start=self.start_arret,
                          type=self.type,
                          masse=self.masse,
                          piste=self.piste,
                          couleur=self.couleur,
                          grammage_papier=self.grammage_papier,
                          grammage_polypro=self.grammage_polypro)
 def add_defaut_day(self):
     start_week = timestamp_at_week_ago(self.week_ago)
     start_next_week = timestamp_at_week_ago(self.week_ago - 1)
     ts_day_ago = start_week
     while ts_day_ago <= start_next_week:
         if is_weekend(ts_day_ago):
             break
         else:
             Database.add_defaut_day(ts_day_ago)
         ts_day_ago += 86400
Beispiel #7
0
 def add_defaut_stop_prod(self):
     day_ago = settings_store_gestion.day_ago
     start_defaut_stop_prod = timestamp_at_time(
         timestamp_at_day_ago(day_ago), hours=FIN_PROD_SOIR_VENDREDI)
     end_defaut_stop_prod = timestamp_at_time(timestamp_at_day_ago(day_ago),
                                              hours=FIN_PROD_SOIR)
     Database.create_event_prod(start=start_defaut_stop_prod,
                                end=end_defaut_stop_prod,
                                p_type="stop")
     self.update()
Beispiel #8
0
 def get_raisons(self):
     list_raisons = Database.get_raison(self.start, self.end)
     # On parcour les raisons de la base de donnée
     for raison in list_raisons:
         start_raison = raison[1]
         id_raison = raison[0]
         # Test si le start de la raison correspond au start de l'arret
         if start_raison == self.start:
             # Test si la raison est déja renseigné dans la liste des raisons
             if self.check_id_raison(id_raison):
                 # Si oui on ne fait rien
                 continue
             else:
                 # Sinon on crée un models raison est on l'insert dans le tableau de raison de l'arret
                 raison_object = Raison(raison)
                 self.raisons.append(raison_object)
     for raison in self.raisons:
         raison_remove = True
         for raison_on_data_base in list_raisons:
             if raison_on_data_base[0] == raison.id:
                 raison_remove = False
                 break
         if raison_remove:
             self.raisons.remove(raison)
     self.raison_store()
 def update_plan_prod_on_database(plan_prod):
     code_bobines_selected = get_code_bobine_selected(
         plan_prod.bobines_filles_selected)
     code_data_reglages = plan_prod.data_reglages.get_data_reglage_code()
     Database.update_plan_prod(
         p_id=plan_prod.p_id,
         bobine_papier=plan_prod.bobine_papier_selected.code,
         code_bobines_selected=code_bobines_selected,
         refente=plan_prod.refente_selected.code,
         start=plan_prod.start,
         longueur=plan_prod.longueur,
         tours=plan_prod.tours,
         bobine_poly=plan_prod.bobine_poly_selected.code,
         code_data_reglages=code_data_reglages,
         encrier_1=plan_prod.encrier_1.color,
         encrier_2=plan_prod.encrier_2.color,
         encrier_3=plan_prod.encrier_3.color)
Beispiel #10
0
 def get_data_on_database(start, end):
     """
     Récupère les données en base de donnée
     :param start: Début des données a récupérer
     :param end: Fin des données a récupérer
     :return: Les données
     """
     if settings_stat_store.data_type == "métrage":
         data = Database.get_metrages(start_time=start, end_time=end)
         data.sort()
     elif settings_stat_store.data_type == "temps":
         data = Database.get_arret(start_time=start, end_time=end)
     else:
         data = [
             Database.get_arret(start_time=start, end_time=end),
             Database.get_raison(start_time=start, end_time=end)
         ]
     return data
Beispiel #11
0
 def update_arret(self):
     ts = timestamp_at_day_ago(self.day_ago)
     list_arrets_database = Database.get_arret(self.start, self.end)
     self.dic_arret_from_database(list_arrets_database)
     list_arrets_data = self.list_new_arret_data()
     list_new_arret = self.update_dic_arret(list_arrets_data)
     self.arrets = self.convert_dic_to_array(self.dic_arret)
     if self.arrets:
         self.get_arret_stat(ts)
     return list_new_arret
Beispiel #12
0
 def get_jour_metrage():
     """
     Recupere les jours ou les metrages sont deja renseignees en base de donnee
     :return: Une liste des jours
     """
     list_jour_metrage = Database.get_all_jour_metrages()
     clean_list = []
     for jour_metrage in list_jour_metrage:
         ts = jour_metrage[0]
         clean_list.append(ts)
     return clean_list
 def add_data(self):
     self.current_data = []
     all_data = Database.get_team_gestion()
     for data in all_data:
         start_day = data[0]
         start_week = timestamp_at_week_ago(
             settings_team_gestion_store.week_ago)
         start_next_week = timestamp_at_week_ago(
             settings_team_gestion_store.week_ago - 1)
         if start_week <= start_day < start_next_week:
             self.current_data.append(data)
 def get_plan_prod_from_database(self):
     data_plan_prod_on_data_base = Database.get_plan_prod()
     for data in data_plan_prod_on_data_base:
         start = data[1]
         new_plan_prod = PlanProd(
             last_plan_prod=self.get_last_plan_prod(start_plan_prod=start),
             data=data)
         self.plans_prods.append(new_plan_prod)
     self.sort_plans_prods()
     for plan_prod in self.plans_prods:
         plan_prod.update_from_last_plan_prod()
 def init_refente_store():
     data_refentes = Database.get_refente()
     for data_refente in data_refentes:
         new_refente = Refente(code=data_refente[0],
                               code_perfo=data_refente[1],
                               dec=data_refente[2],
                               laize1=data_refente[3],
                               laize2=data_refente[4],
                               laize3=data_refente[5],
                               laize4=data_refente[6],
                               laize5=data_refente[7],
                               laize6=data_refente[8],
                               laize7=data_refente[9],
                               chute=data_refente[10])
         refente_store.add_item(new_refente)
Beispiel #16
0
 def get_event_from_database(self):
     self.events = []
     event_on_data_base = Database.get_event_prod()
     day_ago = settings_store_gestion.day_ago if settings_store_gestion.day_ago > 0 else 0
     start_ts = timestamp_at_day_ago(day_ago)
     for event in event_on_data_base:
         if start_ts < event[2]:
             from commun.model.event import Event
             event = Event(p_type=event[1],
                           start=event[2],
                           end=event[3],
                           info=event[4],
                           p_id=event[0],
                           ensemble=event[5])
             self.events.append(event)
     self.sort_events()
 def init_perfo_store():
     data_perfos = Database.get_perfo()
     for data_perfo in data_perfos:
         new_perfo = Perfo(code=data_perfo[0],
                           dec_init=data_perfo[1],
                           cale1=data_perfo[2],
                           bague1=data_perfo[3],
                           cale2=data_perfo[4],
                           bague2=data_perfo[5],
                           cale3=data_perfo[6],
                           bague3=data_perfo[7],
                           cale4=data_perfo[8],
                           bague4=data_perfo[9],
                           cale5=data_perfo[10],
                           bague5=data_perfo[11],
                           cale6=data_perfo[12],
                           bague6=data_perfo[13],
                           cale7=data_perfo[14],
                           bague7=data_perfo[15])
         perfo_store.add_item(new_perfo)
Beispiel #18
0
 def remove_to_raison_primaire(self):
     Database.update_to_raison_primaire(_id=self.id, primaire=0)
     self.primaire = 0
Beispiel #19
0
 def create_on_database(self):
     """
     S'occupe de créer l'arret en base de donnée
     Vérifie si l'arrêt est déja présent en base de donnée
     """
     Database.create_arret(start_arret=self.start, end_arret=self.end)
 def delete_plan_prod(self, plan_prod):
     Database.delete_plan_prod(p_id=plan_prod.p_id)
     from gestion.stores.plan_prod_store import plan_prod_store
     plan_prod_store.plans_prods.remove(plan_prod)
     self.update_plans_prods()
     self.SETTINGS_CHANGED_SIGNAL.emit()
 def delete_event(self, event):
     Database.delete_event_prod(p_id=event.p_id)
     from gestion.stores.event_store import event_store
     event_store.update()
     self.SETTINGS_CHANGED_SIGNAL.emit()
Beispiel #22
0
 def update_arret(self):
     """
     S'occupe de mettre a jours l'arret en base de donnée
     """
     Database.update_arret(start_arret=self.start, end_arret=self.end)
Beispiel #23
0
def update_data_metrage():
    """
    Donnee enregistree de maniere fiable depuis le 23/10/2017 semaine 43 (timestamp: 1508709600)
    Fonction appele a chaque demarrage de l'application
    Parcour tout les jours depuis le 23/10/2017 jusqu'a hier
    Verifie si les donnees metrages de chaque jour est renseigne en base de donnee
    Si les donnees metrages n'existes pas on les calculs et on les inserts en base de donnee
    """
    def get_jour_metrage():
        """
        Recupere les jours ou les metrages sont deja renseignees en base de donnee
        :return: Une liste des jours
        """
        list_jour_metrage = Database.get_all_jour_metrages()
        clean_list = []
        for jour_metrage in list_jour_metrage:
            ts = jour_metrage[0]
            clean_list.append(ts)
        return clean_list

    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"

    def get_metrage(data, vendredi):
        """
        Calcul les metrages de l'equipe du matin et du soir
        Prend en compte si on est vendredi
        :param data: Les donnees triees par seconde
        :param vendredi: True si on traite des donnees d'un vendredi
        :return: Les valeurs arrondies du metrage matin et soir
        """
        metrage_matin = 0
        metrage_soir = 0
        fin_prod_matin = FIN_PROD_MATIN_VENDREDI if vendredi else FIN_PROD_MATIN
        for value in data:
            ts = value[0]
            metrage = value[1] / 60 if value[1] > 0 else 0
            if ts < timestamp_at_time(ts, hours=fin_prod_matin):
                metrage_matin += metrage
            else:
                metrage_soir += metrage
        return round(metrage_matin), round(metrage_soir)

    # On recupere la liste des jours ou le metrage est renseigne en base de donnee
    list_jour_metrage_on_db = get_jour_metrage()
    # Debut des donnees fiable
    start_data_record = 1508709600
    # Duree d'un jour en ms
    ts_to_one_day = 86400
    # Timestamp du debut du jour actuel
    start_ts_of_current_day = timestamp_at_day_ago(day_ago=0)
    start_day = start_data_record
    while start_day < start_ts_of_current_day:
        if start_day in list_jour_metrage_on_db:
            pass
        else:
            start_time = timestamp_at_time(ts=start_day,
                                           hours=DEBUT_PROD_MATIN)
            end_time = timestamp_at_time(start_day, hours=FIN_PROD_SOIR)
            speed_data = Database.get_speeds(start_time=start_time * 1000,
                                             end_time=end_time * 1000)
            clean_speed_data = clean_data_per_second(speed_data, start_time,
                                                     end_time)
            total_metrage = get_metrage(data=clean_speed_data,
                                        vendredi=is_vendredi(start_day))
            Database.insert_jour_metrages(ts_jour=start_day,
                                          metrage_matin=total_metrage[0],
                                          metrage_soir=total_metrage[1])
        start_day = timestamp_after_day_ago(start_day, day_ago=1)
    return True
Beispiel #24
0
 def update_to_raison_primaire(self):
     Database.update_to_raison_primaire(_id=self.id, primaire=1)
     self.primaire = 1
Beispiel #25
0
 def del_raison_on_database(self):
     Database.delete_raison_arret(self.id)