home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / scripts / ckermit / weblog.~1~ < prev    next >
Text File  |  2010-04-05  |  3KB  |  104 lines

  1. #!/p/kd/fdc/solaris9/wermit +
  2. #
  3. # THE FIRST LINE SHOULD INDICATE THE ACTUAL PATH OF C-KERMIT 9.0
  4. # and the script should be given execute permission.
  5. #
  6. # Reads TSV-format web log for a bilingual English-Spanish website.
  7. # Extracts all Google searches.
  8. # Converts the coded search string into plain text.
  9. # If charset of search string is declared, converts it to ISO-8859-1.
  10. # If charset is not declared, it is tested for UTF-8 and converted.
  11. # Normalized search strings are tabulated using associative arrays.
  12. #
  13. # Illustrates:
  14. # . new \fsplit behavior - CK9.0
  15. # . new \fsqueeze() function
  16. # . message and if debug commands - New in CK9.0 Alpha.03
  17. # . decodehex function - New in CK9.0 Alpha.05
  18. # . stringtype function - New in CK9.0 Alpha.05
  19. # . use of MIME charset names - New in CK9.0 Alpha.05
  20. # . associative arrays (not new but little known)
  21. #
  22. # Frank da Cruz, Columbia University, April 2010
  23.  
  24. if not def \%1 exit 1 "usage: weblog logfilename"
  25.  
  26. fopen /read \%i \fcontents(\%1)
  27. if fail exit 1 
  28.  
  29. .lines = 0
  30. .google = 0
  31.  
  32. if def \$(DEBUG) set debug message on   # To print debugging messages
  33.  
  34. while true {
  35.     fread /line \%i line        # Read a record
  36.     if fail break            # End of file
  37.     incr lines                # Have record - count it
  38.     void \fsplit(\m(line),&a,\9,ALL,,1)    # Split it into fields
  39.     if not \findex(.html,\&a[5]) continue # Reject all non-HTML accesses
  40.     .isgoogle := \findex(.google.,\&a[8]) # Reject all non-Google accesses
  41.     if not isgoogle continue
  42.  
  43.     increment google            # Have a Google HTML record
  44.     void \fsplit(\&a[8],&b,&?,ALL,,1)    # Split it into 'clauses'
  45.     if debug show array b
  46.     undef charset string        # Clear result variables
  47.     for i 1 \fdim(&b) 1 {        # Loop through clauses
  48.         void \fsplit(\&b[i],&c,=,ALL)    # Split clause into ID and value
  49.         if equ "\&c[1]" "q" .string := \&c[2] # Query string
  50.         else if equ "\&c[1]" "ie" .charset := \&c[2] # Character set
  51.     }
  52.     if not def string continue        # No string - skip this record
  53.     if debug show mac charset string
  54.  
  55.     # Normalize the string....
  56.  
  57.     .string := \fsqueeze(\flower(\fdecodehex(\freplace(\m(string),+,\32))))
  58.     if debug show mac string
  59.     if def charset {
  60.         _increment cset<\fupper(\m(charset))>
  61.         if debug echo "CONVERTING [\m(string)] \m(charset)->ISO-8859-1"
  62.     .string := \fcvtcset(\m(string),\m(charset),iso-8859-1)
  63.     if debug show mac string
  64.     } else if equal "\fstringtype(\m(string))" "UTF8" {
  65.     .string := \fcvtcset(\m(string),UTF-8,iso-8859-1)
  66.     if debug show mac string
  67.         _increment cset<UNDECLARED_UTF-8_DETECTED> 
  68.     } else {
  69.         _increment cset<UNDECLARED>
  70.     }
  71.     .string := \fsubstitute(\m(string),┴╔═╙┌▄╤,ßΘφ≤·ⁿ±)
  72.     .string := \freplace(\m(string),espanol,espa±ol)
  73.     .string := \freplace(\m(string),ingles,inglΘs)
  74.     _increment search<\m(string)>
  75. }
  76. # Finished - Display statistics
  77.  
  78. echo
  79. echo "Records:  \flpad(\m(lines),8)"
  80. echo "Google:   \flpad(\m(google),8)"
  81. .n := \faaconvert(search,&a,&b)
  82. echo "Unique:   \flpad(\m(n),8)"
  83. .m := \faaconvert(cset,&c,&d)
  84. echo "Charsets: \flpad(\m(m),8)"
  85. echo
  86. echo Charsets by by frequency...
  87. array sort /reverse /numeric &d &c
  88. for i 1 m 1 {
  89.     echo \flpad(\m(i),3). \flpad([\&d[i]],8) \&c[i]
  90. }
  91. if > n 20 .n = 20
  92. echo
  93. echo Top \m(n) searches by frequency...
  94. array sort /reverse /numeric &b &a
  95. for i 1 n 1 {
  96.     echo \flpad(\m(i),3). \flpad([\&b[i]],8) \&a[i]
  97. }
  98. exit 0
  99.  
  100. ; Local Variables:
  101. ; comment-column:40
  102. ; comment-start:"# "
  103. ; End:
  104.