Commit b1047e4d authored by Dexter Sapugay's avatar Dexter Sapugay

1234567

parent 935a370a
......@@ -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(
......
{% 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'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var data = {
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
datasets: [{
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
}]
};
var options = {
scales: {
y: {
beginAtZero: true
}
}
};
var myChart = new Chart(ctx, {
type: 'bar',
data: data,
options: options
});
</script>
{% endblock %}
\ No newline at end of file
......@@ -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,
# })
......
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