def __init__(self, ticket_row, object_material): self.ticket_date = functions.to_datetime(ticket_row["fecha"]) self.material = object_material # self.status = ticket_row["estado_ot"] self.amount = int(ticket_row["cantidad"]) self.grep = ticket_row["grep"] self.set_material() self.is_closed = False self.days_to_close = None self.amount_left = self.amount self.is_broken = False self.is_partial_closed = False
def process_movements(self, df_movements): # Start Timer tic = time.time() message = "Set Historic Movements..." # ------------------------------------------------------------------------------------------------------------------ [self.materials_by_id[material].set_movements_for_teco_simulation(to_datetime(date), cram, amount) for material, date, cram, amount in df_movements.values if material in self.materials_by_id.keys()] # ------------------------------------------------------------------------------------------------------------------ # Stop Timer toc = time.time() elapsed_time_message(toc - tic, message)
def __init__(self, receiving_wh: str, date: dt.date, amount: int, leadtime: int = None, donating_wh: str = None): self.amount = amount self.receiving_wh = receiving_wh self.donating_wh = donating_wh if self.donating_wh is None: # It's a purchase movement self.is_purchase = True self.is_redistribution = False self.donating_wh = 'Buenos Aires' # All purchases arrive to 'Buenos Aires' else: self.is_redistribution = True self.is_purchase = False self.leadtime = leadtime self.emission_date = date # self.arrival_date = self.emission_date + dt.timedelta(days=round(self.leadtime)) self.arrival_date = to_datetime(self.emission_date + dt.timedelta(days=self.leadtime))
def process_demand(self, df_demand): """ Adding Material's demand :param df_demand: :param materials_by_id: :return: """ # Start Timer message = "Processing Demand..." tic = time.time() # ------------------------------------------------------------------------------------------------------------------ [self.materials_by_id[material].add_demand(to_datetime(date), warehouse, demand) for date, material, warehouse, demand in df_demand.values if material in self.materials_by_id] # ------------------------------------------------------------------------------------------------------------------ # Stop Timer toc = time.time() elapsed_time_message(toc - tic, message)
def process_movements(self, movements): # Start Timer tic = time.time() message = "Set Historic Movements..." # ------------------------------------------------------------------------------------------------------------------ greps_banned = [ wh for wh in list(movements['ce_alm_s44'].unique()) if wh not in self.data_class.relation_grep_wh.keys() ] # if greps_banned: # st.warning( # f"Las siguientes relaciones de centro-almacén no se encontraron en la base de datos relacion_grep_almacen: {greps_banned}. " # f"No serán tenidos en cuenta. Para que sean incluidos se deben agregar dichas relaciones con su grep correspondiente en relacion_grep_alamcen") df_movements = movements[~movements['ce_alm_s44'].isin(greps_banned)] df_movements['ce_alm_s44'] = df_movements['ce_alm_s44'].map( lambda x: self.data_class.relation_grep_wh[x]) # Load and process movements df_movements = df_movements.groupby( ["material", "fecha", "ce_alm_s44"])["cantidad"].sum().reset_index() # Convert date column to datetime df_movements["fecha"] = pd.to_datetime(df_movements["fecha"]) df_movements = df_movements[df_movements["fecha"] > self.starting_date] [ self.materials_by_id[material].set_movements_for_teco_simulation( to_datetime(date), cram, amount) for material, date, cram, amount in df_movements.values if material in self.materials_by_id.keys() ] # ------------------------------------------------------------------------------------------------------------------ # Stop Timer toc = time.time() elapsed_time_message(toc - tic, message)
def process_tickets_teco(self): """ Set GEU tickets for simulation tests :param engine: DB connection :param materials_by_id: {id, Material} :param starting_date: dt.date :return: void -> Complete GEU object info """ # Start Timer tic = time.time() message = "Set tickets for sim test..." # ------------------------------------------------------------------------------------------------------------------ # Load tickets query = f"""select * from p02_tickets_by_cram;""" df_tickets = create_query(query, self.conn) if self.grep_type == 'unicram': df_tickets["cram"] = 'C00' # Convert date columns to datetime df_tickets["fecha"] = pd.to_datetime(df_tickets["fecha"]) # Add tickets demands for greps without movements demands [self.materials_by_id[str(material)].add_demand(to_datetime(date), cram, int(amount)) for date, material, amount, cram in df_tickets[["fecha", "material", "cantidad", "cram"]].values if str(material) in self.materials_by_id.keys() and cram not in set([cram for date, cram, amount in self.materials_by_id[str(material)].demands])] # Create Ticket class df_tickets = df_tickets[["fecha", "material", "cantidad", "cram"]] df_tickets.columns = ["fecha", "material", "cantidad", "grep"] [Ticket(row, self.materials_by_id[str(row["material"])]) for iter, row in df_tickets.iterrows() if str(row["material"]) in self.materials_by_id.keys()] # ------------------------------------------------------------------------------------------------------------------ # Stop Timer toc = time.time() elapsed_time_message(toc - tic, message)
def set_movement(self, date, warehouse, amount): self.warehouses.add(warehouse) self.movements[(to_datetime(date), warehouse)] = amount
def try_format(value, format_): """Try to change type to datetime with the given format.""" try: return to_datetime(value, format_) except ValueError: return None