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] Implement lorisInstance in tools directory #9397

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion tools/data_integrity/fix_candidate_age.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
JOIN candidate c ON c.CandID=s.CandID
JOIN test_names tn ON tn.ID=f.TestID
WHERE c.Active='Y' AND s.Active='Y'

victori444 marked this conversation as resolved.
Show resolved Hide resolved
AND tn.Test_name=:tn",
['tn' => $testName]
);
Expand Down
79 changes: 45 additions & 34 deletions tools/detect_conflicts.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
print "instrument is $instrument \n";

//Run the script for all the instruments
$commentids = getCommentIDs($instrument, $visit_label);
$commentids = getCommentIDs($instrument, $visit_label)->getIterator();


//check to make sure that the commentids are set
Expand Down Expand Up @@ -301,7 +301,7 @@ function getCommentIDs($test_name, $visit_label = null, $candid = null)
{
global $db;
$params = [];
$query = "SELECT CommentID, s.visit_label,Test_name,
$query = "SELECT CommentID, s.visit_label, tn.Test_name,
CONCAT('DDE_', CommentID) AS DDECommentID FROM flag f
JOIN session s ON (s.ID=f.SessionID)
JOIN candidate c ON (c.CandID=s.CandID)
Expand All @@ -310,7 +310,7 @@ function getCommentIDs($test_name, $visit_label = null, $candid = null)
AND s.Active='Y' AND c.Active='Y'
AND s.Visit <> 'Failure'";
if ($test_name!=null) {
$where .= " AND tn.Test_name= :instrument ";
$where .= " AND tn.Test_name=:instrument ";
$params['instrument'] = $test_name;

if (($visit_label!=null) && (isset($visit_label))) {
Expand All @@ -330,9 +330,10 @@ function getCommentIDs($test_name, $visit_label = null, $candid = null)
* @param String $test_name The instrument been searched
* @param ?string $visit_label The visit_label been searched
*
* @return array $conflicts An array of conflicts detected
* @return LORIS\Database\Query $conflicts An Query object of conflicts detected
*/
function getCurrentUnresolvedConflicts($test_name, $visit_label = null): array
function getCurrentUnresolvedConflicts($test_name, $visit_label = null):
\LORIS\Database\Query
{
global $db;
$params = [];
Expand Down Expand Up @@ -371,6 +372,7 @@ function getCurrentUnresolvedConflicts($test_name, $visit_label = null): array
*/
function detectConflicts($test_name, $commentids, $current_conflicts)
{
global $lorisInstance;
$detected_conflicts = [];
/**
* Go through each commentid
Expand All @@ -380,6 +382,7 @@ function detectConflicts($test_name, $commentids, $current_conflicts)
* Detect new conflicts
*/
$diff =ConflictDetector::detectConflictsForCommentIds(
$lorisInstance,
$test_name,
$cid['CommentID'],
$cid['DDECommentID']
Expand Down Expand Up @@ -486,19 +489,23 @@ function getInfoUsingCommentID($commentid)
*/
function detectConflictsTobeExcluded($instrument, $commentids, $current_conflicts)
{
global $lorisInstance;
$conflicts_to_excluded = [];
$instance1 =& NDB_BVL_Instrument::factory(
$instrument,
$commentids[0]['CommentID'],
null
);
$ignore_columns = $instance1->_doubleDataEntryDiffIgnoreColumns;
foreach ($current_conflicts as $conflict) {
// if the field is part of the ignore_columns,
// and it doesn exist in the conflict array
// then track it
if (in_array($conflict['FieldName'], $ignore_columns)) {
$conflicts_to_excluded[] = $conflict;
foreach ($commentids as $cid) {
$instance1 =& NDB_BVL_Instrument::factory(
$lorisInstance,
$instrument,
$commentids['CommentID'],
null
);
$ignore_columns = $instance1->_doubleDataEntryDiffIgnoreColumns;
foreach ($current_conflicts as $conflict) {
// if the field is part of the ignore_columns,
// and it doesn exist in the conflict array
// then track it
if (in_array($conflict['FieldName'], $ignore_columns)) {
$conflicts_to_excluded[] = $conflict;
}
}
}
return $conflicts_to_excluded;
Expand Down Expand Up @@ -583,31 +590,35 @@ function findConflict($conflict, $conflicts)
*/
function detectIgnoreColumns($instruments, $confirm)
{
global $lorisInstance;
$instrumentFields = [];

foreach ($instruments as $instrument) {
$file = "../project/instruments/NDB_BVL_Instrument_$instrument.class.inc";
if (file_exists($file)) {
include_once $file;
$commentids = getCommentIDs($instrument, null);
$instance =& NDB_BVL_Instrument::factory(
$instrument,
$commentids[0]['CommentID'],
null
);
$DDEIgnoreFields = $instance->_doubleDataEntryDiffIgnoreColumns;

if ($DDEIgnoreFields != null) {
foreach ($DDEIgnoreFields as $key => $DDEField) {
$instrumentFields = array_merge(
$instrumentFields,
[$DDEField => $instrument]
);
$commentids = getCommentIDs($instrument, null)->getIterator();

foreach ($commentids as $cid) {
$instance = NDB_BVL_Instrument::factory(
$lorisInstance,
$instrument,
$cid['CommentID']
);
$DDEIgnoreFields = $instance->_doubleDataEntryDiffIgnoreColumns;

if ($DDEIgnoreFields != null) {
foreach ($DDEIgnoreFields as $key => $DDEField) {
$instrumentFields = array_merge(
$instrumentFields,
[$DDEField => $instrument]
);
}
} else {
echo "No DDE ignore fields found for " . $instrument;
}
} else {
echo "No DDE ignore fields found for " . $instrument;
ignoreColumn($instrument, $instrumentFields, $confirm);
}
ignoreColumn($instrument, $instrumentFields, $confirm);
} else {
echo $file . " was not found.\n";
}
Expand Down
Loading