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

[tools] Fix efficiency of fix_candidate_age script #8992

Merged
Merged
Changes from all commits
Commits
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
41 changes: 10 additions & 31 deletions tools/data_integrity/fix_candidate_age.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,16 @@
"SELECT f.CommentID FROM flag f
JOIN session s ON s.ID=f.SessionID
JOIN candidate c ON c.CandID=s.CandID
WHERE c.Active='Y' AND s.Active='Y'",
[]
WHERE c.Active='Y' AND s.Active='Y'
AND f.Test_name=:tn",
['tn' => $testName]
);

foreach ($CommentIDs as $commentID) {
// Get Instrument Instance with commentID
try {
$instrument = NDB_BVL_Instrument::factory(
$lorisInstance,
$testName,
$commentID,
'',
false
);
} catch (Exception $e) {
echo "\t$testName instrument row with CommentID: ".$commentID.
" was ignored for one of the following reasons:\n".
" - The candidate is inactive.\n".
" - The session is inactive.\n\n";
continue;
}

if (!$instrument) {
// instrument does not exist
echo "\t"
. "$testName for CommentID:$commentID could not be instantiated."
. "\n";
continue;
}
$instrumentInstances = $instrument->bulkLoadInstanceData($CommentIDs);

$data = $instrument->getInstanceData();
foreach ($instrumentInstances as $instrumentInstance) {
$data = $instrumentInstance->getInstanceData();
$commentID = $instrumentInstance->getCommentID();
$dateTaken = $data['Date_taken'] ?? null;

// Flag for problem with date
Expand All @@ -125,8 +104,8 @@
$trouble =true;
} else {
// get Age from instrument class
$calculatedAge = $instrument->getCandidateAge();
$calculatedAgeMonths = $instrument->calculateAgeMonths(
$calculatedAge = $instrumentInstance->getCandidateAge();
$calculatedAgeMonths = $instrumentInstance->calculateAgeMonths(
$calculatedAge
);
//Compare age to value saved in the instrument table
Expand All @@ -144,7 +123,7 @@
//Fix the saved values if confirm and trouble flags enabled
if ($trouble && $confirm) {
echo "\tFixing age for CommentID: ".$commentID."\n";
$instrument->_saveValues(['Date_taken' => $dateTaken]);
$instrumentInstance->_saveValues(['Date_taken' => $dateTaken]);
}
}
}
Expand Down
Loading