示例#1
27
文件: Image.php 项目: soundake/pd
 /**
  * sharpen( $factor ) - factor goes from -64 to  64 where -64 is max blur and 64 is max sharpen
  **/
 public function sharpenBlur($factor)
 {
     if ($factor == 0) {
         return $this;
     }
     // get a value thats equal to 64 - abs( factor )
     // ( using min/max to limited the factor to 0 - 64 to not get out of range values )
     $val1Adjustment = 64 - min(64, max(0, abs($factor)));
     // the base factor for the "current" pixel depends on if we are blurring or sharpening.
     // If we are blurring use 1, if sharpening use 9.
     $val1Base = abs($factor) != $factor ? 1 : 9;
     // value for the center/currrent pixel is:
     //  1 + 0 - max blurring
     //  1 + 64- minimal blurring
     //  9 + 64- minimal sharpening
     //  9 + 0 - maximum sharpening
     $val1 = $val1Base + $val1Adjustment;
     // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening.
     $val2 = abs($factor) != $factor ? 1 : -1;
     // setup matrix ..
     $matrix = array(array($val2, $val2, $val2), array($val2, $val1, $val2), array($val2, $val2, $val2));
     // calculate the correct divisor
     // actual divisor is equal to "$divisor = $val1 + $val2 * 8;"
     // but the following line is more generic
     $divisor = array_sum(array_map('array_sum', $matrix));
     // apply the matrix
     imageconvolution($this->image, $matrix, $divisor, 0);
     return $this;
 }
 public function format(Node $node, Document $document)
 {
     $node->convertRelativeWidthsOfColumns();
     $node->reduceColumnsWidthsByMargins();
     $columnsWidths = $node->getWidthsOfColumns();
     $columnsMarginsLeft = $node->getMarginsLeftOfColumns();
     $columnsMarginsRight = $node->getMarginsRightOfColumns();
     $numberOfColumns = $node->getNumberOfColumns();
     $totalColumnsWidth = array_sum($columnsWidths);
     $tableWidth = $node->getWidth();
     $enlargeColumnWidth = $numberOfColumns ? ($tableWidth - $totalColumnsWidth) / count($columnsWidths) : 0;
     foreach ($columnsWidths as $index => $width) {
         $columnsWidths[$index] += $enlargeColumnWidth;
     }
     foreach ($node->getChildren() as $row) {
         foreach ($row->getChildren() as $cell) {
             $column = $cell->getNumberOfColumn();
             $colspan = $cell->getColspan();
             $newWidth = 0;
             for ($i = 0; $i < $colspan; $i++) {
                 $newWidth += $columnsWidths[$column + $i];
             }
             $horizontalPaddings = $cell->getPaddingLeft() + $cell->getPaddingRight();
             $cell->setWidth($newWidth - $horizontalPaddings);
             $cell->setMarginLeft($columnsMarginsLeft[$column]);
             $cell->setMarginRight($columnsMarginsRight[$column + $colspan - 1]);
         }
     }
 }
function chmodnum($chmod)
{
    $trans = array('-' => '0', 'r' => '4', 'w' => '2', 'x' => '1');
    $chmod = substr(strtr($chmod, $trans), 1);
    $array = str_split($chmod, 3);
    return array_sum(str_split($array[0])) . array_sum(str_split($array[1])) . array_sum(str_split($array[2]));
}
 public function __construct(array $outputs, $confirms = 1)
 {
     $this->data = $outputs;
     $this->minimumConfirms = $confirms;
     $this->total = count($outputs);
     // do calculation only if at least 1 output
     if ($this->total > 0) {
         $amounts = array_column($outputs, 'amount');
         $this->amountsSum = array_sum($amounts);
         $amountPairs = [];
         foreach ($amounts as $amount) {
             $amount = (string) $amount;
             // cast float to string, because array_key_exists can handle only string or integer
             // if key exists, then add +1 to value that means that amount already was counted
             if (array_key_exists($amount, $amountPairs)) {
                 $amountPairs[$amount] = $amountPairs[$amount] + 1;
             } else {
                 // new result, just add initial 1
                 $amountPairs[$amount] = 1;
             }
         }
         $this->amountPairs = $amountPairs;
         ksort($this->amountPairs);
         // sort incrementing by amount
     }
 }
 function callback($path = '', $blog_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     //upload_files can probably be used for other endpoints but we want contributors to be able to use media too
     if (!current_user_can('edit_posts')) {
         return new WP_Error('unauthorized', 'User cannot view media', 403);
     }
     $args = $this->query_args();
     if ($args['number'] < 1) {
         $args['number'] = 20;
     } elseif (100 < $args['number']) {
         return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
     }
     $media = get_posts(array('post_type' => 'attachment', 'post_parent' => $args['parent_id'], 'offset' => $args['offset'], 'numberposts' => $args['number'], 'post_mime_type' => $args['mime_type']));
     $response = array();
     foreach ($media as $item) {
         $response[] = $this->get_media_item($item->ID);
     }
     $_num = (array) wp_count_attachments();
     $_total_media = array_sum($_num) - $_num['trash'];
     $return = array('found' => $_total_media, 'media' => $response);
     return $return;
 }
示例#6
0
文件: note.php 项目: Astaen/fredi
 function FancyTable($header, $data)
 {
     // Couleurs, épaisseur du trait et police grasse
     $this->SetFillColor(255, 0, 0);
     $this->SetTextColor(255);
     $this->SetDrawColor(128, 0, 0);
     $this->SetLineWidth(0.3);
     $this->SetFont('', 'B');
     // En-tête
     $w = array(40, 35, 45, 40);
     for ($i = 0; $i < count($header); $i++) {
         $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true);
     }
     $this->Ln();
     // Restauration des couleurs et de la police
     $this->SetFillColor(224, 235, 255);
     $this->SetTextColor(0);
     $this->SetFont('');
     // Données
     $fill = false;
     foreach ($data as $row) {
         $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
         $this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
         $this->Cell($w[2], 6, number_format($row[2], 0, ',', ' '), 'LR', 0, 'R', $fill);
         $this->Cell($w[3], 6, number_format($row[3], 0, ',', ' '), 'LR', 0, 'R', $fill);
         $this->Ln();
         $fill = !$fill;
     }
     // Trait de terminaison
     $this->Cell(array_sum($w), 0, '', 'T');
 }
示例#7
0
 /**
  * Browse all absence types
  *
  *
  * @return void
  * @access public
  * @static
  */
 function browse()
 {
     // get all appraisal criteria sorted by value
     $appraisalCriteria = array();
     $dao = new CRM_Appraisals_DAO_AppraisalCriteria();
     $dao->orderBy('value');
     $dao->find();
     $count = $dao->count();
     $i = 1;
     while ($dao->fetch()) {
         $appraisalCriteria[$dao->id] = array();
         $appraisalCriteria[$dao->id]['id'] = $dao->id;
         $appraisalCriteria[$dao->id]['value'] = $dao->value;
         $appraisalCriteria[$dao->id]['label'] = $dao->label;
         $appraisalCriteria[$dao->id]['is_active'] = $dao->is_active;
         // form all action links
         $action = array_sum(array_keys($this->links()));
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $canBeDeleted = TRUE;
         if ($i !== $count) {
             $canBeDeleted = FALSE;
         }
         if (!$canBeDeleted) {
             $action -= CRM_Core_Action::DELETE;
         }
         $appraisalCriteria[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
         $i++;
     }
     $this->assign('rows', $appraisalCriteria);
 }
示例#8
0
/**
 * @param  array $words   抽出対象の配列($weightsと要素数は同数)
 * @param  array $weights 重みの配列(要素はint型)
 *
 * @return mixed $word    抽出された要素
 *
 * @throws Exception      Validationエラー時に投げられる例外
 */
function lotteryWeighted($words, $weights)
{
    //Validation.
    try {
        foreach ($weights as $weight) {
            if (!is_int($weight)) {
                throw new Exception("Weights only type int.");
            }
        }
        $targets = array_combine($words, $weights);
        if (!$targets) {
            throw new Exception("The number of elements does not match.");
        }
    } catch (Exception $e) {
        echo $e->getMessage();
        exit;
    }
    //抽出
    $sum = array_sum($targets);
    $judgeVal = rand(1, $sum);
    foreach ($targets as $word => $weight) {
        if (($sum -= $weight) < $judgeVal) {
            return $word;
        }
    }
}
示例#9
0
function esc($dbfname, $estructura, $contenido)
{
    $fdbf = fopen($dbfname, 'w');
    $long_estruc = count($estructura);
    $primer_registro = ($long_estruc + 1) * 32 + 1;
    $longitud_total = array_sum(array_map(function ($element) {
        return $element['longitud'];
    }, $estructura));
    $bin = pack("C4Vv2@32", 3, date("y"), date("m"), date("d"), count($contenido), $primer_registro, $longitud_total + 1);
    $ini = 1;
    foreach ($estructura as $est) {
        $bin .= pack("a11A1VC2@32", $est["nombre"], $est["tipo"], $ini, $est["longitud"], $est["decimales"]);
        $ini += $est["longitud"];
    }
    $bin .= pack("C", 13);
    foreach ($contenido as $cont) {
        $bin .= pack("C", 32);
        for ($i = 0; $i < $long_estruc; $i++) {
            echo $i . " <br />";
            $bin .= pack("A" . $estructura[$i]['longitud'], $cont[$i]);
        }
    }
    $bin .= pack("C", 26);
    //		echo "<br /><br />";
    print_r(unpack("C*", $bin));
    fwrite($fdbf, $bin);
    fclose($fdbf);
}
 /**
  * Get all data needed for this report and store in the class
  */
 private function query_report_data()
 {
     $this->report_data = new stdClass();
     $this->report_data->orders = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), '_order_shipping' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping'), '_order_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_tax'), '_order_shipping_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping_tax'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => array_merge(array('shop_order_refund'), wc_get_order_types('sales-reports')), 'order_status' => array('completed', 'processing', 'on-hold'), 'parent_order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->order_counts = (array) $this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'count', 'distinct' => true), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->coupons = (array) $this->get_order_report_data(array('data' => array('order_item_name' => array('type' => 'order_item', 'function' => '', 'name' => 'order_item_name'), 'discount_amount' => array('type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'coupon', 'operator' => '=')), 'group_by' => $this->group_by_query . ', order_item_name', 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->refunded_order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')));
     $this->report_data->partial_refunds = (array) $this->get_order_report_data(array('data' => array('_refund_amount' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date'), '_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => false, 'parent_order_status' => array('completed', 'processing', 'on-hold')));
     foreach ($this->report_data->partial_refunds as $key => $value) {
         $this->report_data->partial_refunds[$key]->order_item_count = $this->report_data->partial_refunds[$key]->order_item_count * -1;
     }
     $this->report_data->order_items = array_merge($this->report_data->order_items, $this->report_data->partial_refunds);
     $this->report_data->total_order_refunds = array_sum((array) absint($this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')))));
     $this->report_data->full_refunds = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => array('refunded')));
     $this->report_data->refunds = array_merge($this->report_data->partial_refunds, $this->report_data->full_refunds);
     $this->report_data->total_sales = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_sales')), 2);
     $this->report_data->total_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_tax')), 2);
     $this->report_data->total_shipping = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping')), 2);
     $this->report_data->total_shipping_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping_tax')), 2);
     $this->report_data->total_refunds = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->partial_refunds, 'total_refund')) + array_sum(wp_list_pluck($this->report_data->full_refunds, 'total_refund')), 2);
     $this->report_data->total_coupons = number_format(array_sum(wp_list_pluck($this->report_data->coupons, 'discount_amount')), 2);
     $this->report_data->total_orders = absint(array_sum(wp_list_pluck($this->report_data->order_counts, 'count')));
     $this->report_data->total_partial_refunds = array_sum(wp_list_pluck($this->report_data->partial_refunds, 'order_item_count')) * -1;
     $this->report_data->total_item_refunds = array_sum(wp_list_pluck($this->report_data->refunded_order_items, 'order_item_count')) * -1;
     $this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->order_items, 'order_item_count')) * -1);
     $this->report_data->average_sales = wc_format_decimal($this->report_data->total_sales / ($this->chart_interval + 1), 2);
     $this->report_data->net_sales = wc_format_decimal($this->report_data->total_sales - $this->report_data->total_shipping - $this->report_data->total_tax - $this->report_data->total_shipping_tax, 2);
 }
示例#11
0
 /**
  * Generate a new PID
  */
 function newPID()
 {
     // The PID is split into two parts.  $checksum is appended to $prefix
     // to make the full number.
     if ($this->find('count') > 0) {
         // Get the last PID, work out its prefix and increment by one
         $lastPid = $this->find('first', array('fields' => array('Patient.pid'), 'order' => array('Patient.pid DESC')));
         $lastPid = $lastPid['Patient']['pid'];
         $prefix = substr($lastPid, 0, strlen($lastPid) - 1) + 1;
     } else {
         // This is the prefix to the first PID we will ever assign
         $prefix = 1;
     }
     // Split the prefix into an array in a right-to-left fashion
     $prefixArray = array_reverse(str_split($prefix));
     // Starting with the first digit, double every other number
     for ($i = 0; $i < count($prefixArray); $i += 2) {
         $prefixArray[$i] = $prefixArray[$i] * 2;
     }
     // Add all of the digits up
     $digits = '';
     foreach ($prefixArray as $value) {
         $digits .= $value;
     }
     $sum = array_sum(str_split($digits));
     // When $checksum is added modulo ten, it should equal zero
     $checksum = (10 - $sum % 10) % 10;
     return $prefix . $checksum;
 }
示例#12
0
function super_croissance_check($tab = array())
{
    $current_tab = array();
    if (!count_tab($tab)) {
        echo "ceci est pas un tableau\n";
        return false;
    } else {
        // tableau de check
        $tab_check = array();
        $current_tab = count_tab($tab);
        for ($i = 0; $i < $current_tab; $i++) {
            $actual_count = $i;
            // si c'est diferrent de zero
            for ($j = 0; $j < $actual_count; $j++) {
                // on push les valeur dans un autre tableau
                array_push($tab_check, $tab[$j]);
            }
            // on place la somme du tableau dans une variable
            $result = array_sum($tab_check);
            // si le tableau n'est pas une supercroissante
            if ($tab[$actual_count] < $result) {
                echo "le tableau n'est pas une suite supercroissante\n";
                return false;
            }
            // on reset le tableau pour le prochain resultat
            $tab_check = array();
        }
        // on affiche un message si c'est bien une suite supercroissante
        return true;
    }
}
 function BuildTable($header, $data)
 {
     //Colors, line width and bold font
     $this->SetFillColor(255, 255, 255);
     $this->SetLineWidth(0.3);
     $this->SetFont('', 'B');
     //Header
     // make an array for the column widths
     $w = array(30, 30, 50, 50, 30, 60);
     // send the headers to the PDF document
     for ($i = 0; $i < count($header); $i++) {
         $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
     }
     $this->Ln();
     //Color and font restoration
     $this->SetFillColor(175);
     $this->SetTextColor(0);
     $this->SetFont('');
     //now spool out the data from the $data array
     $fill = true;
     // used to alternate row color backgrounds
     foreach ($data as $row) {
         $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
         $this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
         $this->Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill);
         $this->Cell($w[3], 6, $row[3], 'LR', 0, 'L', $fill);
         $this->Cell($w[4], 6, $row[4], 'LR', 0, 'L', $fill);
         $this->Cell($w[5], 6, number_format($row[5]), 'LR', 0, 'R', $fill);
         $this->Ln();
         $fill = !$fill;
     }
     $this->Cell(array_sum($w), 0, '', 'T');
 }
