Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function _pp_comparing_users_data($users, $types, $dates) {
$db_data = $query->execute()->fetchAllAssoc('timestamp');

$beginning = (!empty($dates['from'])) ? $dates['from'] : REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING;
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_WEEK_GRANULARITY);

$till_time = !empty($dates['till']) ? $dates['till'] : REQUEST_TIME;
while ($timestamp < $till_time) {
Expand All @@ -134,7 +134,7 @@ function _pp_comparing_users_data($users, $types, $dates) {
$table_data[$timestamp]['timestamp'] = format_date($timestamp, 'custom', 'j M y');
$table_data[$timestamp][$doid] = $commits;

$timestamp += PPGETSTAT_TIME_PERIOD_GRANULARITY;
$timestamp += PPGETSTAT_TIME_WEEK_GRANULARITY;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function pp_frontpage_community_quality_content_type_render($subtype, $conf, $pa
//@TODO add user list filtering for future.
$all_user_count = db_select('node', 'n')
->fields('n', array('nid'))
->condition('n.type', 'user')
->condition('type', PPGETSTAT_USER_NODE_TYPE)
->countQuery()
->execute()
->fetchField();
Expand All @@ -37,13 +37,15 @@ function pp_frontpage_community_quality_content_type_render($subtype, $conf, $pa
->execute()
->fetchField();

$block->content = '<div class="bs-callout bs-callout-primary">
<ul>
<li>'.t('Total count').' : <strong>' . $all_user_count . '</strong></li>
<li>'.t('Active committers').' : <strong>' . $active_by_commits_count . ' (' . number_format($active_by_commits_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Active commenters').' : <strong>' . $active_by_comments_count . ' (' . number_format($active_by_comments_count/$all_user_count, 2)*100 . ')%</strong></li>
</ul>
</div>';
if ($all_user_count > 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevented division by zero (when no users in DB).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx.

$block->content = '<div class="bs-callout bs-callout-primary">
<ul>
<li>'.t('Total count').' : <strong>' . $all_user_count . '</strong></li>
<li>'.t('Active committers').' : <strong>' . $active_by_commits_count . ' (' . number_format($active_by_commits_count/$all_user_count, 2)*100 . ')%</strong></li>
<li>'.t('Active commenters').' : <strong>' . $active_by_comments_count . ' (' . number_format($active_by_comments_count/$all_user_count, 2)*100 . ')%</strong></li>
</ul>
</div>';
}

return $block;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* @file
* HTML parser.
*/

/**
* Class PPGetStatHTML.
*/
class PPGetStatHTML {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to parse HTML using XPath. Works faster then regexps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Thx.


/**
* @var bool
*/
private $libxmlState;
/**
* @var DOMDocument
*/
private $document;
/**
* @var DOMXPath
*/
private $xpath;

/**
* PPGetStatHTML constructor.
*
* @param string $content
* HTML content.
*/
public function __construct($content) {
$this->document = new DOMDocument();
// Handle errors/warnings and don't mess up output of your script.
// @see http://stackoverflow.com/a/17559716
$this->libxmlState = libxml_use_internal_errors(true);
$this->document->loadHTML($content);
}

/**
* Clear XML library errors.
*/
public function __destruct() {
libxml_clear_errors();
libxml_use_internal_errors($this->libxmlState);
}

/**
* Make XPath query to the document object.
*
* @return DOMXPath
* XPath object to perform queries.
*/
public function xpath() {
if (NULL === $this->xpath) {
$this->xpath = new DOMXPath($this->document);
}

return $this->xpath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function _ppcc_parse_core_commits($page_content, $data) {
continue;
}

$period_timestamp = $commit_timestamp - ($commit_timestamp % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$period_timestamp = $commit_timestamp - ($commit_timestamp % PPGETSTAT_TIME_WEEK_GRANULARITY);
$last_commits = variable_get('ppgetstat_ppcc_last_commit_timestamp', array($data['doid'] => array($period_timestamp => 0)));

// Save latest commit's date per week into variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _ppcc_commits_data($node) {
)->fetchAllKeyed();

$beginning = REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING;
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_WEEK_GRANULARITY);

$table_data = array();
while ($timestamp < REQUEST_TIME) {
Expand All @@ -79,7 +79,7 @@ function _ppcc_commits_data($node) {
$commits,
);

$timestamp += PPGETSTAT_TIME_PERIOD_GRANULARITY;
$timestamp += PPGETSTAT_TIME_WEEK_GRANULARITY;
}

return $table_data;
Expand Down
30 changes: 14 additions & 16 deletions docroot/sites/all/modules/custom/ppgetstat/ppcmnt/ppcmnt.module
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ function ppcmnt_ppgetstat_stats_job($user_node) {
* Build urls for scanning core commits.
*/
function _ppcmnt_get_comments_tracking_urls($data) {
$last_scan = $data['last_scan'];
$cmt_zero_page = _ppgetstat_fetch_page('https://www.drupal.org/api-d7/comment.json?author=' . urlencode($data['doid']));
$user_data = json_decode($cmt_zero_page);
$count = parse_url($user_data->last);
$urls = array();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent changing the type of return value.


parse_str($count['query'], $query);

if (empty($user_data->list)) {
return NULL;
return $urls;
}
if ($query['page'] == 0) {
return array($user_data->self);
}
// In worst scenario we expect one page of posts per four hours.
// See webchick as example https://www.drupal.org/user/24967/track
$days_number = round((REQUEST_TIME - $last_scan) / (4 * 60 * 60));
$urls = array();
// $days_number = round((REQUEST_TIME - $last_scan) / (4 * 60 * 60));
for ($i = 0; $i <= (int)$query['page']; $i++) {
$urls[] = "https://www.drupal.org/api-d7/comment.json?name=" . urlencode($data['doid']) . "&page=" . $i;
}
Expand Down Expand Up @@ -143,27 +144,24 @@ function _ppcmnt_parse_posts_list($page_content, $data) {
* Parse post page for comments.
*/
function _ppcmnt_parse_post_page($page_content, $data) {

$user_data = json_decode($page_content);
$count = count($user_data->list);
$end = REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING;

$comments_counter_array = [];
$list = &$user_data->list;
$result = [];

$end = REQUEST_TIME - variable_get('ppgetstat_stats_period');
for ($i = ($count - 1); $i >= 0; $i--) {
if ($list[$i]->created < $end) {
foreach ($user_data->list as $i => $item) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplification. for replaced by foreach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Desc loop is done for scanning last users first. Is this construction do the same?

if ($item->created < $end) {
continue;
}
$period_timestamp = $list[$i]->created - ($list[$i]->created % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$comments_counter_array[$period_timestamp][] = $list[$i]->cid;

$result[$item->created - ($item->created % PPGETSTAT_TIME_WEEK_GRANULARITY)][] = $item->cid;
}

if (count($comments_counter_array) != 0) {
$comments_counter_array['#type'] = PPGETSTAT_TYPE_COMMENTS;
if (count($result) > 0) {
$result['#type'] = PPGETSTAT_TYPE_COMMENTS;
}

return $comments_counter_array;
return $result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _pppcmnt_load_the_data($node) {
)->fetchAllKeyed();

$beginning = REQUEST_TIME - PPGETSTAT_DEFAULT_TIME_PERIOD_FOR_SCANNING;
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_PERIOD_GRANULARITY);
$timestamp = $beginning - ($beginning % PPGETSTAT_TIME_WEEK_GRANULARITY);

$table_data = array();
while ($timestamp < REQUEST_TIME) {
Expand All @@ -78,7 +78,7 @@ function _pppcmnt_load_the_data($node) {
$commits,
);

$timestamp += PPGETSTAT_TIME_PERIOD_GRANULARITY;
$timestamp += PPGETSTAT_TIME_WEEK_GRANULARITY;
}

return $table_data;
Expand Down
2 changes: 2 additions & 0 deletions docroot/sites/all/modules/custom/ppgetstat/ppgetstat.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ name = ppgetstat
description = Get drupal.org statistic
core = 7.x
version = 1.0

files[] = includes/ppgetstat.html.inc
Loading