<commit_before><?php

/**
 * AnnaZeepsop.GetSuspects API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
 */
function _civicrm_api3_anna_zeepsop_getsuspects_spec(&$spec) {
  $spec['rule_id']['api.required'] = 1;
}

/**
 * AnnaZeepsop.GetSuspects API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_anna_zeepsop_getsuspects($params) {
  if (array_key_exists('rule_id', $params)) {
    /*
     * set table based on rule_id
     */
    $tableName = _set_table_name($params['rule_id']);
    if (!empty($tableName)) {
      define('DGW_SUSPECT_TABLE', _set_table_name($param['rule_id']));
      /*
       * get all possible dupes with rule
       */
      $dupes = CRM_Dedupe_Finder::dupes($params['rule_id']);
      foreach ($dupes as $dupe) {
        _write_suspect($dupe[0], $dupe[1], $dupe[2]);
      }
      $returnValues = array('is_error' => 0, 'message' => 'Verwerking succesvol afgerond');
      return civicrm_api3_create_success($returnValues, $params, 'AnnaZeepsop', 'GetSuspects');
    } else {
      throw new API_Exception('Parameter rule_id kan alleen 7, 8 of 9 zijn', 0002);
    }
  } else {
    throw new API_Exception('Parameter rule_id moet aanwezig zijn', 0001);
  }
}
/**
 * Function to get table name
 */
function _set_table_name($ruleId) {
  $tableName = '';
  switch ($ruleId) {
    case 7:
      $tableName = 'dgw_suspects1';
      break;
    case 8:
      $tableName = 'dgw_suspects2';
      break;
    case 9:
      $tableName = 'dgw_suspects3';
      break;
  }
  return $tableName;
}
/**
 * Function to write suspect
 * 
 * @param int $contactIdA
 * @param int $contactIdB
 * @param int $score
 */
function _write_suspect($contactIdA, $contactIdB, $score) {
  $insertFields = array();
  $insertParams = array();
  if (!empty($contactIdA) && !empty($contactIdB)) {
    $insertFields[] = 'score = %1';
    $insertParams[1] = array($score, 'Positive');
    $paramCounter = 2;
    $contactA = civicrm_api3('Contact', 'Getsingle', array('id' => $contactIdA));
    $contactB = civicrm_api3('Contact', 'Getsingle', array('id' => $contactIdB));
    setInsertFields($contactA, $contactB, $score, $insertFields, $insertParams, $paramCounter);
    if (!empty($insertFields)) {
      $query = 'INSERT INTO '.DGW_SUSPECT_TABLE.' SET '.implode(', ', $insertFields);
      CRM_Core_DAO::executeQuery($query, $insertParams);
    }
  }
}
/**
 * Function to set insert fields for dgw_suspect
 * 
 * @param array $contactA
 * @param array $contactB
 * @param string $bsn
 * @return array $result;
 */
function setInsertFields($contactA, $contactB, &$fields, &$params, &$counter) {
  $queryFields = array('contact_id' => 'Positive', 'display_name' => 'String',
    'birth_date' => 'Date', 'street_address' => 'String', 'city' => 'String', 'postal_code' => 'String',
    'phone' => 'String', 'email' => 'String', 'phone_type_id' => 'Positive');
  
  foreach ($queryFields as $fieldName => $type) {<commit_msg>tested generate suspects locally<commit_after><?php

/**
 * AnnaZeepsop.GetSuspects API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
 */
function _civicrm_api3_anna_zeepsop_getsuspects_spec(&$spec) {
  $spec['rule_id']['api.required'] = 1;
}

/**
 * AnnaZeepsop.GetSuspects API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_anna_zeepsop_getsuspects($params) {
  if (array_key_exists('rule_id', $params)) {
    /*
     * set table based on rule_id
     */
    $tableName = _set_table_name($params['rule_id']);
    if (!empty($tableName)) {
      define('DGW_SUSPECT_TABLE', _set_table_name($params['rule_id']));
      CRM_Core_DAO::executeQuery('TRUNCATE TABLE '.DGW_SUSPECT_TABLE);
      /*
       * get all possible dupes with rule
       */
      $dupes = CRM_Dedupe_Finder::dupes($params['rule_id']);
      foreach ($dupes as $dupe) {
        _write_suspect($dupe[0], $dupe[1], $dupe[2]);
      }
      $returnValues = array('is_error' => 0, 'message' => 'Verwerking succesvol afgerond');
      return civicrm_api3_create_success($returnValues, $params, 'AnnaZeepsop', 'GetSuspects');
    } else {
      throw new API_Exception('Parameter rule_id kan alleen 7, 8 of 9 zijn', 0002);
    }
  } else {
    throw new API_Exception('Parameter rule_id moet aanwezig zijn', 0001);
  }
}
/**
 * Function to get table name
 */
function _set_table_name($ruleId) {
  $tableName = '';
  switch ($ruleId) {
    case 7:
      $tableName = 'dgw_suspects1';
      break;
    case 8:
      $tableName = 'dgw_suspects2';
      break;
    case 9:
      $tableName = 'dgw_suspects3';
      break;
  }
  return $tableName;
}
/**
 * Function to write suspect
 * 
 * @param int $contactIdA
 * @param int $contactIdB
 * @param int $score
 */
function _write_suspect($contactIdA, $contactIdB, $score) {
  $insertFields = array();
  $insertParams = array();
  if (!empty($contactIdA) && !empty($contactIdB)) {
    $insertFields[] = 'score = %1';
    $insertParams[1] = array($score, 'Positive');
    $paramCounter = 2;
    $contactA = civicrm_api3('Contact', 'Getsingle', array('id' => $contactIdA));
    $contactB = civicrm_api3('Contact', 'Getsingle', array('id' => $contactIdB));
    setInsertFields($contactA, $contactB, $insertFields, $insertParams, $paramCounter);
    if (!empty($insertFields)) {
      $query = 'INSERT INTO '.DGW_SUSPECT_TABLE.' SET '.implode(', ', $insertFields);
      CRM_Core_DAO::executeQuery($query, $insertParams);
    }
  }
}
/**
 * Function to set insert fields for dgw_suspect
 * 
 * @param array $contactA
 * @param array $contactB
 * @param array $fields;
 * @return array $result;
 */
function setInsertFields($contactA, $contactB, &$fields, &$params, &$counter) {
  $queryFields = array('contact_id' => 'Positive', 'display_name' => 'String',
    'birth_date' => 'Date', 'street_address' => 'String', 'city' => 'String', 'postal_code' => 'String',
    'phone' => 'String', 'email' => 'String', 'phone_type_id' => 'Positive');
  
  foreach ($queryFields as $fieldName => $type) {
{'fraction_non_alphanumeric': 0.15710382513661203, 'fraction_numerical': 0.009714632665452338, 'mean_word_length': 4.049042145593869, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208562', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2245, 'n_words': 499}