Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21_22-J 31
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 31
21_22-J 31
Commits
547148db
Commit
547148db
authored
Jan 05, 2022
by
Ravindu Nethsara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Demand Forecast Model Added
parent
8ff30e7d
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
498 additions
and
3 deletions
+498
-3
Data/Purchasefile.csv
Data/Purchasefile.csv
+121
-0
User/forms.py
User/forms.py
+23
-2
User/urls.py
User/urls.py
+3
-0
User/views.py
User/views.py
+132
-1
db.sqlite3
db.sqlite3
+0
-0
templates/Admin/Forecasting.html
templates/Admin/Forecasting.html
+64
-0
templates/Admin/PurchaseHistory.html
templates/Admin/PurchaseHistory.html
+102
-0
templates/Admin/Result.html
templates/Admin/Result.html
+49
-0
templates/Admin/Sidebar2.html
templates/Admin/Sidebar2.html
+4
-0
No files found.
Data/Purchasefile.csv
0 → 100644
View file @
547148db
Month,CALTEX_Delo_Gold_Ultra,Price1
2012-01,380,4100
2012-02,240,4100
2012-03,324,4100
2012-04,381,4300
2012-05,246,4300
2012-06,336,4350
2012-07,282,4350
2012-08,212,4350
2012-09,222,4350
2012-10,301,4350
2012-11,264,4350
2012-12,388,4350
2013-01,354,4350
2013-02,247,4450
2013-03,221,4450
2013-04,363,4450
2013-05,240,4450
2013-06,312,4450
2013-07,233,4450
2013-08,254,4450
2013-09,198,4600
2013-10,246,4600
2013-11,310,4600
2013-12,421,4600
2014-01,313,4600
2014-02,306,4600
2014-03,247,4600
2014-04,353,4650
2014-05,237,4650
2014-06,386,4650
2014-07,260,4650
2014-08,173,4650
2014-09,328,4650
2014-10,211,4650
2014-11,294,4650
2014-12,444,4400
2015-01,388,4725
2015-02,375,4725
2015-03,218,4725
2015-04,414,4630
2015-05,252,4725
2015-06,369,4725
2015-07,313,4725
2015-08,143,4725
2015-09,349,4725
2015-10,328,4725
2015-11,314,4725
2015-12,451,4725
2016-01,422,4725
2016-02,397,4725
2016-03,354,4725
2016-04,421,4725
2016-05,347,4725
2016-06,453,4725
2016-07,365,4725
2016-08,264,4725
2016-09,302,4725
2016-10,324,4725
2016-11,358,4725
2016-12,512,4725
2017-01,416,4725
2017-02,397,4725
2017-03,410,4725
2017-04,476,4725
2017-05,268,4725
2017-06,477,4725
2017-07,125,4725
2017-08,421,4725
2017-09,322,4725
2017-10,373,4725
2017-11,303,4725
2017-12,567,4725
2018-01,239,4725
2018-02,299,4725
2018-03,340,4725
2018-04,370,4725
2018-05,227,4725
2018-06,386,4725
2018-07,317,4725
2018-08,438,4725
2018-09,321,4725
2018-10,394,4725
2018-11,281,5050
2018-12,436,4900
2019-01,334,5130
2019-02,262,5130
2019-03,286,5130
2019-04,476,5130
2019-05,410,5130
2019-06,474,5130
2019-07,343,5130
2019-08,359,5130
2019-09,251,5130
2019-10,281,5130
2019-11,357,5130
2019-12,570,5130
2020-01,348,5130
2020-02,364,5130
2020-03,477,5130
2020-04,488,5130
2020-05,418,5130
2020-06,512,6100
2020-07,429,6100
2020-08,413,6100
2020-09,377,6100
2020-10,421,6100
2020-11,302,6100
2020-12,488,6100
2021-01,424,6250
2021-02,312,6250
2021-03,383,6250
2021-04,521,6250
2021-05,288,6800
2021-06,341,6800
2021-07,324,7400
2021-08,291,7400
2021-09,330,7400
2021-10,382,7400
2021-11,421,8600
2021-12,516,8600
User/forms.py
View file @
547148db
from
django
import
forms
from
django.contrib.auth.models
import
User
from
django.forms
import
DateInput
from
.
import
models
MODE_CHOICES
=
[
...
...
@@ -8,8 +9,18 @@ MODE_CHOICES = [
(
'2'
,
'Painting'
)
]
MODE_DEMAND
=
[
(
''
,
'Select Product'
),
(
'1'
,
'CALTEX Delo Gold Ultra'
)
]
class
DateInput
(
forms
.
DateInput
):
input_type
=
'date'
class
MyForm4
(
forms
.
Form
):
Productid
=
forms
.
IntegerField
(
label
=
"Select Product"
,
required
=
True
,
widget
=
forms
.
Select
(
choices
=
MODE_DEMAND
))
inputdate
=
forms
.
DateField
(
widget
=
DateInput
)
class
MyForm
(
forms
.
Form
):
...
...
@@ -18,7 +29,7 @@ class MyForm(forms.Form):
class
MyForm2
(
forms
.
Form
):
UserName
=
forms
.
CharField
(
label
=
'User Name'
)
UserName
=
forms
.
CharField
(
label
=
'User Name'
)
Password
=
forms
.
CharField
(
label
=
'Password'
,
widget
=
forms
.
PasswordInput
)
...
...
@@ -31,3 +42,13 @@ MODE_CHOICES2 = [
class
MyForm3
(
forms
.
Form
):
StaffID
=
forms
.
CharField
(
label
=
'Enter Staff ID'
)
Availability
=
forms
.
CharField
(
label
=
"Select Availability"
,
widget
=
forms
.
Select
(
choices
=
MODE_CHOICES2
))
#Demand Forecast
class
RequestForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
models
.
PastData
fields
=
[
'inputdate'
]
class
MyFormNew
(
forms
.
Form
):
inputdate
=
forms
.
DateField
(
widget
=
DateInput
)
User/urls.py
View file @
547148db
...
...
@@ -11,5 +11,8 @@ urlpatterns = [
path
(
'AdminLogin/'
,
responseapp_views
.
AdminLogin
),
path
(
'AdminHome/'
,
responseapp_views
.
AdminHome
),
path
(
'Employee_Data/'
,
responseapp_views
.
Employee_Data
),
path
(
'PurchaseHistory/'
,
responseapp_views
.
PurchaseHistory
),
path
(
'Forecasting/'
,
responseapp_views
.
Forecasting
),
path
(
'Result/'
,
responseapp_views
.
Forecasting
),
path
(
''
,
admin
.
site
.
urls
),
]
\ No newline at end of file
User/views.py
View file @
547148db
...
...
@@ -2,7 +2,7 @@ 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
from
User.forms
import
MyForm
,
MyForm2
,
MyForm3
,
MyForm4
from
django.contrib.auth
import
authenticate
,
login
from
User
import
models
as
Umodels
from
django.http
import
HttpResponseRedirect
...
...
@@ -21,6 +21,11 @@ from sklearn.model_selection import train_test_split
from
sklearn.linear_model
import
LinearRegression
# ------------------- EF
# Demand Forecast
import
statsmodels.api
as
sm
from
statsmodels.tsa.stattools
import
adfuller
from
statsmodels.tsa.arima.model
import
ARIMA
from
pandas.tseries.offsets
import
DateOffset
# Start CompanyHome
def
Homepage
(
request
):
...
...
@@ -42,6 +47,132 @@ def Employee_Data(request):
context
=
{
'd'
:
arr
}
return
render
(
request
,
'Admin/Employee_Data.html'
,
context
);
# Demand Forecasting
def
PurchaseHistory
(
request
):
data
=
pd
.
read_csv
(
'Data/Purchasefile.csv'
)
finalpt
=
data
.
head
(
10
)
json_records
=
finalpt
.
reset_index
()
.
to_json
(
orient
=
'records'
)
arr
=
[]
arr
=
json
.
loads
(
json_records
)
context
=
{
'd'
:
arr
}
return
render
(
request
,
'Admin/PurchaseHistory.html'
,
context
);
# start Admin ML
def
Forecasting
(
request
):
if
request
.
method
==
'POST'
:
myForm
=
MyForm4
(
request
.
POST
)
if
myForm
.
is_valid
():
Productid
=
myForm
.
cleaned_data
[
'Productid'
]
inputdate
=
myForm
.
cleaned_data
[
'inputdate'
]
ProductName
=
"CALTEX Delo Gold Ultra"
if
(
ProductName
==
"CALTEX Delo Gold Ultra"
):
# load first product budget
df
=
pd
.
read_csv
(
'Data/Purchasefile.csv'
)
df
.
head
()
df
.
columns
=
[
"Month"
,
"CALTEX Delo Gold Ultra"
,
"Price1"
]
rrr
=
df
.
head
()
# Convert Month into Datetime
df
[
'Month'
]
=
pd
.
to_datetime
(
df
[
'Month'
])
df
.
set_index
(
'Month'
,
inplace
=
True
)
df
.
describe
()
test_result
=
adfuller
(
df
[
'CALTEX Delo Gold Ultra'
])
test_result2
=
adfuller
(
df
[
'Price1'
])
def
adfuller_test
(
Product1
):
result
=
adfuller
(
Product1
)
labels
=
[
'ADF Test Statistic'
,
'p-value'
,
'#Lags Used'
,
'Number of Observations Used'
]
for
value
,
label
in
zip
(
result
,
labels
):
print
(
label
+
' : '
+
str
(
value
))
def
adfuller_test2
(
Price1
):
result2
=
adfuller
(
Price1
)
labels
=
[
'ADF Test Statistic'
,
'p-value'
,
'#Lags Used'
,
'Number of Observations Used'
]
for
value
,
label
in
zip
(
result2
,
labels
):
print
(
label
+
' : '
+
str
(
value
))
adfuller_test
(
df
[
'CALTEX Delo Gold Ultra'
])
adfuller_test2
(
df
[
'Price1'
])
##Differencing
df
[
'Product1 First Difference'
]
=
df
[
'CALTEX Delo Gold Ultra'
]
-
df
[
'CALTEX Delo Gold Ultra'
]
.
shift
(
1
)
df
[
'Product1 First Difference2'
]
=
df
[
'Price1'
]
-
df
[
'Price1'
]
.
shift
(
1
)
# df['Sales'].shift(1)
df
[
'Seasonal First Difference'
]
=
df
[
'CALTEX Delo Gold Ultra'
]
-
df
[
'CALTEX Delo Gold Ultra'
]
.
shift
(
12
)
df
[
'Seasonal First Difference2'
]
=
df
[
'Price1'
]
-
df
[
'Price1'
]
.
shift
(
12
)
# df.head(14)
## Again test dickey fuller test
adfuller_test
(
df
[
'Seasonal First Difference'
]
.
dropna
())
adfuller_test2
(
df
[
'Seasonal First Difference2'
]
.
dropna
())
# ARIMA
model
=
ARIMA
(
df
[
'CALTEX Delo Gold Ultra'
],
order
=
(
1
,
0
,
0
))
model2
=
ARIMA
(
df
[
'Price1'
],
order
=
(
1
,
0
,
0
))
model_fit
=
model
.
fit
()
model_fit2
=
model2
.
fit
()
# model_fit.summary()
df
[
'forecast'
]
=
model_fit
.
predict
(
start
=
104
,
end
=
120
,
dynamic
=
True
)
df
[
'forecastPrice'
]
=
model_fit2
.
predict
(
start
=
104
,
end
=
120
,
dynamic
=
True
)
# df[['Product1','forecast']].plot(figsize=(12,8))
model
=
sm
.
tsa
.
statespace
.
SARIMAX
(
df
[
'CALTEX Delo Gold Ultra'
],
order
=
(
1
,
1
,
1
),
seasonal_order
=
(
1
,
1
,
1
,
12
))
model2
=
sm
.
tsa
.
statespace
.
SARIMAX
(
df
[
'Price1'
],
order
=
(
1
,
1
,
1
),
seasonal_order
=
(
1
,
1
,
1
,
12
))
results
=
model
.
fit
()
results2
=
model2
.
fit
()
future_dates
=
[
df
.
index
[
-
1
]
+
DateOffset
(
months
=
x
)
for
x
in
range
(
0
,
150
)]
future_datest_df
=
pd
.
DataFrame
(
index
=
future_dates
[
1
:],
columns
=
df
.
columns
)
# future_datest_df.tail()
future_df
=
pd
.
concat
([
df
,
future_datest_df
])
inputdatex
=
inputdate
inputdate
=
datetime
.
strftime
(
inputdatex
,
"
%
m/
%
d/
%
Y"
)
# 10/01/2025
lastDate
=
'10/01/2021'
inputdate
=
inputdate
date_format
=
"
%
m/
%
d/
%
Y"
a
=
datetime
.
strptime
(
lastDate
,
date_format
)
# user input date
b
=
datetime
.
strptime
(
inputdate
,
date_format
)
delta
=
b
-
a
delta2
=
delta
.
days
# print(delta2)
forcasting_date
=
int
(
delta2
/
30
)
newDate
=
forcasting_date
+
121
# ending number
# print(forcasting_date)
forecast
=
future_df
[
'forecast'
]
=
results
.
predict
(
start
=
119
,
end
=
newDate
,
dynamic
=
True
)
# future_df[['Sales', 'forecast']].plot(figsize=(12, 8))
forecastPrice
=
future_df
[
'forecastPrice'
]
=
results2
.
predict
(
start
=
119
,
end
=
newDate
,
dynamic
=
True
)
# future_df[['Price1', 'forecastPrice']].plot(figsize=(12, 8))
df3
=
forecast
[
-
1
]
df4
=
forecastPrice
[
-
1
]
PredictedDemand
=
int
(
df3
)
PredictedPrice
=
int
(
df4
)
PredictedBudget
=
PredictedDemand
*
PredictedPrice
context
=
{
'arz'
:
PredictedDemand
,
'arz2'
:
PredictedPrice
,
'arz3'
:
PredictedBudget
,
'datagot'
:
inputdate
}
template
=
loader
.
get_template
(
'Admin/Result.html'
)
return
HttpResponse
(
template
.
render
(
context
,
request
))
else
:
form
=
MyForm4
()
#returning form
return
render
(
request
,
'Admin/Forecasting.html'
,
{
'form'
:
form
});
# end Admin ML
def
AdminLogin
(
request
):
if
request
.
method
==
'POST'
:
...
...
db.sqlite3
View file @
547148db
No preview for this file type
templates/Admin/Forecasting.html
0 → 100644
View file @
547148db
{% 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"
>
<br/><br/>
{% if messages %}
<div
class=
"alert alert-danger"
role=
"alert"
>
{% for message in messages %}
{% if message.tags %} {% endif %} {{ message }}
{% endfor %}
</div>
{% endif %}
<div
class=
"card-heading"
>
<h2
class=
"title"
>
DEMAND BUDGET FORECASTING
</h2>
</div>
<div
class=
"card-body"
>
<form
action=
"/Admin/Result/"
method=
"post"
>
{% csrf_token %}
<table
class=
"table table-light"
>
{{form.as_table}}
</table>
<input
type=
"submit"
value=
"FORECAST"
class=
"btn btn--radius-2 btn-primary"
/>
<div
role=
"alert"
>
<center><h3>
{{ Price_prediction }}
</h3></center>
</div>
</form>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
</div><div
class=
"alert alert-primary"
role=
"alert"
>
© SERVPORT 2022
</div>
</div>
{% endblock content %}
templates/Admin/PurchaseHistory.html
0 → 100644
View file @
547148db
{% 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"
>
PURCHASE HISTORY
</h2>
</div>
<div
id=
"myDiv"
>
<div
id=
"div_print"
>
<div
class=
"card card-body printableArea"
>
<div
class=
"container"
style=
"overflow-x:auto; scrollable"
>
<center>
CALTEX Delo Gold Ultra DATATABLE
</center>
<table
class=
"table table-striped"
>
<thead>
<tr>
<th>
Month
</th>
<th>
CALTEX Delo Gold Ultra Qty
</th>
<th>
CALTEX Delo Gold Ultra Price
</th>
</tr>
</thead>
<tbody>
{% if d %}
{% for i in d %}
<tr>
<td>
{{i.Month}}
</td>
<td>
{{i.CALTEX_Delo_Gold_Ultra}}
</td>
<td>
{{i.Price1}}
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
</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"
>
<input
name=
"b_print"
type=
"button"
class=
"btn btn-primary btn-print"
onClick=
"printdiv('div_print');"
value=
" Print "
>
</div>
<div
class=
"alert alert-primary"
role=
"alert"
>
©SERVPORT 2022
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
templates/Admin/Result.html
0 → 100644
View file @
547148db
{% 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>
<center>
<div
class=
">
<div class="
wrapper
wrapper--w790
"
>
<div
style=
"margin-left: 0px;"
class=
"card card-5"
>
<div
class=
"card-heading"
>
<h2
class=
"title"
>
ADVANCE FORECASTING
</h2>
</div>
{% autoescape off %}
<div>
{{ g }}
</div>
{% endautoescape %}
<div
class=
"alert alert-danger"
role=
"alert"
>
Forecasted Demand as at {{ datagot }} is : {{ arz }} Units
<br/>
Forecasted Price as at Rs: {{ datagot }} is : {{ arz2 }}
<br/>
Total Budget Rs: {{ arz3 }}
</div>
<br>
</div>
</div>
</div>
</div>
{% endblock content %}
templates/Admin/Sidebar2.html
View file @
547148db
...
...
@@ -188,6 +188,10 @@ body{
<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=
"#"
><i
class=
"fas fa-upload"
></i>
Assign Employee
</a>
</li>
<li><a
style=
"text-decoration:none;"
href=
"/Admin/Forecasting/"
><i
class=
"fas fa-bullseye "
></i>
Demand Forecasting
</a>
<li><a
style=
"text-decoration:none;"
href=
"/Admin/PurchaseHistory/"
><i
class=
"fas fa-cubes"
></i>
Purchase History
</a>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment