#!/usr/bin/perl use Getopt::Long; use DB_File; $dbmfile = 'riverweb.dbm'; tie %hash, DB_File, $dbmfile; # open database, to be accessed &PrintQuestions; &PrintIntro; print "\n\trn\t\trunoff"; print "\t\tnt\t\tnitrogen\n"; print "\tph\t\tph"; print "\t\tbd\t\tbod\n"; print "\thm\t\theavymetal"; print "\tdo\t\tdo\n"; print "\tpc\t\tprecip"; print "\t\twt\t\twatertemp\n"; print "\tsd\t\tsaturateddo"; print "\tps\t\tphosphorus\n"; print "\tsm\t\tsediments"; print "\ttx\t\ttoxins\n"; print "\ttm\t\ttemperature"; print "\ttf\t\ttotalflow\n"; print "\tgw\t\tgroundwater"; print "\ta\t\tall\n\n\n\n"; print "Method(rn), User Mode (u), Questions by user(uq) or Quit(q):\n"; while (){ $link = 0; chop; if ($_ eq 'a'){ &DisplayQuestionsArray; } elsif ($_ eq 'q'){ exit; } elsif ($_ eq 'm'){ &menu; } elsif ($_ eq 'u'){ &UserMode; } elsif ($_ eq 'uq'){ &UserQuestions; } elsif ($_ eq 'rn'){ &rn;} elsif ($_ eq 'nt'){ &nt;} elsif ($_ eq 'ph'){ &ph;} elsif ($_ eq 'bd'){ &bo;} elsif ($_ eq 'hm'){ &hm;} elsif ($_ eq 'do'){ &dox;} elsif ($_ eq 'pc'){ &pc;} elsif ($_ eq 'wt'){ &wt;} elsif ($_ eq 'sd'){ &sd;} elsif ($_ eq 'ps'){ &ps;} elsif ($_ eq 'sm'){ &sm;} elsif ($_ eq 'tx'){ &tx;} elsif ($_ eq 'tm'){ &tm;} elsif ($_ eq 'tf'){ &tf;} elsif ($_ eq 'gw'){ &gw;} else{ print "\nUser responses for location $_:\n\n"; ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $hash{$_}); $link = $_; @formkeys = split(/:/, $keywords); foreach $word (@formkeys){ print "$word\n"; } print "\nQuestion: $parsedinfo[4]\n\n"; } while (($key, $val) = each %hash){ ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $val); if ($_ eq 'q'){ exit; } #print "DEBUG:$parsedinfo[3] eq $link?\n"; if ($parsedinfo[3] eq $link){ print "\n"; if ($parsedinfo[1] eq '3'){ print "User: $parsedinfo[2]\nResponse: $parsedinfo[4]\n\n"; } } } $i = 1; print "\n\nMenu(m) Method(pc), Question Index(123), User Mode (u)(uq), or quit(q):\n"; } untie %hash; sub PrintIntro{ print "\n\n\n\n\tThe following are parameters in riverweb. You can search\n"; print "\tfor questions related to a specific parameter, or display\n"; print "\tall of the questions. Type the id number of the question\n"; print "\ti.e. if the keywords are: 0-rn-0-0-bo-0-97 you would type\n"; print "\t97 to display all responses to that question. If you wish\n"; print "\tto view a specific user's responses, type \"u\" to display\n"; print "\ta list of users with available responses.\n"; } sub UserQuestions{ &PrintUsers; $i = 0; while ($i <= $#users){ #print "Users: $#users\n"; print "\'$users[$i]\' "; $i++; } print "Select a user to see a list of the questions the user answered\n"; print "\n\nUser(name), Menu(m), or Quit(q)\n"; LINE: while (){ chop; if ($_ eq 'q'){ exit; } if ($_ eq 'm'){ print "\n\n\n\n"; &PrintIntro; &menu; last LINE; } while (($key, $val) = each %hash){ ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $val); #print "$_ eq $parsedinfo[2]"; if ($_ eq $parsedinfo[2]){ $link = $parsedinfo[3]; ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $hash{$link}); $keywords =~ s/topstation=//g; $keywords =~ s/topindicator=//g; $keywords =~ s/bmptop=//g; $keywords =~ s/bottomstation=//g; $keywords =~ s/bottomindicator=//g; $keywords =~ s/bmpbottom=//g; $keywords =~ s/runoff/rn/g; $keywords =~ s/nitrogen/nt/g; $keywords =~ s/ph/ph/g; $keywords =~ s/bod/bo/g; $keywords =~ s/heavymetal/hm/g; $keywords =~ s/do/do/g; $keywords =~ s/precip/pc/g; $keywords =~ s/watertemp/wt/g; $keywords =~ s/saturateddo/sd/g; $keywords =~ s/phosphorus/ps/g; $keywords =~ s/sediments/sm/g; $keywords =~ s/toxins/tx/g; $keywords =~ s/temperature/tm/g; $keywords =~ s/totalflow/tf/g; $keywords =~ s/groundwater/gw/g; $keywords =~ s/:/-/g; $keywords .= $parsedinfo[0]; $crop = (substr $parsedinfo[4], 0, 60); $question = ($keywords . ': ' . $crop); print "$question\n"; } } print "\n\nUser(name) Menu(m), or Quit(q)\n"; $link = 0; } } sub UserMode{ &PrintUsers; $i = 0; while ($i <= $#users){ #print "Users: $#users\n"; print "\'$users[$i]\' "; $i++; } print "\n\nUser(name), Menu(m), or Quit(q)\n"; LINE: while (){ chop; if ($_ eq 'q'){ exit; } if ($_ eq 'm'){ print "\n\n\n\n"; &PrintIntro; &menu; last LINE; } while (($key, $val) = each %hash){ ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $val); #print "$_ eq $parsedinfo[2]"; if ($_ eq $parsedinfo[2]){ $keywords =~ s/topstation=//g; $keywords =~ s/topindicator=//g; $keywords =~ s/bmptop=//g; $keywords =~ s/bottomstation=//g; $keywords =~ s/bottomindicator=//g; $keywords =~ s/bmpbottom=//g; $keywords =~ s/runoff/rn/g; $keywords =~ s/nitrogen/nt/g; $keywords =~ s/ph/ph/g; $keywords =~ s/bod/bo/g; $keywords =~ s/heavymetal/hm/g; $keywords =~ s/do/do/g; $keywords =~ s/precip/pc/g; $keywords =~ s/watertemp/wt/g; $keywords =~ s/saturateddo/sd/g; $keywords =~ s/phosphorus/ps/g; $keywords =~ s/sediments/sm/g; $keywords =~ s/toxins/tx/g; $keywords =~ s/temperature/tm/g; $keywords =~ s/totalflow/tf/g; $keywords =~ s/groundwater/gw/g; $keywords =~ s/:/-/g; $keywords .= $parsedinfo[0]; $location = $keywords; $datatype = $parsedinfo[1]; $response = $parsedinfo[4]; $id = $parsedinfo[3]; ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $hash{$id}); if ($datatype eq '2'){ print "User Note: $location\n\n"; } elsif ($datatype eq '3'){ print "Question: $parsedinfo[4]\nLocation: $location\n\n"; } else{ print "Unknown Database Entry at $location\n\n"; } print "Response: $response\n\n\n"; } } $i = 0; while ($i <= $#users){ #print "Users: $#users\n"; print "\'$users[$i]\' "; $i++; } print "\n\nUser(name) Menu(m), or Quit(q)\n"; } } sub PrintUsers{ print "Here'is a list of the users for the riverweb database\n"; while (($key, $val) = each %hash){ # pre process the entry for testing ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $val); $found = 'no'; $i = 0; while ($i < $#users){ if ($parsedinfo[2] eq $users[$i]){ $found = 'yes'; } $i++; } if ($found eq 'no'){ #print "\'$parsedinfo[2]\' "; push @users, $parsedinfo[2]; } } } sub DisplayQuestionsArray{ $i = 0; while ($i <= $#questions){ print "$questions[$i]\n"; $i++; } } sub menu{ print "\n\trn\t\trunoff"; print "\t\tnt\t\tnitrogen\n"; print "\tph\t\tph"; print "\t\tbd\t\tbod\n"; print "\thm\t\theavymetal"; print "\tdo\t\tdo\n"; print "\tpc\t\tprecip"; print "\t\twt\t\twatertemp\n"; print "\tsd\t\tsaturateddo"; print "\tps\t\tphosphorus\n"; print "\tsm\t\tsediments"; print "\ttx\t\ttoxins\n"; print "\ttm\t\ttemperature"; print "\ttf\t\ttotalflow\n"; print "\tgw\t\tgroundwater"; print "\ta\t\tall\n"; } sub rn { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/rn/){ print "$questions[$i]\n"; } $i++; } } sub nt { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/nt/){ print "$questions[$i]\n"; } $i++; } } sub ph { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/ph/){ print "$questions[$i]\n"; } $i++; } } sub bo { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/bd/){ print "$questions[$i]\n"; } $i++; } } sub hm { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/hm/){ print "$questions[$i]\n"; } $i++; } } sub dox { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/do/){ print "$questions[$i]\n"; } $i++; } } sub pc { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/pc/){ print "$questions[$i]\n"; } $i++; } } sub wt { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/wt/){ print "$questions[$i]\n"; } $i++; } } sub sd { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/sd/){ print "$questions[$i]\n"; } $i++; } } sub ps { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/ps/){ print "$questions[$i]\n"; } $i++; } } sub sm { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/sm/){ print "$questions[$i]\n"; } $i++; } } sub tx { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/tx/){ print "$questions[$i]\n"; } $i++; } } sub tm { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/tm/){ print "$questions[$i]\n"; } $i++; } } sub tf { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/tf/){ print "$questions[$i]\n"; } $i++; } } sub gw { print "\n"; $i = 0; while ($i <= $#questions){ if ($questions[$i] =~ m/gw/){ print "$questions[$i]\n"; } $i++; } } # topstation=0:topindicator=heavymetal:bmptop=0:bottomstation=4:bottomindicator=heavymetal:bmpbottom=1:290: # runoff # nitrogen # ph # bod # heavymetal # do # precip # watertemp # saturateddo # phosphorus # sediments # toxins # temperature # totalflow # groundwater sub PrintQuestions{ while (($key, $val) = each %hash){ # pre process the entry for testing ($parsedinfo[0], $parsedinfo[1], $parsedinfo[2], $parsedinfo[3], $keywords, $parsedinfo[4]) = split(/\|/, $val); if ($parsedinfo[1] eq 1){ $i++; $crop = (substr $parsedinfo[4], 0, 60); $keywords =~ s/topstation=//g; $keywords =~ s/topindicator=//g; $keywords =~ s/bmptop=//g; $keywords =~ s/bottomstation=//g; $keywords =~ s/bottomindicator=//g; $keywords =~ s/bmpbottom=//g; $keywords =~ s/runoff/rn/g; $keywords =~ s/nitrogen/nt/g; $keywords =~ s/ph/ph/g; $keywords =~ s/bod/bd/g; $keywords =~ s/heavymetal/hm/g; $keywords =~ s/do/do/g; $keywords =~ s/precip/pc/g; $keywords =~ s/watertemp/wt/g; $keywords =~ s/saturateddo/sd/g; $keywords =~ s/phosphorus/ps/g; $keywords =~ s/sediments/sm/g; $keywords =~ s/toxins/tx/g; $keywords =~ s/temperature/tm/g; $keywords =~ s/totalflow/tf/g; $keywords =~ s/groundwater/gw/g; $keywords =~ s/:/-/g; $question = ($keywords . $parsedinfo[0] . ': ' . $crop); #print "$question\n"; push @questions, $question; } } }