| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Copyright (c) 2003 Jason Remillard. All rights reserved.
|
|
|
3 |
#
|
|
|
4 |
# This program is free software; you can redistribute it and modify it under
|
|
|
5 |
# the terms of the GPL.
|
|
|
6 |
|
|
|
7 |
# Action object for displaying a metrics report.
|
|
|
8 |
|
|
|
9 |
package Codestriker::Action::MetricsReport;
|
|
|
10 |
|
|
|
11 |
use strict;
|
|
|
12 |
use Codestriker::Http::Template;
|
|
|
13 |
use Codestriker::Model::Topic;
|
|
|
14 |
use Codestriker::Model::MetricStats;
|
|
|
15 |
|
|
|
16 |
# If the input is valid, produce a metrics report.
|
|
|
17 |
|
|
|
18 |
sub process($$$) {
|
|
|
19 |
my ($type, $http_input, $http_response) = @_;
|
|
|
20 |
|
|
|
21 |
$http_response->generate_header(reload=>0, cache=>0);
|
|
|
22 |
|
|
|
23 |
my $query = $http_response->get_query();
|
|
|
24 |
|
|
|
25 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
26 |
|
|
|
27 |
my $vars = {};
|
|
|
28 |
|
|
|
29 |
my @users_metrics =
|
|
|
30 |
Codestriker::Model::MetricStats::get_basic_user_metrics();
|
|
|
31 |
|
|
|
32 |
# Anti-spam the email addresses.
|
|
|
33 |
foreach my $user (@users_metrics) {
|
|
|
34 |
$user->{name} = Codestriker->filter_email($user->{name});
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
$vars->{user_metrics} = \@users_metrics;
|
|
|
38 |
|
|
|
39 |
# Get the comment metrics.
|
|
|
40 |
my @comment_metrics =
|
|
|
41 |
Codestriker::Model::MetricStats::get_comment_metrics();
|
|
|
42 |
$vars->{comment_metrics} = \@comment_metrics;
|
|
|
43 |
$vars->{comment_metrics_month_names} =
|
|
|
44 |
$comment_metrics[0]->{results}->[0]->{monthnames};
|
|
|
45 |
|
|
|
46 |
# Get the topic metrics.
|
|
|
47 |
my @topic_metrics = Codestriker::Model::MetricStats::get_topic_metrics();
|
|
|
48 |
$vars->{topic_metrics} = \@topic_metrics;
|
|
|
49 |
$vars->{topic_metrics_month_names} = $topic_metrics[0]->{monthnames};
|
|
|
50 |
|
|
|
51 |
$vars->{download_url} = $url_builder->metric_report_download_raw_data();
|
|
|
52 |
|
|
|
53 |
my $template = Codestriker::Http::Template->new("metricsreport");
|
|
|
54 |
$template->process($vars);
|
|
|
55 |
|
|
|
56 |
$http_response->generate_footer();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
sub process_download($$$) {
|
|
|
60 |
my ($type, $http_input, $http_response) = @_;
|
|
|
61 |
|
|
|
62 |
my $query = $http_response->get_query();
|
|
|
63 |
print $query->header(-type=>'text/plain',
|
|
|
64 |
-charset=>"UTF-8",
|
|
|
65 |
-attachment=>"metrics.csv",
|
|
|
66 |
-filename=>"metrics.csv");
|
|
|
67 |
|
|
|
68 |
my $columns = Codestriker::Model::MetricStats::get_download_headers();
|
|
|
69 |
|
|
|
70 |
print join "\t", @{$columns->{base}},@{$columns->{comment}},
|
|
|
71 |
@{$columns->{topic}}, @{$columns->{user}};
|
|
|
72 |
print "\n";
|
|
|
73 |
|
|
|
74 |
my @topicids = Codestriker::Model::MetricStats::get_topic_ids();
|
|
|
75 |
|
|
|
76 |
foreach my $id (@topicids) {
|
|
|
77 |
my @line = Codestriker::Model::MetricStats::get_raw_metric_data($id->[0], $columns);
|
|
|
78 |
print join "\t", @line;
|
|
|
79 |
print "\n";
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
1;
|