Commit 5e89f65f authored by Withana R.D.K's avatar Withana R.D.K

Employee Efficiency

parent a62106af
This diff is collapsed.
......@@ -6,7 +6,11 @@ from . import models
MODE_CHOICES = [
('0', 'Select Work'),
('1', 'Engine Repairering'),
('2', 'Painting')
('2', 'Painting'),
('3', 'Oil Changing'),
('4', 'Interior Cleaning'),
('5', 'Body Wash'),
('6', 'Under Wash')
]
MODE_DEMAND = [
......@@ -23,7 +27,7 @@ class MyForm4(forms.Form):
inputdate = forms.DateField(widget=DateInput)
class MyForm(forms.Form):
class MyForm5(forms.Form):
customerid = forms.IntegerField(label="Select Work To be Done", widget=forms.Select(choices=MODE_CHOICES))
......
......@@ -12,6 +12,7 @@ urlpatterns = [
path('AdminHome/', responseapp_views.AdminHome),
path('Employee_Data/', responseapp_views.Employee_Data),
path('EmployeeStatus_Update/', responseapp_views.EmployeeStatus_Update),
path('Employee_Efficiency/', responseapp_views.Employee_Efficiency),
path('PurchaseHistory/', responseapp_views.PurchaseHistory),
path('Forecasting/', responseapp_views.Forecasting),
path('Result/', responseapp_views.Forecasting),
......
......@@ -2,7 +2,9 @@ from datetime import datetime
from django.shortcuts import render, redirect, reverse
from django.template import loader
from django.http import HttpResponse
from User.forms import MyForm,MyForm2,MyForm3,MyForm4
from sklearn.tree import DecisionTreeClassifier
from User.forms import MyForm,MyForm2,MyForm3,MyForm4,MyForm5
from django.contrib.auth import authenticate, login
from User import models as Umodels
from django.http import HttpResponseRedirect
......@@ -35,7 +37,90 @@ def Homepage(request):
return render(request, 'Admin/Homepage.html');
# End CompanyHome
# Employee_Efficency
# Employee_Efficiency
def Employee_Efficiency(request):
if request.method == 'POST':
myForm = MyForm5(request.POST)
if myForm.is_valid():
workid = myForm.cleaned_data['customerid']
DateSet = pd.read_csv("Data/WorkHistory.csv", skipinitialspace=True)
DateSet['JobDone'].replace({'Engine Repairering': 1, 'Painting': 2, 'Oil Changing': 3,
'Interior Cleaning': 4, 'Body Wash': 5, 'Under Wash': 6}, inplace=True)
DateSet = DateSet[(DateSet.WorkQuality > 1)] # search for job need to be done
DateSet = DateSet.drop(columns=['WorkQuality'])
x = DateSet[['JobDone', 'TakenTime']]
y = DateSet[['StaffID']]
grouped_df = DateSet[(DateSet["JobDone"] == workid)] # get selected work
grouped_df = grouped_df.groupby("StaffID") # group job staff
grouped_df = grouped_df['TakenTime'] # get only taken time to complete work
mean_df = grouped_df.mean() # avarage time to complete work
min_df = mean_df.min() # get less time taken to complete work
# x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=2)
# lm = LinearRegression()
# lm.fit(x_train, y_train)
#
# new_input = [[workid, min_df]] # Best WorkQuality Work
# pred = lm.predict(new_input)
# workid = (int(pred.round())) # final employee ID by ML
#
# print("--------------Accuracy-----------------")
# accuracy = lm.score(x_test, y_test)
# print(accuracy)
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=2)
clf = DecisionTreeClassifier()
clf = clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
new_input = [[workid, min_df]] # Best WorkQuality Work
pred = clf.predict(new_input)
workid = (int(pred.round())) # final employee ID by ML
print("Accuracy:", metrics.accuracy_score(y_test, y_pred))
DateSetLoad = pd.read_csv("Data/WorkHistory.csv", skipinitialspace=True)
data2 = pd.read_csv('Data/EmployeeStatus.csv')
# using merge function by setting how='inner'
output1 = pd.merge(DateSetLoad, data2,
on='StaffID',
how='inner')
DateSetResult = DateSetLoad[(output1.StaffID == workid) & (output1.Availability == "Yes")]
df = DateSetResult[:1]
# data = data.to_html()
# ----------------------------------------------------------------------- aaAccuracy section
# ----------------------------------------------------------------------- aaAccuracy section
json_records = df.reset_index().to_json(orient='records')
arr = []
arr = json.loads(json_records)
if (arr == [] ):
DateSetResult = DateSetLoad[(output1.Availability == "Yes")]
df = DateSetResult[:1]
# data = data.to_html()
json_records = df.reset_index().to_json(orient='records')
arr = []
arr = json.loads(json_records)
else:
a = 2
form = MyForm5()
context = { 'form': form, 'd': arr}
return render(request, 'Admin/Employee_Efficiency.html', context)
else:
form = MyForm5()
return render(request, 'Admin/Employee_Efficiency.html', {'form': form});
def Employee_Data(request):
data1 = pd.read_csv('Data/WorkHistory.csv')
data2 = pd.read_csv('Data/EmployeeStatus.csv')
......
{% extends 'Admin/Sidebar2.html' %}
{% block content %}
{% load widget_tweaks %}
{%load static%}
<head>
<!-- Font special for pages-->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i" rel="stylesheet">
<!-- Main CSS-->
<link href="{% static "css/main.css" %}"rel="stylesheet" media="all">
</head>
<div class=" >
<div class="wrapper wrapper 0">
<div style="margin-left: 0px;" class="card card-5">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li {% if message.tags %} class=" {{ message.tags }} " {% endif %}> {{ message }} </li>
{% endfor %}
</ul>
{% endif %}
<div class="card-heading">
<h2 class="title"> EMPLOYEE EFFICIENCY PREDICTION </h2>
</div>
<div id="myDiv">
<div id="div_print">
<div class="card card-body printableArea">
<div role="alert" >
<div class="container" style="overflow-x:auto;">
<table class="table table-striped">
<thead>
<tr>
<th> StaffID </th>
<th> EmployeeName </th>
<th> Available Status </th>
</tr>
</thead>
<tbody>
{% if d %}
{% for i in d %}
<tr>
<td>{{i.StaffID}}</td>
<td>{{i.EmployeeName}}</td>
<td><div class="alert alert-success">
Available
</div></td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
</div>
</div>
</div></div></div>
<script language="javascript">
function printdiv(printpage) {
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr + newstr + footstr;
window.print();
document.body.innerHTML = oldstr;
location.reload();
return false;
}
</script>
<div class="card-body">
<form action="/Admin/Employee_Efficiency/" method="post">
{% csrf_token %}
<table class="table table-light">
{{form.as_table}}
</table>
<input type="submit" value="PREDICT EMPLOYEE" class="btn btn--radius-2 btn-primary"/>
</form> <br><div class="text-right">
<input name="b_print" type="button" class="btn btn-primary btn-print" onClick="printdiv('div_print');" value=" Print ">
</div>
<br>
</div>
</div>
</div>
<div class="alert alert-primary" role="alert" >© SMART SERVICE STATION 2022 </div>
</div>
{% endblock content %}
......@@ -178,7 +178,7 @@ body{
<ul>
<li><a style="text-decoration:none;" href="/Admin/AdminHome/"><i class="fas fa-desktop"></i>Home</a></li>
<li><a style="text-decoration:none;" href="#"><i class="fas fa-car "></i> Customer Registration </a>
<li><a style="text-decoration:none;" href="#"><i class="fas fa-barcode"></i> Employee Efficiency </a>
<li><a style="text-decoration:none;" href="/Admin/Employee_Efficiency/"><i class="fas fa-barcode"></i> Employee Efficiency </a>
<li><a style="text-decoration:none;" href="/Admin/Employee_Data/"><i class="fas fa-paper-plane "></i> Employee Data </a>
<li><a style="text-decoration:none;" href="/Admin/EmployeeStatus_Update/"><i class="fas fa-upload"></i> Assign Employee </a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment