Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
JARVIS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacob Dylan D. Vitug
JARVIS
Commits
b1047e4d
Commit
b1047e4d
authored
Apr 04, 2023
by
Dexter Sapugay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1234567
parent
935a370a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
40 deletions
+93
-40
wsgi.cpython-38.pyc
IPS/IPS/__pycache__/wsgi.cpython-38.pyc
+0
-0
models.cpython-38.pyc
IPS/IPSapp/__pycache__/models.cpython-38.pyc
+0
-0
views.cpython-38.pyc
IPS/IPSapp/__pycache__/views.cpython-38.pyc
+0
-0
models.py
IPS/IPSapp/models.py
+15
-0
chart_template.html
IPS/IPSapp/templates/EmployeeProdDB/chart_template.html
+30
-29
views.py
IPS/IPSapp/views.py
+48
-11
No files found.
IPS/IPS/__pycache__/wsgi.cpython-38.pyc
0 → 100644
View file @
b1047e4d
File added
IPS/IPSapp/__pycache__/models.cpython-38.pyc
View file @
b1047e4d
No preview for this file type
IPS/IPSapp/__pycache__/views.cpython-38.pyc
View file @
b1047e4d
No preview for this file type
IPS/IPSapp/models.py
View file @
b1047e4d
...
...
@@ -99,6 +99,21 @@ class SummaryReport(models.Model):
date
=
models
.
DateField
()
totalworkhrs
=
models
.
DurationField
()
def
getSrno
(
self
):
return
self
.
sr_no
def
getEmployeename
(
self
):
return
self
.
employee_name
def
getProdScore
(
self
):
return
self
.
prod_score
def
getDate
(
self
):
return
self
.
date
def
__str__
(
self
):
return
"pk: "
+
str
(
self
.
pk
)
+
": "
+
self
.
sr_no
+
", "
+
self
.
employee_name
+
", "
+
self
.
prod_score
+
", "
+
self
.
date
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
...
...
IPS/IPSapp/templates/EmployeeProdDB/chart_template.html
View file @
b1047e4d
{% extends 'EmployeeProdDB/base.html' %}
{% block content %}
<div>
<canvas
id=
"myChart"
></canvas>
</div>
<canvas
id=
"myChart"
width=
"250"
height=
"250"
></canvas>
<script
src=
"https://cdn.jsdelivr.net/npm/chart.js"
></script>
<script>
const
ctx
=
document
.
getElementById
(
'myChart'
);
new
Chart
(
ctx
,
{
type
:
'bar'
,
data
:
{
labels
:
[
'Red'
,
'Blue'
,
'Yellow'
,
'Green'
,
'Purple'
,
'Orange'
],
<script>
var
ctx
=
document
.
getElementById
(
'myChart'
).
getContext
(
'2d'
);
var
data
=
{
labels
:
[
'Monday'
,
'Tuesday'
,
'Wednesday'
,
'Thursday'
,
'Friday'
,
'Saturday'
,
'Sunday'
],
datasets
:
[{
label
:
'# of Votes'
,
data
:
[
12
,
19
,
3
,
5
,
2
,
3
],
label
:
'Productivity Score'
,
data
:
[
{
%
for
score
in
daily_scores
%
}
{{
score
.
date
}},
{
%
endfor
%
}
],
backgroundColor
:
'rgba(255, 99, 132, 0.2)'
,
borderColor
:
'rgba(255, 99, 132, 1)'
,
borderWidth
:
1
}]
},
options
:
{
};
var
options
=
{
scales
:
{
y
:
{
beginAtZero
:
true
}
}
}
};
var
myChart
=
new
Chart
(
ctx
,
{
type
:
'bar'
,
data
:
data
,
options
:
options
});
</script>
</script>
{% endblock %}
\ No newline at end of file
IPS/IPSapp/views.py
View file @
b1047e4d
...
...
@@ -12,6 +12,7 @@ from django.views.generic import View
from
django.contrib.auth.decorators
import
login_required
from
django.db.models
import
Sum
from
django.http
import
JsonResponse
from
django.utils
import
timezone
def
home
(
request
):
return
render
(
request
,
'EmployeeProdDB/home.html'
)
...
...
@@ -113,10 +114,6 @@ def loginpage(request):
# return render(request, 'EmployeeProdDB/upload_csv.html')
def
upload_csv
(
request
):
if
request
.
method
==
'POST'
:
csv_file
=
request
.
FILES
[
'csv_file'
]
...
...
@@ -147,14 +144,54 @@ def upload_csv(request):
return
render
(
request
,
'EmployeeProdDB/upload_csv.html'
)
def
chart_template
(
request
):
data
=
SummaryReport
.
objects
.
values
(
'employee_name'
)
.
annotate
(
total_prod_score
=
Sum
(
'prod_score'
))
.
order_by
(
'-total_prod_score'
)[:
10
]
labels
=
list
(
map
(
lambda
x
:
x
[
'employee_name'
],
data
))
data
=
list
(
map
(
lambda
x
:
x
[
'total_prod_score'
],
data
))
return
render
(
request
,
'EmployeeProdDB/chart_template.html'
,
{
'labels'
:
labels
,
'data'
:
data
,
})
data
=
SummaryReport
.
objects
.
all
()
# Get the start and end dates from the request GET parameters
start_date
=
request
.
GET
.
get
(
'start_date'
)
end_date
=
request
.
GET
.
get
(
'end_date'
)
# Set default values if the dates are not provided
if
not
start_date
:
start_date
=
(
datetime
.
now
()
-
timedelta
(
days
=
7
))
.
strftime
(
'
%
Y-
%
m-
%
d'
)
if
not
end_date
:
end_date
=
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
# Query the SummaryReport model to get the daily productivity scores
daily_scores
=
[]
test1array
=
[]
test2array
=
[]
for
day
in
range
(
7
):
date
=
(
datetime
.
strptime
(
start_date
,
'
%
Y-
%
m-
%
d'
)
+
timedelta
(
days
=
day
))
.
date
()
total_score
=
SummaryReport
.
objects
.
filter
(
date
=
date
)
.
aggregate
(
total_score
=
Sum
(
'prod_score'
))[
'total_score'
]
#test1 = SummaryReport.objects.filter(date=date)
test1
=
SummaryReport
.
objects
.
filter
(
date
=
date
)
.
values
()
test2
=
test1
.
aggregate
(
total_score
=
Sum
(
'prod_score'
))[
'total_score'
]
daily_scores
.
append
(
total_score
or
0
)
test1array
.
append
(
test1
)
test2array
.
append
(
test2
)
# Pass the data to the template context
context
=
{
'a1'
:
test1array
,
'a2'
:
test2array
,
'data'
:
data
,
'start_date'
:
start_date
,
'end_date'
:
end_date
,
'daily_scores'
:
daily_scores
}
return
render
(
request
,
'EmployeeProdDB/chart_template.html'
,
context
)
# def chart_template(request):
# data = SummaryReport.objects.values('employee_name').annotate(total_prod_score=Sum('prod_score')).order_by('-total_prod_score')[:10]
# labels = list(map(lambda x: x['employee_name'], data))
# data = list(map(lambda x: x['total_prod_score'], data))
# return render(request, 'EmployeeProdDB/chart_template.html', {
# 'labels': labels,
# 'data': data,
# })
...
...
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