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

Adds Student Research Applications Charts #165

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
eba8c2b
📊 Adds student research charts
betsyecastro Sep 13, 2024
e2a1510
Refactors methods to retrieve student applications by semesters, scho…
betsyecastro Sep 16, 2024
588ddef
Refactors progressTextPlugin plugin for doughnut charts to refresh da…
betsyecastro Sep 16, 2024
c35bea8
Refactoring corrections 🥹
betsyecastro Sep 16, 2024
c7351f0
Adjustments on parameters for weeks before and end of the semester
betsyecastro Sep 16, 2024
fe269a3
Fixes closure to sort semesters chronologically
betsyecastro Sep 17, 2024
96fda56
Fixes filter by semester when looping through student applications
betsyecastro Sep 17, 2024
db2c84c
Includes user info students data and renames variables in groupAppsBy…
betsyecastro Sep 17, 2024
f0f0f09
Changes advanced settings button interaction to dropdown
betsyecastro Sep 17, 2024
727cfd3
Rounds increment in progress animation function for doughnut charts
betsyecastro Sep 17, 2024
1149505
Adds title for applied filters and centers doughnut charts
betsyecastro Sep 17, 2024
42775cd
Fixes filter by school when looping through student applications
betsyecastro Sep 18, 2024
fc5b835
Centers doughnut charts, Corrects filters title and charts titles
betsyecastro Sep 18, 2024
6fc5ff8
Changes bar charts to use alpine.js and avoid the DOM manipulation el…
betsyecastro Sep 18, 2024
07d3baf
Fixes chart dimensions to support responsive behavior and adds loadin…
betsyecastro Sep 20, 2024
3dc13ea
Removes unnecessary variables from charts and removes original animat…
betsyecastro Sep 20, 2024
695a042
Draws vertical line on bar charts to mark current semester
betsyecastro Sep 24, 2024
9c64416
Adds 'No results found image' when charts' data is empty and move plu…
betsyecastro Sep 27, 2024
2ff2c95
Modifies method to convert selected parameters to title
betsyecastro Sep 27, 2024
eaca8a1
Removes future semesters from default parameters
betsyecastro Sep 30, 2024
b443dad
Corrects values checked by default for schools
betsyecastro Sep 30, 2024
43a742b
Changes charts colors and highlight color for current semester in bar…
betsyecastro Sep 30, 2024
b044ed8
Refactor Flexbox container alignment for titles, charts, and footer n…
betsyecastro Sep 30, 2024
587b820
Adds spacing between the color box and the value on doughnut charts t…
betsyecastro Sep 30, 2024
8a1df80
Improves dropdown behavior of the advance settings button to display …
betsyecastro Sep 30, 2024
113fbb1
Adjusts Livewire components to implement computed properties for char…
betsyecastro Sep 30, 2024
cdfab91
Removes unnecessary classes, Livewire component and reverts changes o…
betsyecastro Sep 30, 2024
2858f5f
Changes loading animation trigger from afterDraw to onComplete hook.
betsyecastro Sep 30, 2024
415ed8d
Fixes typo in chart description
betsyecastro Oct 1, 2024
db169a3
Changes current semester background color to a lighter one
betsyecastro Oct 1, 2024
8593ea5
Implemented corrections from the previous review.
betsyecastro Oct 2, 2024
db3ea10
Corrects chart hook for progressTextPlugin
betsyecastro Oct 2, 2024
6a644dd
Enhances base query to handle empty semester and school parameters
betsyecastro Oct 4, 2024
7389609
Adjusts `progressTextPlugin` for doughnut charts to render a "no resu…
betsyecastro Oct 4, 2024
0ecec4b
Refactor StudentDataInsight class and rename methods
betsyecastro Oct 25, 2024
fa05516
Install Alpine.js and chartjs-plugin-datalabels and optimize chart in…
betsyecastro Jan 16, 2025
6ee4173
Move Livewire view files into a dedicated folder
betsyecastro Jan 16, 2025
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
70 changes: 70 additions & 0 deletions app/Helpers/Semester.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,74 @@ public static function date(string $name, bool $start_of_season = true)

return Carbon::parse($month_and_day . ' ' . $parsed['year']->year);
}

