/[suikacvs]/perl/kanzan/kanzan.cgi
Suika

Contents of /perl/kanzan/kanzan.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Nov 5 12:52:46 2003 UTC (21 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.4: +47 -9 lines
Don't use obsoleted Suika::CGI module

1 wakaba 1.5 #!/usr/bin/perl
2 wakaba 1.2
3     use strict;
4 wakaba 1.5
5     for (split /[&;]/, $main::ENV{QUERY_STRING}) {
6    
7     }
8 wakaba 1.2
9 wakaba 1.3 my %ex_point1 = ();
10     (
11 wakaba 1.2 kokugo => 54,
12     suugaku => 55,
13     eigo => 57,
14     sekaishi => 53,
15     nihonshi => 0,
16     chiri => 0,
17     butsuri => 54,
18     kagaku => 52,
19     seibutsu => 0,
20     _OBJECT => 57,
21     );
22    
23 wakaba 1.3 my %ex_point2 = ();
24     (
25 wakaba 1.2 kokugo => 53,
26     suugaku => 55,
27     eigo => 55,
28     sekaishi => 52,
29     nihonshi => 0,
30     chiri => 0,
31     butsuri => 54,
32     kagaku => 51,
33     seibutsu => 0,
34     _OBJECT => 58,
35     );
36    
37 wakaba 1.3 my %ex_haiten1 = ();
38     (
39 wakaba 1.2 kokugo => 80,
40     suugaku => 80,
41     eigo => 80,
42     sekaishi => 40,
43     nihonshi => 0,
44     chiri => 0,
45     butsuri => 40,
46     kagaku => 0,
47     seibutsu => 0,
48     );
49    
50 wakaba 1.3 my %ex_haiten2 = ();
51     (
52 wakaba 1.2 kokugo => 0,
53     suugaku => 300,
54     eigo => 150,
55     sekaishi => 0,
56     nihonshi => 0,
57     chiri => 0,
58     butsuri => 150,
59     kagaku => 150,
60     seibutsu => 0,
61     );
62    
63    
64     sub kanzan (%%%%) {
65     my ($point1, $full1, $point2, $full2) = @_;
66     my (%kanzaned1, %kanzaned2);
67     $$full1{_ALL} = 0;
68     for my $subject (keys %$full1) {
69     next if $subject =~ /^_/;
70     $kanzaned1{$subject} = $$point1{$subject}*$$full1{$subject}/100;
71     $kanzaned1{_ALL} += $kanzaned1{$subject};
72     $$full1{_ALL} += $$full1{$subject};
73     }
74 wakaba 1.4 $kanzaned1{_PERCENT} = $$full1{_ALL}==0?0:100*$kanzaned1{_ALL}/$$full1{_ALL};
75 wakaba 1.2 $$full2{_ALL} = 0;
76     for my $subject (keys %$full2) {
77     next if $subject =~ /^_/;
78     $kanzaned2{$subject} = $$point2{$subject}*$$full2{$subject}/100;
79     $kanzaned2{_ALL} += $kanzaned2{$subject};
80     $$full2{_ALL} += $$full2{$subject};
81     }
82 wakaba 1.4 $kanzaned2{_PERCENT} = $$full2{_ALL}==0?0:100*$kanzaned2{_ALL}/$$full2{_ALL};
83 wakaba 1.2
84     my ($percent, $object_percent);
85 wakaba 1.4 $percent = ($$full1{_ALL}+$$full2{_ALL})==0?0:
86     100*($kanzaned1{_ALL}+$kanzaned2{_ALL})
87 wakaba 1.2 /($$full1{_ALL}+$$full2{_ALL});
88 wakaba 1.4 $object_percent = ($$full1{_ALL}+$$full2{_ALL})==0?0:
89     ($$point1{_OBJECT}*$$full1{_ALL}
90 wakaba 1.2 +$$point2{_OBJECT}*$$full2{_ALL})
91     /($$full1{_ALL}+$$full2{_ALL});
92     ($percent, $object_percent, \%kanzaned1, \%kanzaned2);
93     }
94    
95 wakaba 1.5 %Suika::CGI::param = %{__get_parameter ()};
96 wakaba 1.2 my (%mypoint1, %mypoint2, %haiten1, %haiten2);
97     if ($Suika::CGI::param{newform} ne 'no') {
98     %mypoint1 = %ex_point1;
99     %mypoint2 = %ex_point2;
100     %haiten1 = %ex_haiten1;
101     %haiten2 = %ex_haiten2;
102     } else {
103     for my $s (keys %Suika::CGI::param) {
104     $mypoint1{$1} = $Suika::CGI::param{$s} if $s =~ /^(.+[^H_])1$/;
105     $mypoint2{$1} = $Suika::CGI::param{$s} if $s =~ /^(.+[^H_])2$/;
106     $mypoint1{'_'.$1} = $Suika::CGI::param{$s} if $s =~ /^(.+)_1$/;
107     $mypoint2{'_'.$1} = $Suika::CGI::param{$s} if $s =~ /^(.+)_2$/;
108     $haiten1{$1} = $Suika::CGI::param{$s} if $s =~ /^(.+)H1$/;
109     $haiten2{$1} = $Suika::CGI::param{$s} if $s =~ /^(.+)H2$/;
110     }
111     }
112     my ($percent, $object, $kanzan1, $kanzan2)
113     = kanzan ({%mypoint1} => {%haiten1}, {%mypoint2} => {%haiten2});
114    
115 wakaba 1.3 print STDOUT "Content-Type: text/html; charset=euc-jp
116     Content-Style-Type: text/css
117     Content-Language: ja
118 wakaba 1.2
119     ";
120     output_html (\%mypoint1 => \%haiten1 => $kanzan1,
121     \%mypoint2 => \%haiten2 => $kanzan2,
122     percent => $percent, object => $object);
123    
124     sub diffmark ($) {
125     my $diff = shift;
126     return '□' if $diff < -4;
127     return '△' if $diff < -2;
128     return '○' if $diff < 0;
129     return '◎';
130     }
131    
132     sub output_html (%%%%%) {
133     my ($p1 => $h1 => $k1, $p2 => $h2 => $k2, %misc) = @_;
134     for my $n ($$k1{_PERCENT}, $$k2{_PERCENT}, $misc{percent}, $misc{object}) {
135     $n = int ($n);
136     }
137     $$k1{_DIFF} = $$k1{_PERCENT}-$$p1{_OBJECT};
138     $$k2{_DIFF} = $$k2{_PERCENT}-$$p2{_OBJECT};
139     $misc{_DIFF} = $misc{percent}-$misc{object};
140     $$k1{_DIFFMARK} = diffmark ($$k1{_DIFF});
141     $$k2{_DIFFMARK} = diffmark ($$k2{_DIFF});
142     $misc{_DIFFMARK} = diffmark ($misc{_DIFF});
143     print <<EOH;
144     <!DOCTYPE html PUBLIC "-//W3D//DTD HTML 4.01//EN">
145     <html lang="ja">
146     <head>
147     <title>配点換算</title>
148 wakaba 1.4 <link rev="made" href="mailto:w\@suika.fam.cx">
149 wakaba 1.5 <link rel="contents" href="http://tomikou.net/tokshuu/kanzan.html" title="換算点算出システム
150     ">
151 wakaba 1.3 <link rel="contents" href="/chuubu/">
152 wakaba 1.5 <link rel="stylesheet" href="/s/default/xhtml1" media="all">
153     <style type="text/css" media="all">
154 wakaba 1.2 input {width: 3em}
155     </style>
156     </head>
157     <body>
158     <h1>配点換算</h1>
159 wakaba 1.5 <form action="kanzan" method="post" accept-charset="iso-2022-jp">
160 wakaba 1.2 <table>
161     <thead>
162     <tr>
163     <th colspan="2">教科</th>
164     <th>国語</th><th>数学</th><th>英語</th>
165     <th>世界史</th><th>日本史</th><th>地理</th>
166     <th>物理</th><th>化学</th><th>生物</th>
167     </tr>
168     </thead>
169     <tbody>
170     <tr>
171     <th rowspan="3">一次</th><th>持ち点</th>
172     <td><input type="text" name="kokugo1" value="$$p1{kokugo}"></td>
173     <td><input type="text" name="suugaku1" value="$$p1{suugaku}"></td>
174     <td><input type="text" name="eigo1" value="$$p1{eigo}"></td>
175     <td><input type="text" name="sekaishi1" value="$$p1{sekaishi}"></td>
176     <td><input type="text" name="nihonshi1" value="$$p1{nihonshi}"></td>
177     <td><input type="text" name="chiri1" value="$$p1{chiri}"></td>
178     <td><input type="text" name="butsuri1" value="$$p1{butsuri}"></td>
179     <td><input type="text" name="kagaku1" value="$$p1{kagaku}"></td>
180     <td><input type="text" name="seibutsu1" value="$$p1{seibutsu}"></td>
181     </tr>
182     <tr>
183     <th>配点</th>
184     <td><input type="text" name="kokugoH1" value="$$h1{kokugo}"></td>
185     <td><input type="text" name="suugakuH1" value="$$h1{suugaku}"></td>
186     <td><input type="text" name="eigoH1" value="$$h1{eigo}"></td>
187     <td><input type="text" name="sekaishiH1" value="$$h1{sekaishi}"></td>
188     <td><input type="text" name="nihonshiH1" value="$$h1{nihonshi}"></td>
189     <td><input type="text" name="chiriH1" value="$$h1{chiri}"></td>
190     <td><input type="text" name="butsuriH1" value="$$h1{butsuri}"></td>
191     <td><input type="text" name="kagakuH1" value="$$h1{kagaku}"></td>
192     <td><input type="text" name="seibutsuH1" value="$$h1{seibutsu}"></td>
193     </tr>
194     <tr>
195     <th>換算点</th>
196     <td>$$k1{kokugo}</td><td>$$k1{suugaku}</td><td>$$k1{eigo}</td>
197     <td>$$k1{sekaishi}</td><td>$$k1{nihonshi}</td><td>$$k1{chiri}</td>
198     <td>$$k1{butsuri}</td><td>$$k1{kagaku}</td><td>$$k1{seibutsu}</td>
199     </tr>
200    
201     <tr>
202     <th rowspan="3">二次</th><th>持ち点</th>
203     <td><input type="text" name="kokugo2" value="$$p2{kokugo}"></td>
204     <td><input type="text" name="suugaku2" value="$$p2{suugaku}"></td>
205     <td><input type="text" name="eigo2" value="$$p2{eigo}"></td>
206     <td><input type="text" name="sekaishi2" value="$$p2{sekaishi}"></td>
207     <td><input type="text" name="nihonshi2" value="$$p2{nihonshi}"></td>
208     <td><input type="text" name="chiri2" value="$$p2{chiri}"></td>
209     <td><input type="text" name="butsuri2" value="$$p2{butsuri}"></td>
210     <td><input type="text" name="kagaku2" value="$$p2{kagaku}"></td>
211     <td><input type="text" name="seibutsu2" value="$$p2{seibutsu}"></td>
212     </tr>
213     <tr>
214     <th>配点</th>
215     <td><input type="text" name="kokugoH2" value="$$h2{kokugo}"></td>
216     <td><input type="text" name="suugakuH2" value="$$h2{suugaku}"></td>
217     <td><input type="text" name="eigoH2" value="$$h2{eigo}"></td>
218     <td><input type="text" name="sekaishiH2" value="$$h2{sekaishi}"></td>
219     <td><input type="text" name="nihonshiH2" value="$$h2{nihonshi}"></td>
220     <td><input type="text" name="chiriH2" value="$$h2{chiri}"></td>
221     <td><input type="text" name="butsuriH2" value="$$h2{butsuri}"></td>
222     <td><input type="text" name="kagakuH2" value="$$h2{kagaku}"></td>
223     <td><input type="text" name="seibutsuH2" value="$$h2{seibutsu}"></td>
224     </tr>
225     <tr>
226     <th>換算点</th>
227     <td>$$k2{kokugo}</td><td>$$k2{suugaku}</td><td>$$k2{eigo}</td>
228     <td>$$k2{sekaishi}</td><td>$$k2{nihonshi}</td><td>$$k2{chiri}</td>
229     <td>$$k2{butsuri}</td><td>$$k2{kagaku}</td><td>$$k2{seibutsu}</td>
230     </tr>
231     </tbody>
232     </table>
233    
234     <table>
235     <thead>
236     <tr>
237     <th></th><th>得点率</th><th>目標点</th><th colspan="2">差</th>
238     </tr>
239     </thead>
240     <tbody>
241     <tr>
242     <th>一次</th>
243     <td>$$k1{_PERCENT}</td>
244     <td><input type="text" name="OBJECT_1" value="$$p1{_OBJECT}"></td>
245     <td>$$k1{_DIFF}</td>
246     <td>$$k1{_DIFFMARK}</td>
247     </tr>
248     <tr>
249     <th>二次</th>
250     <td>$$k2{_PERCENT}</td>
251     <td><input type="text" name="OBJECT_2" value="$$p2{_OBJECT}"></td>
252     <td>$$k2{_DIFF}</td>
253     <td>$$k2{_DIFFMARK}</td>
254     </tr>
255     <tr>
256     <th>合計</th>
257     <td>$misc{percent}</td>
258     <td>$misc{object}</td>
259     <td>$misc{_DIFF}</td>
260     <td>$misc{_DIFFMARK}</td>
261     </tr>
262     </tbody>
263     </table>
264    
265     <p>
266     <input type="hidden" name="newform" value="no">
267     <input type="submit" value="OK">
268     </p>
269     </form>
270 wakaba 1.3
271     <div class="navigation">
272 wakaba 1.5 [<a href="/gate/cvs/perl/kanzan/" lang="en">source</a>]
273 wakaba 1.3 </div>
274     </body>
275     </html>
276 wakaba 1.2 EOH
277     }
278    
279 wakaba 1.5 sub __get_parameter () {
280     my @src;
281    
282     ## Query-string of Request-URI
283     my $qs = $main::ENV{QUERY_STRING};
284     push @src, $qs if (index ($qs, '=') > -1);
285    
286     ## Entity-body
287     if ($main::ENV{REQUEST_METHOD} eq 'POST') {
288     my $mt = $main::ENV{CONTENT_TYPE};
289     if ($mt =~ m<^application/(?:x-www|sgml)-form-urlencoded\b>) {
290     my $body;
291     read STDIN, $body, $main::ENV{CONTENT_LENGTH};
292     push @src, $body;
293     }
294     }
295    
296     my %temp_params;
297     for my $src (@src) {
298     for (split /[;&]/, $src) {
299     my ($name, $val) = split '=', $_, 2;
300     for ($name, $val) {
301     tr/+/ /;
302     s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge;
303     }
304     $temp_params{$name} = $val;
305     }
306     }
307     \%temp_params;
308     }
309    
310    
311 wakaba 1.3 =head1 LICENSE
312    
313 wakaba 1.5 Copyright 2001-2003 Wakaba E<lt>w@suika.fam.cxE<gt>.
314 wakaba 1.3
315     This program is free software; you can redistribute it and/or modify
316     it under the terms of the GNU General Public License as published by
317     the Free Software Foundation; either version 2 of the License, or
318     (at your option) any later version.
319    
320     This program is distributed in the hope that it will be useful,
321     but WITHOUT ANY WARRANTY; without even the implied warranty of
322     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
323     GNU General Public License for more details.
324    
325     You should have received a copy of the GNU General Public License
326     along with this program; see the file COPYING. If not, write to
327     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
328     Boston, MA 02111-1307, USA.
329    
330     =cut
331    
332 wakaba 1.5 1; # $Date: 2002/09/04 09:02:38 $
333    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24