Commit fe5feca9 authored by chalaka78's avatar chalaka78

fix service date prediction backend issues

parent 2264a27f
This diff is collapsed.
......@@ -551,35 +551,26 @@ def NextMaintain(request):
# message_count = int(parts[0])
# print(message_count)
# ARIMA SECTION
# inputdate = '12/01/2020'
# HERE I USE AN EXMAMPLE FROM MATPLOTLIB SITE
# Data for plotting
# t = np.arange(0.0, 2.0, 0.01)
# s = 1 + np.sin(2 * np.pi * t)
import numpy as np
import matplotlib.pyplot as plt
#ARIMA SECTION
df2 = pd.read_csv('Data/MaintainData.csv')
df2 = df2[(df2["Customer"] == customerid)]
df2 = df2[(df2["Service"] == ServiceType)]
df = df2[(df2["VehicleNumber"] == Vnumber)]
#df.drop('Service','ServiceName','TakenTime','Customer','VehicleType','VehicleMake','VehicleModel','VehicleNumber','MeterReading','VehicleManufacturedYear','AvergeUsage','mailID', axis=1, inplace=True)
df = df.drop(columns=['Service','ServiceName','TakenTime','Customer','VehicleType','VehicleMake','VehicleModel','VehicleNumber','MeterReading','VehicleManufacturedYear','AvergeUsage','mailID', ])
# df.drop('Service','ServiceName','TakenTime','Customer','VehicleType','VehicleMake','VehicleModel','VehicleNumber','MeterReading','VehicleManufacturedYear','AvergeUsage','mailID', axis=1, inplace=True)
df = df.drop(columns=['Service', 'ServiceName', 'TakenTime', 'Customer', 'VehicleType', 'VehicleMake',
'VehicleModel', 'VehicleNumber', 'MeterReading', 'VehicleManufacturedYear',
'AvergeUsage', 'mailID', ])
df.head()
## Cleaning up the data
df.columns = ["Date", "Price"]
rrr = df.head()
## Drop last 2 rows
#df.drop(106, axis=0, inplace=True)
#df.tail()
# df.drop(105, axis=0, inplace=True)
# df.tail()
# df.drop(106, axis=0, inplace=True)
# df.tail()
# df.drop(105, axis=0, inplace=True)
# df.tail()
# Convert Date into Datetime
df['Date'] = pd.to_datetime(df['Date'])
......@@ -618,12 +609,12 @@ def NextMaintain(request):
import statsmodels.api as sm
# For non-seasonal data
# p=1, d=1, q=0 or 1
# from statsmodels.tsa.arima_model import ARIMA
# from statsmodels.tsa.arima_model import ARIMA
from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(df['Price'], order=(1, 1, 1))
model_fit = model.fit()
# model_fit.summary()
# df['forecast'] = model_fit.predict(start=8, end=8, dynamic=True)
# df['forecast'] = model_fit.predict(start=8, end=8, dynamic=True)
# df[['Price','forecast']].plot(figsize=(12,8))
model = sm.tsa.statespace.SARIMAX(df['Price'], order=(1, 1, 1), seasonal_order=(1, 1, 1, 12))
results = model.fit()
......@@ -635,26 +626,23 @@ def NextMaintain(request):
future_df = pd.concat([df, future_datest_df])
print(future_df)
Datefinding = int(df.shape[1] + 15)
print(Datefinding)
forecastedPrice = future_df['forecast'] = results.predict(start=Datefinding, end=Datefinding, dynamic=True)
print("its Arima output")
forecastedPrice = (forecastedPrice.to_string())
print("Arima output - Servport price prediction")
forecastedPrice = str(forecastedPrice.to_list()[0])
forecastedPrice = int(float(forecastedPrice))
forecastedPrice = str(forecastedPrice)
print(forecastedPrice)
print(forecastedPrice[5:13])
else:
form = MyFormServices()
context = {'form': form,'d': "CUSTOMER NOT FOUND"}
context = {'form': form, 'd': "CUSTOMER NOT FOUND"}
return render(request, 'Admin/NextMaintain.html', context)
context = { 'form': form, 'd': enddate , 'forecastedPrice':' Rs ' + forecastedPrice[5:13] }
context = {'form': form, 'd': enddate, 'forecastedPrice': ' Rs ' + forecastedPrice}
return render(request, 'Admin/NextMaintain.html', context)
else:
......@@ -666,7 +654,7 @@ def NextMaintain(request):
def MaintainData(request):
data1 = pd.read_csv('Data/MaintainData.csv')
finalpt = data1.head(10)
finalpt = data1.head(518)
json_records = finalpt.reset_index().to_json(orient='records')
arr = []
arr = json.loads(json_records)
......
No preview for this file type
......@@ -24,66 +24,50 @@
{% endif %}
<div class="card-heading">
<h2 class="title"> MAINTAINS DATA </h2>
<h2 class="title mt-3" style="color: #02111f;"> MAINTENANCE DATA </h2>
</div>
<div id="myDiv">
<div id="myDiv">
<div id="div_print">
<div class="card card-body printableArea">
<div class="container" style="overflow-x:auto;">
Customer Maintains Data
<table class="table table-striped">
<thead>
<tr>
<th> Service Date </th>
<th> Service </th>
<th> Taken Time </th>
<th> Price </th>
<th> Customer </th>
<th> Vehicle Type </th>
<th> Vehicle Make </th>
<th> Vehicle Model </th>
<th> Vehicle Number </th>
<th> Meter Reading </th>
<th> Vehicle Manufactured Year </th>
<th> Average Usage </th>
<th>Service Date</th>
<th>Service</th>
<th>Taken Time</th>
<th>Price</th>
<th>Customer</th>
<th>Vehicle Type</th>
<th>Vehicle Make</th>
<th>Vehicle Model</th>
<th>Vehicle Number</th>
<th>Meter Reading</th>
<th>Vehicle Manufactured Year</th>
<th>Average Usage</th>
</tr>
</thead>
<tbody>
{% if d %}
{% for i in d %}
<tr>
<td>{{i.Date}}</td>
<td>{{i.ServiceName}}</td>
<td>{{i.Date}}</td>
<td>{{i.ServiceName}}</td>
<td>{{i.TakenTime}}</td>
<td>{{i.Price}}</td>
<td>{{i.Customer}}</td>
<td>{{i.VehicleType}} </td>
<td>{{i.VehicleMake}} </td>
<td>{{i.VehicleModel}} </td>
<td>{{i.VehicleNumber}} </td>
<td>{{i.MeterReading}} </td>
<td>{{i.VehicleManufacturedYear}} </td>
<td>{{i.AverageUsage}} </td>
<td>{{i.VehicleType}}</td>
<td>{{i.VehicleMake}}</td>
<td>{{i.VehicleModel}}</td>
<td>{{i.VehicleNumber}}</td>
<td>{{i.MeterReading}}</td>
<td>{{i.VehicleManufacturedYear}}</td>
<td>{{i.AverageUsage}}</td>
</tr>
{% endfor %}
{% endif %}
......@@ -98,7 +82,7 @@
<script language="javascript">
function printdiv(printpage) {
function printdiv(printpage) {
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
......@@ -115,10 +99,10 @@
<div class="card-body">
<input name="b_print" type="button" class="btn btn-primary btn-print" onClick="printdiv('div_print');" value=" Print ">
<input name="b_print" type="button" class="btn btn-print" onClick="printdiv('div_print');" value=" Print " style="background: #02111f;">
</div>
<div class="alert alert-primary" role="alert" >© SMART SERVICE STATION 2022 </div>
<div class="alert alert-primary fixed-bottom mb-0 text-center" style="background: #747578; border: none; color: white;" role="alert" > © SERVPORT 2022 </div>
</div>
......
......@@ -15,16 +15,18 @@
<div style="margin-left: 0px;" class="card card-5">
<br/><br/>
{% if messages %}
<ul class="messages">
<div class="alert alert-danger" role="alert">
{% for message in messages %}
<li {% if message.tags %} class=" {{ message.tags }} " {% endif %}> {{ message }} </li>
{% if message.tags %} {% endif %} {{ message }}
{% endfor %}
</ul>
</div>
{% endif %}
<div class="card-heading">
<h2 class="title"> NEXT MAINTAIN DATE PREDICTION </h2>
<h2 class="title" style="color:#02111f"> NEXT MAINTAIN DATE PREDICTION </h2>
</div>
......@@ -35,43 +37,47 @@
<form action="/Admin/NextMaintain/" method="post">
{% csrf_token %}
<table class="table table-light">
{{form3.as_table}}
{{form3.as_table}}
{{form.as_table}}
</table>
<input type="submit" value="NEXT MAINTAIN DATE" class="btn btn--radius-2 btn-primary"/>
<input type="submit" value="NEXT MAINTAIN DATE" class="btn btn--radius-2 btn" style="background:#02111f"/>
</form>
<br>
<br>
{% if d %}
<center> <div class="alert alert-success">
{{ d }}
{{ forecastedPrice }}
Predicted Date: {{ d }}
<br/>
Approximate Price: {{ forecastedPrice }}
</div> </center>
{% endif %}
<br>
</div>
</div>
</div>
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>
</div>
</div>
</div>
<div class="alert alert-primary" role="alert" >© SMART SERVICE STATION 2022 </div>
<div class="alert alert-primary fixed-bottom mb-0 text-center" style="background: #747578; border: none; color: white;" role="alert" > © SERVPORT 2022 </div>
</div>
{% endblock content %}
......
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