-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_summaries.pl
executable file
·184 lines (151 loc) · 6.09 KB
/
show_summaries.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#! /usr/bin/perl -w
use CGI qw(param);
use strict;
use Cwd;
my $username = param("username");
my $threadid = param("threadid");
my $versus = param("versus");
my $compare = param("compare");
my $comments = param("comments");
my $time = localtime();
print "Content-type: text/html\n\n";
my $show_next_topic = 1; #boolean
my $data = "/var/www1/lst/live/writable/discosumo/postselection/annotations/comparisons.txt";
#my $data = "/www/lst/live/writable/discosumo/postselection/annotations/comparisons.txt";
my %usernames = (
"A" => "F.",
"B" => "Judith",
"C" => "Niree Bakker",
"D" => "Lian Bouten",
);
sub print_header {
open(HD,"</var/www1/lst/live/htdocs/discosumo/postselection/header.html") or print "error opening header.html: $!\n";
while(my $line=<HD>) {
if ($line =~ /<title/) {
$line = "<title>Oeps, er is iets misgegaan</title>\n";
}
print $line;
}
print
close(HD);
}
sub print_footer {
open(FT,"</var/www1/lst/live/htdocs/discosumo/postselection/footer.html") or print "error opening footer.html: $!\n";
while(<FT>) {
print;
}
close(FT);
}
if (not defined $threadid) {
# coming from login screen
if ($username !~ /[a-zA-Z]/) {
$show_next_topic = 0;
&print_header;
print "<table width=\"80\%\" align=\"center\"><tr><td><h2>Oeps, er is iets fout gegaan</h2>
<p>Je hebt geen naam geselecteerd ($username). Wil je dat alsnog doen?
Klik <a href=\"#\" onclick=\"history.go(-1);return false;\">hier</a>
om terug te gaan.</p></td></tr></table><br><br>\n";
&print_footer;
}
} else {
# coming from previous topic
if ($compare !~ /[0A-Z]/) {
$show_next_topic = 0;
&print_header;
print "<table width=\"80\%\" align=\"center\"><tr><td><h2>Oeps, er is iets fout gegaan</h2>
<p>Je hebt geen keuze gemaakt voor 1 van de twee samenvattingen (of 'Ik weet het niet' gekozen.<br>
Klik <a href=\"#\" onclick=\"history.go(-1);\">hier</a> om terug te gaan naar het topic.</p></td></tr></table><br><br>\n";
&print_footer;
} elsif ($compare eq "NA" && length($comments) < 4) {
$show_next_topic = 0;
&print_header;
print "<table width=\"80\%\" align=\"center\"><tr><td><h2>Oeps, er is iets fout gegaan</h2>
<p>Je hebt 'Ik weet het niet' gekozen maar het opmerkingen-veld leeggelaten.
Wil je in het opmerkingen-veld invullen waarom je geen keuze kon maken?<br>
Klik <a href=\"#\" onclick=\"history.go(-1);\">hier</a> om terug te gaan naar het topic.</p></td></tr></table><br><br>\n";
&print_footer;
}
}
if ($show_next_topic == 1) {
#print "hoi";
my $picked_file;
my $nooffilesleftforuser=123;
my $sampledir = "/var/www1/lst/live/htdocs/discosumo/postselection/sample_eval/for$username";
#my $sampledir = "/www/lst/live/htdocs/discosumo/postselection/sample_eval/for$username";
my $nofilesforuser = 0;
if ($threadid =~ /[0-9a-zA-Z]/){
open(DATA, ">>$data") or printf "error opening %s for writing: %s ; cwd=%s<br>\n", $data, $!, getcwd;
print DATA "$time\t$username\t$threadid\t$versus\t$compare\t$comments\n" if ($threadid ne "");
close(DATA);
}
my %files_done;
#my %noofusers_per_file;
open(DATA, "<$data") or printf "error opening %s for reading: %s ; cwd=%s<br><br>\n", $data, $!, getcwd;
while(<DATA>) {
# print;
chomp;
my ($time,$uname,$threadid,$versus,$compare,$comments) = split(/\t/);
if (defined $threadid) {
#my $f = $threadid.".html";
#my $f = $threadid;
$files_done{$uname}{$versus} = 1;
#print "DONE: $versus<br>";
}
}
close(DATA);
$nofilesforuser = scalar(keys %{$files_done{$username}});
my @htmlfiles;
opendir(DIR, $sampledir) or printf "$!\n$sampledir\n";
while (my $file = readdir(DIR)) {
next if ($file !~ /html/);
#print $file;
chomp($file);
push(@htmlfiles,$file)
}
if (scalar(@htmlfiles) > 0) {
my @filesnotdonebyuser;
closedir(DIR);
my $i=0;
foreach my $htmlf (@htmlfiles) {
$i++;
#print "$i\t$htmlf ";
my $file = "evaluation/for$username/$htmlf";
if (not defined($files_done{$username}{$file})) {
#print "not done";
push(@filesnotdonebyuser,$htmlf);
} else {
#print "done";
}
#print "<br>\n";
}
$nooffilesleftforuser = scalar(@filesnotdonebyuser);
if ($nooffilesleftforuser > 0) {
my $random_number = int(rand($nooffilesleftforuser));
$picked_file = $filesnotdonebyuser[$random_number];
}
}
#print "<br>$sampledir/$picked_file";
open(HTML,"<$sampledir/$picked_file") or print "error opening $picked_file for reading<br><br>\n";
my @htmllines = <HTML>;
foreach my $line (@htmllines) {
if ($line =~ /<body/) {
$line .= "\n\n<div style=\"font-size:small;padding-left:2em;border-bottom-style:solid\">Je bent ingelogd als $usernames{$username}. Je hebt tot nu toe $nofilesforuser vergelijkingen gedaan. ";
if ($nooffilesleftforuser == 0) {
$line .= "Heel erg bedankt! Je hebt alles gedaan! ";
$line .= "Je ontvangt binnen enkele dagen een cadeaubon per e-mail. ";
$line .= "Je kunt deze pagina afsluiten. ";
print $line;
print "</div></body></html>\n";
last;
} else {
$line .= "Je kunt er nog $nooffilesleftforuser doen. (<b>Let op: je krijgt elk topic 3 keer te zien.</b>) Je kunt op elk moment stoppen door dit venster te sluiten en later opnieuw inloggen met dezelfde naam.";
}
$line .= "</div>\n";
}
if ($line =~ /<input type="hidden" name="threadid"/) {
$line .= "<input type=\"hidden\" name=\"username\" value=\"$username\">\n";
}
print $line;
}
close(HTML)
}