示例#14
0
 function FancyTable($header, $data)
 {
     // Colors, line width and bold font
     $this->SetFillColor(255, 0, 0);
     $this->SetTextColor(255);
     $this->SetDrawColor(128, 0, 0);
     $this->SetLineWidth(0.3);
     $this->SetFont('', '');
     // Header
     $w = array(40, 35, 40, 45);
     for ($i = 0; $i < count($header); $i++) {
         $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true);
     }
     $this->Ln();
     // Color and font restoration
     $this->SetFillColor(224, 235, 255);
     $this->SetTextColor(0);
     $this->SetFont('');
     // Data
     $fill = false;
     foreach ($data as $row) {
         $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
         // $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
         // $this->Cell($w[2],6,number_format(doubleval($row[2])),'LR',0,'R',$fill);
         // $this->Cell($w[3],6,number_format(doubleval($row[3])),'LR',0,'R',$fill);
         $this->Ln();
         $fill = !$fill;
     }
     // Closing line
     $this->Cell(array_sum($w), 0, '', 'T');
 }
示例#15
0
 public function getLoanSummary($loanid)
 {
     $ret = array();
     $qty = array();
     $this->db->select('DateReceived, Number1');
     $this->db->from('loan');
     $this->db->where('LoanID', $loanid);
     $query = $this->db->get();
     $row = $query->row();
     $ret[] = $row->DateReceived . ': ' . (int) $row->Number1 . ' specimens received';
     $qty[] = $row->Number1;
     $this->db->select('ShipmentDate, Number1');
     $this->db->from('shipment');
     $this->db->where('LoanID', $loanid);
     $this->db->order_by('ShipmentDate', 'asc');
     $query = $this->db->get();
     if ($query->num_rows()) {
         foreach ($query->result() as $row) {
             $ret[] = $row->ShipmentDate . ': ' . (int) $row->Number1 . ' specimens returned';
             $qty[] = $row->Number1;
         }
     }
     $qty_outstanding = array_shift($qty);
     if ($qty) {
         $qty_outstanding -= array_sum($qty);
     }
     $ret[] = date('Y-m-d') . ': ' . (int) $qty_outstanding . ' specimens outstanding';
     return $ret;
 }
