echo elgg_view('output/longtext', array('value' => elgg_echo('plugins:admin:trends:help'))); echo elgg_view_form('plugins/admin/plugin_select', array('action' => current_page_url(), 'method' => 'get')); // default parameters for downloads plot $num_days = 30; $guid = (int) get_input('guid', 0); if ($guid != 0) { $num_days = 0; } if ($guid) { $project = get_entity($guid); echo "<h4>" . elgg_echo('plugins:admin:trends:single', array($plugin->title)) . "</h4>"; } else { echo "<h4>" . elgg_echo('plugins:admin:trends:all') . "</h4>"; } $histogram = get_downloads_histogram($guid, $num_days); // create string for flot $plot_string = ''; foreach ($histogram as $k => $v) { $plot_string .= "[{$k}, {$v}],"; } $plot_string = rtrim($plot_string, ','); ?> <div id="plugins_download_plot" data-plot="[<?php echo $plot_string; ?> ]"></div> <?php elgg_require_js('elgg/community_plugins/plugin_trends'); if ($guid) {
<?php /** * Finds daily download total outliers and replaces them with the median */ namespace Elgg\CommunityPlugins; $guid = get_input('guid'); if (!$guid) { register_error(elgg_echo('plugins:action:normalize:invalid_guid')); forward(REFERER); } $preview = get_input('preview', FALSE); $downloads = get_downloads_histogram($guid, 0); $mean = array_sum($downloads) / count($downloads); $std_dev = 0; foreach ($downloads as $count) { $std_dev += ($count - $mean) * ($count - $mean); } $std_dev /= count($downloads); $std_dev = sqrt($std_dev); // calculate cutoff - 95% assuming Gaussian distribution $cutoff = $mean + 2 * $std_dev; // calculate median sort($downloads); $median = $downloads[(int) round(0.5 * count($downloads))]; // delete annotations beyond the daily cutoff - there must be a better way to do this // This does not process the last day $options = array('guid' => $guid, 'type' => 'object', 'subtype' => 'plugin_project', 'annotation_name' => 'download', 'limit' => 0, 'order_by' => 'n_table.time_created asc'); $downloads = elgg_get_annotations($options); $start_date = $downloads[0]->time_created;