<commit_before><?php

namespace App\Model\Repository;

use App\Helpers\Pair;
use App\Model\Entity\ShadowAssignment;
use App\Model\Entity\ShadowAssignmentPoints;
use App\Model\Entity\User;
use Kdyby\Doctrine\EntityManager;

/**
 * @method ShadowAssignmentPoints findOrThrow($id)
 */
class ShadowAssignmentPointsRepository extends BaseRepository {

  public function __construct(EntityManager $em) {
    parent::__construct($em, ShadowAssignmentPoints::class);
  }

  /**
   * Find points for given user of given assignments.
   * @param ShadowAssignment[] $shadowAssignments
   * @param User $user
   * @return Pair[] indexed by the shadow assignment identification, value is
   * pair which key is assignment and value is points. Points can be null if
   * there are no points for the assignment and user
   */
  public function findPointsForAssignments(array $shadowAssignments, User $user): array {
    $result = [];
    foreach ($shadowAssignments as $assignment) {
      $result[$assignment->getId()] = new Pair($assignment, null);
    }

    $pointsList = $this->findBy([
      "author" => $user,
      "shadowAssignment" => $shadowAssignments, // doctrine will handle given array with IN operator
    ]);

    /** @var ShadowAssignmentPoints $points */
    foreach ($pointsList as $points) {
      $result[$points->getShadowAssignment()->getId()]->value = $points;
    }
    return $result;
  }

}<commit_msg>Bugfix: find shadow assignment points for awardee not author<commit_after><?php

namespace App\Model\Repository;

use App\Helpers\Pair;
use App\Model\Entity\ShadowAssignment;
use App\Model\Entity\ShadowAssignmentPoints;
use App\Model\Entity\User;
use Kdyby\Doctrine\EntityManager;

/**
 * @method ShadowAssignmentPoints findOrThrow($id)
 */
class ShadowAssignmentPointsRepository extends BaseRepository {

  public function __construct(EntityManager $em) {
    parent::__construct($em, ShadowAssignmentPoints::class);
  }

  /**
   * Find points for given user of given assignments.
   * @param ShadowAssignment[] $shadowAssignments
   * @param User $awardee
   * @return Pair[] indexed by the shadow assignment identification, value is
   * pair which key is assignment and value is points. Points can be null if
   * there are no points for the assignment and user
   */
  public function findPointsForAssignments(array $shadowAssignments, User $awardee): array {
    $result = [];
    foreach ($shadowAssignments as $assignment) {
      $result[$assignment->getId()] = new Pair($assignment, null);
    }

    $pointsList = $this->findBy([
      "awardee" => $awardee,
      "shadowAssignment" => $shadowAssignments, // doctrine will handle given array with IN operator
    ]);

    /** @var ShadowAssignmentPoints $points */
    foreach ($pointsList as $points) {
      $result[$points->getShadowAssignment()->getId()]->value = $points;
    }
    return $result;
  }

}
{'fraction_non_alphanumeric': 0.11395912712157949, 'fraction_numerical': 0.0, 'mean_word_length': 4.0755711775043935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '1886546', 'n_tokens_mistral': 794, 'n_tokens_neox': 804, 'n_words': 236}