Skip to content

Commit

Permalink
Table view changes (#45)
Browse files Browse the repository at this point in the history
* updates to basic buttons

* added animation to home page and updated theme

* tailwind formatting

* added smooth home page animation

* crud table addition

* cleaned up inspection view

* same update to download csv view

* more frontend fixes

* updated logo

* created skelton for docs page

* new branch with buggy code

* removed secret key for sendgrid

* bug fix

* another bug fix

* more fixes

* edits to table view

* edits to schedule backend

* removed generte sch url

* styled schedule table view

* table styling

* new branch

* stats and some changes for schedule editing

* stats and some changes data collection templataes

* table view editing feature

Co-authored-by: NullDefault <[email protected]>
Co-authored-by: abax17 <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2021
1 parent f441df3 commit f57453c
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 76 deletions.
10 changes: 8 additions & 2 deletions database/models/schedule_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ class Timeblock(models.Model):
end_minutes = models.IntegerField(choices=POSSIBLE_MINUTES)

def __str__(self):
def pad(val):
if len(val) == 1:
return "0" + val
else:
return val

return self.block_id + " " + "(" + str(self.weekdays) + ")" \
+ " " + str(self.start_hour) + ":" + str(self.start_minutes) + \
" - " + str(self.end_hour) + ":" + str(self.end_minutes)
+ " " + pad(str(self.start_hour)) + ":" + pad(str(self.start_minutes)) + \
" - " + pad(str(self.end_hour)) + ":" + pad(str(self.end_minutes))
54 changes: 52 additions & 2 deletions database/templatetags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,56 @@ def parse_var(value):
return value


@register.filter
@stringfilter
def get_timeblock_letter(value):
return value[0]


@register.filter
@stringfilter
def parse_time(value):
id_letter = value[0] # will return the letter name of the block
if id_letter == 'A':
return '7:45 AM - 8:50 AM'
elif id_letter == 'B':
return '8:00 AM - 8:50 AM'
elif id_letter == 'C':
return '09:00 AM - 10:15 AM'
elif id_letter == 'D':
return '09:00 AM - 10:15 AM'
elif id_letter == 'E':
return '10:25 AM - 11:40 AM'
elif id_letter == 'F':
return '10:25 AM - 11:40 AM'
elif id_letter == 'G':
return '11:50 AM - 01:05 PM'
elif id_letter == 'H':
return '11:50 AM - 01:05 PM'
elif id_letter == 'J':
return '01:15 PM - 02:30 PM'
elif id_letter == 'K':
return '01:15 PM - 02:30 PM'
elif id_letter == 'L':
return '04:30 PM - 05:45 PM'
elif id_letter == 'M':
return '04:30 PM - 05:45 PM'
elif id_letter == 'P':
return '07:00 PM - 09:30 PM'
elif id_letter == 'Q':
return '07:00 PM - 09:30 PM'
elif id_letter == 'R':
return '07:00 PM - 09:30 PM'
elif id_letter == 'S':
return '07:00 PM - 09:30 PM'
elif id_letter == 'T':
return '02:40 PM - 03:55 PM'
elif id_letter == 'Z':
return '02:40 PM - 03:55 PM'

return value


@register.filter
@stringfilter
def clean_preference_field_name(value):
Expand Down Expand Up @@ -64,13 +114,13 @@ def obj_to_dynamic_model_name(value):


@register.simple_tag()
def get_course_stats(form):
def get_course_stats(form, total):
stats_list = []
courses = Course.objects.filter(sets__set=form.course_set)
for course in courses:
stats_list.append({
'course': course,
'count': form.entries.filter(courses=course).count()
'count': form.entries.filter(courses=course).count()/(total*1.00)*100
})

return stats_list
Expand Down
12 changes: 10 additions & 2 deletions schedule/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from django.forms import forms, ModelChoiceField
from database.forms import CrispyModelForm, label_dict

from database.models.schedule_models import Schedule
from django.forms import forms, ModelChoiceField
from database.models.schedule_models import Schedule, Section
from database.models.structural_models import ModelSet


class CheckScheduleForm(forms.Form):
schedule = ModelChoiceField(queryset=Schedule.objects.all())
preference_set = ModelChoiceField(queryset=ModelSet.objects.filter(obj_type__model='preference'))


class ScheduleSectionEditForm(CrispyModelForm):
class Meta:
model = Section
fields = ('timeblock', 'primary_instructor', 'other_instructor',)
labels = label_dict
4 changes: 4 additions & 0 deletions schedule/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
path('schedule/<slug:schedule_id>/<slug:preference_set_id>', schedule.views.ScheduleView.as_view(),
name='schedule-table-view'),
path('schedule-redirect', schedule.views.ScheduleRedirectView.as_view(), name='schedule-redirect'),
path(
'schedule/<slug:schedule_id>/<slug:preference_set_id>/<slug:section_id>',
schedule.views.ScheduleSectionEditView.as_view(), name='schedule-section-edit'
),
]

