from functools import wraps, reduce
from collections import defaultdict
from tqdm import tqdm

import os
import time
import math
import random
import copy
import argparse
# import joblib
import pickle
import warnings
import heapq
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import traceback
import openpyxl
import itertools


matplotlib.use('TkAgg')

# feeder_width = {'SM8': (7.25, 7.25), 'SM12': (7.00, 20.00), 'SM16': (7.00, 22.00),
#                 'SM24': (7.00, 29.00), 'SM32': (7.00, 44.00), 'SME8': (7.25, 7.25),
#                 'SME12': (7.00, 20.00), 'SME16': (7.00, 22.00), 'SME24': (7.00, 29.00),
#                 'SME32': (7.00, 44.00), 'Tray Feeder': (7.25, 7.25)}
feeder_width = {'SM8': (7.25, 7.25), 'SM12': (7.25, 7.25), 'SM16': (7.25, 7.25),
                'SM24': (7.25, 7.25), 'SM32': (7.25, 7.25), 'SME8': (7.25, 7.25),
                'SME12': (7.25, 7.25), 'SME16': (7.25, 7.25), 'SME24': (7.25, 7.25),
                'SME32': (7.25, 7.25), 'Tray Feeder': (7.25, 7.25)}

nozzle_limit = {'CN065': 100, 'CN040': 100, 'CN020': 100, 'CN400': 100, 'CN140': 100, 'CN220': 100, 'CN750': 100}


def timer_wrapper(func):
    @wraps(func)
    def measure_time(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        hinter = True
        for key, val in kwargs.items():
            if key == 'hinter':
                hinter = val
        if hinter:
            print(f"function {func.__name__} running time :  {time.time() - start_time:.3f} s")
        return result

    return measure_time
