Scheduling/model.py

126 lines
3.4 KiB
Python
Raw Normal View History

2021-04-18 05:53:07 +00:00
from __future__ import annotations
from datetime import datetime
2021-04-18 19:34:13 +00:00
from typing import List, Dict, Set, Optional
from utils import *
2021-04-18 05:53:07 +00:00
2021-04-18 19:34:13 +00:00
@auto_str
@auto_repr
2021-04-18 05:53:07 +00:00
class Order:
def __init__(self, order_id: str, description: str):
self.order_id: str = order_id
self.description: str = description
self.earliest_start_time: datetime = datetime.today()
self.latest_end_time: datetime = datetime.today()
self.products: List[Dict[str, any]] = []
def set_time(self, earliest_start_time: datetime, latest_end_time: datetime):
self.earliest_start_time = earliest_start_time
self.latest_end_time = latest_end_time
def add_product(self, product, amount):
self.products.append({
"product": product,
"amount": amount
})
2021-04-18 19:34:13 +00:00
@auto_str
@auto_repr
2021-04-18 05:53:07 +00:00
class Product:
def __init__(self, product_id: str, product_name: str):
self.product_id: str = product_id
self.product_name: str = product_name
2021-04-18 19:34:13 +00:00
self.semi_products: List[Dict[str, any]] = []
2021-04-19 09:37:36 +00:00
self.processes: List[Process] = []
2021-04-18 05:53:07 +00:00
2021-04-18 19:34:13 +00:00
def add_semi_product(self, semi_product: Product, amount):
if semi_product.product_id != self.product_id:
self.semi_products.append({
"semi_product": semi_product,
"amount": amount
})
2021-04-18 05:53:07 +00:00
2021-04-19 09:37:36 +00:00
def add_process(self, process):
self.processes.append(process)
2021-04-18 19:34:13 +00:00
@auto_str
@auto_repr
2021-04-18 05:53:07 +00:00
class Workspace:
def __init__(self, name: str):
self.name: str = name
2021-04-18 19:34:13 +00:00
@auto_str
@auto_repr
2021-04-18 05:53:07 +00:00
class Process:
def __init__(self,
pcs_id: str,
pcs_name: str,
product: Product,
workspace: Workspace):
self.pcs_id: str = pcs_id
self.pcs_name: str = pcs_name
self.product: Product = product
self.production_mode: int = 0
self.min_quantity: int = 0
self.max_quantity: int = 0
self.pdt_time: int = 0
2021-04-18 19:34:13 +00:00
self.prev_pcs: Optional[Process] = None
self.last_pcs: Optional[Process] = None
2021-04-18 05:53:07 +00:00
self.res_needs: List[Dict[str, any]] = []
self.workspace: Workspace = workspace
2021-04-18 19:34:13 +00:00
def set_pre_last_pcs(self, prev_pcs: Optional[Process], last_pcs: Optional[Process]):
self.prev_pcs: Process = prev_pcs
self.last_pcs: Process = last_pcs
2021-04-18 05:53:07 +00:00
def set_mode_quantity(self, production_mode: int, min_quantity: int, max_quantity: int):
self.production_mode: int = production_mode
self.min_quantity: int = max_quantity
self.max_quantity: int = min_quantity
def set_product_time(self, pdt_time: int):
self.pdt_time: int = pdt_time
def add_res_need(self, rcs_attr: str, amount: int):
2021-04-18 05:53:07 +00:00
self.res_needs.append({
"rcs_attr": rcs_attr,
2021-04-18 05:53:07 +00:00
"amount": amount
})
2021-04-18 19:34:13 +00:00
@auto_str
@auto_repr
2021-04-18 05:53:07 +00:00
class Resource:
2021-04-19 09:37:36 +00:00
def __init__(self, rsc_id: str, rsc_name: str, rsc_type: str, workspace: str):
2021-04-18 05:53:07 +00:00
self.rsc_id: str = rsc_id
self.rsc_name: str = rsc_name
self.rsc_type: str = rsc_type
2021-04-18 19:34:13 +00:00
self.amount: int = 0
2021-04-18 05:53:07 +00:00
2021-04-18 19:34:13 +00:00
self.basic_attr: Optional[str] = None
self.attrs: Set = set()
2021-04-19 09:37:36 +00:00
self.workspace: str = workspace
2021-04-18 05:53:07 +00:00
2021-04-18 19:34:13 +00:00
def set_amount(self, amount: int):
self.amount: int = amount
def set_basic_attr(self, basic_attr: Optional[str]):
self.basic_attr = basic_attr
self.attrs.add(basic_attr)
2021-04-18 05:53:07 +00:00
2021-04-18 19:34:13 +00:00
def add_attr(self, attr: str):
self.attrs.add(attr)