/**
* Sort chronologically an array of semesters in the 'Semester YY' format
* @param array $semesters
* @return array
*/
public static function sortCollectionWithSemestersKeyChronologically() {
return function ($a, $b) {
// Extract the year and season from both semesters
list($seasonA, $yearA) = explode(' ', $a);
list($seasonB, $yearB) = explode(' ', $b);

// Define a mapping of seasons to values for sorting
$seasonOrder = [
'Spring' => 1,
'Summer' => 2,
'Fall' => 3,
'Winter' => 4,
];

// First, compare the years
if ($yearA != $yearB) {
return $yearA <=> $yearB;
}

// If the years are the same, compare the seasons using the seasonOrder
return $seasonOrder[$seasonA] <=> $seasonOrder[$seasonB];
};
}

/**
* Sort chronologically an array of semesters in the 'Semester YY' format
* @param array $semesters
* @return array
*/
public static function sortSemestersChronologically($semesters) {
return
usort($semesters, function ($a, $b) {
// Extract year and season
preg_match('/(Spring|Summer|Fall) (\d+)/', $a, $matchesA);
preg_match('/(Spring|Summer|Fall) (\d+)/', $b, $matchesB);

// Map seasons to an order
$seasonOrder = ['Spring' => 1, 'Summer' => 2, 'Fall' => 3];

// Compare by year first
if ($matchesA[2] != $matchesB[2]) {
return $matchesA[2] - $matchesB[2];
}

// If years are the same, compare by season
return $seasonOrder[$matchesA[1]] - $seasonOrder[$matchesB[1]];
});
}

/**
* Given a list of semesters, removes the ones that are in the future
*/
public static function removeFutureSemesters($semesters)
{
$current_semester = static::current();
$current_semester_index = array_search($current_semester, $semesters);

if ($current_semester_index !== false) {
return array_slice($semesters, 0, $current_semester_index + 1);
}

return $semesters;

}
}
36 changes: 36 additions & 0 deletions app/Http/Controllers/InsightsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use App\Helpers\Semester;
use App\Insights\StudentApplications\StudentDataInsight;
use App\StudentData;
use Illuminate\Contracts\View\View as ViewContract;
use Illuminate\Http\Request;

class InsightsController extends Controller
{
/**
* Controller constructor. Middleware can be defined here.
*/
public function __construct()
{
$this->middleware('auth');

$this->middleware('can:viewAdminIndex,App\LogEntry')->only('index');
}

/**
* Display a listing of the resource.
*/
public function index(Request $request): ViewContract
{

$schools_options = StudentDataInsight::getLabels('school')->toArray();
$semesters_options = StudentDataInsight::getLabels('semester')->toArray();
$semesters_selected = Semester::removeFutureSemesters($semesters_options);
$title = StudentDataInsight::convertParameterstoTitle($semesters_options, $schools_options);

return view('insights.index', compact('schools_options', 'semesters_options', 'semesters_selected', 'title'));
}
}
55 changes: 55 additions & 0 deletions app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Livewire;

use App\Helpers\Semester;
use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;

class AcceptedAndFollowUpAppsPercentageChart extends Component
{

public array $labels;
public array $data;
public array $selected_semesters;
public array $selected_schools;
public $weeks_before_semester_start;
public $weeks_before_semester_end;
public array $filing_statuses_category_1;
public array $filing_statuses_category_2;
protected $listeners = ['refreshData5', 'refreshChart5'];

public function mount()
{
$this->weeks_before_semester_start = 4;
$this->weeks_before_semester_end = 4;
$this->filing_statuses_category_1 = ['accepted', 'follow up'];
$this->filing_statuses_category_2= ['not interested', 'maybe later'];
$this->data = $this->dataset;
$this->labels = ['Accepted & Follow Up', 'Other'];
}

public function refreshChart5($data, $labels) {}

public function refreshData5($selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end)
{
$this->weeks_before_semester_start = $weeks_before_semester_start;
$this->weeks_before_semester_end = $weeks_before_semester_end;
$this->selected_semesters = $selected_semesters;
$this->selected_schools = $selected_schools;

$this->data = $this->dataset;
$this->emit('refreshChart5', $this->data, $this->labels);
}

public function getDatasetProperty()
{
$report = new StudentDataInsight();
return $report->appsCountForTwoCategoriesOfFilingStatus($this->selected_semesters, $this->selected_schools, $this->filing_statuses_category_1, $this->filing_statuses_category_2, $this->weeks_before_semester_start, $this->weeks_before_semester_end);
}

public function render()
{
return view('livewire.charts.accepted-and-follow-up-apps-percentage-chart');
}
}
55 changes: 55 additions & 0 deletions app/Http/Livewire/AcceptedStudentAppsPercentageChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Livewire;

use App\Helpers\Semester;
use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;