示例#16
0
 public function save_daily($line_id = 0)
 {
     $daily = I('post.daily');
     if ($line_id && !empty($daily)) {
         $where['line_id'] = $line_id;
         M('line_daily')->where($where)->delete();
         foreach ($daily as $key => $value) {
             if ($key > 0) {
                 $data = array();
                 $spot = array();
                 $shop = array();
                 $diet = $value['diet'] ? $value['diet'] : array();
                 foreach ($value['spot']['name'] as $spot_key => $spot_value) {
                     $spot[$spot_key]['name'] = $value['spot']['name'][$spot_key];
                     $spot[$spot_key]['time'] = $value['spot']['time'][$spot_key];
                 }
                 foreach ($value['shop']['name'] as $shop_key => $shop_value) {
                     $shop[$shop_key]['name'] = $value['shop']['name'][$shop_key];
                     $shop[$shop_key]['time'] = $value['shop']['time'][$shop_key];
                 }
                 $data['line_id'] = $line_id;
                 $data['name'] = $value['name'];
                 $data['hotel'] = $value['hotel'];
                 $data['diet'] = array_sum($diet);
                 $data['spot'] = json_encode($spot);
                 $data['shop'] = json_encode($shop);
                 $data['sort'] = $key;
                 M('line_daily')->add($data);
             }
         }
     }
 }
 public function build($username, $repository)
 {
     $this->repository = new Repository($username, $repository);
     // repository data
     $data = $this->client->api('repo')->show($this->repository->username, $this->repository->repository);
     $this->repository->size = $data['size'];
     $this->repository->stargazersCount = $data['stargazers_count'];
     $this->repository->forks = $data['forks'];
     $this->repository->openIssues = $data['open_issues'];
     $this->repository->subscribersCount = $data['subscribers_count'];
     // repository commit activity
     do {
         $activity = $this->client->api('repo')->activity($this->repository->username, $this->repository->repository);
         $responseStatusCode = $this->client->getHttpClient()->getLastResponse()->getStatusCode();
         if ($responseStatusCode != 200) {
             sleep(3);
         } else {
             break;
         }
     } while (true);
     $commitsLastYear = array_map(function (array $weekCommits) {
         return $weekCommits['total'];
     }, $activity);
     $this->repository->commitsCount = array_sum($commitsLastYear);
     $this->repository->commitsLastMonthCount = array_sum(array_slice($commitsLastYear, -4));
     $this->repository->avgCommitsPerWeek = count($commitsLastYear) > 0 ? floor(array_sum($commitsLastYear) / count($commitsLastYear)) : 0;
     // repository contributors
     $paginator = new ResultPager($this->client);
     $contributors = $paginator->fetchAll($this->client->api('repo'), 'contributors', [$this->repository->username, $this->repository->repository, true]);
     $this->repository->contributorsCount = count($contributors);
     // user data
     $user = $this->client->api('user')->show($this->repository->username);
     $this->repository->userPublicRepos = $user['public_repos'];
     return $this;
 }
示例#18
0
 public function getAttributeValues()
 {
     $model = Mage::registry('entity_attribute');
     $customerCollection = Mage::getResourceModel('customer/customer_collection');
     $customerCollection->addAttributeToSelect($model->getAttributeCode());
     $customerCollection->addAttributeToFilter($model->getAttributeCode(), array('notnull' => true));
     $customerValue = $customerCollection->getColumnValues($model->getAttributeCode());
     $guestCollection = Mage::getModel('amcustomerattr/guest')->getCollection();
     $guestCollection->addFieldToFilter($model->getAttributeCode(), array('notnull' => true));
     $guestValue = $guestCollection->getColumnValues($model->getAttributeCode());
     $valuesAsString = array_merge($customerValue, $guestValue);
     $valuesAsArray = array();
     foreach ($valuesAsString as $attrIdsString) {
         $valuesAsArray = array_merge($valuesAsArray, explode(',', $attrIdsString));
     }
     $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($model->getAttributeId())->addFieldToFilter('main_table.option_id', array('in' => $valuesAsArray))->setStoreFilter();
     $qtyValues = array_count_values($valuesAsArray);
     $result = array();
     $options = $optionCollection->toOptionArray();
     $sum = array_sum($qtyValues);
     foreach ($options as $value) {
         $qty = $qtyValues[$value['value']];
         $label = $value['label'] . ' - ' . $qty . ' (' . round($qty / $sum * 100, 1) . '%)';
         $result[$value['value']] = array('qty' => $qty, 'label' => $label);
     }
     return $result;
 }
示例#19
0
 /**
  * see class description
  * 
  * @param array $A
  *        	Either a vector or a collection of tokens to be transformed to a vector
  * @param array $B
  *        	Either a vector or a collection of tokens to be transformed to a vector
  * @return float The euclidean distance between $A and $B
  */
 public function dist(&$A, &$B)
 {
     if (is_int(key($A))) {
         $v1 = array_count_values($A);
     } else {
         $v1 =& $A;
     }
     if (is_int(key($B))) {
         $v2 = array_count_values($B);
     } else {
         $v2 =& $B;
     }
     $r = array();
     foreach ($v1 as $k => $v) {
         $r[$k] = $v;
     }
     foreach ($v2 as $k => $v) {
         if (isset($r[$k])) {
             $r[$k] -= $v;
         } else {
             $r[$k] = $v;
         }
     }
     return sqrt(array_sum(array_map(function ($x) {
         return $x * $x;
     }, $r)));
 }
 protected function _render_border(Frame_Decorator $frame, $corner_style = "bevel")
 {
     $style = $frame->get_style();
     $bbox = $frame->get_border_box();
     $bp = $style->get_border_properties();
     // find the radius
     $radius = $style->get_computed_border_radius($bbox["w"], $bbox["h"]);
     // Short-cut: If all the borders are "solid" with the same color and style, and no radius, we'd better draw a rectangle
     if (in_array($bp["top"]["style"], array("solid", "dashed", "dotted")) && $bp["top"] == $bp["right"] && $bp["right"] == $bp["bottom"] && $bp["bottom"] == $bp["left"] && array_sum($radius) == 0) {
         $props = $bp["top"];
         if ($props["color"] === "transparent" || $props["width"] <= 0) {
             return;
         }
         list($x, $y, $w, $h) = $bbox;
         $width = $style->length_in_pt($props["width"]);
         $pattern = $this->_get_dash_pattern($props["style"], $width);
         $this->_canvas->rectangle($x + $width / 2, $y + $width / 2, $w - $width, $h - $width, $props["color"], $width, $pattern);
         return;
     }
     // Do it the long way
     $widths = array($style->length_in_pt($bp["top"]["width"]), $style->length_in_pt($bp["right"]["width"]), $style->length_in_pt($bp["bottom"]["width"]), $style->length_in_pt($bp["left"]["width"]));
     foreach ($bp as $side => $props) {
         list($x, $y, $w, $h) = $bbox;
         $length = 0;
         $r1 = 0;
         $r2 = 0;
         if (!$props["style"] || $props["style"] === "none" || $props["width"] <= 0 || $props["color"] == "transparent") {
             continue;
         }
         switch ($side) {
             case "top":
                 $length = $w;
                 $r1 = $radius["top-left"];
                 $r2 = $radius["top-right"];
                 break;
             case "bottom":
                 $length = $w;
                 $y += $h;
                 $r1 = $radius["bottom-left"];
                 $r2 = $radius["bottom-right"];
                 break;
             case "left":
                 $length = $h;
                 $r1 = $radius["top-left"];
                 $r2 = $radius["bottom-left"];
                 break;
             case "right":
                 $length = $h;
                 $x += $w;
                 $r1 = $radius["top-right"];
                 $r2 = $radius["bottom-right"];
                 break;
             default:
                 break;
         }
         $method = "_border_" . $props["style"];
         // draw rounded corners
         $this->{$method}($x, $y, $length, $props["color"], $widths, $side, $corner_style, $r1, $r2);
     }
 }
 /**
  * @When /^I hit "divide"$/
  */
 public function iHitDivide($argument1)
 {
     $this->calculator->pressDivide($argument1);
     $this->result = array_shift($this->numbers);
     $this->result /= array_sum($this->numbers);
     $this->numbers = array();
 }
示例#22
0
 public function end()
 {
     $jobCount = $this->runner->getJobCount();
     $results = $this->runner->getResults();
     $count = array_sum($results);
     fwrite($this->file, ($results[Runner::FAILED] ? 'FAILURES!' : 'OK') . " ({$jobCount} tests" . ($results[Runner::FAILED] ? ", {$results[Runner::FAILED]} failures" : '') . ($results[Runner::SKIPPED] ? ", {$results[Runner::SKIPPED]} skipped" : '') . ($jobCount !== $count ? ', ' . ($jobCount - $count) . ' not run' : '') . ')');
 }
示例#23
0
 public function ColoredTable($header, $data)
 {
     // Colors, line width and bold font
     $this->SetFillColor(255, 0, 0);
     $this->SetTextColor(255);
     $this->SetDrawColor(128, 0, 0);
     $this->SetLineWidth(0.3);
     $this->SetFont('', 'B');
     // Header
     $w = array(40, 35, 40, 45);
     $num_headers = count($header);
     for ($i = 0; $i < $num_headers; ++$i) {
         $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
     }
     $this->Ln();
     // Color and font restoration
     $this->SetFillColor(224, 235, 255);
     $this->SetTextColor(0);
     $this->SetFont('');
     // Data
     $fill = 0;
     foreach ($data as $row) {
         $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
         $this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
         $this->Cell($w[2], 6, number_format($row[2]), 'LR', 0, 'R', $fill);
         $this->Cell($w[3], 6, number_format($row[3]), 'LR', 0, 'R', $fill);
         $this->Ln();
         $fill = !$fill;
     }
     $this->Cell(array_sum($w), 0, '', 'T');
 }
示例#24
0
文件: Reporte.php 项目: Rabp9/sirall2
 function Table($header, $cols, $data, $w)
 {
     // Colores, ancho de línea y fuente en negrita
     $this->SetFillColor(124, 169, 206);
     $this->SetTextColor(255);
     $this->SetDrawColor(67, 128, 175);
     $this->SetLineWidth(0.3);
     $this->SetFont('helvetica', 'B', 8);
     // Cabecera
     for ($i = 0; $i < count($header); $i++) {
         $this->Cell($w[$i], 5, $header[$i], 1, 0, 'C', true);
     }
     $this->Ln();
     // Restauración de colores y fuentes
     $this->SetFillColor(124, 169, 206);
     $this->SetTextColor(0);
     $this->SetFont('helvetica', '', 6);
     // Datos
     $fill = false;
     if (is_array($data)) {
         foreach ($data as $oRow) {
             $row = $oRow->toArray();
             for ($i = 0; $i < count($cols); $i++) {
                 $this->Cell($w[$i], 4, $row[$cols[$i]], 1);
             }
             $this->Ln();
             $fill = !$fill;
         }
     }
     // Línea de cierre
     $this->Cell(array_sum($w), 0, '', 'T');
 }
示例#25
0
 private function getCheckDigit($input)
 {
     // this method performs the luhn algorithm
     // to obtain a check digit
     $input = (string) $input;
     // first split up the string
     $numbers = str_split($input);
     // calculate the positional value.
     // when there is an even number of digits the second group will be multiplied, so p starts on 0
     // when there is an odd number of digits the first group will be multiplied, so p starts on 1
     $p = count($numbers) % 2;
     // run through each number
     foreach ($numbers as $i => $num) {
         $num = (int) $num;
         // every positional number needs to be multiplied by 2
         if ($p % 2) {
             $num = $num * 2;
             // if the result was more than 9
             // add the individual digits
             $num = array_sum(str_split($num));
         }
         $numbers[$i] = $num;
         $p++;
     }
     // get the total value of all the digits
     $sum = array_sum($numbers);
     // get the remainder when dividing by 10
     $mod = $sum % 10;
     // subtract from 10
     $rem = 10 - $mod;
     // mod from 10 to catch if the result was 0
     $digit = $rem % 10;
     return $digit;
 }