app_name = 'schedule'
65 changes: 51 additions & 14 deletions schedule/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from database.models.schedule_models import Section, Timeblock
from database.models.structural_models import Preference
from schedule.forms import CheckScheduleForm
from schedule.forms import CheckScheduleForm, ScheduleSectionEditForm


class ScheduleRedirectView(LoginRequiredMixin, FormView):
Expand Down Expand Up @@ -69,8 +69,10 @@ def get_context_data(self, **kwargs):
section_time_block_dict[section.timeblock.id].append(section)
sections_dict[section.id] = {
'section': section,
'section_edit_form': ScheduleSectionEditForm(instance=section),
'color': '',
'hints': []
'positive_points': [],
'negative_points': []
}

for idx, section1 in enumerate(sections):
Expand All @@ -81,32 +83,39 @@ def get_context_data(self, **kwargs):
if preference_courses == section_courses:
color1 = sections_dict[section1.id].get('color')
color2 = sections_dict[section2.id].get('color')
print(preference)
if preference.weight:
if section1.timeblock == section2.timeblock:
# If two courses with a positive preference are at the same time, highlight both green.
if color1 != 'red':
sections_dict[section1.id]['color'] = 'green'
if color2 != 'red':
sections_dict[section2.id]['color'] = 'green'
sections_dict[section1.id]['positive_points'].append(
'courses with a positive preference are at the same time'
)
sections_dict[section2.id]['positive_points'].append(
'courses with a positive preference are at the same time'
)
else:
# If two courses with a positive preference are at different times, highlight both red.
sections_dict[section1.id]['color'] = 'red'
sections_dict[section1.id]['hints'].append(
sections_dict[section1.id]['negative_points'].append(
'courses with a positive preference are at different times'
)
sections_dict[section2.id]['color'] = 'red'
sections_dict[section2.id]['hints'].append(
sections_dict[section2.id]['negative_points'].append(
'courses with a positive preference are at different times'
)
else:
# If two courses with a negative preference are at the same time, highlight both red.
if section1.timeblock == section2.timeblock:
sections_dict[section1.id]['color'] = 'red'
sections_dict[section1.id]['hints'].append(
sections_dict[section1.id]['negative_points'].append(
'courses with a negative preference are at the same time'
)
sections_dict[section2.id]['color'] = 'red'
sections_dict[section2.id]['hints'].append(
sections_dict[section2.id]['negative_points'].append(
'courses with a negative preference are at the same time'
)

Expand All @@ -124,9 +133,10 @@ def get_context_data(self, **kwargs):
'time_blocks': time_blocks,
'timeblock_day_dict': timeblock_day_dict,
'day_list': ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
'sections': sections_dict
'sections': sections_dict,
'schedule_id': kwargs.get('schedule_id'),
'preference_set_id': kwargs.get('preference_set_id')
})
print(sections_dict)

return context_data

Expand Down Expand Up @@ -161,18 +171,21 @@ def check_course_timeblock_preference(self, section, preferences, sections_dict)
# green.
if color != 'red':
sections_dict[section.id]['color'] = 'green'
sections_dict[section.id]['positive_points'].append(
'preference is positive, and the course is at the specified timeblock'
)
else:
# If the preference is positive, and the course is not at the specified timeblock, highlight
# it red.
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'the course is not at the specified timeblock'
)
else:
# If the preference is negative, and the course is at the specified timeblock, highlight it red.
if section.timeblock == preference.object_2:
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'preference is negative, and the course is at the specified timeblock'
)

