Advertisement
UniQuet0p1

Untitled

Sep 29th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.20 KB | None | 0 0
  1. """
  2. EX05 - OEE
  3. """
  4. import csv
  5.  
  6. def read_production_data(filename: str) -> dict:
  7.     """
  8.    Open the file in the provided path, read in values and return them as a dictionary,
  9.    where the key is the machine name and value is a list of integers for the production data for each shift.
  10.  
  11.    {
  12.    'Machine Name': [Run Time (minutes), Ideal Run Rate (pcs/min), Total Count (pcs), Good Count (pcs)]
  13.    }
  14.  
  15.    :param filename: string file path for the CSV file to be read
  16.    :return: dictionary with the production data per machine
  17.    """
  18.     return {}
  19.  
  20.  
  21. def calculate_quality(production_data: dict) -> dict:
  22.     """
  23.    Go through the input dictionary and for each machine, calculate the Quality percentage (as a float, e.g. 98.1).
  24.    Save each value in a new dictionary, where the key is the machine name and value is the calculated Quality.
  25.    Return the newly created dictionary.
  26.  
  27.    :param production_data: dictionary with production data
  28.    :return: dictionary with OEE Quality value per machine
  29.    """
  30.     return {}
  31.  
  32.  
  33. def calculate_availability(production_data: dict) -> dict:
  34.     """
  35.    Go through the input dictionary and for each machine, calculate the Availability percentage (as a float, e.g. 98.1).
  36.    Save each value in a new dictionary, where the key is the machine name and value is the calculated Availability.
  37.    Return the newly created dictionary.
  38.  
  39.    :param production_data: dictionary with production data
  40.    :return: dictionary with OEE Availability value per machine
  41.    """
  42.     return {}
  43.  
  44.  
  45. def calculate_performance(production_data: dict) -> dict:
  46.     """
  47.    Go through the input dictionary and for each machine, calculate the Performance percentage (as a float, e.g. 98.1).
  48.    Save each value in a new dictionary, where the key is the machine name and value is the calculated Performance.
  49.    Return the newly created dictionary.
  50.  
  51.    :param production_data: dictionary with production data
  52.    :return: dictionary with OEE Performance value per machine
  53.    """
  54.     return {}
  55.  
  56.  
  57. def calculate_oee(production_data: dict) -> dict:
  58.     """
  59.    Using the previously defined functions, calculate the final OEE percentage for each machine.
  60.    Save each value in a new dictionary, where the key is the machine name and value is the calculated Performance.
  61.    Return the newly created dictionary.
  62.  
  63.    :return: dictionary with OEE percentage value per machine
  64.    """
  65.     return {}
  66.  
  67.  
  68. def write_results_to_file(production_data: dict, filename: str):
  69.     """
  70.    Write the calculation results to a CSV formatted file.
  71.  
  72.    :param filename: string file path for the CSV file to be written to
  73.    :param production_data: dictionary with production data
  74.    """
  75.     pass
  76.  
  77.  
  78. if __name__ == '__main__':
  79.     prod_data = read_production_data("reedene_vahetus.csv")
  80.     print('\n- Production data -')
  81.     print('[Run Time (minutes), Ideal Run Rate (pcs/min), Total Count (pcs), Good Count (pcs)]')
  82.     for key, value in prod_data.items():
  83.         print(f"{key}: {value}")
  84.  
  85.     # Sildistaja: [358, 57, 18602, 18388]
  86.     # Hapukurgipurgitaja: [415, 12, 4800, 2013]
  87.     # Autoklaav: [450, 10, 4500, 4500]
  88.     # Supivillija: [402, 36, 14230, 14214]
  89.     # Makaronikeetja: [410, 25, 10230, 10230]
  90.     # Kartulikoorija: [420, 111, 46620, 44123]
  91.     # Mahlapress: [0, 0, 0, 0]
  92.  
  93.     quality_dict = calculate_quality(prod_data)
  94.     print('\n- Quality calculation results -')
  95.     for key, value in quality_dict.items():
  96.         print(f"{key}: {value}")
  97.  
  98.     # Sildistaja: 98.8
  99.     # Hapukurgipurgitaja: 41.9
  100.     # Autoklaav: 100.0
  101.     # Supivillija: 99.9
  102.     # Makaronikeetja: 100.0
  103.     # Kartulikoorija: 94.6
  104.     # Mahlapress: 0.0
  105.  
  106.     availability_dict = calculate_availability(prod_data)
  107.     print('\n- Availability calculation results -')
  108.     for key, value in availability_dict.items():
  109.         print(f"{key}: {value}")
  110.  
  111.     # Sildistaja: 85.2
  112.     # Hapukurgipurgitaja: 98.8
  113.     # Autoklaav: 107.1
  114.     # Supivillija: 95.7
  115.     # Makaronikeetja: 97.6
  116.     # Kartulikoorija: 100.0
  117.     # Mahlapress: 0.0
  118.  
  119.     performance_dict = calculate_performance(prod_data)
  120.     print('\n- Performance calculation results -')
  121.     for key, value in performance_dict.items():
  122.         print(f"{key}: {value}")
  123.  
  124.     # Sildistaja: 91.2
  125.     # Hapukurgipurgitaja: 96.4
  126.     # Autoklaav: 100.0
  127.     # Supivillija: 98.3
  128.     # Makaronikeetja: 99.8
  129.     # Kartulikoorija: 100.0
  130.     # Mahlapress: 0.0
  131.  
  132.     oee_dict = calculate_oee(prod_data)
  133.     print('\n- Total OEE calculation results -')
  134.     for key, value in oee_dict.items():
  135.         print(f"{key}: {value}")
  136.  
  137.     # Sildistaja: 76.8
  138.     # Hapukurgipurgitaja: 39.9
  139.     # Autoklaav: 107.1
  140.     # Supivillija: 94.0
  141.     # Makaronikeetja: 97.4
  142.     # Kartulikoorija: 94.6
  143.     # Mahlapress: 0.0
  144.  
  145.     write_results_to_file(prod_data, 'reedene_oee.csv')
  146.  
  147.     # contents of 'reedene_oee.csv':
  148.     # Liin, Saadavus, Tootlus, Kvaliteet, OEE
  149.     # Sildistaja, 85.2, 91.2, 98.8, 76.8
  150.     # Hapukurgipurgitaja, 98.8, 96.4, 41.9, 39.9
  151.     # Autoklaav, 107.1, 100.0, 100.0, 107.1
  152.     # Supivillija, 95.7, 98.3, 99.9, 94.0
  153.     # Makaronikeetja, 97.6, 99.8, 100.0, 97.4
  154.     # Kartulikoorija, 100.0, 100.0, 94.6, 94.6
  155.     # Mahlapress, 0.0, 0.0, 0.0, 0.0
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement