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
d3b3629f
Commit
d3b3629f
authored
Apr 04, 2023
by
DwyxE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
csv now read yay
parent
07abeafd
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
161 additions
and
42 deletions
+161
-42
models.cpython-39.pyc
IPS/IPSapp/__pycache__/models.cpython-39.pyc
+0
-0
urls.cpython-39.pyc
IPS/IPSapp/__pycache__/urls.cpython-39.pyc
+0
-0
views.cpython-39.pyc
IPS/IPSapp/__pycache__/views.cpython-39.pyc
+0
-0
0002_summaryreport_employee_name_and_more.py
...p/migrations/0002_summaryreport_employee_name_and_more.py
+23
-0
0003_alter_summaryreport_prod_score.py
IPS/IPSapp/migrations/0003_alter_summaryreport_prod_score.py
+18
-0
0002_summaryreport_employee_name_and_more.cpython-39.pyc
.../0002_summaryreport_employee_name_and_more.cpython-39.pyc
+0
-0
0003_alter_summaryreport_prod_score.cpython-39.pyc
...ache__/0003_alter_summaryreport_prod_score.cpython-39.pyc
+0
-0
models.py
IPS/IPSapp/models.py
+3
-3
chart_template.html
IPS/IPSapp/templates/EmployeeProdDB/chart_template.html
+43
-6
show_csv_data2.html
IPS/IPSapp/templates/EmployeeProdDB/show_csv_data2.html
+1
-1
urls.py
IPS/IPSapp/urls.py
+2
-1
views.py
IPS/IPSapp/views.py
+71
-31
No files found.
IPS/IPSapp/__pycache__/models.cpython-39.pyc
View file @
d3b3629f
No preview for this file type
IPS/IPSapp/__pycache__/urls.cpython-39.pyc
View file @
d3b3629f
No preview for this file type
IPS/IPSapp/__pycache__/views.cpython-39.pyc
View file @
d3b3629f
No preview for this file type
IPS/IPSapp/migrations/0002_summaryreport_employee_name_and_more.py
0 → 100644
View file @
d3b3629f
# Generated by Django 4.2 on 2023-04-04 12:23
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'IPSapp'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'summaryreport'
,
name
=
'employee_name'
,
field
=
models
.
CharField
(
default
=
'No Name'
,
max_length
=
255
),
),
migrations
.
AlterField
(
model_name
=
'productivity'
,
name
=
'report_no'
,
field
=
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
),
),
]
IPS/IPSapp/migrations/0003_alter_summaryreport_prod_score.py
0 → 100644
View file @
d3b3629f
# Generated by Django 4.2 on 2023-04-04 13:02
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'IPSapp'
,
'0002_summaryreport_employee_name_and_more'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'summaryreport'
,
name
=
'prod_score'
,
field
=
models
.
FloatField
(),
),
]
IPS/IPSapp/migrations/__pycache__/0002_summaryreport_employee_name_and_more.cpython-39.pyc
0 → 100644
View file @
d3b3629f
File added
IPS/IPSapp/migrations/__pycache__/0003_alter_summaryreport_prod_score.cpython-39.pyc
0 → 100644
View file @
d3b3629f
File added
IPS/IPSapp/models.py
View file @
d3b3629f
...
@@ -22,7 +22,7 @@ class Employee(models.Model):
...
@@ -22,7 +22,7 @@ class Employee(models.Model):
# db_table = 'employee'
# db_table = 'employee'
class
Productivity
(
models
.
Model
):
class
Productivity
(
models
.
Model
):
report_no
=
models
.
AutoField
(
max_length
=
10
,
primary_key
=
True
)
report_no
=
models
.
AutoField
(
primary_key
=
True
)
#employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
#employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
prod_date
=
models
.
DateField
(
null
=
True
)
prod_date
=
models
.
DateField
(
null
=
True
)
workinghours
=
models
.
DurationField
()
workinghours
=
models
.
DurationField
()
...
@@ -94,8 +94,8 @@ class History(models.Model):
...
@@ -94,8 +94,8 @@ class History(models.Model):
class
SummaryReport
(
models
.
Model
):
class
SummaryReport
(
models
.
Model
):
sr_no
=
models
.
AutoField
(
primary_key
=
True
)
sr_no
=
models
.
AutoField
(
primary_key
=
True
)
employee_name
=
models
.
CharField
(
max_length
=
255
)
employee_name
=
models
.
CharField
(
max_length
=
255
,
default
=
"No Name"
)
prod_score
=
models
.
Integer
Field
()
prod_score
=
models
.
Float
Field
()
date
=
models
.
DateField
()
date
=
models
.
DateField
()
totalworkhrs
=
models
.
DurationField
()
totalworkhrs
=
models
.
DurationField
()
...
...
IPS/IPSapp/templates/EmployeeProdDB/chart_template.html
View file @
d3b3629f
{% extends 'base.html' %}
<html>
<head>
<title>
Bar Chart Example using Chart.js
</title>
<!-- Load Chart.js from jsdelivr -->
<script
src=
"https://cdn.jsdelivr.net/npm/chart.js"
></script>
</head>
<!-- <body>
<canvas id="myChart"></canvas>
<script>
// Get the data from the server using Django templates
const data = JSON.parse('{{ summary_data | safe }}');
// Get the labels and values from the data
const labels = data.map(entry => entry.employee_name);
const values = data.map(entry => entry.prod_score);
// Create a new Chart.js instance
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Productivity Score',
data: values,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
</body> -->
</html>
{% block content %}
<div
id=
"chart-container"
>
{{ chart|safe }}
</div>
{% endblock %}
\ No newline at end of file
IPS/IPSapp/templates/EmployeeProdDB/show_csv_data2.html
View file @
d3b3629f
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<td>
{{ row.sr_no}}
</td>
<td>
{{ row.sr_no}}
</td>
<td>
{{ row.employee_name}}
</td>
<td>
{{ row.employee_name}}
</td>
<td>
{{ row.date}}
</td>
<td>
{{ row.date}}
</td>
<td>
{{ row.prod
uctivity
_score }}
</td>
<td>
{{ row.prod_score }}
</td>
<td>
{{ row.totalworkhrs }}
</td>
<td>
{{ row.totalworkhrs }}
</td>
<!-- add more cells for additional fields -->
<!-- add more cells for additional fields -->
</tr>
</tr>
...
...
IPS/IPSapp/urls.py
View file @
d3b3629f
...
@@ -9,7 +9,8 @@ urlpatterns = [
...
@@ -9,7 +9,8 @@ urlpatterns = [
path
(
'upload_csv/'
,
views
.
upload_csv
,
name
=
'upload_csv'
),
path
(
'upload_csv/'
,
views
.
upload_csv
,
name
=
'upload_csv'
),
path
(
'show_csv_data/'
,
views
.
show_csv_data
,
name
=
'show_csv_data'
),
path
(
'show_csv_data/'
,
views
.
show_csv_data
,
name
=
'show_csv_data'
),
path
(
'signup/'
,
views
.
signup
,
name
=
'signup'
),
path
(
'signup/'
,
views
.
signup
,
name
=
'signup'
),
path
(
'show_csv_data2/'
,
views
.
show_csv_data2
,
name
=
'show_csv_data2'
)
path
(
'show_csv_data2/'
,
views
.
show_csv_data2
,
name
=
'show_csv_data2'
),
path
(
'chart_template/'
,
views
.
chart_template
,
name
=
'chart_template'
)
# path('', views.login_page, name='loginpage'),
# path('', views.login_page, name='loginpage'),
]
]
\ No newline at end of file
IPS/IPSapp/views.py
View file @
d3b3629f
...
@@ -10,6 +10,8 @@ from django.views.generic import View
...
@@ -10,6 +10,8 @@ from django.views.generic import View
# from chartjs.views.lines import BaseLineChartView
# from chartjs.views.lines import BaseLineChartView
# import Chart from 'chart.js/auto';
# import Chart from 'chart.js/auto';
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.db.models
import
Sum
from
django.http
import
JsonResponse
def
home
(
request
):
def
home
(
request
):
return
render
(
request
,
'EmployeeProdDB/home.html'
)
return
render
(
request
,
'EmployeeProdDB/home.html'
)
...
@@ -75,46 +77,84 @@ def loginpage(request):
...
@@ -75,46 +77,84 @@ def loginpage(request):
else
:
else
:
return
render
(
request
,
'EmployeeProdDB/loginpage.html'
)
return
render
(
request
,
'EmployeeProdDB/loginpage.html'
)
# def upload_csv(request):
# if request.method == 'POST':
# csv_file = request.FILES['csv_file']
# if not csv_file.name.endswith('.csv'):
# messages.error(request, 'This is not a CSV file')
# else:
# # read the data from the uploaded file
# csv_data = csv.reader(
# (line.decode('utf-8') for line in csv_file),
# delimiter=',',
# quotechar='"'
# )
# #Loop through data rows
# for i, row in enumerate(csv_data):
# # Check if this row is the start of a new report
# if row[0] == 'PRODUCTIVITY REPORT':
# # Reset variables for the new report
# sr_no = row[1]
# employee_name= None
# prod_score = None
# date = None
# totalworkhrs = None
# # Check if this is the fifth row after the start of the report
# elif i == 4 and employee_name is None:
# employee_name = row[0]
# # Check if this row contains a date and "Total Duration:" and "Productivity %"
# if len(row) > 2 and "/" in row[0] and "Total Duration:" in row and "Productivity %" in row:
# date = datetime.strptime(row[0], '%m/%d/%Y').date()
# totalworkhrs = timedelta(hours=float(row[row.index("Total Duration:") + 2]))
# prod_score = int(row[row.index("Productivity %") + 2])
# summary_pr = SummaryReport.objects.create(sr_no=sr_no, employee_name=employee_name, prod_score=prod_score, date=date, totalworkhrs=totalworkhrs)
# summary_pr.save()
# return redirect('home')
# return render(request, 'EmployeeProdDB/upload_csv.html')
def
upload_csv
(
request
):
def
upload_csv
(
request
):
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
csv_file
=
request
.
FILES
[
'csv_file'
]
csv_file
=
request
.
FILES
[
'csv_file'
]
if
not
csv_file
.
name
.
endswith
(
'.csv'
):
if
not
csv_file
.
name
.
endswith
(
'.csv'
):
messages
.
error
(
request
,
'This is not a CSV file'
)
messages
.
error
(
request
,
'This is not a CSV file'
)
else
:
else
:
# read the data from the uploaded file
# Read the data from the uploaded file
csv_data
=
csv
.
reader
(
csv_data
=
csv
.
DictReader
(
csv_file
.
read
()
.
decode
(
'utf-8'
)
.
splitlines
())
(
line
.
decode
(
'utf-8'
)
for
line
in
csv_file
),
delimiter
=
','
,
# Loop through data rows
quotechar
=
'"'
for
row
in
csv_data
:
)
# Convert duration string to a Duration object
#Loop through data rows
working_hours
=
row
[
'Work Hours'
]
for
i
,
row
in
enumerate
(
csv_data
):
if
working_hours
:
# Check if this row is the start of a new report
hours
,
minutes
,
seconds
=
map
(
int
,
working_hours
.
split
(
':'
))
if
row
[
0
]
==
'PRODUCTIVITY REPORT'
:
working_hours
=
timedelta
(
hours
=
hours
,
minutes
=
minutes
,
seconds
=
seconds
)
# Reset variables for the new report
sr_no
=
row
[
1
]
# Create a new SummaryReport object
employee_name
=
None
summary_report
=
SummaryReport
.
objects
.
create
(
prod_score
=
None
employee_name
=
row
[
'Employee Name'
],
date
=
None
prod_score
=
row
[
'Productivity Score'
],
totalworkhrs
=
None
date
=
row
[
'Date'
],
# Check if this is the fifth row after the start of the report
totalworkhrs
=
working_hours
elif
i
==
4
and
employee_name
is
None
:
)
employee_name
=
row
[
0
]
# Check if this row contains a date and "Total Duration:" and "Productivity %"
return
render
(
request
,
'EmployeeProdDB/upload_csv.html'
,
{
'message'
:
'Data imported successfully!'
})
if
len
(
row
)
>
2
and
"/"
in
row
[
0
]
and
"Total Duration:"
in
row
and
"Productivity
%
"
in
row
:
date
=
datetime
.
strptime
(
row
[
0
],
'
%
m/
%
d/
%
Y'
)
.
date
()
totalworkhrs
=
timedelta
(
hours
=
float
(
row
[
row
.
index
(
"Total Duration:"
)
+
2
]))
prod_score
=
int
(
row
[
row
.
index
(
"Productivity
%
"
)
+
2
])
summary_pr
=
SummaryReport
.
objects
.
create
(
sr_no
=
sr_no
,
employee_name
=
employee_name
,
prod_score
=
prod_score
,
date
=
date
,
totalworkhrs
=
totalworkhrs
)
summary_pr
.
save
()
return
redirect
(
'home'
)
return
render
(
request
,
'EmployeeProdDB/upload_csv.html'
)
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
,
})
...
...
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