Expand All @@ -186,19 +199,22 @@ def check_user_course_preference(self, section, preferences, sections_dict):
# it green.
if color != 'red':
sections_dict[section.id]['color'] = 'green'
sections_dict[section.id]['positive_points'].append(
'preference is positive, and the course is taught by the specified teacher'
)
else:
# If the preference is positive, and the course is not taught by the specified teacher,
# highlight it red.
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'the course is not taught by the specified teacher'
)
else:
# If the preference is negative, and the course is taught by the specified teacher, highlight it
# red.
if section.primary_instructor == preference.object_1:
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'the preference is negative, and the course is taught by the specified teacher'
)

Expand All @@ -212,19 +228,40 @@ def check_user_timeblock_preference(self, section, preferences, sections_dict):
# specified timeblock, highlight the section green.
if color != 'red':
sections_dict[section.id]['color'] = 'green'
sections_dict[section.id]['positive_points'].append(
'The specified teacher is teaching a class during the specified timeblock'
)
else:
# If the preference is positive, and the specified teacher is not teaching a class during the
# specified timeblock, highlight it red.
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'specified teacher is not teaching a class during the specified timeblock'
)
else:
# If the preference is negative, and the specified teacher is teaching a class during the
# specified timeblock, highlight the section red.
if section.timeblock == preference.object_2:
sections_dict[section.id]['color'] = 'red'
sections_dict[section.id]['hints'].append(
sections_dict[section.id]['negative_points'].append(
'preference is negative, and the specified teacher is teaching a class during the '
'specified timeblock '
)


class ScheduleSectionEditView(LoginRequiredMixin, FormView):

def get_form(self, form_class=None):
return ScheduleSectionEditForm(
instance=Section.objects.get(id=self.kwargs['section_id']), **self.get_form_kwargs()
)

def form_valid(self, form):
form.save()
return HttpResponseRedirect(reverse(
'schedule:schedule-table-view',
kwargs={
'schedule_id': self.kwargs['schedule_id'],
'preference_set_id': self.kwargs['preference_set_id']
}
))
50 changes: 34 additions & 16 deletions templates/components/data-collection-statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,40 @@
</form>
{% endif %}
</p>

<div @click.away="open = false" class="relative" x-data="{ open: false }">
<button @click="open = !open"
class="flex flex-row items-center p-1 m-1 text-lg font-semibold text-left bg-gray-400 rounded-md hover:text-gray-200 focus:text-gray-100 focus:outline-none focus:shadow-outline">
<span class="text-gray-800">Stats</span>
<svg fill="currentColor" viewBox="0 0 20 20"
:class="{'rotate-180': open, 'rotate-0': !open}"
class="inline w-4 h-4 transition-transform duration-200 transform">
<path fill-rule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clip-rule="evenodd"></path>
</svg>
</button>
<div x-show="open" x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute right-0 origin-top-right rounded-md shadow-lg bg-white p-4 w-72 z-50">
{% get_course_stats preference_form preference_form.total_students as stat_list %}
{% for stat in stat_list %}
<div class="flex gap-2">
<div>{{ stat.course }}</div>
<div class="relative pt-1 w-full">
<div class="overflow-hidden h-4 mb-4 text-xs flex rounded bg-green-200">
<div style="width:{{ stat.count }}%"
class="shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-green-500"></div>
</div>
</div>
<p>{{ stat.count }}%</p>
</div>
{% endfor %}
</div>
</div>
</div>
<div>
<div class="flex flex-wrap justify-center text-center">
Expand All @@ -109,21 +142,6 @@
</div>
</div>
</div>
{% get_course_stats preference_form as stat_list %}

<button class="w-full h-10 text-white outline-none focus:outline-none"
onclick="createChart('{{ preference_form.id }}',[
{% for stat in stat_list %}'{{ stat.course }}',{% endfor %}
],[
{% for stat in stat_list %}{{ stat.count }},{% endfor %}
])">
<span class="text-gray-800">Stats</span> <i
class="text-gray-800 fa fa-chevron-circle-down"></i>
</button>
<div>
<!-- id dynamic hogi -->
<canvas id="{{ preference_form.id }}"></canvas>
</div>
</div>
</div>
{% endif %}
Expand Down
Loading

0 comments on commit f57453c

Please sign in to comment.