Skip to content

Commit

Permalink
Merge pull request #104 from ICESI-PI1-2024A-G1/analysis-with-cancele…
Browse files Browse the repository at this point in the history
…d-requests

END: Analysis with canceled requests
  • Loading branch information
Sebastian-411 authored May 12, 2024
2 parents 3ac7607 + 28254db commit 0698264
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 50 deletions.
1 change: 1 addition & 0 deletions hiring_module/hiring_app/model/contract_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .user_model import CustomUser
from django.utils import timezone
from .contract_request_snapshot_model import ContractRequestSnapshot

def state_choices():
return (
('pending', 'Pending'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var leaderChart;

function createOrUpdateLeaderChart() {
var chartCanvas = document.getElementById("leader_chart_pie");

// Eliminar el gráfico anterior si existe
if (leaderChart) {
leaderChart.destroy();
Expand All @@ -13,15 +13,16 @@ function createOrUpdateLeaderChart() {
leaderChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["Solicitudes Aprobadas", "Solicitudes En revisión", "Solicitudes por validar"],
labels: ["Solicitudes Aprobadas", "Solicitudes En revisión", "Solicitudes por validar","Solicitudes canceladas"],
datasets: [{
data: [
parseInt(document.getElementById("solicitudes_aprobadas_leader").innerText),
parseInt(document.getElementById("solicitudes_en_revision_leader").innerText),
parseInt(document.getElementById("solicitudes_por_validar_leader").innerText)
parseInt(document.getElementById("solicitudes_por_validar_leader").innerText),
parseInt(document.getElementById("solicitudes_canceladas_leader").innerText)
],
backgroundColor: ['#1cc88a', '#f6c23e', '#e74a3b'],
hoverBackgroundColor: ['#188f64', '#c99f33', '#9d342a'],
backgroundColor: ['#1cc88a', '#f6c23e', '#e74a3b','#858795'],
hoverBackgroundColor: ['#188f64', '#c99f33', '#9d342a','#666873'],
hoverBorderColor: "rgba(234, 236, 244, 1)",
}],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var managerChart;

function createOrUpdateManagerChart() {
var chartCanvas = document.getElementById("manager_chart_pie");

// Eliminar el gráfico anterior si existe
if (managerChart) {
managerChart.destroy();
Expand All @@ -13,15 +13,16 @@ function createOrUpdateManagerChart() {
managerChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["Solicitudes Aprobadas", "Solicitudes En revisión", "Solicitudes por validar"],
labels: ["Solicitudes Aprobadas", "Solicitudes En revisión", "Solicitudes por validar", "Solicitudes canceladas"],
datasets: [{
data: [
parseInt(document.getElementById("solicitudes_aprobadas_manager").innerText),
parseInt(document.getElementById("solicitudes_en_revision_manager").innerText),
parseInt(document.getElementById("solicitudes_por_validar_manager").innerText)
parseInt(document.getElementById("solicitudes_por_validar_manager").innerText),
parseInt(document.getElementById("solicitudes_canceladas_manager").innerText)
],
backgroundColor: ['#1cc88a', '#f6c23e', '#e74a3b'],
hoverBackgroundColor: ['#188f64', '#c99f33', '#9d342a'],
backgroundColor: ['#1cc88a', '#f6c23e', '#e74a3b','#858795'],
hoverBackgroundColor: ['#188f64', '#c99f33', '#9d342a','#666873'],
hoverBorderColor: "rgba(234, 236, 244, 1)",
}],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% load static %}
<div class="col-xl-5 col-lg-5">
<div class="card shadow mb-4">

<div class="card-body">
<div class="form-group">
<label for="data_select">Seleccionar Datos:</label>
<label for="data_leader_select">Seleccionar Datos:</label>
<select class="form-control" id="data_leader_select">
{% for item in leader_data %}
<option value="{{ item }}">{{ item.0 }}</option>
Expand All @@ -16,23 +15,27 @@
<canvas id="leader_chart_pie"></canvas>
</div>
<div class="mt-4 text-center small" id="solicitudes_info">


<span class="mr-2">
<i class="fas fa-circle text-success"></i> Solicitudes Aprobadas: <strong><span
id="solicitudes_aprobadas_leader">{{ leader_data.0.1 }}</span></strong>
<i class="fas fa-circle text-success"></i> Solicitudes Aprobadas:
<strong><span id="solicitudes_aprobadas_leader">{{ leader_data.0.1 }}</span></strong>
</span>
<br>
<br>
<span class="mr-2">
<i class="fas fa-circle text-warning"></i> Solicitudes En revisión:
<strong><span id="solicitudes_en_revision_leader">{{ leader_data.0.2 }}</span></strong>
</span>
<br>
<br>
<span class="mr-2">
<i class="fas fa-circle text-warning"></i> Solicitudes En revisión: <strong><span
id="solicitudes_en_revision_leader">{{ leader_data.0.2 }}</span></strong>
<i class="fas fa-circle text-danger"></i> Solicitudes por validar:
<strong><span id="solicitudes_por_validar_leader">{{ leader_data.0.3 }}</span></strong>
</span>
<br>
<br>
<span class="mr-2">
<i class="fas fa-circle text-danger"></i> Solicitudes por validar: <strong><span
id="solicitudes_por_validar_leader">{{ leader_data.0.3 }}</span></strong>
<i class="fas fa-circle text-danger"></i> Solicitudes canceladas:
<strong><span id="solicitudes_canceladas_leader">{{ leader_data.0.4 }}</span></strong>
</span>
</div>
</div>
Expand All @@ -41,22 +44,23 @@
</div>
</div>




<script src="{% static 'js/statistics/leader_pie_chart.js' %}"></script>

<script>

var dailyLeaderSelect = document.getElementById('data_leader_select');

dailyLeaderSelect.addEventListener('change', function () {
var selectedValue = dailyLeaderSelect.value.replace(/[\[\]']/g, '').split(',');

document.getElementById('solicitudes_aprobadas_leader').innerText = selectedValue[1];
document.getElementById('solicitudes_en_revision_leader').innerText = selectedValue[2];
document.getElementById('solicitudes_por_validar_leader').innerText = selectedValue[3];
document.getElementById('solicitudes_canceladas_leader').innerText = selectedValue[4];

createOrUpdateLeaderChart();
});

</script>
</script>

<script>createOrUpdateLeaderChart()</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="card shadow mb-4">
<div class="card-body">
<div class="form-group">
<label for="data_select">Seleccionar Datos:</label>
<select class="form-control" id="data_select">
<label for="data_manager_select">Seleccionar Datos:</label>
<select class="form-control" id="data_manager_select">
{% for item in manager_data %}
<option value="{{ item }}">{{ item.0 }}</option>
{% endfor %}
Expand All @@ -31,22 +31,34 @@
<i class="fas fa-circle text-danger"></i> Solicitudes por validar:
<strong><span id="solicitudes_por_validar_manager">{{ manager_data.0.3 }}</span></strong>
</span>
<br />
<br />
<span class="mr-2">
<i class="fas fa-circle text-secondary"></i> Solicitudes canceladas:
<strong><span id="solicitudes_canceladas_manager">{{ manager_data.0.4 }}</span></strong>
</span>
</div>
</div>
</div>
</div>

<script>
<script src="{% static 'js/statistics/manager_pie_chart.js' %}"></script>


var dailySelect = document.getElementById('data_select');
<script>

dailySelect.addEventListener('change', function () {
var selectedValue = dailySelect.value.replace(/[\[\]']/g, '').split(',');
var dailyManagerSelect = document.getElementById('data_manager_select');

dailyManagerSelect.addEventListener('change', function () {
var selectedValue = dailyManagerSelect.value.replace(/[\[\]']/g, '').split(',');

document.getElementById('solicitudes_aprobadas_manager').innerText = selectedValue[1];
document.getElementById('solicitudes_en_revision_manager').innerText = selectedValue[2];
document.getElementById('solicitudes_por_validar_manager').innerText = selectedValue[3];
document.getElementById('solicitudes_canceladas_manager').innerText = selectedValue[4];

createOrUpdateManagerChart();
});
</script>
</script>

<script>createOrUpdateManagerChart()</script>
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ <h2>General</h2>

</div>


<script>
function onPageLoad() {
window.onload = function() {
createOrUpdateLeaderChart();
createOrUpdateManagerChart();
createOrUpdateDailyRequestChart();
createOrUpdateDateRangeRequestChart();
}

document.addEventListener("DOMContentLoaded", onPageLoad);
</script>

<script src="{% static 'vendor/chart.js/Chart.min.js' %}"></script>
<script src="{% static 'js/statistics/manager_pie_chart.js' %}"></script>
<script src="{% static 'js/statistics/leader_pie_chart.js' %}"></script>


{% endblock %}
42 changes: 39 additions & 3 deletions hiring_module/hiring_app/views/control_board/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from django.http import HttpResponse
from openpyxl import Workbook

from datetime import datetime
from django.db.models import Q
from django.utils import timezone
from itertools import chain


# Decorator to redirect users to the correct dashboard based on their role
def role_redirect(view_func):
@wraps(view_func)
Expand Down Expand Up @@ -96,10 +102,40 @@ def get_requests(user):
groupLeader = Group.objects.get(name='leader')
managers = list(CustomUser.objects.filter(groups=groupManager))
leaders = list(CustomUser.objects.filter(groups=groupLeader))

current_date = timezone.now()
current_month = current_date.month
current_year = current_date.year

requests = list(
chain(
requests_CEX.filter(start_date__month=current_month, start_date__year=current_year),
requests_monitoring.filter(start_date__month=current_month, start_date__year=current_year),
requests_pos.filter(start_date__month=current_month, start_date__year=current_year)
)
)

filled_requests = list(
chain(
requests_CEX.filter(start_date__month=current_month, start_date__year=current_year, state='filed'),
requests_monitoring.filter(start_date__month=current_month, start_date__year=current_year, state='filed'),
requests_pos.filter(start_date__month=current_month, start_date__year=current_year, state='filed')
)
)

reviewed_requests = list(
chain(
requests_CEX.filter(start_date__month=current_month, start_date__year=current_year, state='review'),
requests_monitoring.filter(start_date__month=current_month, start_date__year=current_year, state='review'),
requests_pos.filter(start_date__month=current_month, start_date__year=current_year, state='review')
)
)


return {
'requests': list(requests_CEX) + list(requests_monitoring) + list(requests_pos),
'filled_requests': list(requests_CEX.filter(state='filed')) + list(requests_monitoring.filter(state='filed')) + list(requests_pos.filter(state='filed')),
'reviewed_requests': list(requests_CEX.filter(state='review')) + list(requests_monitoring.filter(state='review')) + list(requests_pos.filter(state='review')),
'requests': requests,
'filled_requests': filled_requests,
'reviewed_requests': reviewed_requests,
'for_validate_requests': list(requests_CEX.filter(state__in=['pending', 'incomplete'])) + list(requests_monitoring.filter(state__in=['pending', 'incomplete'])) + list(requests_pos.filter(state__in=['pending', 'incomplete'])),
'leaders': leaders,
'managers': managers,
Expand Down
29 changes: 19 additions & 10 deletions hiring_module/hiring_app/views/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ def get_manager_metrics():
) + pos_requests.filter(state='incomplete').count(
)

cancelled_requests = cex_requests.filter(state='cancelled').count(
) + monitoring_requests.filter(state='cancelled').count(
) + pos_requests.filter(state='cancelled').count(
)

data.append([(manager.first_name + ' ' + manager.last_name), approved_requests,
review_requests, for_validate_requests])
review_requests, for_validate_requests,cancelled_requests])


best_to_worse_manager.append([(manager.first_name + ' ' + manager.last_name), quality_calculator(approved_requests, review_requests, for_validate_requests)])
best_to_worse_manager.append([(manager.first_name + ' ' + manager.last_name), quality_calculator(approved_requests, review_requests, for_validate_requests,cancelled_requests)])

best_to_worse_manager = sorted(best_to_worse_manager, key=lambda x: x[1], reverse=True)

Expand Down Expand Up @@ -191,12 +195,17 @@ def get_leader_metrics():
) + pos_requests.filter(state='incomplete').count(
)

cancelled_requests = cex_requests.filter(state='cancelled').count(
) + monitoring_requests.filter(state='cancelled').count(
) + pos_requests.filter(state='cancelled').count(
)


data.append([(leader.first_name + ' ' + leader.last_name), approved_requests,
review_requests, for_validate_requests])
review_requests, for_validate_requests,cancelled_requests])


best_to_worse_leader.append([(leader.first_name + ' ' + leader.last_name), quality_calculator(approved_requests, review_requests, for_validate_requests)])
best_to_worse_leader.append([(leader.first_name + ' ' + leader.last_name), quality_calculator(approved_requests, review_requests, for_validate_requests,cancelled_requests)])

best_to_worse_leader = sorted(best_to_worse_leader, key=lambda x: x[1], reverse=True)

Expand All @@ -212,13 +221,13 @@ def get_leader_metrics():
}


def quality_calculator(aprobadas, en_revision, por_validar):
total = aprobadas + en_revision + por_validar
def quality_calculator(approved_requests, under_review_requests, for_validate_requests, cancelled_requests):
total = approved_requests + under_review_requests + for_validate_requests + cancelled_requests

if total != 0:
porcentaje_aprobadas = (aprobadas / total) * 100
porcentaje_aprobadas = round(porcentaje_aprobadas, 2)
return porcentaje_aprobadas
quality = ((approved_requests + cancelled_requests)/ total) * 100
quality = round(quality, 2)
return quality
else:
return 0

Expand All @@ -229,7 +238,7 @@ def get_average_duration():
list(ProvisionOfServicesContractRequest.objects.filter(Q(state='filed') | Q(state='cancelled')))
)

total_duration_seconds = sum((request.completion_date - timezone.make_aware(datetime.combine(request.start_date, datetime.min.time()), timezone.utc)).total_seconds() for request in approved_or_cancelled_requests if request.completion_date and request.start_date)
total_duration_seconds = sum((request.completion_date - timezone.make_aware(datetime.combine(request.start_date, datetime.min.time()))).total_seconds() for request in approved_or_cancelled_requests if request.completion_date and request.start_date)
total_count = len(approved_or_cancelled_requests)
total_avg_duration_seconds = total_duration_seconds / total_count if total_count > 0 else 0

Expand Down

0 comments on commit 0698264

Please sign in to comment.