⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metrics.pm

📁 codestriker is a develop useful tool to review code on web user interface.
💻 PM
📖 第 1 页 / 共 3 页
字号:
            # Get the outputs for this user.            my $select_user_metrics =              $dbh->prepare_cached('SELECT metric_name, value ' .                                   'FROM topicusermetric ' .                                   'WHERE topicid = ? AND LOWER(email) = LOWER(?) ' .                                   'ORDER BY metric_name');            $select_user_metrics->execute($self->{topicid}, $username);            my @user_stored_metrics =              @{$select_user_metrics->fetchall_arrayref()};            # Stuff the complete list with the values from the current            # user list.  Handle displaying metrics that are in the            # db, but not enabled for new topics.            foreach my $metric (@stored_metrics) {                my $foundit = 0;                foreach my $user_metric (@user_stored_metrics) {                    if ($user_metric->[0] eq $metric->[0]) {                        $foundit = 1;                        push @$metric, $user_metric->[1];                        last;                    }                }                if ($foundit == 0) {                    push @$metric,'';                }            }            # Close the connection, and check for any database errors.            Codestriker::DB::DBI->release_connection($dbh, 1);        }        foreach my $metric_schema (Codestriker::get_metric_schema()) {            if ($metric_schema->{scope} ne 'topic') {                my $metric =                  {                   name        => $metric_schema->{name},                   description => $metric_schema->{description},                   value       => '',                   enabled     => $metric_schema->{enabled},                   scope       => $metric_schema->{scope},                   filter      => $metric_schema->{filter},                  };                for (my $index = 0; $index < scalar(@stored_metrics);                     ++$index) {                    my $stored_metric = $stored_metrics[$index];                    if ($stored_metric->[0] eq $metric_schema->{name}) {                        $metric->{value} = $stored_metric->[1];                        $metric->{in_database} = 1;                        splice @stored_metrics, $index,1;                        last;                    }                }                if ($metric_schema->{enabled} || $metric->{in_database}) {                    if ($username eq "") {                        # don't let any metrics be set into the db for unknown users.                        $metric->{enabled} = 0;                    }                    push @user_metrics, $metric;                }            }        }        # Clean up any metrics that are in the database but not in the        # schema, we will not let them change them, and we don't have        # the description anymore.        for (my $index = 0; $index < scalar(@stored_metrics); ++$index) {            my $stored_metric = $stored_metrics[$index];            my $metric =              {                 # this is the topic metric               name=>$stored_metric->[0],               description=>'',               value=>$stored_metric->[1],               scope=>'participant',               enabled=>0, # user can not change the metric, no schema.               in_database=>1              };            push @user_metrics, $metric;        }        $self->{usermetrics}->{$username} = \@user_metrics;    }    push @user_metrics, $self->_get_built_in_user_metrics($username);    return @user_metrics;}# Returns the user metrics as a collection of references to hashs.sub get_user_metrics_totals {    my ($self,@users) = @_;    my @user_metrics;    if (exists($self->{usermetrics_totals})) {        @user_metrics = @$self->{usermetrics_totals};    }    my @total_metrics;    foreach my $user (@users) {        my @metrics = $self->get_user_metrics($user);        if (scalar(@total_metrics) == 0) {            # Copy the metrics in.            foreach my $metric (@metrics) {                my %temp = %$metric;                push @total_metrics, \%temp;            }        } else {            # Add them up!            for (my $index = 0; $index < scalar(@total_metrics) ; ++$index) {                if ($metrics[$index]->{value} ne '') {                    if ($total_metrics[$index]->{value} eq '') {                        $total_metrics[$index]->{value} = 0;                    }                    $total_metrics[$index]->{value} +=                      $metrics[$index]->{value};                }            }        }    }    $self->{usermetrics_totals}= \@total_metrics;    return @total_metrics;}# Returns a list of hashes. Each hash is an event. In the hash is stored who# caused the event, when it happened, and what happened. The hashes are defined# as:#   email -> the email address of the user who caused the event.#   date  -> when the event happened.#   description -> the event description.## The topic must be loaded from the db before this function can be called.sub get_topic_history {    my ($self) = @_;    my @topic_history = $self->_get_topic_history_rows();    my @event_list;    my $last_history_row;    foreach my $current_history_row (@topic_history) {        if ( !defined($last_history_row) ) {            # The first event is always the topic creation, so lets make            # that now.            my $filteredemail =              Codestriker->filter_email($current_history_row->{author});            my $formatted_time =              Codestriker->format_short_timestamp($current_history_row->{modified_ts});            push @event_list,              {               email=>$filteredemail,               date =>$formatted_time,               description=>'The topic is created.'              };        } else {            my %event =              (               email=> Codestriker->filter_email(                                                 $current_history_row->{modified_by}),               date => Codestriker->format_short_timestamp(                                                           $current_history_row->{modified_ts}),               description=>''              );            # Look for changes in all of the fields. Several fields could have            # changed at once.            if ($current_history_row->{author} ne $last_history_row->{author}) {                my %new_event = %event;                $new_event{description} =                  "Author changed: $last_history_row->{author} to " .                    "$current_history_row->{author}.";                push @event_list, \%new_event;            }            if ($current_history_row->{title} ne $last_history_row->{title}) {                my %new_event = %event;                $new_event{description} =                  "Title changed to: \"$current_history_row->{title}\".";                push @event_list, \%new_event;            }            if ($current_history_row->{description} ne $last_history_row->{description}) {                my %new_event = %event;                $new_event{description} = "Description changed to: " .                  "$current_history_row->{description}.";                push @event_list, \%new_event;            }            if ($current_history_row->{state} ne $last_history_row->{state}) {                my %new_event = %event;                $new_event{description} =                  "Topic state changed to: " .                    $Codestriker::topic_states[$current_history_row->{state}];                push @event_list, \%new_event;            }            if ($current_history_row->{repository} ne $last_history_row->{repository}) {                my %new_event = %event;                $new_event{description} =                  "Repository changed to: $current_history_row->{repository}.";                push @event_list, \%new_event;            }            if ($current_history_row->{project} ne $last_history_row->{project}) {                my %new_event = %event;                $new_event{description} =                  "Project changed to: $current_history_row->{project}.";                push @event_list, \%new_event;            }            if ($current_history_row->{reviewers} ne $last_history_row->{reviewers}) {                my %new_event = %event;                # Figure out who was removed, and who was added to the list.                my @reviewers = split /,/,$current_history_row->{reviewers};                my @l_reviewers = split /,/,$last_history_row->{reviewers};                my @new;                my @removed;                Codestriker::set_differences(\@reviewers, \@l_reviewers, \@new, \@removed);                if (@new == 0) {                    $new_event{description} =                      "Reviewers removed: " . join(',',@removed);;                } elsif (@removed == 0) {                    $new_event{description} =                      "Reviewers added: " . join(',',@new);                } else {                    $new_event{description} =                      "Reviewers added: " . join(',',@new) .                        " and reviewers removed: " . join(',',@removed);                }                push @event_list, \%new_event;            }            if ($current_history_row->{cc} ne $last_history_row->{cc}) {                my %new_event = %event;                $new_event{description} =                  "CC changed to $current_history_row->{cc}.";                push @event_list, \%new_event;            }        }        $last_history_row = $current_history_row    }    return @event_list;}# Returns the topic metrics as a collection of references to# hashes. The hash that is returned has the same keys as the# metrics_schema hash, plus a value key. This private function# returns "built in" metrics derived from the topic history# table.sub _get_built_in_topic_metrics {    my $self = shift;    my @topic_metrics;    my @topic_history = $self->_get_topic_history_rows();    my %state_times;    my $last_history_row;    # Figure out how long the topic has spent in each state.    for ( my $topic_history_index = 0;          $topic_history_index <= scalar(@topic_history);          ++$topic_history_index) {        my $current_history_row;        if ($topic_history_index < scalar(@topic_history)) {            $current_history_row = $topic_history[$topic_history_index];        }        if (defined($last_history_row)) {            my $start =              Codestriker->convert_date_timestamp_time(                                                       $last_history_row->{modified_ts});            my $end   = 0;            if (defined($current_history_row)) {                $end = Codestriker->convert_date_timestamp_time(                                                                $current_history_row->{modified_ts});            } else {                $end = time();            }            if (exists($state_times{$last_history_row->{state}})) {                $state_times{$last_history_row->{state}} += $end - $start;            } else {                $state_times{$last_history_row->{state}} = $end - $start;            }        }        $last_history_row = $current_history_row    }    foreach my $state ( sort keys %state_times) {        my $statename = $Codestriker::topic_states[$state];        my $time_days = sprintf("%1.1f",$state_times{$state} / (60*60*24));        # This is the topic metric.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -