Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
asteng88 committed Mar 15, 2024
1 parent b819d45 commit 3853aad
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 0 deletions.
Binary file added calculator2.ico
Binary file not shown.
Binary file added calculator2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions oee-calc.py
@@ -0,0 +1,95 @@
from PyQt6 import (uic, QtWidgets, QtGui)
from PyQt6.QtWidgets import (QMainWindow, QApplication, QMessageBox)
from PyQt6.QtGui import QIcon
from PyQt6.uic import loadUi
import os, sys

basedir = os.path.dirname(__file__) # Set a path as the same directory as this file

# this block ensures that the ICON is definately displayed on the taskbar in Windows
try:
from ctypes import windll

myappid = 'com.asteng88.OEE-Calc.OEE-Calc.1.0'
windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except ImportError:
pass


class UiMainWindow(QMainWindow):
def __init__(self):
super(UiMainWindow, self).__init__()
ui = os.path.join(basedir, 'ops_toolbox.ui') # Set the path of the ui file
uic.loadUi(ui, self)

# Exit button action is handled in the ui file. No need to connect it here
# Find widgets
self.planned_time_input = self.findChild(QtWidgets.QLineEdit, 'planned_time_input')
self.run_time_input = self.findChild(QtWidgets.QLineEdit, 'run_time_input')
self.target_count_input = self.findChild(QtWidgets.QLineEdit, 'target_count_input')
self.total_parts_made_input = self.findChild(QtWidgets.QLineEdit, 'total_parts_made_input')
self.good_parts_input = self.findChild(QtWidgets.QLineEdit, 'good_parts_input')
self.answers_box = self.findChild(QtWidgets.QTextBrowser, 'answers_box')

# Connect calculate button to the slot
self.calculate_button = self.findChild(QtWidgets.QPushButton, 'calculate_button')
self.calculate_button.clicked.connect(self.calculate_oee)

# Connect clear button to the slot
self.clear_button = self.findChild(QtWidgets.QPushButton, 'clear_button')
self.clear_button.clicked.connect(self.clear_contents)

def calculate_oee(self):
try:
run_time = float(self.run_time_input.text())
planned_production_time = float(self.planned_time_input.text())
total_count = float(self.total_parts_made_input.text())
target_count = float(self.target_count_input.text())
good_count = float(self.good_parts_input.text())

availability = run_time / planned_production_time
performance = total_count / target_count
quality = good_count / total_count

oee = availability * performance * quality

factors = {'Availability': availability, 'Performance': performance, 'Quality': quality}
lowest_factor = min(factors, key=factors.get)

result_text = (f'The OEE percentage is: {(oee * 100):.1f}%\n\n'
f'Availability: {availability * 100:.1f}%\n'
f'Performance: {performance * 100:.1f}%\n'
f'Quality: {quality * 100:.1f}%\n\n'
f'The area affecting OEE the most is: {lowest_factor}')

self.answers_box.append(result_text)

except ValueError:
msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Critical)
msg.setText("Error")
msg.setInformativeText('Please ensure all fields are complete and are numeric')
msg.setWindowTitle("Error")
msg.setWindowIcon(QIcon(icon_1))
msg.exec()

def clear_contents(self):
# Clear all line edits and the text box
self.planned_time_input.clear()
self.run_time_input.clear()
self.target_count_input.clear()
self.total_parts_made_input.clear()
self.good_parts_input.clear()
self.answers_box.clear()

def quit_application(self):
# Exit the application
self.close()


app = QApplication(sys.argv)
window = UiMainWindow()
icon_1 = os.path.join (basedir, 'calculator2.png')
window.setWindowIcon(QIcon(icon_1))
window.show()
app.exec()
296 changes: 296 additions & 0 deletions ops_toolbox.ui
@@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>275</height>
</rect>
</property>
<property name="windowTitle">
<string>OEE Calculator - Andrew Thomas</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="calculate_button">
<property name="geometry">
<rect>
<x>310</x>
<y>190</y>
<width>81</width>
<height>41</height>
</rect>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="text">
<string>Calculate</string>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>290</x>
<y>10</y>
<width>20</width>
<height>171</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QTextBrowser" name="answers_box">
<property name="geometry">
<rect>
<x>310</x>
<y>10</y>
<width>221</width>
<height>171</height>
</rect>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>11</y>
<width>280</width>
<height>170</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="planned_time">
<property name="toolTip">
<string>Production time planned in Hrs</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Planned Production Time&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="planned_time_input"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="run_time">
<property name="toolTip">
<string extracomment="Enter the time production actuall ran in Hrs"/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Actual Run Time&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="run_time_input"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="target_count">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Target Part Count</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="target_count_input"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="total_parts_made">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Total Parts Made</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="total_parts_made_input"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="good_parts">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Number of Good Parts</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="good_parts_input"/>
</item>
</layout>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>OEE = Availability x Performance x Quality</string>
</property>
</widget>
<widget class="QPushButton" name="quitButton">
<property name="geometry">
<rect>
<x>484</x>
<y>190</y>
<width>41</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Quit</string>
</property>
</widget>
<widget class="QPushButton" name="clear_button">
<property name="geometry">
<rect>
<x>400</x>
<y>190</y>
<width>75</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Ensure all time units are equal (Hrs, Mins or Secs)</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuOEE_Calculator">
<property name="title">
<string>File</string>
</property>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuOEE_Calculator"/>
</widget>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
<property name="menuRole">
<enum>QAction::QuitRole</enum>
</property>
</action>
</widget>
<tabstops>
<tabstop>planned_time_input</tabstop>
<tabstop>run_time_input</tabstop>
<tabstop>target_count_input</tabstop>
<tabstop>total_parts_made_input</tabstop>
<tabstop>good_parts_input</tabstop>
<tabstop>answers_box</tabstop>
<tabstop>calculate_button</tabstop>
<tabstop>clear_button</tabstop>
<tabstop>quitButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>quitButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>504</x>
<y>232</y>
</hint>
<hint type="destinationlabel">
<x>270</x>
<y>137</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>270</x>
<y>137</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 3853aad

Please sign in to comment.