Commit 4ee6d524 authored by Chalaka Tharindu Jayasinghe's avatar Chalaka Tharindu Jayasinghe

Merge branch 'ServiceChargePrediction' into 'master'

service charge prediction completed

See merge request !33
parents 9c42be55 f9f1b865
This diff is collapsed.
...@@ -912,35 +912,26 @@ def NextMaintain(request): ...@@ -912,35 +912,26 @@ def NextMaintain(request):
# message_count = int(parts[0]) # message_count = int(parts[0])
# print(message_count) # print(message_count)
#ARIMA SECTION
# 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
df2 = pd.read_csv('Data/MaintainData.csv') df2 = pd.read_csv('Data/MaintainData.csv')
df2 = df2[(df2["Customer"] == customerid)] df2 = df2[(df2["Customer"] == customerid)]
df2 = df2[(df2["Service"] == ServiceType)] df2 = df2[(df2["Service"] == ServiceType)]
df = df2[(df2["VehicleNumber"] == Vnumber)] df = df2[(df2["VehicleNumber"] == Vnumber)]
#df.drop('Service','ServiceName','TakenTime','Customer','VehicleType','VehicleMake','VehicleModel','VehicleNumber','MeterReading','VehicleManufacturedYear','AvergeUsage','mailID', axis=1, inplace=True) # 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 = df.drop(columns=['Service', 'ServiceName', 'TakenTime', 'Customer', 'VehicleType', 'VehicleMake',
'VehicleModel', 'VehicleNumber', 'MeterReading', 'VehicleManufacturedYear',
'AvergeUsage', 'mailID', ])
df.head() df.head()
## Cleaning up the data ## Cleaning up the data
df.columns = ["Date", "Price"] df.columns = ["Date", "Price"]
rrr = df.head() rrr = df.head()
## Drop last 2 rows ## Drop last 2 rows
#df.drop(106, axis=0, inplace=True) # df.drop(106, axis=0, inplace=True)
#df.tail() # df.tail()
# df.drop(105, axis=0, inplace=True) # df.drop(105, axis=0, inplace=True)
# df.tail() # df.tail()
# Convert Date into Datetime # Convert Date into Datetime
df['Date'] = pd.to_datetime(df['Date']) df['Date'] = pd.to_datetime(df['Date'])
...@@ -979,12 +970,12 @@ def NextMaintain(request): ...@@ -979,12 +970,12 @@ def NextMaintain(request):
import statsmodels.api as sm import statsmodels.api as sm
# For non-seasonal data # For non-seasonal data
# p=1, d=1, q=0 or 1 # 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 from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(df['Price'], order=(1, 1, 1)) model = ARIMA(df['Price'], order=(1, 1, 1))
model_fit = model.fit() model_fit = model.fit()
# model_fit.summary() # 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)) # df[['Price','forecast']].plot(figsize=(12,8))
model = sm.tsa.statespace.SARIMAX(df['Price'], order=(1, 1, 1), seasonal_order=(1, 1, 1, 12)) model = sm.tsa.statespace.SARIMAX(df['Price'], order=(1, 1, 1), seasonal_order=(1, 1, 1, 12))
results = model.fit() results = model.fit()
...@@ -996,26 +987,23 @@ def NextMaintain(request): ...@@ -996,26 +987,23 @@ def NextMaintain(request):
future_df = pd.concat([df, future_datest_df]) future_df = pd.concat([df, future_datest_df])
print(future_df)
Datefinding = int(df.shape[1] + 15) Datefinding = int(df.shape[1] + 15)
print(Datefinding)
forecastedPrice = future_df['forecast'] = results.predict(start=Datefinding, end=Datefinding, dynamic=True) forecastedPrice = future_df['forecast'] = results.predict(start=Datefinding, end=Datefinding, dynamic=True)
print("its Arima output") print("Arima output - Servport price prediction")
forecastedPrice = (forecastedPrice.to_string())
forecastedPrice = str(forecastedPrice.to_list()[0])
forecastedPrice = int(float(forecastedPrice))
forecastedPrice = str(forecastedPrice)
print(forecastedPrice)
print(forecastedPrice[5:13])
else: else:
form = MyFormServices() form = MyFormServices()
context = {'form': form,'d': "CUSTOMER NOT FOUND"} context = {'form': form, 'd': "CUSTOMER NOT FOUND"}
return render(request, 'Admin/NextMaintain.html', context) return render(request, 'Admin/NextMaintain.html', context)
context = {'form': form, 'd': enddate, 'forecastedPrice': ' Rs ' + forecastedPrice}
context = { 'form': form, 'd': enddate , 'forecastedPrice':' Rs ' + forecastedPrice[5:13] }
return render(request, 'Admin/NextMaintain.html', context) return render(request, 'Admin/NextMaintain.html', context)
else: else:
...@@ -1027,7 +1015,7 @@ def NextMaintain(request): ...@@ -1027,7 +1015,7 @@ def NextMaintain(request):
def MaintainData(request): def MaintainData(request):
data1 = pd.read_csv('Data/MaintainData.csv') data1 = pd.read_csv('Data/MaintainData.csv')
finalpt = data1.head(10) finalpt = data1.head(518)
json_records = finalpt.reset_index().to_json(orient='records') json_records = finalpt.reset_index().to_json(orient='records')
arr = [] arr = []
arr = json.loads(json_records) arr = json.loads(json_records)
...@@ -1062,10 +1050,3 @@ def AdminHome(request): ...@@ -1062,10 +1050,3 @@ def AdminHome(request):
No preview for this file type
...@@ -24,66 +24,50 @@ ...@@ -24,66 +24,50 @@
{% endif %} {% endif %}
<div class="card-heading"> <div class="card-heading">
<h2 class="title"> MAINTAINS DATA </h2> <h2 class="title mt-3" style="color: #02111f;"> MAINTENANCE DATA </h2>
</div> </div>
<div id="myDiv"> <div id="myDiv">
<div id="div_print"> <div id="div_print">
<div class="card card-body printableArea"> <div class="card card-body printableArea">
<div class="container" style="overflow-x:auto;"> <div class="container" style="overflow-x:auto;">
Customer Maintains Data
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th> Service Date </th> <th>Service Date</th>
<th> Service </th> <th>Service</th>
<th> Taken Time </th> <th>Taken Time</th>
<th> Price </th> <th>Price</th>
<th> Customer </th> <th>Customer</th>
<th> Vehicle Type </th> <th>Vehicle Type</th>
<th> Vehicle Make </th> <th>Vehicle Make</th>
<th> Vehicle Model </th> <th>Vehicle Model</th>
<th> Vehicle Number </th> <th>Vehicle Number</th>
<th> Meter Reading </th> <th>Meter Reading</th>
<th> Vehicle Manufactured Year </th> <th>Vehicle Manufactured Year</th>
<th> Average Usage </th> <th>Average Usage</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% if d %} {% if d %}
{% for i in d %} {% for i in d %}
<tr> <tr>
<td>{{i.Date}}</td>
<td>{{i.ServiceName}}</td>
<td>{{i.Date}}</td>
<td>{{i.ServiceName}}</td>
<td>{{i.TakenTime}}</td> <td>{{i.TakenTime}}</td>
<td>{{i.Price}}</td> <td>{{i.Price}}</td>
<td>{{i.Customer}}</td> <td>{{i.Customer}}</td>
<td>{{i.VehicleType}} </td> <td>{{i.VehicleType}}</td>
<td>{{i.VehicleMake}} </td> <td>{{i.VehicleMake}}</td>
<td>{{i.VehicleModel}} </td> <td>{{i.VehicleModel}}</td>
<td>{{i.VehicleNumber}} </td> <td>{{i.VehicleNumber}}</td>
<td>{{i.MeterReading}} </td> <td>{{i.MeterReading}}</td>
<td>{{i.VehicleManufacturedYear}} </td> <td>{{i.VehicleManufacturedYear}}</td>
<td>{{i.AverageUsage}} </td> <td>{{i.AverageUsage}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
...@@ -98,7 +82,7 @@ ...@@ -98,7 +82,7 @@
<script language="javascript"> <script language="javascript">
function printdiv(printpage) { function printdiv(printpage) {
var headstr = "<html><head><title></title></head><body>"; var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>"; var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML; var newstr = document.all.item(printpage).innerHTML;
...@@ -115,10 +99,10 @@ ...@@ -115,10 +99,10 @@
<div class="card-body"> <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>
<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> </div>
......
...@@ -15,16 +15,18 @@ ...@@ -15,16 +15,18 @@
<div style="margin-left: 0px;" class="card card-5"> <div style="margin-left: 0px;" class="card card-5">
<br/><br/>
{% if messages %} {% if messages %}
<ul class="messages"> <div class="alert alert-danger" role="alert">
{% for message in messages %} {% for message in messages %}
<li {% if message.tags %} class=" {{ message.tags }} " {% endif %}> {{ message }} </li> {% if message.tags %} {% endif %} {{ message }}
{% endfor %} {% endfor %}
</ul> </div>
{% endif %} {% endif %}
<div class="card-heading"> <div class="card-heading">
<h2 class="title"> NEXT MAINTAIN DATE PREDICTION </h2> <h2 class="title" style="color:#02111f"> NEXT MAINTAIN DATE PREDICTION </h2>
</div> </div>
...@@ -35,43 +37,47 @@ ...@@ -35,43 +37,47 @@
<form action="/Admin/NextMaintain/" method="post"> <form action="/Admin/NextMaintain/" method="post">
{% csrf_token %} {% csrf_token %}
<table class="table table-light"> <table class="table table-light">
{{form3.as_table}} {{form3.as_table}}
{{form.as_table}} {{form.as_table}}
</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> </form>
<br> <br>
{% if d %}
<center> <div class="alert alert-success"> <center> <div class="alert alert-success">
{{ d }} Predicted Date: {{ d }}
<br/>
{{ forecastedPrice }} Approximate Price: {{ forecastedPrice }}
</div> </center> </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> </div>
{% endblock content %} {% 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