Merge in HEAD, up to 9866.

This commit is contained in:
Colin Kuskie 2009-03-17 23:45:21 +00:00
parent c7a66861a6
commit 2bd7a60a01
107 changed files with 6258 additions and 2436 deletions

View file

@ -0,0 +1,153 @@
package WebGUI::Workflow::Activity::BucketPassiveAnalytics;
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::PassiveAnalytics::Rule;
use WebGUI::Inbox;
=head1 NAME
Package WebGUI::Workflow::Activity::BucketPassiveAnalytics
=head1 DESCRIPTION
Run through a set of rules to figure out how to classify log file entries.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "PassiveAnalytics");
push( @{$definition}, {
name=>$i18n->get("Bucket Passive Analytics"),
properties=> {
notifyUser => {
fieldType => 'user',
label => $i18n->get('User'),
hoverHelp => $i18n->get('User help'),
defaultValue => $session->user->userId,
},
},
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
Analyze the deltaLog table, and generate the bucketLog table.
=head3 notes
=cut
sub execute {
my ($self, undef, $instance) = @_;
my $session = $self->session;
my $endTime = time() + $self->getTTL;
my $expired = 0;
##Load all the rules into an array
my @rules = ();
my $getARule = WebGUI::PassiveAnalytics::Rule->getAllIterator($session);
while (my $rule = $getARule->()) {
my $regexp = $rule->get('regexp');
push @rules, [ $rule->get('bucketName'), qr/$regexp/];
}
##Get the index stored from the last invocation of the Activity. If this is
##the first run, then clear out the table.
my $logIndex = $instance->getScratch('lastPassiveLogIndex') || 0;
if ($logIndex == 0) {
$session->db->write('delete from bucketLog');
}
my %bucketCache = ();
##Configure all the SQL
my $deltaSql = <<"EOSQL1";
select userId, assetId, url, delta, from_unixtime(timeStamp) as stamp
from deltaLog order by timestamp limit $logIndex, 1234567890
EOSQL1
my $deltaSth = $session->db->read($deltaSql);
my $bucketSth = $session->db->prepare('insert into bucketLog (userId, Bucket, duration, timeStamp) VALUES (?,?,?,?)');
##Walk through the log file entries, one by one. Run each entry against
##all the rules until 1 matches. If it doesn't match any rule, then bin it
##into the "Other" bucket.
DELTA_ENTRY: while (my $entry = $deltaSth->hashRef()) {
++$logIndex;
my $bucketFound = 0;
my $url = $entry->{url};
if (exists $bucketCache{$url}) {
$bucketSth->execute([$entry->{userId}, $bucketCache{$url}, $entry->{delta}, $entry->{stamp}]);
}
else {
RULE: foreach my $rule (@rules) {
next RULE unless $url =~ $rule->[1];
# Into the bucket she goes..
$bucketCache{$url} = $rule->[0];
$bucketSth->execute([$entry->{userId}, $rule->[0], $entry->{delta}, $entry->{stamp}]);
$bucketFound = 1;
last RULE;
}
if (!$bucketFound) {
$bucketCache{$url} = 'Other';
$bucketSth->execute([$entry->{userId}, 'Other', $entry->{delta}, $entry->{stamp}]);
}
}
if (time() > $endTime) {
$expired = 1;
last DELTA_ENTRY;
}
}
if ($expired) {
$instance->setScratch('logIndex', $logIndex);
return $self->WAITING(1);
}
my $message = 'Passive analytics is done.';
if ($session->setting->get('passiveAnalyticsDeleteDelta')) {
$session->log->info('Clearing Passive Analytics delta log');
$session->db->write('delete from deltaLog');
$message .= ' The delta log has been cleaned up.';
}
##If userId was set to 0, do not send any emails.
if ($self->get('userId')) {
my $inbox = WebGUI::Inbox->new($self->session);
$inbox->addMessage({
status => 'unread',
subject => 'Passive analytics is done',
userId => $self->get('userId'),
message => $message,
});
}
$session->db->write('update passiveAnalyticsStatus set endDate=NOW(), running=0');
return $self->COMPLETE;
}
1;
#vim:ft=perl

View file

@ -0,0 +1,152 @@
package WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2008 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::DateTime;
use DateTime::Duration;
=head1 NAME
Package WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses
=head1 DESCRIPTION
This activity deletes the survey responses for which the allowed time has expired and emails the survey user.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_ExpireIncompleteSurveyResponses");
push(@{$definition}, {
name => $i18n->get("name"),
properties => {
deleteExpired=>{
fieldType=>"yesNo",
defaultValue=>0,
label=>$i18n->get("Delete expired survey responses"),
hoverHelp=>$i18n->get("delete expired")
},
emailUsers=>{
fieldType=>"yesNo",
defaultValue=>0,
label=>$i18n->get("Email users that responses were deleted"),
hoverHelp=>$i18n->get("email users")
},
emailTemplateId => {
fieldType => "template",
defaultValue => 'ExpireIncResptmpl00001',
namespace => "ExpireIncompleteSurveyResponses",
label => $i18n->get('Email template sent to user'),
hoverHelp => $i18n->get('email template'),
},
from => {
fieldType=>"text",
label=>$i18n->get("from"),
defaultValue=>$session->setting->get("companyEmail"),
hoverHelp=>$i18n->get("from mouse over"),
},
subject => {
fieldType=>"text",
label=>$i18n->get("subject"),
defaultValue=>"Expired Survey",
hoverHelp=>$i18n->get("subject mouse over"),
},
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
Finds all the expired Survey Responses on the system. If delete is selected, they are removed. Then if
email is selected, the users are emailed the template.
=cut
sub execute {
my $self = shift;
my $session = $self->session;
my $sql = "select r.Survey_responseId, r.username, r.userId, upd.email,upd.firstName,upd.lastName, r.startDate, s.timeLimit, ad.title, ad.url
from Survey s, Survey_response r, assetData ad, userProfileData upd
where r.isComplete = 0 and s.timeLimit > 0 and (unix_timestamp() - r.startDate) > (s.timeLimit * 60)
and r.assetId = s.assetId and s.revisionDate = (select max(revisionDate) from Survey where assetId = s.assetId)
and ad.assetId = s.assetId and ad.revisionDate = s.revisionDate and upd.userId = r.userId";
my $refs = $self->session->db->buildArrayRefOfHashRefs($sql);
for my $ref (@{$refs}) {
if($self->get("deleteExpired") == 1){
$self->session->db->write("delete from Survey_response where Survey_responseId = ?",[$ref->{Survey_responseId}]);
}else{#else sent to expired but not deleted
$self->session->db->write("update Survey_response set isComplete = 99 where Survey_responseId = ?",[$ref->{Survey_responseId}]);
}
if($self->get("emailUsers") == 1 && $ref->{email} =~ /\@/){
my $var = {
to => $ref->{email},
from => $self->get("from"),
firstName => $ref->{firstName},
lastName => $ref->{lastName},
surveyTitle => $ref->{title},
surveyUrl => $ref->{url},
responseId => $ref->{Survey_responseId},
deleted => $self->get("deleteExpired"),
companyName => $self->session->setting->get("companyName"),
};
my $template = WebGUI::Asset->newByDynamicClass($self->session,$self->get('emailTemplateId'));
my $message = $template->processTemplate($var, $self->get("emailTemplateId"));
WebGUI::Macro::process($self->session,\$message);
my $mail = WebGUI::Mail::Send->create($self->session,{
to => $ref->{email},
subject => $self->get("subject"),
from => $self->get('from'),
});
$mail->addHtml($message);
$mail->addFooter;
$mail->queue;
}
}
return $self->COMPLETE;
}
1;

View file

@ -342,8 +342,10 @@ sub setMessageCompleted {
# Set all messages to completed
for my $messageId ( split /,/, $instance->getScratch("messageId") ) {
my $message = $inbox->getMessage( $messageId );
$message->setCompleted;
if($messageId){
my $message = $inbox->getMessage( $messageId );
$message->setCompleted if $message;
}
}
$instance->deleteScratch( "messageId" );

View file

@ -0,0 +1,148 @@
package WebGUI::Workflow::Activity::SummarizePassiveAnalytics;
use strict;
use base 'WebGUI::Workflow::Activity';
=head1 NAME
Package WebGUI::Workflow::Activity::SummarizePassiveAnalytics
=head1 DESCRIPTION
Summarize how long a user stayed on a page, using a user supplied interval.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, 'PassiveAnalytics');
push(@{$definition}, {
name=>$i18n->get('Summarize Passive Analytics'),
properties=> {
deltaInterval => {
fieldType => 'interval',
label => $i18n->get('pause interval'),
defaultValue => 15,
hoverHelp => $i18n->get('pause interval help'),
},
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
Analyze the passiveLog table, and generate the deltaLog table.
=head3 notes
If there is only 1 line in the table for a particular sessionId or
userId, no conclusions as to how long the user viewed a page can be
drawn from that. Similarly, the last entry in their browsing log
yields no data, since we require another entry in the passiveLog to
determine a delta.
=cut
sub execute {
my ($self, undef, $instance) = @_;
my $session = $self->session;
my $endTime = time() + $self->getTTL;
my $deltaInterval = $self->get('deltaInterval');
my $passive = q{select * from passiveLog where userId <> '1' order by userId, sessionId, timeStamp};
my $sth;
my $lastUserId;
my $lastSessionId;
my $lastTimeStamp;
my $lastAssetId;
my $lastUrl;
my $counter = $instance->getScratch('counter');
if ($counter) {
$passive .= ' limit '. $counter .', 1234567890';
$sth = $session->db->read($passive);
$lastUserId = $instance->getScratch('lastUserId');
$lastSessionId = $instance->getScratch('lastSessionId');
$lastTimeStamp = $instance->getScratch('lastTimeStamp');
$lastAssetId = $instance->getScratch('lastAssetId');
$lastUrl = $instance->getScratch('lastUrl');
}
else {
$sth = $session->db->read($passive);
my $logLine = $sth->hashRef();
$lastUserId = $logLine->{userId};
$lastSessionId = $logLine->{sessionId};
$lastTimeStamp = $logLine->{timeStamp};
$lastAssetId = $logLine->{assetId};
$lastUrl = $logLine->{url};
}
$session->db->write('delete from deltaLog'); ##Only if we're starting out
my $deltaLog = $session->db->prepare('insert into deltaLog (userId, assetId, delta, timeStamp, url) VALUES (?,?,?,?,?)');
my $expired = 0;
LOG_ENTRY: while (my $logLine = $sth->hashRef()) {
$counter++;
my $delta = $logLine->{timeStamp} - $lastTimeStamp;
if ( $logLine->{userId} eq $lastUserId
&& $logLine->{sessionId} eq $lastSessionId
&& $delta < $deltaInterval ) {
$deltaLog->execute([$lastUserId, $lastAssetId, $delta, $lastTimeStamp, $lastUrl]);
}
$lastUserId = $logLine->{userId};
$lastSessionId = $logLine->{sessionId};
$lastTimeStamp = $logLine->{timeStamp};
$lastAssetId = $logLine->{assetId};
$lastUrl = $logLine->{url};
if (time() > $endTime) {
$instance->setScratch('lastUserId', $lastUserId);
$instance->setScratch('lastSessionId', $lastSessionId);
$instance->setScratch('lastTimeStamp', $lastTimeStamp);
$instance->setScratch('lastAssetId', $lastAssetId);
$instance->setScratch('lastUrl', $lastUrl);
$instance->setScratch('counter', $counter);
$expired = 1;
last LOG_ENTRY;
}
}
if ($expired) {
return $self->WAITING(1);
}
$instance->deleteScratch('lastUserId');
$instance->deleteScratch('lastSessionId');
$instance->deleteScratch('lastTimeStamp');
$instance->deleteScratch('lastAssetId');
$instance->deleteScratch('lastUrl');
$instance->deleteScratch('counter');
return $self->COMPLETE;
}
1;
#vim:ft=perl