Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: STATISTIC TO RANGE #99

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var rangeRequestChart;

function createOrUpdateDateRangeRequestChart() {
var chartCanvas = document.getElementById("date_range_requests_pie_chart");

// Eliminar el gráfico anterior si existe
if (rangeRequestChart) {
rangeRequestChart.destroy();
}

// Crear el nuevo gráfico
var ctx = chartCanvas.getContext("2d");
rangeRequestChart = new Chart(ctx, {
type: "doughnut",
data: {
labels: ["Solicitudes CEX", "Solicitudes Monitoria", "Solicitudes POS"],
datasets: [
{
data: [
parseInt(document.getElementById("contratos_cex").innerText),
parseInt(document.getElementById("contratos_monitoria").innerText),
parseInt(document.getElementById("contratos_pos").innerText),
],
backgroundColor: ["#1cc88a", "#f6c23e", "#5a5c69"],
hoverBackgroundColor: ["#188f64", "#c99f33", "#3c3e49"],
hoverBorderColor: "rgba(234, 236, 244, 1)",
},
],
},
options: {
maintainAspectRatio: false,
tooltips: {
backgroundColor: "rgb(255,255,255)",
bodyFontColor: "#858796",
borderColor: "#dddfeb",
borderWidth: 1,
xPadding: 15,
yPadding: 15,
displayColors: true,
caretPadding: 10,
},
legend: {
display: true,
},
cutoutPercentage: 80,
},
});
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{% 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="start_date">Seleccionar rango de fechas:</label>
<input type="date" class="form-control" id="start_date" />
<label for="end_date">a</label>
<input type="date" class="form-control" id="end_date" />
</div>

<div class="chart-pie pt-4 pb-2">
<canvas id="date_range_requests_pie_chart"></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 CEX:
<strong><span id="contratos_cex">0</span></strong>
</span>
<br />
<br />
<span class="mr-2">
<i class="fas fa-circle text-warning"></i> Solicitudes Monitorias:
<strong><span id="contratos_monitoria">0</span></strong>
</span>
<br />
<br />
<span class="mr-2">
<i class="fas fa-circle text-gray-800"></i> Solicitudes Prestacion de
Servicios: <strong><span id="contratos_pos">0</span></strong>
</span>
</div>
</div>
</div>
</div>

<p hidden id="date_range_requests">{{ daily_requests }}</p>
<script src="{% static 'vendor/chart.js/Chart.min.js' %}"></script>
<script src="{% static 'js/statistics/date_range_requests_pie_chart.js' %}"></script>

<script>
var startDateInput = document.getElementById("start_date");
var endDateInput = document.getElementById("end_date");

startDateInput.addEventListener("change", updateDateRangeChart);
endDateInput.addEventListener("change", updateDateRangeChart);

function updateDateRangeChart() {
var startDate = startDateInput.value.replace(/[\[\]']/g, "").split(",");
var endDate = endDateInput.value.replace(/[\[\]']/g, "").split(",");

var dateRangeRequests = document.getElementById(
"date_range_requests"
).innerText;
dateRangeRequests = eval(dateRangeRequests);
var selectedData = [];
for (let i = 0; i < dateRangeRequests.length; i++) {
if (
dateRangeRequests[i][0] >= startDate &&
dateRangeRequests[i][0] <= endDate
) {
selectedData.push(dateRangeRequests[i]);
}
}

if (selectedData) {
var sumContratosCex = 0;
var sumContratosMonitoria = 0;
var sumContratosPos = 0;

for (let i = 0; i < selectedData.length; i++) {
sumContratosCex += parseInt(selectedData[i][1]);
sumContratosMonitoria += parseInt(selectedData[i][2]);
sumContratosPos += parseInt(selectedData[i][3]);
}

document.getElementById("contratos_cex").innerText = sumContratosCex;
document.getElementById("contratos_monitoria").innerText = sumContratosMonitoria;
document.getElementById("contratos_pos").innerText = sumContratosPos;
} else {
document.getElementById("contratos_cex").innerText = 0;
document.getElementById("contratos_monitoria").innerText = 0;
document.getElementById("contratos_pos").innerText = 0;
}
createOrUpdateDateRangeRequestChart();
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>General</h2>
{% include 'statistical_registers/components/monthly_requests.html' %}

<!-- Pie Chart -->
{% include 'statistical_registers/components/pie_chart_daily_requests.html' %}
{% include 'statistical_registers/components/pie_chart_date_range_requests.html' %}

{% include 'statistical_registers/components/average_time_and_overdue_requests.html' %}
</div>
Expand All @@ -35,9 +35,7 @@ <h2>General</h2>
function onPageLoad() {
createOrUpdateLeaderChart();
createOrUpdateManagerChart();
createOrUpdateDailyRequestChart();


createOrUpdateDateRangeRequestChart();
}

document.addEventListener("DOMContentLoaded", onPageLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from ..utilities import leader_or_admin_redirect_to_manager_statistics, get_manager_metrics, get_leader_metrics, get_average_duration



class StatisticsView(View):
template_name = 'statistical_registers/statistics.html'

#@method_decorator(leader_or_admin_redirect_to_manager_statistics)
# @method_decorator(leader_or_admin_redirect_to_manager_statistics)
def dispatch(self, request, *args, **kwargs):
# Get the required metrics

Expand All @@ -19,6 +18,6 @@ def dispatch(self, request, *args, **kwargs):
group = {'actualgroup': 'other'}
if self.request.user.groups.first().name == 'admin':
group = {'actualgroup': 'admin'}

# Pass metrics as context to template
return render(request, self.template_name, manager_metrics|leader_metrics|average_duration|group)
return render(request, self.template_name, manager_metrics | leader_metrics | average_duration | group)
6 changes: 5 additions & 1 deletion hiring_module/hiring_app/views/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_manager_metrics():

cex_requests = CEXContractRequest.objects.all()
monitoring_requests = MonitoringContractRequest.objects.all()
pos_requests = ProvisionOfServicesContractRequest.objects.all()
pos_requests = ProvisionOfServicesContractRequest.objects.all()

# Initialize a defaultdict to store requests count for each date
requests_count_by_date = defaultdict(lambda: [0, 0, 0])
Expand Down Expand Up @@ -262,6 +262,10 @@ def get_resolved_after_estimated_date():
return resolved_after_estimated_date_count









Loading