Skip to content

Commit

Permalink
Filtered out MAKE events and special reservations.
Browse files Browse the repository at this point in the history
Fixed issues with importing charts.
  • Loading branch information
elisakiv committed Aug 31, 2023
1 parent d7baa9a commit c046436
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 46 deletions.
35 changes: 16 additions & 19 deletions src/makerspace/static/makerspace/js/statistics_charts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Chart.defaults.font.family = "Ubuntu";
Chart.defaults.font.weight = 500;
Chart.defaults.font.size = 12.5;

function span_printer_reservations() {
const ct1 = $('#span_printer_reservations').get(0).getContext("2d");
const data = JSON.parse($('#span_of_printer_reservations').get(0).textContent);
Chart.defaults.font.family = "Ubuntu";
Chart.defaults.font.weight = 500;
Chart.defaults.font.size = 12.5;

new Chart(ct1, {
type: 'bar',
Expand Down Expand Up @@ -77,8 +79,7 @@ function printer_reservations() {
'rgb(250, 163, 7)',
'rgb(255, 186, 8)',
],
fill:
true,
fill: true,
}]
},
options: {
Expand All @@ -99,7 +100,7 @@ function printer_reservations() {
}
}
},
plugins:{
plugins: {
legend: {
display: false
}
Expand Down Expand Up @@ -131,8 +132,7 @@ function span_of_sewingmachine_reservations() {
'rgb(72, 149, 239)',
'rgb(76, 201, 240)',
],
fill:
true,
fill: true,
}]
},
options: {
Expand All @@ -144,10 +144,10 @@ function span_of_sewingmachine_reservations() {
title: {
display: true,
text: gettext("Hours reserved"),
}
},
}
},
},
plugins:{
plugins: {
legend: {
display: false
}
Expand Down Expand Up @@ -177,8 +177,7 @@ function sewingmachine_reservations() {
'rgb(174, 32, 18)',
'rgb(155, 34, 38)',
],
fill:
true,
fill: true,
}]
},
options: {
Expand All @@ -194,7 +193,7 @@ function sewingmachine_reservations() {
}
},
},
plugins:{
plugins: {
legend: {
display: false
}
Expand All @@ -221,14 +220,12 @@ function longest_printer_reservations() {
'rgb(192,192,192)',
'rgb(205,127,50)',
],
fill:
true,
fill: true,
}]
},
options: {
events: [],
scales:
{
scales: {
y: {
beginAtZero: true,
display: true,
Expand All @@ -245,7 +242,7 @@ function longest_printer_reservations() {
}
}
},
plugins:{
plugins: {
legend: {
display: false
}
Expand Down
20 changes: 14 additions & 6 deletions src/makerspace/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,29 @@ class EquipmentDeleteView(PermissionRequiredMixin, PreventGetRequestsMixin, Dele
class StatisticsView(TemplateView):
template_name = 'makerspace/statistics.html'
get_time_in_hours = 3600000000 # number the reservation length needs to be divided by to get the length in hours
filter_reservations = Q(reservations__special=False) & Q(reservations__event__isnull=True)

reservations = Reservation.objects.prefetch_related(Prefetch('machine', queryset=Machine.objects.
prefetch_related('machine_type'))).annotate(q_overnight=Sum(F('start_time__hour') - F('end_time__hour')))
sewingmachines = Machine.objects.prefetch_related('machine_type', 'reservation').filter(machine_type__name__icontains="Symaskiner").annotate(len=(Sum((F('reservations__end_time')-F('reservations__start_time'))/get_time_in_hours, output_field=IntegerField()))).\
annotate(number_of_reservations=Count('reservations'))
printers = Machine.objects.prefetch_related('machine_type', 'reservation').filter(machine_type__name__icontains="3D-printere").annotate(len=(Sum((F('reservations__end_time')-F('reservations__start_time'))/get_time_in_hours, output_field=IntegerField()))).\
annotate(number_of_reservations=Count('reservations'))
prefetch_related('machine_type'))).filter(special=False).annotate(
q_overnight=Sum(F('start_time__hour') - F('end_time__hour')))

sewingmachines = Machine.objects.prefetch_related('machine_type', 'reservation').filter(
Q(machine_type__name__icontains="Symaskiner") & filter_reservations).annotate(
len=(Sum((F('reservations__end_time') - F('reservations__start_time')) / get_time_in_hours, output_field=IntegerField()))).annotate(
number_of_reservations=Count('reservations'))

printers = Machine.objects.prefetch_related('machine_type', 'reservation').filter(
Q(machine_type__name__icontains="3D-printere") & filter_reservations).annotate(
len=(Sum((F('reservations__end_time') - F('reservations__start_time')) / get_time_in_hours, output_field=IntegerField()))).annotate(
number_of_reservations=Count('reservations'))

def get_time_distribution(self):
overnight = self.reservations.filter(q_overnight__gte=0) # reservations overnight has to be counted differently
not_overnight = self.reservations.exclude(q_overnight__gte=0)
time = {}
for r in range(0, 24):
time[r] = not_overnight.filter(Q(start_time__hour__lte=r) & Q(end_time__hour__gte=(r - 1))).count()
time[r] += overnight.filter(Q(start_time__hour__lte=r) | Q(end_time__hour__gte=(r-1))).count()
time[r] += overnight.filter(Q(start_time__hour__lte=r) | Q(end_time__hour__gte=(r - 1))).count()
return dict(time.items())

Check warning on line 101 in src/makerspace/views.py

View check run for this annotation

Codecov / codecov/patch

src/makerspace/views.py#L95-L101

Added lines #L95 - L101 were not covered by tests

def get_context_data(self, **kwargs):
Expand Down
20 changes: 0 additions & 20 deletions src/web/static/lib/chartsjs/charts.min.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/web/static/lib/chartsjs/charts.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/templates/web/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<script src="{% static 'lib/jquery/jquery.min.js' %}"></script>
<script src="{% static 'lib/jquery/jquery.dirty.js' %}"></script>
<script src="{% static 'lib/fomantic-ui/semantic.min.js' %}"></script>
<script src="{% static 'lib/chartsjs/charts.min.js' %}"></script>
<script src="{% static 'lib/chartsjs/charts.umd.js' %}"></script>

<script src="{% static 'fomantic-ui/settings.js' %}"></script>

Expand Down

0 comments on commit c046436

Please sign in to comment.