示例#26
0
 /**
  * validate 1-2 type keys, based on Social Scurity B2 Norm
  * French & Belgian "Clef type 1-2 Norme B2 Securité Sociale".
  *
  * @param string $code
  * @param int    $key
  *
  * @return bool
  */
 public static function validate($code = '', $key = -1)
 {
     if (strlen($key) < 1) {
         return false;
     }
     if (!is_numeric($key)) {
         return false;
     }
     if (!is_string($code)) {
         return false;
     }
     if (strlen($code) < 2) {
         return false;
     }
     $numerals = str_split($code);
     $rank = array_reverse(array_keys($numerals));
     $orderedNumerals = array();
     foreach ($rank as $i => $rankValue) {
         $orderedNumerals[$rankValue + 1] = $numerals[$i];
     }
     $results = array();
     foreach ($orderedNumerals as $cle => $value) {
         $results[$value] = $cle % 2 == 0 ? $value * 1 : $value * 2;
     }
     $sum = 0;
     foreach ($results as $cle => $value) {
         $sum += array_sum(str_split($value));
     }
     $validKey = str_split($sum);
     $validKey = 10 - array_pop($validKey);
     return $key === $validKey;
 }
 protected function get_views()
 {
     global $wpdb, $post_mime_types, $avail_post_mime_types;
     $type_links = array();
     $_num_posts = (array) wp_count_attachments();
     $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
     $total_orphans = $wpdb->get_var("SELECT COUNT( * ) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1");
     $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
     foreach ($matches as $type => $reals) {
         foreach ($reals as $real) {
             $num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
         }
     }
     $selected = empty($_GET['attachment-filter']) ? ' selected="selected"' : '';
     $type_links['all'] = "<option value=''{$selected}>" . sprintf(_nx('All (%s)', 'All (%s)', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</option>';
     foreach ($post_mime_types as $mime_type => $label) {
         if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
             continue;
         }
         $selected = '';
         if (!empty($_GET['attachment-filter']) && strpos($_GET['attachment-filter'], 'post_mime_type:') === 0 && wp_match_mime_types($mime_type, str_replace('post_mime_type:', '', $_GET['attachment-filter']))) {
             $selected = ' selected="selected"';
         }
         if (!empty($num_posts[$mime_type])) {
             $type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr($mime_type) . '"' . $selected . '>' . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</option>';
         }
     }
     $type_links['detached'] = '<option value="detached"' . ($this->detached ? ' selected="selected"' : '') . '>' . sprintf(_nx('Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files'), number_format_i18n($total_orphans)) . '</option>';
     $type_links['uncategorized'] = '<option value="uncategorized"' . ($this->uncategorized ? ' selected="selected"' : '') . '>' . __('All Uncategorized', 'eml') . '</option>';
     if (!empty($_num_posts['trash'])) {
         $type_links['trash'] = '<option value="trash"' . (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ? ' selected="selected"' : '') . '>' . sprintf(_nx('Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files'), number_format_i18n($_num_posts['trash'])) . '</option>';
     }
     return $type_links;
 }
 /**
  * @return string
  */
 public function actionHotelRooming()
 {
     /**
      * @var $models Registration[]
      */
     $eventDates = Registration::$eventDates;
     $query = Registration::find()->notDeleted()->with(['hotel', 'country', 'roomType', 'departmentRel'])->andWhere(['status' => Registration::STATUS_CONFIRM])->orderBy('hotel_id');
     //->asArray()
     $models = $query->all();
     $data = [];
     foreach ($models as $model) {
         foreach ($eventDates as $key => $time) {
             $model[$key] = $time >= $model['check_in'] && $time < $model['check_out'];
         }
         $parts[$model->hotel_id][] = $model;
     }
     foreach ($parts as $k => $part) {
         $data = array_merge($data, $part);
         $counts = [];
         foreach ($eventDates as $key => $time) {
             $counts[$key] = array_sum(ArrayHelper::getColumn($part, $key));
         }
         $data[] = $counts;
         $data[] = [];
     }
     $dataProvider = new ArrayDataProvider(['allModels' => $data]);
     return $this->render('hotel-rooming', ['dataProvider' => $dataProvider]);
 }
示例#29
0
 public function getSum()
 {
     foreach ($this->chunkProduct as $chunKey => $sumProduct) {
         $this->sumProduct[] = array_sum($sumProduct);
     }
     return $this->sumProduct;
 }
示例#30
0
 public function _blend($opacity = 1, $fill = 1, $options = array())
 {
     $opacity = min(max($opacity, 0), 1);
     if ($opacity === 0) {
         return $this->base->getImage();
     }
     $destX = ($this->base->getWidth() - $this->top->getWidth()) / 2;
     $destY = ($this->base->getHeight() - $this->top->getHeight()) / 2;
     $w = $this->top->getWidth();
     $h = $this->top->getHeight();
     $baseImg = $this->base->getImage();
     $overlayImg = $this->top->getImage();
     for ($x = 0; $x < $w; ++$x) {
         for ($y = 0; $y < $h; ++$y) {
             // First get the colors for the base and top pixels.
             $baseColor = $this->normalisePixel($this->getColorAtPixel($baseImg, $x + $destX, $y + $destY, $this->base->getIsTrueColor()));
             $topColor = $this->normalisePixel($this->getColorAtPixel($overlayImg, $x, $y, $this->top->getIsTrueColor()));
             $destColor = $baseColor;
             if (array_sum($topColor) < array_sum($destColor)) {
                 $destColor = $topColor;
             }
             if ($opacity !== 1) {
                 $destColor = $this->opacityPixel($baseColor, $destColor, $opacity);
             }
             $destColor = $this->integerPixel($this->deNormalisePixel($destColor));
             // Now that we have a valid color index, set the pixel to that color.
             imagesetpixel($baseImg, $x + $destX, $y + $destY, $this->getColorIndex($baseImg, $destColor));
         }
     }
     return $baseImg;
 }