class AcceptedStudentAppsPercentageChart extends Component
{

public array $labels;
public array $data;
public array $selected_semesters;
public array $selected_schools;
public $selected_filing_statuses;
protected $listeners = ['refreshData3', 'refreshChart3'];


public function mount($selected_semesters, $selected_schools)
{
$this->selected_semesters = [Semester::current()];
//$this->selected_schools = $selected_schools;
// $this->selected_filing_statuses = ["accepted"];
}

public function refreshChart3($data, $labels) {}

public function refreshData3($selected_semesters, $selected_schools) {
$this->selected_semesters = $selected_semesters;
$this->selected_schools = $selected_schools;

$data = $this->getData();

$this->data = $data['datasets'];
$this->labels = $data['labels'];

$this->emit('refreshChart3', $this->data, $this->labels);
}

public function getData()
{
$report = new StudentDataInsight();
return $report->transformDataAcceptedInCurrentSeason($this->selected_semesters, $this->selected_schools);
}

public function render()
{
$data = $this->getData();
$this->data = $data['datasets'];
$this->labels = $data['labels'];

return view('livewire.accepted-student-apps-percentage-chart');
}
}
39 changes: 39 additions & 0 deletions app/Http/Livewire/InsightsFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Livewire;

use App\Helpers\Semester;
use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;

class InsightsFilter extends Component
{

public $semester_options = [];
public $semesters_selected = [];
public $school_options = [];
public $charts_loaded;
public $title;
public $current_semester;
protected $listeners = ['applyFilters'];

public function mount()
{
$this->charts_loaded = true;
$this->current_semester = Semester::current();
}

public function applyFilters($selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end) {
$this->charts_loaded = false;
$this->title = StudentDataInsight::convertParameterstoTitle($selected_semesters, $selected_schools);
$this->emitTo('accepted-and-follow-up-apps-percentage-chart', 'refreshData5', $selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end);
$this->emitTo('student-apps-viewed-not-viewed-chart', 'refreshData4', $selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end);
$this->emitTo('students-app-count-chart', 'refreshData2', $selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end);
$this->emitTo('students-app-filing-status-chart', 'refreshData1', $selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end);
}

public function render()
{
return view('livewire.charts.insights-filter');
}
}
50 changes: 50 additions & 0 deletions app/Http/Livewire/StudentAppsViewedNotViewedChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Http\Livewire;

use App\Helpers\Semester;
use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;

class StudentAppsViewedNotViewedChart extends Component
{

public array $labels;
public array $data;
public array $selected_semesters;
public array $selected_schools;
public $selected_filing_statuses;
protected $listeners = ['refreshData4', 'refreshChart4'];

public function mount()
{
$data = $this->dataset;
$this->data = $data['datasets'];
$this->labels = $data['labels'];
}

public function refreshChart4($data, $labels) {}

public function refreshData4($selected_semesters, $selected_schools) {
$this->selected_semesters = $selected_semesters;
$this->selected_schools = $selected_schools;

$data = $this->dataset;

$this->data = $data['datasets'];
$this->labels = $data['labels'];

$this->emit('refreshChart4', $this->data, $this->labels);
}

public function getDatasetProperty()
{
$report = new StudentDataInsight();
return $report->appsCountViewedAndNotViewed($this->selected_semesters, $this->selected_schools);
}

public function render()
{
return view('livewire.charts.student-apps-viewed-not-viewed-chart');
}
}
49 changes: 49 additions & 0 deletions app/Http/Livewire/StudentsAppCountChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Livewire;

use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;

class StudentsAppCountChart extends Component
{

public array $labels;
public array $data;
public $selected_semesters = [];
public $selected_schools = [];
protected $listeners = ['refreshData2', 'refreshChart2'];

public function mount()
{
$data = $this->dataset;
$this->data = $data['datasets'];
$this->labels = $data['labels'];
}

public function refreshChart2($data, $labels) {}

public function refreshData2($selected_semesters, $selected_schools) {

$this->selected_semesters = $selected_semesters;
$this->selected_schools = $selected_schools;

$data = $this->dataset;

$this->data = $data['datasets'];
$this->labels = $data['labels'];

$this->emit('refreshChart2', $this->data, $this->labels);
}

public function getDatasetProperty()
{
$report = new StudentDataInsight();
return $report->appsCountBySemestersAndSchools($this->selected_semesters, $this->selected_schools);
}

public function render()
{
return view('livewire.charts.students-app-count-chart');
}
}
Loading