+ Select/Unselect All
+ @foreach($semester_options as $key => $value)
+
+ {{$value}}
+
+ @endforeach
+
+
+
+
+
+
+
+
+ Select/Unselect All
+ @foreach($school_options as $key => $value)
+
+ {{$value}}
+
+ @endforeach
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To ensure accurate results, the data displayed is set by default to cover a period from three weeks before the start of the semester to three weeks before its end, as student research applications are reviewed and filed for the following semester. You can adjust this timeframe by using the sliders below to select the number of weeks that best suits your needs.
+
@endif
diff --git a/routes/web.php b/routes/web.php
index b0d54d39..4f8b4f85 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -15,6 +15,7 @@
* Auth
******************/
+use App\Http\Controllers\InsightsController;
use App\Http\Controllers\ProfilesController;
use App\Http\Controllers\UsersController;
@@ -27,6 +28,7 @@
******************/
Route::name('app.')->group(function () {
Route::name('logs.index')->get('/logs', 'LogsController@index');
+ Route::name('insights.index')->get('insights', [InsightsController::class, 'index']);
Route::name('settings.edit')->get('/settings', 'SettingsController@edit');
Route::name('settings.update')->post('/settings', 'SettingsController@update');
Route::name('settings.update-image')->post('/settings/image/{image}', 'SettingsController@updateImage')
From e2a1510c89ac255e5f11de79eee17b1751e9adaa Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Mon, 16 Sep 2024 14:24:43 -0500
Subject: [PATCH 02/37] Refactors methods to retrieve student applications by
semesters, schools and filing status
For 'accepted & follow up' applications count doughnut chart and applications count by filing status bar chart.
Reorganizes and adds doc blocks to StudentDataInsight model.
Removes unnecessary parameters for applications count bar chart.
---
...AcceptedAndFollowUpAppsPercentageChart.php | 13 +-
app/Http/Livewire/StudentsAppCountChart.php | 2 +-
.../Livewire/StudentsAppFilingStatusChart.php | 2 +-
.../StudentDataInsight.php | 442 +++++++++---------
4 files changed, 223 insertions(+), 236 deletions(-)
diff --git a/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php b/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
index 081217fe..e470c1a7 100644
--- a/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
+++ b/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
@@ -13,12 +13,19 @@ class AcceptedAndFollowUpAppsPercentageChart extends Component
public array $data;
public array $selected_semesters;
public array $selected_schools;
- public $selected_filing_statuses;
+ public array $filing_statuses_category_1;
+ public array $filing_statuses_category_2;
protected $listeners = ['refreshData5', 'refreshChart5'];
+ public function mount()
+ {
+ $this->filing_statuses_category_1 = ['accepted', 'follow up'];
+ $this->filing_statuses_category_2= ['not interested', 'maybe later'];
+ }
public function refreshChart5($data, $labels) {}
- public function refreshData5($selected_semesters, $selected_schools) {
+ public function refreshData5($selected_semesters, $selected_schools)
+ {
$this->selected_semesters = $selected_semesters;
$this->selected_schools = $selected_schools;
@@ -32,7 +39,7 @@ public function refreshData5($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsForSemestersAndSchoolsWithFilingStatuses($this->selected_semesters, $this->selected_schools, ["accepted", "follow up"]);
+ return $report->getAppsForSemestersAndSchoolsWithFilingStatuses($this->selected_semesters, $this->selected_schools, $this->filing_statuses_category_1, $this->filing_statuses_category_2);
}
public function render()
diff --git a/app/Http/Livewire/StudentsAppCountChart.php b/app/Http/Livewire/StudentsAppCountChart.php
index 2cb1018b..52a4a5b1 100644
--- a/app/Http/Livewire/StudentsAppCountChart.php
+++ b/app/Http/Livewire/StudentsAppCountChart.php
@@ -32,7 +32,7 @@ public function refreshData2($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsBySemestersAndSchools($this->selected_semesters, $this->selected_schools, "count", "submitted");
+ return $report->getAppsBySemestersAndSchools($this->selected_semesters, $this->selected_school);
}
public function render()
diff --git a/app/Http/Livewire/StudentsAppFilingStatusChart.php b/app/Http/Livewire/StudentsAppFilingStatusChart.php
index ad2e548b..93895735 100644
--- a/app/Http/Livewire/StudentsAppFilingStatusChart.php
+++ b/app/Http/Livewire/StudentsAppFilingStatusChart.php
@@ -38,7 +38,7 @@ public function refreshData1($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_filing_statuses, $this->selected_schools, "count", "submitted");
+ return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_filing_statuses, $this->selected_schools);
}
public function render()
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index 8300a2f3..c466dc42 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -9,6 +9,7 @@
use App\StudentData;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
@@ -16,252 +17,204 @@
class StudentDataInsight extends Insight
{
- // public function getDataSet(string $criteria, ?string $type = null, ?string $status = 'submitted', ?string $stats_progress = null)
- public function getDataSet(?array $semesters_params = [], ?array $schools_params = [], ?string $type = null, ?string $status = 'submitted')
+ /**
+ * DOUGHNUT CHART #1 DATA - APPLICATIONS COUNT BY FILING STATUS FOR SEMESTERS AND SCHOOLS
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @param array $filing_status_category_1 Filing statuses for the first category. Example: ['accepted', 'follow up'].
+ * @param array $filing_status_category_2 Filing statuses for the first category. Example: ['not interested', 'maybe later'].
+ * @return array
+ */
+ public function getAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_category_1, $filing_status_category_2)
{
- $insight_parameters[] = [
- 'label' => 'Applications for Semester',
- 'type' => 'bar',
- 'backgroundColor' => 'rgba(15,64,97,255)',
- 'borderColor' => 'rgba(15,64,97,255)',
- // 'data' => $this->getDataSemesterAndSchool($semesters_params, $schools_params, $type, $status),
- //'labels' => $this->getLabels($semester),
- ];
+ $filing_status_category_1_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_1)->count();
+ $filing_status_category_2_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_2)->count();
- return $this->getDataArray($insight_parameters);
+ return [$filing_status_category_1_total, $filing_status_category_2_total];
}
- //Query to retrieve student applications for given semesters and schools
- public function appsForSemestersAndSchools($semesters_params, $schools_params)
- {
- return Student::query()
- ->submitted()
- ->withWhereHas('research_profile', function($q) use ($semesters_params, $schools_params) {
- $q->where(function($q) use ($semesters_params) {
- foreach ($semesters_params as $semester) {
- $q->orDataContains('semesters', $semester);
- }
- });
- $q->where(function($q) use ($schools_params) {
- foreach ($schools_params as $school) {
- $q->orDataContains('schools', $school);
- }
- });
- });
- }
+ /**
+ * Auxiliary caching and grouping methods for Chart #1 (Doughnut) and Chart #4 (Bar).
+ */
/**
- * DOUGHNUT CHART #1 DATA - APPLICATIONS PERCENTAGE BY FILING STATUS FOR SEMESTERS AND SCHOOLS
+ * Retrieve and cache a collection of student applications whose last filing status matches
+ * the provided filing status parameters for the specified semesters and schools.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
+ * @return \Illuminate\Support\Collection
*/
-
- public function getCachedAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params)
+ public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
{
$sm = implode('-', $semesters_params);
$sch = implode('-', $schools_params);
- $fs = implode('-', $filing_status_params);
-
- return Cache::remember(
- "student-apps-for-semesters-schools-with-flstatus-{$sm}-{$sch}-{$fs}",
- 15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
- ->withWhereHas('stats', function($q) use ($filing_status_params) {
- $q->whereNotNull('data->status_history');
- $q->where(function($q) use ($filing_status_params) {
- foreach ($filing_status_params as $key => $filing_status) {
- $q = $key == 0 ?
- $q->whereJsonContains('data->status_history', ['new_status' => $filing_status]) :
- $q->orWhereJsonContains('data->status_history', ['new_status' => $filing_status]);
- }
- });
- })->get()
- );
- }
+ $fls = implode('-', $filing_status_params);
- public function getCachedAppsForSemestersAndSchoolsWithoutFilingStatuses($semesters_params, $schools_params, $filing_status_params)
- {
- $sm = implode('-', $semesters_params);
- $sch = implode('-', $schools_params);
-
return Cache::remember(
- "student-apps-for-semesters-schools-without-flstatus-{$sm}-{$sch}",
+ "student-apps-for-semesters-schools-with-flstatus-{$sm}-{$sch}-{$fls}",
15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
- ->withWhereHas('stats', function($q) use ($filing_status_params) {
- $q->whereNot(function($q) use ($filing_status_params) {
- foreach ($filing_status_params as $key => $filing_status) {
- $q = $key == 0 ?
- $q->whereJsonContains('data->status_history', ['new_status' => $filing_status]) :
- $q->orWhereJsonContains('data->status_history', ['new_status' => $filing_status]);
- }
- });
- })->get()
+ fn() => $this->groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
);
}
- public function groupAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params, $student_apps)
+ /**
+ * Return a collection of student applications whose last filing status matches
+ * the provided filing status parameters for the specified semesters and schools.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
+ * @return \Illuminate\Support\Collection
+ */
+ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
{
+ $student_applications = $this->getCachedAppsForSemestersAndSchoolsWithStats($semesters_params, $schools_params);
$semesters_params_start_end = $this->semestersParamsStartAndEnd($semesters_params);
-
- $filing_status_count = 0;
-
- foreach ($semesters_params_start_end as $semester_start_end) {
- $start_date = $semester_start_end['start'];
- $end_date = $semester_start_end['end'];
+ $results = [];
- $filing_status_count = $filing_status_count +
- $student_apps->where(function($app) use ($filing_status_params, $start_date, $end_date, &$filing_status_count) {
- return collect($app->stats->data['status_history'])
- ->groupBy('profile')
- ->where(function($group) use ($app, $filing_status_params, $start_date, $end_date, &$filing_status_count) {
- $last_update = $group->sortByDesc(function ($item) {
- return Carbon::parse($item['updated_at']);
- })->first();
- $filing_date = Carbon::parse($last_update['updated_at']);
- // if (in_array($last_update['new_status'], $filing_status_params) && $filing_date->between($start_date, $end_date)) {
- // // dump($app->stats->id);
- // $filing_status_count = $filing_status_count + 1;
- // }
- return (in_array($last_update['new_status'], $filing_status_params) && $filing_date->between($start_date, $end_date));
- })->count();
- })->count();
-
- }
- return $filing_status_count;
- }
-
- public function getAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params)
- {
- $student_apps = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params);
- $filing_status_params_total = $this->groupAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params, $student_apps);
-
- $filing_status_params = ['maybe later', 'not interested'];
- $student_apps = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params);
- $others_total = $this->groupAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_params, $student_apps);
-
- // $filing_status_params_total = $grouped_student_apps_with_flstatus;
- // $others_total = $grouped_student_apps_without_flstatus;
- // $filing_status_params_total = array_sum($grouped_student_apps_with_flstatus);
- // $others_total = array_sum($grouped_student_apps_without_flstatus);
-
- // $total = $filing_status_params_total + $others_total;
-
- // if ($total > 0) { // Avoid division by zero
- // $result[0] = round(($filing_status_params_total / $total) * 100);
- // $result[1] = round(($others_total / $total) * 100);
- // } else {
- // $result[0] = 0;
- // $result[1] = 0;
- // }
- return [$filing_status_params_total, $others_total];
+ $student_applications->each(function ($application) use ($semesters_params_start_end, $filing_status_params, &$results) {
+ if (!empty($application->research_profile->data['semesters']) && !empty($application->stats->data['status_history'])) {
+ foreach ($semesters_params_start_end as $semester => $semester_start_end) {
+ $start_date = $semester_start_end['start'];
+ $end_date = $semester_start_end['end'];
+ foreach ($filing_status_params as $filing_status) {
+ collect($application->stats->data['status_history'])
+ ->groupBy('profile')
+ ->each(function($group) use ($start_date, $end_date, $filing_status, $semester, $application, &$results) {
+ $last_update = $group->sortByDesc(function ($item) {
+ return Carbon::parse($item['updated_at']);
+ })->first();
+ $filing_date = Carbon::parse($last_update['updated_at']);
+ if ($last_update['new_status'] === $filing_status && $filing_date->between($start_date, $end_date)) {
+ $results[] = [
+ 'id' => $application->stats->id,
+ 'semester' => $semester,
+ 'filing_status' => $filing_status,
+ ];
+ }
+ });
+ }
+ }
+ }
+ });
+ return collect($results);
}
/**
- * DOUGHNUT CHART #2 DATA - APPLICATIONS COUNT VIEWED AND NOT FOR SEMESTERS AND SCHOOLS
- */
-
- public function getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params, $schools_params)
- {
- $sm = implode('-', $semesters_params);
- $sch = implode('-', $schools_params);
-
- return Cache::remember(
- "student-apps-for-semesters-schools-not-viewed-{$sm}-{$sch}",
- 15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
- ->where(function($query) {
- $query->whereHas('stats', function($q) {
- $q->whereNull('data->views');
- });
- $query->orDoesntHave('stats');
- })->count()
- );
- }
-
- public function getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $schools_params)
- {
+ * Retrieve and cache a collection of student applications for given semesters and schools with stats.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return \Illuminate\Support\Collection
+ */
+ public function getCachedAppsForSemestersAndSchoolsWithStats($semesters_params, $schools_params)
+ {
$sm = implode('-', $semesters_params);
$sch = implode('-', $schools_params);
return Cache::remember(
- "student-apps-for-semesters-schools-viewed-{$sm}-{$sch}",
+ "student-apps-for-semesters-schools-with-stats-{$sm}-{$sch}",
15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
- ->where(function($query) {
- $query->whereHas('stats', function($q) {
- $q->whereNotNull('data->views');
- $q->where('data->views', '>', 0);
- });
- })->count()
+ fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)->with('stats')->get()
);
}
- public function getViewedAndNotViewedApps(array $semesters_params, array $schools_params,)
+ /**
+ * Return query builder to retrieve students records with applications ('research_profile') for given semesters and schools.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return Illuminate\Database\Eloquent\Builder
+ */
+ public function appsForSemestersAndSchools($semesters_params, $schools_params)
{
- $result = [];
-
- $submitted_not_viewed = $this->getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params, $schools_params);
-
- $submitted_and_viewed = $this->getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $schools_params);
-
- // $total = $submitted_and_viewed + $submitted_not_viewed;
+ return Student::query()
+ ->submitted()
+ ->withWhereHas('research_profile', function($q) use ($semesters_params, $schools_params) {
+ $q->where(function($q) use ($semesters_params) {
+ foreach ($semesters_params as $semester) {
+ $q->orDataContains('semesters', $semester);
+ }
+ });
+ $q->where(function($q) use ($schools_params) {
+ foreach ($schools_params as $school) {
+ $q->orDataContains('schools', $school);
+ }
+ });
+ });
+ }
- // if ($total > 0) { // Avoid division by zero
- // $result[0] = round(($submitted_and_viewed / $total) * 100);
- // $result[1] = round(($submitted_not_viewed / $total) * 100);
- // } else {
- // $result[0] = 0;
- // $result[1] = 0;
- // }
+ /**
+ * DOUGHNUT CHART #2 DATA - APPLICATIONS COUNT VIEWED AND NOT VIEWED FOR SEMESTERS AND SCHOOLS
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return array
+ */
+ public function getViewedAndNotViewedApps($semesters_params, $schools_params,)
+ {
+ $submitted_and_viewed = $this->getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $schools_params)->count();
+ $submitted_not_viewed = $this->getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params, $schools_params)->count();
return [
'labels' => [ 'Viewed', 'Not Viewed' ],
'datasets' => [$submitted_and_viewed, $submitted_not_viewed],
];
}
-
/**
- * BAR CHART #3 DATA - APPLICATIONS COUNT BY SEMESTER AND SCHOOL
- */
-
- public function getCachedAppsForSemestersAndSchools($semesters_params, $schools_params)
+ * Retrieve and cache a collection of student applications for given semesters and schools that have been viewed.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return Illuminate\Database\Eloquent\Builder
+ */
+ public function getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $schools_params)
+ {
+ $sm = implode('-', $semesters_params);
+ $sch = implode('-', $schools_params);
+
+ return Cache::remember(
+ "student-apps-for-semesters-schools-viewed-{$sm}-{$sch}",
+ 15 * 60,
+ fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
+ ->where(function($query) {
+ $query->whereHas('stats', function($q) {
+ $q->whereNotNull('data->views');
+ $q->where('data->views', '>', 0);
+ });
+ })
+ );
+ }
+
+ /**
+ * Retrieve and cache a collection of student applications for given semesters and schools that have not been viewed.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return Illuminate\Database\Eloquent\Builder
+ */
+ public function getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params, $schools_params)
{
$sm = implode('-', $semesters_params);
$sch = implode('-', $schools_params);
-
+
return Cache::remember(
- "student-apps-for-semesters-schools-{$sm}-{$sch}",
+ "student-apps-for-semesters-schools-not-viewed-{$sm}-{$sch}",
15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)->get()
+ fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
+ ->where(function($query) {
+ $query->whereHas('stats', function($q) {
+ $q->whereNull('data->views');
+ });
+ $query->orDoesntHave('stats');
+ })
);
}
- public function groupAppsBySemestersAndSchools(array $semesters_params, array $schools_params)
- {
- $student_applications = $this->getCachedAppsForSemestersAndSchools($semesters_params, $schools_params);
-
- return $student_applications->flatMap(function ($application) use ($semesters_params, $schools_params) {
-
- if (!empty($application->research_profile->data['semesters']) && !empty($application->research_profile->data['schools'])) {
-
- $semesters_values = array_intersect($application->research_profile->data['semesters'], $semesters_params);
- $schools_values = array_intersect($application->research_profile->data['schools'], $schools_params);
-
- return array_map(function ($school_value) use ($application, $semesters_values) {
- return array_map(function ($semester_value) use ($application, $school_value) {
- return [
- 'id' => $application->id,
- 'semester' => $semester_value,
- 'school' => $school_value,
- ];
- }, $semesters_values);
- }, $schools_values);
- }
- })->flatten(1);
- }
-
- public function getAppsBySemestersAndSchools(array $semesters_params, array $schools_params, $type, $status)
+ /**
+ * BAR CHART #3 DATA - APPLICATIONS COUNT BY SEMESTER AND SCHOOL
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return array
+ */
+ public function getAppsBySemestersAndSchools($semesters_params, $schools_params)
{
- $applications = $this->groupAppsBySemestersAndSchools($semesters_params, $schools_params);
+ $applications = $this->transformAppsBySemestersAndSchools($semesters_params, $schools_params);
$counted_apps = $applications
->groupBy(['semester', 'school'])
@@ -293,62 +246,74 @@ public function getAppsBySemestersAndSchools(array $semesters_params, array $sch
];
}
-
/**
- * BAR CHART #4 DATA - APPLICATIONS COUNT BY SEMESTER, SCHOOL AND FILING STATUS
- */
-
- public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params)
- {
- $sm = implode('-', $semesters_params);
- $sch = implode('-', $schools_params);
-
- return Cache::remember(
- "student-apps-for-semesters-schools-with-flstatus-{$sm}-{$sch}",
- 15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)->with('stats')->get()
- );
- }
-
- public function groupAppsBySemestersAndSchoolsWithFilingStatus(array $semesters_params, array $filing_status_params, array $schools_params)
+ * Auxiliary method for Chart #3 to transform student applications by semesters and schools.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return \Illuminate\Support\Collection
+ */
+ public function transformAppsBySemestersAndSchools(array $semesters_params, array $schools_params)
{
- $student_applications = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params);
+ $student_applications = $this->getCachedAppsForSemestersAndSchools($semesters_params, $schools_params);
- return $student_applications->flatMap(function ($application) use ($semesters_params, $filing_status_params) {
+ return $student_applications->flatMap(function ($application) use ($semesters_params, $schools_params) {
- if (!empty($application->research_profile->data['semesters']) && !empty($application->stats->data['status'])) {
+ if (!empty($application->research_profile->data['semesters']) && !empty($application->research_profile->data['schools'])) {
$semesters_values = array_intersect($application->research_profile->data['semesters'], $semesters_params);
- $status_values = array_intersect(array_keys($application->stats->data['status']), $filing_status_params);
+ $schools_values = array_intersect($application->research_profile->data['schools'], $schools_params);
- return array_map(function ($status_value) use ($application, $semesters_values) {
- return array_map(function ($semester_value) use ($application, $status_value) {
+ return array_map(function ($school_value) use ($application, $semesters_values) {
+ return array_map(function ($semester_value) use ($application, $school_value) {
return [
'id' => $application->id,
'semester' => $semester_value,
- 'status' => $status_value,
- 'status_count' => $application->stats->data['status'][$status_value],
+ 'school' => $school_value,
];
}, $semesters_values);
- }, $status_values);
+ }, $schools_values);
}
})->flatten(1);
}
- public function getAppsBySemestersAndSchoolsWithFilingStatus(array $semesters_params, array $filing_status_params, array $schools_params, $type, $status)
+ /**
+ * Retrieve and cache a collection of student applications for given semesters and schools.
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @return \Illuminate\Support\Collection
+ */
+ public function getCachedAppsForSemestersAndSchools($semesters_params, $schools_params)
+ {
+ $sm = implode('-', $semesters_params);
+ $sch = implode('-', $schools_params);
+
+ return Cache::remember(
+ "student-apps-for-semesters-schools-{$sm}-{$sch}",
+ 15 * 60,
+ fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)->get()
+ );
+ }
+
+ /**
+ * BAR CHART #4 DATA - APPLICATIONS COUNT BY SEMESTER, SCHOOL AND FILING STATUS
+ * @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
+ * @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
+ * @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
+ */
+ public function getAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
{
- $applications = $this->groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $filing_status_params, $schools_params);
+ $applications = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params);
$counted_apps = $applications
- ->groupBy(['semester', 'status'])
+ ->groupBy(['semester', 'filing_status'])
->map(function ($semester_group) {
return $semester_group->map(function ($status_group) {
- return $status_group->sum('status_count');
+ return $status_group->count();
});
});
$all_semesters = $applications->pluck('semester')->unique()->sort()->values();
- $all_filing_statuses = $applications->pluck('status')->unique()->sort()->values();
+ $all_filing_statuses = $applications->pluck('filing_status')->unique()->sort()->values();
$datasets = $all_filing_statuses->mapWithKeys(function ($filing_status) use ($all_semesters) { // Initialize datasets for each status
return [$filing_status => ['label' => $filing_status, 'data' => array_fill(0, $all_semesters->count(), 0)]];
@@ -367,6 +332,21 @@ public function getAppsBySemestersAndSchoolsWithFilingStatus(array $semesters_pa
];
}
+ // public function getDataSet(string $criteria, ?string $type = null, ?string $status = 'submitted', ?string $stats_progress = null)
+ public function getDataSet(?array $semesters_params = [], ?array $schools_params = [], ?string $type = null, ?string $status = 'submitted')
+ {
+ $insight_parameters[] = [
+ 'label' => 'Applications for Semester',
+ 'type' => 'bar',
+ 'backgroundColor' => 'rgba(15,64,97,255)',
+ 'borderColor' => 'rgba(15,64,97,255)',
+ // 'data' => $this->getDataSemesterAndSchool($semesters_params, $schools_params, $type, $status),
+ //'labels' => $this->getLabels($semester),
+ ];
+
+ return $this->getDataArray($insight_parameters);
+ }
+
/** AUXILIARY METHODS */
public static function getLabels(string $criteria)
{
@@ -393,7 +373,7 @@ public static function getLabels(string $criteria)
}
}
- public function semestersParamsStartAndEnd($semesters_params, $weeks_before_start = 3, $weeks_before_end = 3) : array {
+ public function semestersParamsStartAndEnd($semesters_params, $weeks_before_start = 4, $weeks_before_end = 4) : array {
$result = [];
foreach ($semesters_params as $semester_params) {
@@ -406,7 +386,7 @@ public function semestersParamsStartAndEnd($semesters_params, $weeks_before_star
->subweeks($weeks_before_end)
->format('Y-m-d');
- $result[] = [ 'start' => $start_date, 'end' => $end_date ];
+ $result[$semester_params] = [ 'start' => $start_date, 'end' => $end_date ];
}
return $result;
From 588ddef5c8e6367f68ceb98bb0f1f4a7c3300991 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Mon, 16 Sep 2024 14:27:04 -0500
Subject: [PATCH 03/37] Refactors progressTextPlugin plugin for doughnut charts
to refresh data percentage upon chart refresh.
---
...-follow-up-apps-percentage-chart.blade.php | 35 +++++------
...ent-apps-viewed-not-viewed-chart.blade.php | 61 ++++++-------------
2 files changed, 37 insertions(+), 59 deletions(-)
diff --git a/resources/views/livewire/accepted-and-follow-up-apps-percentage-chart.blade.php b/resources/views/livewire/accepted-and-follow-up-apps-percentage-chart.blade.php
index dffc67c1..45267e33 100644
--- a/resources/views/livewire/accepted-and-follow-up-apps-percentage-chart.blade.php
+++ b/resources/views/livewire/accepted-and-follow-up-apps-percentage-chart.blade.php
@@ -5,30 +5,34 @@
labels: @entangle('labels'),
selected_semesters: @entangle('selected_semesters'),
init() {
+ if (this.data.every(value => value === 0)) {
+ this.data = [1, 1]; // Fallback to ensure the chart renders
+ }
+
var progress = this.data[0];
- var total = Number(this.data[0]) + Number(this.data[1]);
- var progress_percentage = total === 0 ? 0 : Math.round((this.data[0] / total) * 100);
const progressTextPlugin = {
id: 'progressText',
afterDraw: function(chart) {
- var ctx = chart.ctx;
- var width = chart.width;
- var height = chart.height;
+ const {ctx, data} = chart;
- ctx.restore();
+ var progress = Number(data.datasets[0].data[0]);
+ var remaining = Number(data.datasets[0].data[1]);
+ var total = progress + remaining;
+ var progress_percentage = total === 0 ? 0 : Math.round((progress / total) * 100);
+ ctx.save();
+ const xCoor = chart. getDatasetMeta(0).data[0].x;
+ const yCoor = chart. getDatasetMeta(0).data[0].y;
+
+ var height = chart.height;
var fontSize = (height / 140).toFixed(2);
ctx.font = fontSize + 'em Roboto';
- ctx.textBaseline = 'middle';
ctx.fillStyle = '#198754';
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+ ctx.fillText(`${progress_percentage}%`, xCoor, yCoor);
- var text = progress_percentage + '%',
- textX = Math.round((width - ctx.measureText(text).width) / 2),
- textY = height / 2.15;
-
- ctx.fillText(text, textX, textY);
- ctx.save();
}
};
@@ -78,11 +82,9 @@
plugins: [progressTextPlugin],
});
- animateProgress(chart_instance, progress, false);
+ //animateProgress(chart_instance, progress, false);
Livewire.on('refreshChart5', (data, labels) => {
- var progress = data[0];
-
if (data.every(value => value === 0)) {
var data = [1, 1]; // Fallback to ensure the chart renders
}
@@ -93,7 +95,6 @@
backgroundColor: ['#4CAF50', '#E0E0E0'],
borderWidth: 3
}];
- chart_instance.data.plugins = [progressTextPlugin];
chart_instance.update();
});
}
diff --git a/resources/views/livewire/student-apps-viewed-not-viewed-chart.blade.php b/resources/views/livewire/student-apps-viewed-not-viewed-chart.blade.php
index 3db03bb0..d365bb0f 100644
--- a/resources/views/livewire/student-apps-viewed-not-viewed-chart.blade.php
+++ b/resources/views/livewire/student-apps-viewed-not-viewed-chart.blade.php
@@ -6,56 +6,36 @@
labels: @entangle('labels'),
selected_semesters: @entangle('selected_semesters'),
init() {
+ if (this.data.every(value => value === 0)) {
+ this.data = [1, 1]; // Fallback to ensure the chart renders
+ }
+
var progress = this.data[0];
- var total = Number(this.data[0]) + Number(this.data[1]);
- var progress_percentage = total === 0 ? 0 : Math.round((this.data[0] / total) * 100);
const progressTextPlugin = {
id: 'progressText',
afterDraw: function(chart) {
- var ctx = chart.ctx;
- var width = chart.width;
- var height = chart.height;
+ const {ctx, data} = chart;
- ctx.restore();
+ var progress = Number(data.datasets[0].data[0]);
+ var remaining = Number(data.datasets[0].data[1]);
+ var total = progress + remaining;
+ var progress_percentage = total === 0 ? 0 : Math.round((progress / total) * 100);
+ ctx.save();
+ const xCoor = chart. getDatasetMeta(0).data[0].x;
+ const yCoor = chart. getDatasetMeta(0).data[0].y;
+
+ var height = chart.height;
var fontSize = (height / 140).toFixed(2);
ctx.font = fontSize + 'em Roboto';
- ctx.textBaseline = 'middle';
ctx.fillStyle = '#198754';
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+ ctx.fillText(`${progress_percentage}%`, xCoor, yCoor);
- var text = progress_percentage + '%',
- textX = Math.round((width - ctx.measureText(text).width) / 2),
- textY = height / 2.15;
-
- ctx.fillText(text, textX, textY);
- ctx.save();
}
};
- // var progress = this.data[0];
-
- // const progressTextPlugin = {
- // id: 'progressText',
- // afterDraw: function(chart) {
- // var ctx = chart.ctx;
- // var width = chart.width;
- // var height = chart.height;
-
- // ctx.restore();
-
- // var fontSize = (height / 140).toFixed(2);
- // ctx.font = 'bold ' + fontSize + 'em Roboto';
- // ctx.textBaseline = 'middle';
- // ctx.fillStyle = '#198754';
-
- // var text = progress,
- // textX = Math.round((width - ctx.measureText(text).width) / 2),
- // textY = height / 2.15;
-
- // ctx.fillText(text, textX, textY);
- // ctx.save();
- // }
- // };
const chart_options = {
cutout: '35%',
@@ -102,10 +82,8 @@
animateProgress(chart_instance, progress, false);
Livewire.on('refreshChart4', (data, labels) => {
- var progress = data[0];
-
- if (this.data.every(value => value === 0)) {
- this.data = [1, 1]; // Fallback to ensure the chart renders
+ if (data.every(value => value === 0)) {
+ data = [1, 1]; // Fallback to ensure the chart renders
}
chart_instance.data.labels = labels;
@@ -114,7 +92,6 @@
backgroundColor: ['#4CAF50', '#E0E0E0'],
borderWidth: 3
}];
- chart_instance.data.plugins = [progressTextPlugin];
chart_instance.update();
});
}
From c35bea8d3679ad66ec1ddc611ff93e9601ba7b75 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Mon, 16 Sep 2024 14:34:37 -0500
Subject: [PATCH 04/37] =?UTF-8?q?Refactoring=20corrections=20=F0=9F=A5=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Http/Livewire/StudentsAppCountChart.php | 2 +-
app/Http/Livewire/StudentsAppFilingStatusChart.php | 2 +-
app/Insights/StudentApplications/StudentDataInsight.php | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/app/Http/Livewire/StudentsAppCountChart.php b/app/Http/Livewire/StudentsAppCountChart.php
index 52a4a5b1..dead13b8 100644
--- a/app/Http/Livewire/StudentsAppCountChart.php
+++ b/app/Http/Livewire/StudentsAppCountChart.php
@@ -32,7 +32,7 @@ public function refreshData2($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsBySemestersAndSchools($this->selected_semesters, $this->selected_school);
+ return $report->getAppsBySemestersAndSchools($this->selected_semesters, $this->selected_schools);
}
public function render()
diff --git a/app/Http/Livewire/StudentsAppFilingStatusChart.php b/app/Http/Livewire/StudentsAppFilingStatusChart.php
index 93895735..9ada6aeb 100644
--- a/app/Http/Livewire/StudentsAppFilingStatusChart.php
+++ b/app/Http/Livewire/StudentsAppFilingStatusChart.php
@@ -38,7 +38,7 @@ public function refreshData1($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_filing_statuses, $this->selected_schools);
+ return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_schools, $this->selected_filing_statuses);
}
public function render()
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index c466dc42..c43c5f41 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -162,7 +162,7 @@ public function getViewedAndNotViewedApps($semesters_params, $schools_params,)
* Retrieve and cache a collection of student applications for given semesters and schools that have been viewed.
* @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
* @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
- * @return Illuminate\Database\Eloquent\Builder
+ * @return \Illuminate\Support\Collection
*/
public function getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $schools_params)
{
@@ -178,7 +178,7 @@ public function getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $sc
$q->whereNotNull('data->views');
$q->where('data->views', '>', 0);
});
- })
+ })->get()
);
}
@@ -186,7 +186,7 @@ public function getCachedAppsForSemestersAndSchoolsViewed($semesters_params, $sc
* Retrieve and cache a collection of student applications for given semesters and schools that have not been viewed.
* @param array $semesters_params Semesters filter. Example: ["Summer 2023", "Fall 2023"].
* @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
- * @return Illuminate\Database\Eloquent\Builder
+ * @return \Illuminate\Support\Collection
*/
public function getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params, $schools_params)
{
@@ -202,7 +202,7 @@ public function getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params,
$q->whereNull('data->views');
});
$query->orDoesntHave('stats');
- })
+ })->get()
);
}
From c7351f006ba34c7e10a666c45d447688e22319d7 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Mon, 16 Sep 2024 17:17:22 -0500
Subject: [PATCH 05/37] Adjustments on parameters for weeks before and end of
the semester
---
...AcceptedAndFollowUpAppsPercentageChart.php | 10 +-
app/Http/Livewire/InsightsFilter.php | 10 +-
.../Livewire/StudentsAppFilingStatusChart.php | 10 +-
.../StudentDataInsight.php | 30 ++---
.../views/livewire/insights-filter.blade.php | 119 +++++++++---------
5 files changed, 97 insertions(+), 82 deletions(-)
diff --git a/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php b/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
index e470c1a7..0e3982db 100644
--- a/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
+++ b/app/Http/Livewire/AcceptedAndFollowUpAppsPercentageChart.php
@@ -13,19 +13,25 @@ class AcceptedAndFollowUpAppsPercentageChart extends Component
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'];
}
public function refreshChart5($data, $labels) {}
- public function refreshData5($selected_semesters, $selected_schools)
+ 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;
@@ -39,7 +45,7 @@ public function refreshData5($selected_semesters, $selected_schools)
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsForSemestersAndSchoolsWithFilingStatuses($this->selected_semesters, $this->selected_schools, $this->filing_statuses_category_1, $this->filing_statuses_category_2);
+ return $report->getAppsForSemestersAndSchoolsWithFilingStatuses($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()
diff --git a/app/Http/Livewire/InsightsFilter.php b/app/Http/Livewire/InsightsFilter.php
index ae48e827..0bca77ff 100644
--- a/app/Http/Livewire/InsightsFilter.php
+++ b/app/Http/Livewire/InsightsFilter.php
@@ -11,11 +11,11 @@ class InsightsFilter extends Component
public $school_options = [];
protected $listeners = ['applyFilters'];
- public function applyFilters($selected_semesters, $selected_schools) {
- $this->emitTo('students-app-count-chart', 'refreshData2', $selected_semesters, $selected_schools);
- $this->emitTo('students-app-filing-status-chart', 'refreshData1', $selected_semesters, $selected_schools);
- $this->emitTo('accepted-and-follow-up-apps-percentage-chart', 'refreshData5', $selected_semesters, $selected_schools);
- $this->emitTo('student-apps-viewed-not-viewed-chart', 'refreshData4', $selected_semesters, $selected_schools);
+ public function applyFilters($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);
+ $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);
}
public function render()
diff --git a/app/Http/Livewire/StudentsAppFilingStatusChart.php b/app/Http/Livewire/StudentsAppFilingStatusChart.php
index 9ada6aeb..ad790b96 100644
--- a/app/Http/Livewire/StudentsAppFilingStatusChart.php
+++ b/app/Http/Livewire/StudentsAppFilingStatusChart.php
@@ -12,18 +12,24 @@ class StudentsAppFilingStatusChart extends Component
public array $data;
public $selected_semesters = [];
public $selected_schools = [];
+ public $weeks_before_semester_start;
+ public $weeks_before_semester_end;
public $selected_filing_statuses;
protected $listeners = ['refreshData1', 'refreshChart1'];
public function mount()
{
+ $this->weeks_before_semester_start = 4;
+ $this->weeks_before_semester_end = 4;
$this->selected_filing_statuses = ["accepted", "maybe later", "not interested", "new", "follow up"];
}
public function refreshChart1($data, $labels) {}
- public function refreshData1($selected_semesters, $selected_schools) {
+ public function refreshData1($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;
@@ -38,7 +44,7 @@ public function refreshData1($selected_semesters, $selected_schools) {
public function getData()
{
$report = new StudentDataInsight();
- return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_schools, $this->selected_filing_statuses);
+ return $report->getAppsBySemestersAndSchoolsWithFilingStatus($this->selected_semesters, $this->selected_schools, $this->selected_filing_statuses, $this->weeks_before_semester_start, $this->weeks_before_semester_end);
}
public function render()
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index c43c5f41..dc5e8a5f 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -25,10 +25,10 @@ class StudentDataInsight extends Insight
* @param array $filing_status_category_2 Filing statuses for the first category. Example: ['not interested', 'maybe later'].
* @return array
*/
- public function getAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_category_1, $filing_status_category_2)
+ public function getAppsForSemestersAndSchoolsWithFilingStatuses($semesters_params, $schools_params, $filing_status_category_1, $filing_status_category_2, $weeks_before_semester_start, $weeks_before_semester_end)
{
- $filing_status_category_1_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_1)->count();
- $filing_status_category_2_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_2)->count();
+ $filing_status_category_1_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_1, $weeks_before_semester_start, $weeks_before_semester_end)->count();
+ $filing_status_category_2_total = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_category_2, $weeks_before_semester_start, $weeks_before_semester_end)->count();
return [$filing_status_category_1_total, $filing_status_category_2_total];
}
@@ -45,16 +45,18 @@ public function getAppsForSemestersAndSchoolsWithFilingStatuses($semesters_param
* @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
* @return \Illuminate\Support\Collection
*/
- public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
+ public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
{
$sm = implode('-', $semesters_params);
$sch = implode('-', $schools_params);
$fls = implode('-', $filing_status_params);
+ $wbs = $weeks_before_semester_start;
+ $wbe = $weeks_before_semester_end;
return Cache::remember(
- "student-apps-for-semesters-schools-with-flstatus-{$sm}-{$sch}-{$fls}",
+ "student-apps-for-semesters-schools-with-flstatus-{$sm}-{$sch}-{$fls}-{$wbs}-{$wbe}",
15 * 60,
- fn() => $this->groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
+ fn() => $this->groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
);
}
@@ -66,10 +68,10 @@ public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_p
* @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
* @return \Illuminate\Support\Collection
*/
- public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
+ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
{
$student_applications = $this->getCachedAppsForSemestersAndSchoolsWithStats($semesters_params, $schools_params);
- $semesters_params_start_end = $this->semestersParamsStartAndEnd($semesters_params);
+ $semesters_params_start_end = $this->semestersParamsStartAndEnd($semesters_params, $weeks_before_semester_start, $weeks_before_semester_end);
$results = [];
$student_applications->each(function ($application) use ($semesters_params_start_end, $filing_status_params, &$results) {
@@ -300,9 +302,9 @@ public function getCachedAppsForSemestersAndSchools($semesters_params, $schools_
* @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
* @param array $filing_status_params Filing status filter for the last status of the applications. Example: ['accepted', 'follow up'].
*/
- public function getAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params)
+ public function getAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
{
- $applications = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params);
+ $applications = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end);
$counted_apps = $applications
->groupBy(['semester', 'filing_status'])
@@ -373,17 +375,17 @@ public static function getLabels(string $criteria)
}
}
- public function semestersParamsStartAndEnd($semesters_params, $weeks_before_start = 4, $weeks_before_end = 4) : array {
+ public function semestersParamsStartAndEnd($semesters_params, $weeks_before_start, $weeks_before_end) : array {
$result = [];
-
+
foreach ($semesters_params as $semester_params) {
$semester = explode(' ', $semester_params);
$start_date = Carbon::createFromFormat('M j Y', Semester::seasonDates()[$semester[0]][0].' '.$semester[1])
- ->subweeks($weeks_before_start)
+ ->subweeks((int) $weeks_before_start)
->format('Y-m-d');
$end_date = Carbon::createFromFormat('M j Y', Semester::seasonDates()[$semester[0]][1].' '.$semester[1])
- ->subweeks($weeks_before_end)
+ ->subweeks((int) $weeks_before_end)
->format('Y-m-d');
$result[$semester_params] = [ 'start' => $start_date, 'end' => $end_date ];
diff --git a/resources/views/livewire/insights-filter.blade.php b/resources/views/livewire/insights-filter.blade.php
index 8748e817..6002e01f 100644
--- a/resources/views/livewire/insights-filter.blade.php
+++ b/resources/views/livewire/insights-filter.blade.php
@@ -1,11 +1,13 @@
- @push('scripts')
+@push('scripts')
@endpush
-
-
-
-
-
- Select/Unselect All
- @foreach($semester_options as $key => $value)
-
- {{$value}}
-
- @endforeach
+
+
+
+
+
+
+ Select/Unselect All
+ @foreach($semester_options as $key => $value)
+
+ {{$value}}
+
+ @endforeach
+
-
-
-
-
-
- Select/Unselect All
- @foreach($school_options as $key => $value)
-
- {{$value}}
-
- @endforeach
+
+
+
+
+ Select/Unselect All
+ @foreach($school_options as $key => $value)
+
+ {{$value}}
+
+ @endforeach
+
-
-
-
-
+
+
+
-
-
+
+
+
-
-
-
- To ensure accurate results, the data displayed is set by default to cover a period from three weeks before the start of the semester to three weeks before its end, as student research applications are reviewed and filed for the following semester. You can adjust this timeframe by using the sliders below to select the number of weeks that best suits your needs.
+ Students typically submit their applications before the start of the semester. By default, we include applications filed within a range starting 4 weeks before the semester begins and ending 4 weeks before it ends. For example, for Summer 2023, the included application period would be from May 4th, 2023, to August 8th, 2023. You can adjust this timeframe by changing the number of weeks below, then clicking 'Apply Filters'.
- Weeks before semester start:
+ Weeks before semester's start:
- Weeks before semester end:
+ Weeks before semester's end:
@@ -137,5 +139,4 @@ function selectAllToggle(fieldset_selector) {
-
From fe269a345c6c4599dd24fb70d9594417f97066a7 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 10:50:05 -0500
Subject: [PATCH 06/37] Fixes closure to sort semesters chronologically
Capitalizes the first character of x-axis labels
Changes the chart refresh order
---
app/Helpers/Semester.php | 35 +++++++++++--------
app/Http/Livewire/InsightsFilter.php | 4 +--
.../StudentDataInsight.php | 17 ++++-----
3 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/app/Helpers/Semester.php b/app/Helpers/Semester.php
index 29dc18c0..e8e9a66c 100644
--- a/app/Helpers/Semester.php
+++ b/app/Helpers/Semester.php
@@ -136,25 +136,30 @@ public static function date(string $name, bool $start_of_season = true)
* @return array
*/
public static function sortCollectionWithSemestersKeyChronologically() {
- return
- function($a, $b) {
- // Extract the year from the semesters
- [$semesterA, $yearA] = explode(' ', $a);
- [$semesterB, $yearB] = explode(' ', $b);
-
- // Define the semester order
- $order = ['Spring' => 1, 'Summer' => 2, 'Fall' => 3];
-
- // Sort by year first, and by semester order if the years are the same
- if ($yearA === $yearB) {
- return $order[$semesterA] <=> $order[$semesterB];
+ 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;
}
-
- 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
diff --git a/app/Http/Livewire/InsightsFilter.php b/app/Http/Livewire/InsightsFilter.php
index 0bca77ff..8b24edd4 100644
--- a/app/Http/Livewire/InsightsFilter.php
+++ b/app/Http/Livewire/InsightsFilter.php
@@ -12,10 +12,10 @@ class InsightsFilter extends Component
protected $listeners = ['applyFilters'];
public function applyFilters($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);
$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()
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index dc5e8a5f..9fd4e3e2 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -91,7 +91,7 @@ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params
$results[] = [
'id' => $application->stats->id,
'semester' => $semester,
- 'filing_status' => $filing_status,
+ 'filing_status' => ucfirst($filing_status),
];
}
});
@@ -217,24 +217,24 @@ public function getCachedAppsForSemestersAndSchoolsNotViewed($semesters_params,
public function getAppsBySemestersAndSchools($semesters_params, $schools_params)
{
$applications = $this->transformAppsBySemestersAndSchools($semesters_params, $schools_params);
+ $semesters_sort_closure = Semester::sortCollectionWithSemestersKeyChronologically();
$counted_apps = $applications
->groupBy(['semester', 'school'])
+ ->sortKeysUsing($semesters_sort_closure)
->map(function ($semester_group) {
return $semester_group->map(function ($school_group) {
return $school_group->count();
});
});
- $semesters_sort_closure = Semester::sortCollectionWithSemestersKeyChronologically();
- $all_semesters = $applications->pluck('semester')->unique()->sort()->values();
- // $all_semesters = $applications->pluck('semester')->unique()->sortBy($semesters_sort_closure)->values();
+
+ $all_semesters = $counted_apps->keys();
$all_schools = $applications->pluck('school')->unique()->sort()->values();
$datasets = $all_schools->mapWithKeys(function ($school) use ($all_semesters) { // Initialize datasets for each school
return [ $school => ['label' => $school, 'data' => array_fill(0, $all_semesters->count(), 0)]];
})->toArray();
- // $sorted_apps = $counted_apps->sortKeysUsing(Semester::sortCollectionWithSemestersKeyChronologically());
foreach ($counted_apps as $semester => $school_counts) {
$semester_index = $all_semesters->search($semester);
foreach ($school_counts as $school => $count) {
@@ -305,20 +305,21 @@ public function getCachedAppsForSemestersAndSchools($semesters_params, $schools_
public function getAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
{
$applications = $this->getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end);
-
+ $semesters_sort_closure = Semester::sortCollectionWithSemestersKeyChronologically();
$counted_apps = $applications
->groupBy(['semester', 'filing_status'])
+ ->sortKeysUsing($semesters_sort_closure)
->map(function ($semester_group) {
return $semester_group->map(function ($status_group) {
return $status_group->count();
});
});
- $all_semesters = $applications->pluck('semester')->unique()->sort()->values();
+ $all_semesters = $counted_apps->keys();
$all_filing_statuses = $applications->pluck('filing_status')->unique()->sort()->values();
$datasets = $all_filing_statuses->mapWithKeys(function ($filing_status) use ($all_semesters) { // Initialize datasets for each status
- return [$filing_status => ['label' => $filing_status, 'data' => array_fill(0, $all_semesters->count(), 0)]];
+ return [$filing_status => ['label' => ucfirst($filing_status), 'data' => array_fill(0, $all_semesters->count(), 0)]];
})->toArray();
foreach ($counted_apps as $semester => $filing_status_counts) {
From 96fda56af88551975bbe1ebdc0e7eebad1df5ea8 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 15:22:00 -0500
Subject: [PATCH 07/37] Fixes filter by semester when looping through student
applications
---
.../StudentDataInsight.php | 52 ++++++++++---------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index 9fd4e3e2..0cba64b8 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -74,31 +74,35 @@ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params
$semesters_params_start_end = $this->semestersParamsStartAndEnd($semesters_params, $weeks_before_semester_start, $weeks_before_semester_end);
$results = [];
- $student_applications->each(function ($application) use ($semesters_params_start_end, $filing_status_params, &$results) {
- if (!empty($application->research_profile->data['semesters']) && !empty($application->stats->data['status_history'])) {
- foreach ($semesters_params_start_end as $semester => $semester_start_end) {
- $start_date = $semester_start_end['start'];
- $end_date = $semester_start_end['end'];
- foreach ($filing_status_params as $filing_status) {
- collect($application->stats->data['status_history'])
- ->groupBy('profile')
- ->each(function($group) use ($start_date, $end_date, $filing_status, $semester, $application, &$results) {
- $last_update = $group->sortByDesc(function ($item) {
- return Carbon::parse($item['updated_at']);
- })->first();
- $filing_date = Carbon::parse($last_update['updated_at']);
- if ($last_update['new_status'] === $filing_status && $filing_date->between($start_date, $end_date)) {
- $results[] = [
- 'id' => $application->stats->id,
- 'semester' => $semester,
- 'filing_status' => ucfirst($filing_status),
- ];
- }
- });
- }
- }
+ foreach ($semesters_params_start_end as $semester => $semester_start_end) {
+ $start_date = $semester_start_end['start'];
+ $end_date = $semester_start_end['end'];
+ foreach ($filing_status_params as $filing_status) {
+ $student_applications->filter(function($app) use ($semester) {
+ return in_array($semester, $app->research_profile->data['semesters']);
+ })->each(function ($application) use ($start_date, $end_date, $filing_status, $semester, &$results) {
+ if (!empty($application->stats->data['status_history'])) {
+ collect($application->stats->data['status_history'])
+ ->groupBy('profile')
+ ->each(function($group) use ($start_date, $end_date, $filing_status, $semester, $application, &$results) {
+ $last_update = $group->sortByDesc(function ($item) {
+ return Carbon::parse($item['updated_at']);
+ })->first();
+ $filing_date = Carbon::parse($last_update['updated_at']);
+ if ($last_update['new_status'] === $filing_status && $filing_date->between($start_date, $end_date)) {
+ $results[] = [
+ 'id' => $application->stats->id,
+ 'semester' => $semester,
+ 'filing_status' => ucfirst($last_update['new_status']),
+ 'updated_at' => $last_update['updated_at'],
+ 'profile' => $last_update['profile'],
+ ];
+ }
+ });
+ }
+ });
}
- });
+ }
return collect($results);
}
From db2c84c5c2a2faabab64f4f79e7a9e31847904be Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 15:46:26 -0500
Subject: [PATCH 08/37] Includes user info students data and renames variables
in groupAppsBySemestersAndSchoolsWithFilingStatus() method
---
.../StudentDataInsight.php | 26 ++++++++++++-------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index 0cba64b8..f26e3949 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -70,7 +70,7 @@ public function getCachedAppsForSemestersAndSchoolsWithFilingStatus($semesters_p
*/
public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params, $schools_params, $filing_status_params, $weeks_before_semester_start, $weeks_before_semester_end)
{
- $student_applications = $this->getCachedAppsForSemestersAndSchoolsWithStats($semesters_params, $schools_params);
+ $students = $this->getCachedAppsForSemestersAndSchoolsWithStatsWithUser($semesters_params, $schools_params);
$semesters_params_start_end = $this->semestersParamsStartAndEnd($semesters_params, $weeks_before_semester_start, $weeks_before_semester_end);
$results = [];
@@ -78,24 +78,27 @@ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params
$start_date = $semester_start_end['start'];
$end_date = $semester_start_end['end'];
foreach ($filing_status_params as $filing_status) {
- $student_applications->filter(function($app) use ($semester) {
- return in_array($semester, $app->research_profile->data['semesters']);
- })->each(function ($application) use ($start_date, $end_date, $filing_status, $semester, &$results) {
- if (!empty($application->stats->data['status_history'])) {
- collect($application->stats->data['status_history'])
+ $students->filter(function($student) use ($semester) {
+ return in_array($semester, $student->research_profile->data['semesters']);
+ })->each(function ($student) use ($start_date, $end_date, $filing_status, $semester, &$results) {
+ if (!empty($student->stats->data['status_history'])) {
+ collect($student->stats->data['status_history'])
->groupBy('profile')
- ->each(function($group) use ($start_date, $end_date, $filing_status, $semester, $application, &$results) {
+ ->each(function($group) use ($student, $start_date, $end_date, $filing_status, $semester, &$results) {
$last_update = $group->sortByDesc(function ($item) {
return Carbon::parse($item['updated_at']);
})->first();
$filing_date = Carbon::parse($last_update['updated_at']);
if ($last_update['new_status'] === $filing_status && $filing_date->between($start_date, $end_date)) {
$results[] = [
- 'id' => $application->stats->id,
+ 'id' => $student->stats->id,
'semester' => $semester,
+ 'school' => $student->research_profile->data['schools'],
'filing_status' => ucfirst($last_update['new_status']),
'updated_at' => $last_update['updated_at'],
'profile' => $last_update['profile'],
+ 'display_name' => $student->user->display_name,
+ 'pea' => $student->user->pea,
];
}
});
@@ -112,7 +115,7 @@ public function groupAppsBySemestersAndSchoolsWithFilingStatus($semesters_params
* @param array $schools_params Schools filter. Example: ["BBS", "NSM"].
* @return \Illuminate\Support\Collection
*/
- public function getCachedAppsForSemestersAndSchoolsWithStats($semesters_params, $schools_params)
+ public function getCachedAppsForSemestersAndSchoolsWithStatsWithUser($semesters_params, $schools_params)
{
$sm = implode('-', $semesters_params);
$sch = implode('-', $schools_params);
@@ -120,7 +123,10 @@ public function getCachedAppsForSemestersAndSchoolsWithStats($semesters_params,
return Cache::remember(
"student-apps-for-semesters-schools-with-stats-{$sm}-{$sch}",
15 * 60,
- fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)->with('stats')->get()
+ fn() => $this->appsForSemestersAndSchools($semesters_params, $schools_params)
+ ->with('stats')
+ ->with('user')
+ ->get()
);
}
From f0f0f0925edc1ba44343e4ccee204c5973520110 Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 16:00:49 -0500
Subject: [PATCH 09/37] Changes advanced settings button interaction to
dropdown
---
resources/views/insights/index.blade.php | 4 +-
.../views/livewire/insights-filter.blade.php | 53 +++++++++++--------
2 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/resources/views/insights/index.blade.php b/resources/views/insights/index.blade.php
index 33778bc7..8bdd1a40 100644
--- a/resources/views/insights/index.blade.php
+++ b/resources/views/insights/index.blade.php
@@ -68,8 +68,8 @@ function step() {
-
-
+
+
diff --git a/resources/views/livewire/insights-filter.blade.php b/resources/views/livewire/insights-filter.blade.php
index 6002e01f..eb78cbfc 100644
--- a/resources/views/livewire/insights-filter.blade.php
+++ b/resources/views/livewire/insights-filter.blade.php
@@ -81,32 +81,40 @@ function selectAllToggle(fieldset_selector) {
-
-
-
-
+
+
+
+
+ Students typically submit their applications before the start of the semester. By default, we include applications filed within a range starting 4 weeks before the semester begins and ending 4 weeks before it ends. For example, for Summer 2023, the included application period would be from May 4th, 2023, to August 8th, 2023. You can adjust this timeframe by changing the number of weeks below, then clicking 'Apply Filters'.
+
+
+
+ Weeks before semester's start:
+
+
+
+ Weeks before semester's end:
+
+
+
+
+
+
-
-
- Students typically submit their applications before the start of the semester. By default, we include applications filed within a range starting 4 weeks before the semester begins and ending 4 weeks before it ends. For example, for Summer 2023, the included application period would be from May 4th, 2023, to August 8th, 2023. You can adjust this timeframe by changing the number of weeks below, then clicking 'Apply Filters'.
-
-
- Weeks before semester's start:
-
-
-
- Weeks before semester's end:
-
-
-
-
From 727cfd3244b10e21907ca4420314596f183113fa Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 16:05:03 -0500
Subject: [PATCH 10/37] Rounds increment in progress animation function for
doughnut charts
---
resources/views/insights/index.blade.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/insights/index.blade.php b/resources/views/insights/index.blade.php
index 8bdd1a40..ac3c0fe7 100644
--- a/resources/views/insights/index.blade.php
+++ b/resources/views/insights/index.blade.php
@@ -20,7 +20,7 @@ function animateProgress(chart_instance, progress, percentage) {
var start = 0;
var end = progress;
var current = start;
- var increment = end / 100;
+ var increment = Math.round(end / 100);
function step() {
current += increment;
From 11495059cdf750c78aff957b32f768237e2f9a4a Mon Sep 17 00:00:00 2001
From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com>
Date: Tue, 17 Sep 2024 17:12:02 -0500
Subject: [PATCH 11/37] Adds title for applied filters and centers doughnut
charts
---
app/Http/Controllers/InsightsController.php | 4 ++--
app/Http/Livewire/InsightsFilter.php | 3 +++
.../StudentDataInsight.php | 19 +++++++++++++++++++
resources/views/insights/index.blade.php | 12 ++++++------
...-follow-up-apps-percentage-chart.blade.php | 2 +-
.../views/livewire/insights-filter.blade.php | 2 ++
...ent-apps-viewed-not-viewed-chart.blade.php | 2 +-
7 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/app/Http/Controllers/InsightsController.php b/app/Http/Controllers/InsightsController.php
index c4a7472b..753c6fb4 100644
--- a/app/Http/Controllers/InsightsController.php
+++ b/app/Http/Controllers/InsightsController.php
@@ -28,8 +28,8 @@ public function index(Request $request): ViewContract
$schools_options = StudentDataInsight::getLabels('school')->toArray();
$semesters_options = StudentDataInsight::getLabels('semester')->toArray();
- // $filing_status_params = ["accepted", "maybe later", "not interested", "new", "follow up"];
+ $title = StudentDataInsight::convertParameterstoTitle($semesters_options, $schools_options);
- return view('insights.index', compact('schools_options', 'semesters_options'));
+ return view('insights.index', compact('schools_options', 'semesters_options', 'title'));
}
}
diff --git a/app/Http/Livewire/InsightsFilter.php b/app/Http/Livewire/InsightsFilter.php
index 8b24edd4..c6c37c2b 100644
--- a/app/Http/Livewire/InsightsFilter.php
+++ b/app/Http/Livewire/InsightsFilter.php
@@ -2,6 +2,7 @@
namespace App\Http\Livewire;
+use App\Insights\StudentApplications\StudentDataInsight;
use Livewire\Component;
class InsightsFilter extends Component
@@ -9,9 +10,11 @@ class InsightsFilter extends Component
public $semester_options = [];
public $school_options = [];
+ public $title;
protected $listeners = ['applyFilters'];
public function applyFilters($selected_semesters, $selected_schools, $weeks_before_semester_start, $weeks_before_semester_end) {
+ $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);
diff --git a/app/Insights/StudentApplications/StudentDataInsight.php b/app/Insights/StudentApplications/StudentDataInsight.php
index f26e3949..589df911 100644
--- a/app/Insights/StudentApplications/StudentDataInsight.php
+++ b/app/Insights/StudentApplications/StudentDataInsight.php
@@ -405,4 +405,23 @@ public function semestersParamsStartAndEnd($semesters_params, $weeks_before_star
return $result;
}
+ public static function convertParameterstoTitle($semesters_params, $schools_params)
+ {
+ // If there is only one semester, just return it
+ if (count($semesters_params) === 1) {
+ return $semesters_params[0];
+ }
+
+ // If there is only one semester, just return it
+ if (count($schools_params) === 1) {
+ return $schools_params[0];
+ }
+
+ // For more than one semester, format with commas and "and" before the last item
+ $lastSchool = array_pop($schools_params);
+ $lastSemester = array_pop($semesters_params);
+ $title = [implode(', ', $semesters_params) . ' and ' . $lastSemester, implode(', ', $schools_params) . ' and ' . $lastSchool];
+
+ return "{$title[0]} and for {$title[1]} schools.";
+ }
}
diff --git a/resources/views/insights/index.blade.php b/resources/views/insights/index.blade.php
index ac3c0fe7..c49a1e06 100644
--- a/resources/views/insights/index.blade.php
+++ b/resources/views/insights/index.blade.php
@@ -66,13 +66,13 @@ function step() {