Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a0912af

Browse files
committedDec 1, 2009
Added command used to find epass bug
1 parent 7a75b3a commit a0912af

File tree

1 file changed

+279
-0
lines changed

1 file changed

+279
-0
lines changed
 

‎lib/WGDev/Command/Bug.pm

+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
package WGDev::Command::Bug;
2+
use strict;
3+
use warnings;
4+
use 5.008008;
5+
6+
our $VERSION = '0.1.0';
7+
8+
use WGDev::Command::Base;
9+
BEGIN { our @ISA = qw(WGDev::Command::Base) }
10+
11+
use lib '/projects/WebFlow/lib';
12+
use NETC;
13+
14+
sub process2 {
15+
my $self = shift;
16+
my $wgd = $self->wgd;
17+
my $session = $wgd->session;
18+
19+
for my $username qw(test1 test2) {
20+
if (my $u = WebGUI::User->newByUsername($session, $username)) {
21+
$u->delete;
22+
}
23+
}
24+
25+
my $user = WebGUI::User->new($session, 'new');
26+
$user->profileField('username', 'test1');
27+
my $userId = $user->userId;
28+
29+
my $user2 = WebGUI::User->new($session, 'new');
30+
$user2->profileField('username', 'test2');
31+
my $userId2 = $user2->userId;
32+
33+
# Remove existing responses
34+
$session->db->write( 'delete from Survey_response where userId = ? or userId = ?', [ $userId, $userId2 ] );
35+
36+
# Start a response
37+
{
38+
my $pre = WebGUI::Asset->new( $session, NETC::ASSET_PRE_ASSESSMENT );
39+
my $pre_responseId = $pre->responseId( { userId => $userId } );
40+
41+
my $pre_rJSON = $pre->responseJSON;
42+
$pre_rJSON->processGoto('S_DEM3');
43+
$pre_rJSON->recordResponses({
44+
'6-0-0' => '1981',
45+
});
46+
$pre_rJSON->recordResponses({
47+
'7-0-0' => 'Male',
48+
});
49+
$pre_rJSON->recordResponses({
50+
'8-0-0' => 'Married',
51+
'8-1-0' => 'Australia',
52+
'8-2-0' => 'Australia',
53+
});
54+
55+
print Data::Dumper::Dumper($pre_rJSON->responses);
56+
print Data::Dumper::Dumper($pre_rJSON->tags);
57+
58+
$pre->persistResponseJSON;
59+
$pre->surveyEnd();
60+
}
61+
62+
# Start another response as a different user
63+
{
64+
my $pre = WebGUI::Asset->new( $session, NETC::ASSET_PRE_ASSESSMENT );
65+
my $pre_responseId = $pre->responseId( { userId => $userId2 } );
66+
67+
my $pre_rJSON = $pre->responseJSON;
68+
$pre_rJSON->processGoto('S_DEM3');
69+
$pre_rJSON->recordResponses({
70+
'6-0-0' => '1982',
71+
});
72+
$pre_rJSON->recordResponses({
73+
'7-0-1' => 'Female',
74+
});
75+
$pre_rJSON->recordResponses({
76+
'8-0-0' => 'Married',
77+
'8-1-0' => 'Australia',
78+
'8-2-0' => 'Australia',
79+
});
80+
81+
print Data::Dumper::Dumper($pre_rJSON->responses);
82+
print Data::Dumper::Dumper($pre_rJSON->tags);
83+
84+
$pre->persistResponseJSON;
85+
$pre->surveyEnd();
86+
}
87+
88+
# Start an ePASS response as the second user
89+
{
90+
my $epass = WebGUI::Asset->new( $session, NETC::ASSET_EPASS );
91+
$session->user( { userId => $userId2 } );
92+
my $epass_responseId = $epass->responseId( { userId => $userId2 } );
93+
94+
my $epass_rJSON = $epass->responseJSON;
95+
96+
print Data::Dumper::Dumper($epass_rJSON->responses);
97+
print Data::Dumper::Dumper($epass_rJSON->tags);
98+
99+
$epass->persistResponseJSON;
100+
$epass->surveyEnd();
101+
}
102+
103+
# Start an ePASS response as the first user
104+
{
105+
my $epass = WebGUI::Asset->new( $session, NETC::ASSET_EPASS );
106+
$session->user( { userId => $userId } );
107+
my $epass_responseId = $epass->responseId( { userId => $userId } );
108+
109+
my $epass_rJSON = $epass->responseJSON;
110+
111+
print Data::Dumper::Dumper($epass_rJSON->responses);
112+
print Data::Dumper::Dumper($epass_rJSON->tags);
113+
114+
$epass->persistResponseJSON;
115+
$epass->surveyEnd();
116+
}
117+
118+
119+
$user->delete;
120+
$user2->delete;
121+
}
122+
123+
sub process {
124+
my $self = shift;
125+
my $wgd = $self->wgd;
126+
my $session = $wgd->session;
127+
128+
use Tie::IxHash;
129+
tie my %epass, 'Tie::IxHash';
130+
%epass
131+
= $session->db->buildHash( <<END_SQL, [ NETC::ASSET_EPASS, NETC::GROUP_CONSUMERS, NETC::GROUP_DEMO ] );
132+
select Survey_responseId, userId
133+
from Survey_response r
134+
where assetId = ?
135+
and userId in (select userId from groupings where groupId = ?)
136+
and userId not in (select userId from groupings where groupId = ?)
137+
order by startDate asc
138+
END_SQL
139+
my %username = $session->db->buildHash('select userId, username from users');
140+
141+
require WebGUI::Asset::Wobject::Survey;
142+
for my $epass_responseId ( keys %epass ) {
143+
my $epass = WebGUI::Asset::Wobject::Survey->newByResponseId( $session, $epass_responseId );
144+
my $epass_tags = $epass->responseJSON->tags;
145+
146+
# print Data::Dumper::Dumper($epass_tags);
147+
148+
my $userId = $epass{$epass_responseId} or next;
149+
my @pre_responseIds = $session->db->buildArray(
150+
'select Survey_responseId from Survey_response where userId = ? and assetId = ? and (isComplete = 1 or isComplete = -1) order by endDate desc',
151+
[ $userId, NETC::ASSET_PRE_ASSESSMENT ]
152+
);
153+
my $warn = '';
154+
if ( @pre_responseIds > 1 ) {
155+
$warn .= "Count: " . @pre_responseIds . "\n";
156+
}
157+
if ( !@pre_responseIds || !$pre_responseIds[0] ) {
158+
print "!No pre! [$username{$userId}]\n";
159+
next;
160+
}
161+
162+
my $pre_responseId = $pre_responseIds[0];
163+
my $pre = WebGUI::Asset::Wobject::Survey->newByResponseId( $session, $pre_responseId );
164+
my $pre_tags = $pre->responseJSON->tags;
165+
166+
if (!$pre_tags->{DOB}) {
167+
$warn .= "No DOB\n";
168+
}
169+
170+
# print Data::Dumper::Dumper($pre_tags);
171+
my $diff = '';
172+
for my $field qw(AUSTRALIAN_RESIDENT DOB MALE FEMALE) {
173+
no warnings;
174+
if ($pre_tags->{$field} && $pre_tags->{$field} ne $epass_tags->{$field}) {
175+
if ($epass_tags->{$field}) {
176+
$diff .= "Got $field = '$epass_tags->{$field}', Expected '$pre_tags->{$field}'\n";
177+
} else {
178+
$diff .= "Expected $field\n";
179+
}
180+
}
181+
if (!$pre_tags->{$field} && $epass_tags->{$field}) {
182+
$diff .= "Did Not Expect $field\n";
183+
}
184+
}
185+
if ( $diff ) {
186+
187+
my ( $preStartDate, $preEndDate )
188+
= $session->db->quickArray(
189+
'select startDate, endDate from Survey_response where Survey_responseId = ?',
190+
[$pre_responseId] );
191+
( $preStartDate, $preEndDate )
192+
= map { $_ && DateTime->from_epoch( epoch => $_ ) } ( $preStartDate, $preEndDate );
193+
# print "Pre:\n Start:\t $preStartDate\n End:\t $preEndDate\n";
194+
195+
my ( $epassStartDate, $epassEndDate )
196+
= $session->db->quickArray(
197+
'select startDate, endDate from Survey_response where Survey_responseId = ?',
198+
[$epass_responseId] );
199+
( $epassStartDate, $epassEndDate )
200+
= map { $_ && DateTime->from_epoch( epoch => $_ ) } ( $epassStartDate, $epassEndDate );
201+
# print "ePASS:\n Start:\t $epassStartDate\n End:\t $epassEndDate\n";
202+
203+
#print "[$username{$userId} $pre_responseId $epassStartDate]\n";
204+
print "$epass_responseId\n";
205+
206+
# my ($epassStartDate, $epassEndDate) = $session->db->quickArray('select startDate, endDate from Survey_response where Survey_responseId = ?', [$epass->getId]);
207+
# print "ePASS\tStart: " . DateTime->from_epoch( epoch => $epassStartDate );
208+
# print " End: " . DateTime->from_epoch( epoch => $epassEndDate ) . "\n";
209+
#print $warn if $warn;
210+
# my $diag = Test::Deep::deep_diag($stack);
211+
# $diag =~ s/^.*\n//;
212+
#print "$diff\n";
213+
}
214+
}
215+
return 1;
216+
}
217+
218+
1;
219+
220+
__END__
221+
222+
=head1 NAME
223+
224+
WGDev::Command::Bug - Manipulate Survey instances
225+
226+
=head1 SYNOPSIS
227+
228+
wgd survey [--check] [--fix] [--variables] [--dump] [--stats] [--branching] [--graph] [--setYesNo]
229+
230+
=head1 DESCRIPTION
231+
232+
Various utilities for Survey instances (dump structure, visualise, etc..).
233+
234+
=head1 OPTIONS
235+
236+
=over 8
237+
238+
=item C<--check> C<--fix>
239+
240+
Check for corruption, and optionally try to fix it.
241+
242+
=item C<--variables>
243+
244+
Set Section and Question variables from title text
245+
246+
=item C<--dump>
247+
248+
Dump Survey structure
249+
250+
=item C<--stats>
251+
252+
Show Survey stats
253+
254+
=item C<--branching>
255+
256+
Dumps brief outline of survey branching
257+
258+
=item C<--graph>
259+
260+
Generates a graph visualisation to survey.svg using GraphViz.
261+
262+
=item C<--setYesNo>
263+
264+
Updates YesNo type questions to more sensible defaults.
265+
266+
=back
267+
268+
=head1 AUTHOR
269+
270+
Patrick Donelan <pat@patspam.com>
271+
272+
=head1 LICENSE
273+
274+
Copyright (c) Patrick Donelan. All rights reserved.
275+
276+
This library is free software; you can redistribute it and/or modify it under
277+
the same terms as Perl itself.
278+
279+
=cut

0 commit comments

Comments
 (0)
Please sign in to comment.