PERL   56

action code pl

Guest on 16th August 2022 01:11:42 AM

  1. #code the transaction using individual code
  2.  
  3.  
  4. #print "id      ipaddress       day     month   year    time    url     reference       searchterm      textfield       facet   sort    expand  more    page    record  follow  refine  seconds visit_num       elapsed visit_step      code\n";
  5.  
  6. my (%url,%more,%record,%visit_num, %visit_step, %searchterm, %textfield, %facet, %sort, %view, %page, %expand,%follow, %refine,%count_facets,$count_facets, %count_expand,$count_expand, %code,$code,%searchterm_ref, %facet_ref, %textfield_ref, %page_ref, %expand_ref, %sort_ref,%more_ref,%record_ref,%follow_ref,%refine_ref,$searchterm_ref, $facet_ref, $textfield_ref, $page_ref, $expand_ref, $sort_ref,$more_ref,$record_ref,$follow_ref,$refine_ref, $count_facets_ref, $count_expand_ref,%count_searchterm,$count_searchterm);
  7.  
  8. while(<>){
  9.        
  10. my ($id,$ipaddress,$day,$month,$year,$time,$url,$reference,$searchterm,$textfield,$facet,$sort,$expand,$more,$page,$record,$follow,$refine,$seconds,$visit_num,$elapsed,$visit_step)=split(";", $_);
  11.  
  12. chomp ($visit_step);
  13.  
  14.  
  15.  
  16. # extract "searchterm, textfield, facet, page, sort, expand, more, record, follow" from reference
  17.  
  18. # searchterm;
  19.                 if ($reference =~ /Ntt=&/ || $reference =~ /Ntt=$/) {
  20.                 $searchterm_ref = "-";
  21.                 } elsif ($reference =~ /Ntt=(\S*?)&/) {
  22.                 $searchterm_ref = $1;
  23.                 } elsif ($reference =~ /Ntt=(\S*?)$/) {
  24.                 $searchterm_ref = $1;
  25.                 } else {
  26.                 $searchterm_ref = "-";
  27.                 }
  28.   # textfield
  29.  if ($reference =~ /Ntk=&/ || $reference =~ /Ntk=$/) {
  30.                 $textfield_ref = "-";
  31.                 } elsif ($reference =~ /Ntk=(\S*?)&/) {
  32.                 $textfield_ref =  $1;
  33.                 } elsif ($reference =~ /Ntk=(\S*?)$/) {
  34.                 $textfield_ref = $1;
  35.                 } else {
  36.                 $textfield_ref = "-";
  37.                 }
  38.        
  39.         # facet;
  40.                 if ($reference =~ /N=&/ || $reference =~ /N=$/) {
  41.                 $facet_ref = "-";
  42.                 } elsif ($reference =~ /N=([^0]\d+?)$/) {
  43.                 $facet_ref = $1;
  44.                 } elsif ($reference =~ /N=([0-9+#]*)$/) {
  45.                 $facet_ref = $1;
  46.                 } elsif ($reference =~ /N=([^0].*?)&/) {
  47.                 $facet_ref = $1;
  48.                 } elsif ($reference =~ /N=(0)/) {
  49.                 $facet_ref = $1;
  50.                 } else {
  51.                 $facet_ref = "-";
  52.                 }
  53.                
  54.         # sort order;
  55.                 if ($reference =~ /Ns=&/ || $reference =~ /Ns=$/) {
  56.                 $sort_ref = "-";
  57.                 } elsif ($reference =~ /Ns=(\S*?)&/) {
  58.                 $sort_ref = $1;
  59.                 } elsif ($reference =~ /Ns=(\S*?)$/) {
  60.                 $sort_ref = $1;
  61.                 } else {
  62.                 $sort_ref = "-";
  63.                 }
  64.                
  65.         # expand facet;
  66.                 if ($reference =~ /Ne=&/ || $reference =~ /Ne=$/) {
  67.                 $expand_ref = "-";
  68.                 } elsif ($reference =~ /Ne=(\S*?)&/) {
  69.                 $expand_ref = $1;
  70.                 } elsif ($reference =~ /Ne=(\S*?)$/) {
  71.                 $expand_ref = $1;
  72.                 } else {
  73.                 $expand_ref = "-";
  74.                 }
  75.         #page
  76.                 if ($reference =~ /No=&/ || $reference =~ /No=$/) {
  77.                 $page_ref = "-";
  78.                 } elsif ($reference =~ /No=(\S*?)&/) {
  79.                 $page_ref = $1;
  80.                 } elsif ($reference =~ /No=(\S*?)$/) {
  81.                 $page_ref = $1;
  82.                 } else {
  83.                 $page_ref = "-";
  84.                 }
  85.         #more
  86.         if ($reference =~ /more=&/ || $reference =~ /more=$/) {
  87.                 $more_ref = "-";
  88.                 } elsif ($reference =~ /closed=(\S*?)$/) {
  89.                 $more_ref = $1;
  90.                 } elsif ($reference =~ /more=(\S*?)&/) {
  91.                 $more_ref = $1;
  92.                 } elsif ($reference =~ /more=(\S*?)$/) {
  93.                 $more_ref = $1;
  94.                 } else {
  95.                 $more_ref = "-";
  96.                 }
  97.         #record
  98.                         if ($reference =~ /R=&/ || $reference=~ /R=$/) {
  99.                 } elsif ($reference =~ /R=(\S*?)&/) {
  100.                 $record_ref = $1;
  101.                 } elsif ($reference =~ /R=(\S*?)$/) {
  102.                 $record_ref = $1;
  103.                 } else {
  104.                 $record_ref = "-";
  105.                 }              
  106.                
  107.                 #follow-up analysis
  108.                 if ($reference =~ /follow=(\S*)/) {
  109.                 $follow_ref = $1;
  110.                 } elsif ($reference=~/follow=(\S*)$/) {
  111.                 $follow_ref= $1;
  112.                 } else {
  113.                 $follow_ref = "-";
  114.                 }
  115.                
  116.                 #refine years
  117.                 if ($reference =~ /Nf=&/ ||$reference=~/Nf=$/) {
  118.                 $refine_ref = "-";
  119.                 } elsif ($reference =~ /Nf=(\S*?)&/) {
  120.                 $refine_ref = $1;
  121.                 } elsif ($reference=~/Nf=(\S*?)$/) {
  122.                 $refine_ref = $1;
  123.                 } else {
  124.                 $refine_ref = "-";
  125.                 }
  126.                
  127.                
  128. my $count_facets =0;
  129.   if ($facet ne "-"){
  130.   my @split_facets = split(/\+/, $facet);
  131.         foreach (@split_facets) {
  132.         my $count_facets = $count_facets++;
  133.         }
  134.        
  135.         if ($facet eq "0") {
  136.         $count_facets = 0;
  137.         }
  138.   }
  139.  
  140. my $count_facets_ref =0;
  141.  
  142.   if($facet_ref ne "-"){
  143.   my @split_facets_ref = split(/\+/, $facet_ref);
  144.        
  145.         foreach (@split_facets_ref) {
  146.         my $count_facets_ref = $count_facets_ref++;
  147.         }
  148.        
  149.         if ($facet_ref eq "0") {
  150.         $count_facets_ref = 0;
  151.         }
  152.   }
  153.        
  154. my $count_expand = 0;
  155.  
  156. if ($expand ne "-"){
  157. my @split_expand=split(/\+/,$expand);
  158.    foreach (@split_expand){
  159.     my $count_expand =$count_expand++;
  160.   }
  161.   }
  162.  
  163. my $count_expand_ref =0;
  164.  
  165. if ($expand_ref ne "-"){
  166. my @split_expand_ref=split(/\+/,$expand_ref);
  167.    foreach (@split_expand_ref){
  168.    my $count_expand_ref =$count_expand_ref++;
  169.   }
  170. }
  171.  
  172. my $count_searchterm = 0;
  173. if ($searchterm ne "-"){
  174.         my @split_searchterm=split(/\+/,$searchterm);
  175.    foreach (@split_searchterm){
  176.    my $count_searchterm =$count_searchterm++;
  177.   }
  178.        
  179. }
  180.  
  181. #  %url =("$visit_num" => "$url");
  182. #       %searchterm = ("$visit_num" => "$searchterm");
  183. #       %textfield = ("$visit_num" => "$textfield");
  184. #       %facet = ("$visit_num" => "$facet");
  185. #       %sort = ("$visit_num" => "$sort");
  186. #       %page = ("$visit_num" => "$page");
  187. #       %expand = ("$visit_num" => "$expand");
  188. #       %more = ("$visit_num" => "$more");
  189. #       %record = ("$visit_num" => "$record");
  190. #       %follow= ("$visit_num" => "$follow");
  191. #       %refine=("$visit_num" => "$refine");
  192. #      
  193. #       %count_facets=("$visit_num" => "$count_facets");
  194. #       %count_expand=("$visit_num" => "$count_expand");
  195. #       %count_searchterm=("$visit_num" => "$count_searchterm");
  196. #
  197. #       %searchterm_ref = ("$visit_num" => "$searchterm_ref");
  198. #       %textfield_ref = ("$visit_num" => "$textfield_ref");
  199. #       %facet_ref = ($"$visit_num" => "$facet_ref");
  200. #       %sort_ref = ("$visit_num" => "$sort_ref");
  201. #       %page_ref = ("$visit_num" => "$page_ref");
  202. #       %expand_ref = ("$visit_num" => "$expand_ref");
  203. #       %more_ref = ("$visit_num" => "$more_ref");
  204. #       %record_ref = ("$visit_num" => "$record_ref");
  205. #       %follow_ref = ("$visit_num" => "$follow_ref");
  206. #       %refine_ref =("$visit_num" => "$refine_ref");
  207.  
  208.        
  209.         push @{ $url{$visit_num} }, "$url";
  210.         push @{ $searchterm{$visit_num} }, "$searchterm";
  211.         push @{ $textfield{$visit_num} }, "$textfield";
  212.         push @{ $facet{$visit_num} }, "$facet";
  213.         push @{ $sort{$visit_num} }, "$sort";
  214.         push @{ $page{$visit_num} }, "$page";
  215.         push @{ $expand{$visit_num} }, "$expand";
  216.         push @{ $more{$visit_num} }, "$more";
  217.         push @{ $record{$visit_num} }, "$record";
  218.         push @{ $follow{$visit_num} }, "$follow";
  219.         push @{ $refine{$visit_num} }, "$refine";
  220.        
  221.         push @{ $count_facets{$visit_num} }, "$count_facets";
  222.         push @{ $count_expand{$visit_num} }, "$count_expand";
  223.   push @{ $count_searchterm{$visit_num} }, "$count_searchterm";
  224.  
  225.         push @{ $searchterm_ref{$visit_num} }, "$searchterm_ref";
  226.         push @{ $textfield_ref{$visit_num} }, "$textfield_ref";
  227.         push @{ $facet_ref{$visit_num} }, "$facet_ref";
  228.         push @{ $sort_ref{$visit_num} }, "$sort_ref";
  229.         push @{ $page_ref{$visit_num} }, "$page_ref";
  230.         push @{ $expand_ref{$visit_num} }, "$expand_ref";
  231.         push @{ $more_ref{$visit_num} }, "$more_ref";
  232.         push @{ $record_ref{$visit_num} }, "$record_ref";
  233.   push @{ $follow_ref{$visit_num} }, "$follow_ref";
  234.   push @{ $refine_ref{$visit_num} }, "$refine_ref";
  235.        
  236.         my $code= 0;
  237.        
  238.        
  239.         if ($url=~/tab=advanced/){
  240.                 $code= "BeginAdvancedSearch";
  241.                 }elsif ($url=~/search.jsp$/){
  242.         $code= "BeginSimpleText";
  243.         }elsif ($url=~/tab=callnumbers/){
  244.                 $code= "BeginCallNumberSearch";
  245.                 }elsif ($url=~/tab=newtitles/){
  246.                 $code= "BeginNewTitlesSearch";
  247.                  }elsif ($url=~/Ntx=/){
  248.          $code = "BooleanTextSearch"
  249.                 }elsif ($reference=~/tab=advanced/){
  250.          $code = "MultipleFieldsText";
  251.          }elsif($reference=~/tab=callnumbers/){
  252.          $code= "SelectCallNumberRange";
  253.     }elsif ($reference=~/tab=newtitles/){
  254.      $code= "SelectNewTitles";
  255.    
  256.  
  257.  } elsif($url=~/format=rss/){
  258.          $code = "RSS";
  259.   }elsif($url=~/output-format=export/){
  260.         $code = "ExportService"
  261.   }elsif ($record ne "-"){
  262.          $code = "ViewRecord";
  263.   } elsif ($follow ne "-"){
  264.          $code = "FollowupAction";
  265.  
  266.   } elsif($url =~ /query=&searchType=*$/){
  267.             $code = "EmptyTextSearch";
  268.    }elsif($url =~ /query=/){
  269.                  $code = "EmptyTextSearch";
  270.    }elsif($url =~/publishedFrom=(\S*?)&publishedTo=(\S*?)&/){
  271.      $code= "RefineYears";
  272.      
  273.   }elsif(($searchterm ne "-") and ($searchterm ne $searchterm_ref)and($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  274.            $code ="TextSearch";
  275.            if ($count_searchterm==1){
  276.                 $code = "SingleTermText";
  277.           }elsif($count_searchterm>1){
  278.                 $code = "MultipleTermText";
  279.           }
  280.            }
  281.            elsif (($searchterm eq "-")and ($url =~ /Ntt=&/ ||$url=~/Ntt=(\+)*$/)){
  282.         $code = "EmptyTextSearch";  
  283.       } elsif(($searchterm ne "-") and ($searchterm eq $searchterm_ref)and ($textfield ne $textfield_ref)and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  284.        $code ="SwitchTextField";
  285.  
  286.   }elsif (($page ne "-")and ($page ne $page_ref)and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  287.          $code = "NextPage";
  288.    } elsif (($sort ne "-")and($sort ne $sort_ref) and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")) {
  289.        $code = "SortResult";
  290.  
  291.   }elsif (($more ne "-") and ($more ne $more_ref) and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  292.         $code= "ShowMoreFacet";
  293.   }elsif ( ($count_expand != $count_expand_ref) and ($count_expand - $count_expand_ref !=5) and ($count_expand_ref-$count_expand!=5)and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){  
  294.                           if ($count_expand < $count_expand_ref){
  295.            $code = "CloseFacet";
  296.           }else{
  297.                   $code= "OpenFacet";
  298.         }
  299.   }elsif (($facet ne $facet_ref)and ($count_facets+$count_facets_ref !=0)and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  300.           if ($count_facets < $count_facets_ref){
  301.                 $code = "RemoveFacet";
  302.          }else{
  303.                 $code= "AddFacet";
  304.            }
  305.           }elsif (($refine ne "-")and ($refine ne $refine_ref)and($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  306.                
  307.                 $code = "RefineYears";
  308.        
  309.            }elsif (($refine eq "-")and ($refine ne $refine_ref)and($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  310.                
  311.                 $code = "RemoveFacet";
  312.      }elsif (($searchterm eq $searchterm_ref) and ($textfield eq $textfield_ref)and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  313.         $code = "Refresh";
  314.        
  315. #    } elsif (($searchterm eq $searchterm_ref)and($sort eq $sort_ref)and($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){
  316. #        $code = "RemoveFacet";
  317.    
  318.       }  elsif(($searchterm eq "-")and($searchterm ne $searchterm_ref) and ($reference ne "-")and ($reference ne "http://search.lib.unc.edu/search")){  
  319.            $code = "RemoveFacet";
  320.           }
  321.    
  322.     #reference page is null
  323.    
  324.     elsif (($reference eq "-")||($reference eq "http://search.lib.unc.edu/search")){
  325.         if(($searchterm ne "-") and ($searchterm ne $searchterm{$visit_num}[$visit_step-2])){
  326.           $code = "TextSearch";
  327.           if ($url{$visit_num}[$visit_step-2]=~/tab=advanced/){
  328.             $code = "MultipleFieldsText";
  329.           }elsif ($count_searchterm==1){
  330.                 $code = "SingleTermText";
  331.           }elsif($count_searchterm>1){
  332.                 $code = "MultipleTermText";
  333.       }
  334.       }elsif ($url{$visit_num}[$visit_step-2]=~/tab=newtitles/){
  335.           $code= "SelectNewTitles";
  336.        }elsif($url{$visit_num}[$visit_step-2]=~/tab=callnumbers/){
  337.        
  338.         $code= "SelectCallNumberRange";
  339.           }elsif(($searchterm ne "-") and ($searchterm eq $searchterm{$visit_num}[$visit_step-2])and ($textfield ne $textfield{$visit_num}[$visit_step-2])){
  340.           $code ="SwitchTextField";
  341.         }elsif(($page ne "-")and ($page ne $page{$visit_num}[$visit_step-2])){
  342.                 $code = "NextPage";
  343.       }elsif(($sort ne "-")and($sort ne $sort{$visit_num}[$visit_step-2])){
  344.         $code = "SortResult";
  345.       }elsif(($more ne "-") and ($more ne $more{$visit_num}[$visit_step-2])){
  346.         $code = "ShowMoreFacet";
  347.       }elsif ( ($count_expand != $count_expand{$visit_num}[$visit_step-2]) and ($count_expand - $count_expand{$visit_num}[$visit_step-2] !=5) and ($count_expand{$visit_num}[$visit_step-2]-$count_expand!=5)){  
  348.                           if ($count_expand < $count_expand{$visit_num}[$visit_step-2]){
  349.             $code = "CloseFacet";
  350.               }else{
  351.                   $code= "OpenFacet";
  352.               }
  353.               }elsif (($facet ne $facet{$visit_num}[$visit_step-2])and ($count_facets+$count_facets{$visit_num}[$visit_step-2] !=0)){
  354.                  if ($count_facets < $count_facets{$visit_num}[$visit_step-2]){
  355.                 $code = "RemoveFacet";
  356.             }else{
  357.                 $code= "AddFacet";
  358.                }
  359.                }elsif (($refine ne "-")and ($refine ne $refine{$visit_num}[$visit_step-2])){
  360.                
  361.                     $code = "RefineYears";
  362.        
  363.                }elsif (($refine eq "-")and ($refine ne $refine{$visit_num}[$visit_step-2])){
  364.                
  365.                      $code = "RemoveFacet";
  366.                    }elsif(($searchterm eq $searchterm{$visit_num}[$visit_step-2])and ($textfield eq $textfield{$visit_num}[$visit_step-2])){
  367.            $code = "Refresh";
  368.        
  369.                  
  370.          }elsif(($searchterm eq "-")and($searchterm ne $searchterm{$visit_num}[$visit_step-2])){  
  371.            $code="RemoveFacet";
  372.           }
  373.         }
  374.        
  375.        
  376.    
  377.  
  378.  
  379.  
  380.   #%code = ("$visit_num" => "$code");
  381.        
  382.         push @{ $code{$visit_num} }, "$code";
  383.        
  384.  
  385.  #print "$id    $ipaddress      $day    $month  $year   $time   $url    $reference      $searchterm     $textfield      $facet  $sort   $expand $more   $page   $record $follow $refine $seconds        $visit_num      $elapsed        $visit_step     $code\n";
  386. #print "$searchterm,$searchterm{$visit_num}[$visit_step-2]\n";
  387. print "@{$searchterm{$visit_num}}\n";
  388. # print "please enter\n";
  389. # my $enter =<STDIN>;
  390. # chomp ($enter);
  391. # print "$serchterm{$visitnum}";
  392. }

Raw Paste


Login or Register to edit or fork this paste. It's free.