Closed dan-tang-ssd closed 6 months ago
Code Refactoring on GenericDashboardController.php
:
The syntax of certain key areas in the code, like mapping functions, has been made more traditional which enhances compatibility. Unnecessary spaces have been removed with relevant spaces and line breaks inserted for better readability. This makes it easier for other developers to understand and maintain the code.
Enhancement of enquire
Method:
The filter function in the method enquire
, has been modified from a more modern fn
to a traditional function
enhancing the backward compatibility. The readability of the variables $yoursPrinciplesSummarySorted
, $allAssessmentsYours
, and $allAssessmentsOthers
has been improved with better spacing and line breaks. This translates into more maintainable and understandable code from a developer's perspective.
These changes lead to a code that is not only easier to read but also is more robust as it is now compatible with systems using traditional syntax.
I have a little question about getting all assessments. For a project with re-assessment. e.g.
Both assessments are included, I am not sure whether it is the expected result.
Um... different perspective for including / excluding the first assessment:
// add overall score from PHP side because this is already calculated on the Assessment Model.
$allAssessments = Project::withoutGlobalScope('organisation')->with([
'assessments' => ['principleAssessments.principle', 'principles', 'failingRedlines']
])
// only initiatives that are fully assessed
->whereHas('assessments', function (Builder $query) {
$query->where('redline_status', AssessmentStatus::Failed->value)
->orWhere('principle_status', AssessmentStatus::Complete->value);
})
->get()
->pluck('assessments')
->flatten();
Both assessments are included, I am not sure whether it is the expected result.
Um... different perspective for including / excluding the first assessment:
Mm, good point. You're right this is something worth reviewing. The overall goal is to look at the current state of the organisation's portfolios. If a project gets re-assessed, the latest assessment is the one to include. Older ones are kept in the database for accounting and review purposes, but I think they should be skipped in the analysis.
Quick check in the generate_dashboard_summary
- this is how it works there:
-- find latest assessments of projects (others)
INSERT INTO dashboard_assessment (dashboard_id, assessment_id)
SELECT dashboardOthersId, MAX(id) AS latest_assessment_id
FROM assessments
WHERE project_id IN
(SELECT project_id FROM dashboard_project where dashboard_id = dashboardOthersId)
GROUP BY project_id;
So you're right - we should update the logic for getting $allAssessments
to match.
In dashboard, I have revised program to exclude previously completed assessments.
I tried to modify the eloquent query for $allAssessments, but failed.
For clarity and readability, I added a separate query to obtain all latest assessments. And then use it on collection to keep latest assessments only.
This PR is submitted to fix an uinexpected message in dashboard.
Root cause identified: Incorrect column used in query. In whereIn() clause, the column should be "project_id" instead of "id". The fix has been applied to both $allAssessmentsYours and $allAssessmentsOthers.
Screen shots
BEFORE:
AFTER: