protected function finishImpl(array &$records = NULL) {
        parent::finishImpl($records);

        if (!isset($records)) {
            return;
        }

        $valueMin = $valueMax = NULL;
        // preparing minimum and maximum values
        foreach ($records as $record) {
            if (!isset($record[$this->valueColumnName])) {
                continue;
            }

            $value = $record[$this->valueColumnName];

            $valueMin = MathHelper::min($valueMin, $value);
            $valueMax = MathHelper::max($value, $valueMax);
        }
        $valueRange = $valueMax - $valueMin;

        // generating weighted grade
        foreach ($records as &$record) {
            if (!isset($record[$this->valueColumnName])) {
                continue;
            }

            $value = $record[$this->valueColumnName];

            $rank = ($valueRange == 0) ? 1 : ($value - $valueMin) / $valueRange;
            $record[$this->memberRankColumnName] = $rank;
        }
        unset($record);
    }
 public function postFormatRecords(array &$records = NULL)
 {
     parent::postFormatRecords($records);
     if (!isset($records)) {
         return;
     }
     $valueMin = NULL;
     $valueMax = NULL;
     // preparing minimum and maximum values
     foreach ($records as $record) {
         if (!isset($record[$this->valuePropertyName])) {
             continue;
         }
         $value = $record[$this->valuePropertyName];
         $valueMin = MathHelper::min($valueMin, $value);
         $valueMax = MathHelper::max($value, $valueMax);
     }
     // generating weighted grade
     foreach ($records as &$record) {
         if (!isset($record[$this->valuePropertyName])) {
             continue;
         }
         $value = $record[$this->valuePropertyName];
         $weightedGrade = ($value - $valueMin) / ($valueMax - $valueMin);
         $record[$this->weightedGradeProperyName] = $weightedGrade;
     }
 }
    protected function calculateLinkWeight(ReferenceLink $link, $weightMultiplier, ReferenceLink $parentLink = NULL) {
        if (isset($parentLink)) {
            $weight = NULL;
            foreach ($link->columnNames as $referencePointColumnIndex => $columnName) {
                $column = $link->dataset->getColumn($columnName);

                $parentColumnName = $link->parentColumnNames[$referencePointColumnIndex];
                $parentColumn = $parentLink->dataset->getColumn($parentColumnName);

                // calculating the link weight
                $columnWeight = $parentColumn->isKey()
                    ? ($column->isKey() ? self::$LINK_WEIGHT__PK_to_PK : self::$LINK_WEIGHT__from_LOOKUP)
                    : ($column->isKey() ? self::$LINK_WEIGHT__to_LOOKUP : self::$LINK_WEIGHT__NON_PK_to_NON_PK);

                $weight = MathHelper::min($weight, $columnWeight);
            }
            // calculating the link weight and adjusting the valued based on multiplier
            $link->weight = $weight / pow($weightMultiplier, count($link->columnNames) - 1);
        }

        if (isset($link->nestedLinks)) {
            foreach ($link->nestedLinks as $nestedLink) {
                $this->calculateLinkWeight($nestedLink, $weightMultiplier, $link);
            }
        }
    }
    public function readLineFromResource() {
        $this->incrementLineNumber();

        $delimiterSize = 1;

        $i = 0;

        $n = strpos($this->buffer, "\n", $this->index);
        $r = strpos($this->buffer, "\r", $this->index);
        if ($n === FALSE) {
            if ($r === FALSE) {
                // last line in the stream
                if (($this->index + 1) < $this->bufferSize) {
                    $s = substr($this->buffer, $this->index);
                    $this->index = $this->bufferSize;

                    return $s;
                }
                else {
                    return FALSE;
                }
            }
            else {
                // continue with just $r
                $i = $r;
            }
        }
        else {
            if ($r === FALSE) {
                // continue with just $n
                $i = $n;
            }
            else {
                // both delimiters are set
                if (($r + 1) == $n) {
                    // it is one delimiter \r\n
                    $delimiterSize = 2;

                    $i = $r;
                }
                else {
                    $i = MathHelper::min($r, $n);
                }
            }
        }

        $line = ($i == $this->index)
            ? ''
            : substr($this->buffer, $this->index, $i - $this->index);

        $this->index = $i + $delimiterSize;

        return $line;
    }