#! /usr/local/bin/perl ####################################################### #BooDataAnalyzer for CSV v1.01 / this script is free. # #(C) BooBooClub 2001-2005 # ####################################################### #set data $cgi = './bdanalyz.cgi'; $dat = './csvdata.csv'; $out = './output.csv'; $setdat = './dataset.txt'; $bar = './bar.gif'; #read lib require './jcode.pl'; $ENV{'TZ'}='JST-9'; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = ($year + 1900); $mon++; if ($sec < 10) { $sec = "0$sec";} if ($min < 10) { $min = "0$min";} if ($hour < 10){ $hour = "0$hour";} if ($mon < 10) { $mon = "0$mon";} if ($mday < 10){ $mday = "0$mday";} $time = "$year/$mon/$mday $hour:$min:$sec"; #read if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/\cM\n//g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); if($FORM{$name} eq ''){ $FORM{$name} = $value; } else{ $FORM{$name} .= ','.$value; } } #branch if($FORM{'ws'}){ $dat = $FORM{'datfile'}; $out = $FORM{'outfile'}; $head = $FORM{'dathead'}; &ws_action; } elsif($FORM{'ss'}){ $dat = $FORM{'datfile'}; $out = $FORM{'outfile'}; $head = $FORM{'dathead'}; @head = split(/,/,$head); &ss_action; } elsif($FORM{'rs'}){ $dat = $FORM{'datfile'}; $out = $FORM{'outfile'}; $head = $FORM{'dathead'}; @head = split(/,/,$head); &rs_action; } else{ open (HEAD,"$setdat"); $hfile = join('',); close (HEAD); $hfile =~ s/\r\n|[\r\n]//g; $head = $hfile; &ready; } sub ws_action{ $target = $FORM{'wsh'}; open (DAT,"$dat"); @dats = ; close (DAT); foreach $dats1(@dats){ $w = 0; @edat1 = split(/,/,$dats1); foreach $dats2(@dats){ @edat2 = split(/,/,$dats2); if($edat1[$target] eq $edat2[$target]){ $w++; } } if($w >= 2){ push(@wdat,$dats1); } else{ push(@ndat,$dats1); } } if($FORM{'wdtype'} eq 'search'){ @outdat = @wdat; } else{ @outdat = @ndat; } if($FORM{'write'} eq 'yes'){ if($FORM{'wtype'} eq 'rewrite'){ open (OUT,">$out"); } else{ open (OUT,">>$out"); } print OUT @outdat; close (OUT); } print "Content-type: text/html\n\n"; print "重複データ処理\n"; print "\n"; print "

重複データ処理



\n"; if($FORM{'write'} eq 'yes'){ print "OUTPUT-File = $out\n"; } else{ print "OUTPUT-File = ファイル出力はしない\n"; } print "
\n"; print "
\n"; foreach $outdat(@outdat){ print "$outdat
\n"; } print "
\n"; exit 0; } sub ss_action{ $target = $FORM{'ssh'}; open (DAT,"$dat"); @dats = ; close (DAT); $total = @dats; if($target eq 'all'){ @target = (0..$#head); } else{ @target = split(/,/,$target); } foreach $tdat(@target){ if($head[$tdat] eq '' || $head[$tdat] =~ /^-+$/){ next; } else{ $ht .= $head[$tdat].','; } foreach $dats(@dats){ @edat = split(/,/,$dats); $DAT{$head[$tdat]}{$edat[$tdat]}++; } } print "Content-type: text/html\n\n"; print "データ集計\n"; print "\n"; print "

データ集計



\n"; if($target eq 'all'){ print "\"すべて\""; } else{ chop $ht; print "\"$ht\""; } print "の項目のデータ集計
\n"; print "
\n"; print "
\n"; print "\n"; foreach $tdat(@target){ if($head[$tdat] eq '' || $head[$tdat] =~ /^-+$/){ next; } print "\n"; $i = 0; foreach $edat(sort keys %{$DAT{$head[$tdat]}}){ if(($i % 2) != 0){ $bgcolor = 'bgcolor=#eeeeee'; } else{ $bgcolor = ''; } if($edat eq '' || $edat =~ /^[\s\Q \E]+$/){ print ""; } else{ print ""; } $per = (100 * ($DAT{$head[$tdat]}{$edat}) / $total); $per = (int($per * 100)) / 100; if($per !~ /\./){$per .= '.00';} elsif($per =~ /\.\d$/){$per .= '0';} print ""; print "\n"; print ""; print ""; if($FORM{'sdtype'} eq 'graph'){ $imgw = int($per * 2); print "\n"; } else{ print "\n"; } $i++; } } print "
$head[$tdat]
[Null]
$edat:$DAT{$head[$tdat]}{$edat}($per\%):
\n"; print "
\n"; exit 0; } sub rs_action{ $target = $FORM{'rsh'}; open (DAT,"$dat"); @dats = ; close (DAT); foreach $dats(@dats){ @edat = split(/,/,$dats); if(($target ne 'all' && $edat[$target] =~ /\Q$FORM{'stxt'}\E/) || ($target eq 'all' && $dats =~ /\Q$FORM{'stxt'}\E/)){ push(@idat,$dats); } else{ push(@udat,$dats); } } if($FORM{'sctype'} eq 'in'){ @outdat = @idat; } else{ @outdat = @udat; } if($FORM{'write'} eq 'yes'){ if($FORM{'wtype'} eq 'rewrite'){ open (OUT,">$out"); } else{ open (OUT,">>$out"); } print OUT @outdat; close (OUT); } print "Content-type: text/html\n\n"; print "データ検索\n"; print "\n"; print "

データ検索



\n"; if($target eq 'all'){ print "\"いずれか\""; } else{ print "\"$head[$target]\""; } print "の項目に\"$FORM{'stxt'}\"を"; if($FORM{'sctype'} eq 'in'){ print "含むデータ
\n"; } else{ print "含まないデータ
\n"; } print "
\n"; if($FORM{'write'} eq 'yes'){ print "OUTPUT-File = $out\n"; } else{ print "OUTPUT-File = ファイル出力はしない\n"; } print "
\n"; print "
\n"; foreach $outdat(@outdat){ print "$outdat
\n"; } print "
\n"; exit 0; } sub ready{ print "Content-type: text/html\n\n"; print "BooDataAnalyzer for CSV\n"; print "\n"; print "
\n"; print "
\n"; print "

Boo Data Analyzer for CSV

− CSVファイル用データ検索集計システム − 


\n"; print "
\n"; print "対象ファイル:
\n"; print "出力ファイル: 保存する
\n"; print "保存タイプ :上書き   \n"; print "追記
\n"; print "データ項目名:
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "重複項目処理:\n"; print "抽出 \n"; print "削除\n"; print "
\n"; print "選択した項目について同じ値を持つデータが複数ある場合の抽出や削除
\n"; print "
\n"; print "
\n"; print "データの集計:\n"; print "グラフ\n"; print "数値 \n"; print "
\n"; print "全項目または選択した項目についてのデータ集計
\n"; print "データの集計結果は表\示のみでファイル出力できません。
\n"; print "
\n"; print "
\n"; print "
\n"; print "[ データ検索 ]
\n"; print "
\n"; print "対象項目:に\n"; print "という文字列を
\n"; print "含むもの \n"; print "含まないもの\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; exit 0; }