PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/bike/error-find.lisp

https://bitbucket.org/mt/biobike
Lisp | 247 lines | 158 code | 51 blank | 38 comment | 8 complexity | d421a9b2f89610940f1641d5832e458f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. ;;; -*- Package: bio; mode: lisp; base: 10; Syntax: Common-Lisp; -*-
  2. (in-package :bio)
  3. ;;; +=========================================================================+
  4. ;;; | Copyright (c) 2002, 2003, 2004 JP Massar, Jeff Shrager, Mike Travers |
  5. ;;; | |
  6. ;;; | Permission is hereby granted, free of charge, to any person obtaining |
  7. ;;; | a copy of this software and associated documentation files (the |
  8. ;;; | "Software"), to deal in the Software without restriction, including |
  9. ;;; | without limitation the rights to use, copy, modify, merge, publish, |
  10. ;;; | distribute, sublicense, and/or sell copies of the Software, and to |
  11. ;;; | permit persons to whom the Software is furnished to do so, subject to |
  12. ;;; | the following conditions: |
  13. ;;; | |
  14. ;;; | The above copyright notice and this permission notice shall be included |
  15. ;;; | in all copies or substantial portions of the Software. |
  16. ;;; | |
  17. ;;; | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
  18. ;;; | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
  19. ;;; | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
  20. ;;; | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
  21. ;;; | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
  22. ;;; | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
  23. ;;; | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
  24. ;;; +=========================================================================+
  25. ;;; Author: Mark Slupesky, JP Massar.
  26. #|
  27. <6>> (setq p (ppcre:create-scanner \"attempt to call .* which is an undefined function."))
  28. :: #<Closure (:INTERNAL CL-PPCRE::CREATE-SCANNER-AUX 4) @ #x921e5c1a>
  29. <7>> (ppcre:all-matches p "attempt to call `BLAH' which is an undefined function.")
  30. :: (0 54)
  31. <8>> (ppcre:all-matches p "sdfa.")
  32. :: NIL
  33. <9>> (ppcre:all-matches p "attempt.")
  34. :: NIL
  35. |#
  36. ;;
  37. ;; open each file once, do the regexps on each file
  38. ;; all the error strings end up in teh string vector
  39. ;; clean up the error strings with extra spaces.
  40. (length (setq m (remove-if (lambda (x) (second x)) *matching-strings-array*)))
  41. (defvar *matching-strings-array* nil)
  42. (defvar *string-counter* 0)
  43. (defparameter *error-lists-2*
  44. ".* does not exist, cannot load"
  45. "[iI]llegal keyword given"
  46. "can't figure this out"
  47. "[iI]f-true statement missing body"
  48. "comma not inside a backquote"
  49. "figure this out"
  50. "not a list of organisms")
  51. (defparameter *error-lists*
  52. (list
  53. "[aA]ttempt to call .* which is an undefined function"
  54. "[eE]of encountered on stream"
  55. "[aA]ttempt to take the value of the unbound variable"
  56. ".* found where a LOOP keyword or LOOP type keyword expected"
  57. "[fF]unction position must contain a symbol or lambda expression"
  58. "is an unknown keyword"
  59. "[bB]adly formed let"
  60. "[Ii]llegal argument to"
  61. "is not of the expected type"
  62. "expects .* arguments?"
  63. "[aA]ttempt to access the name field"
  64. "[dD]uplicated .* iteration variable"
  65. "does not introduce .* that can follow"
  66. "[aA]rgument must be a list"
  67. "[sS]ource code ran out when another token was expected"
  68. "[aA]ttempt to take the length of a non-sequence"
  69. "[gG]ot .* args?, wanted .* args?"
  70. "where a form was expected"
  71. "is not an even number of items"
  72. "[tT]rying to access never set position"
  73. "[aA]ttempt to divide .* by (0|(zero))"
  74. "[aA]ttempt to take the (car)|(cdr) of .* which is not listp"
  75. "Compound form expected, but found"
  76. "Missing keyword or value"
  77. "Package .* not found"
  78. "Attempt to store the wrong type of a value"
  79. "is not the name or nickname of an available organism"
  80. "Destructuring type pattern .* contains unrecognized type keyword"
  81. "[iI]nvalid key-word"
  82. "[Oo]bject of function must be a list"
  83. "found where LOOP keyword expected"
  84. "[iI]teration in LOOP follows body code"
  85. "not a list, gene, protein, replicon, contig, organism, or string"
  86. "[Ee]ntity .* does not exist or is not a valid frame"
  87. ))
  88. (defvar *errors-contexts*
  89. (list
  90. "/home/biovcu/bioetc/saved-sl2/logs1.txt" "/home/biovcu/bioetc/saved-sl2/logs2.txt"
  91. "/home/biovcu/bioetc/saved-sl2/logs3.txt" "/home/biovcu/bioetc/saved-sl2/logs4.txt"
  92. "/home/biovcu/bioetc/saved-sl2/logs5.txt" "/home/biovcu/bioetc/saved-sl2/logs6.txt"
  93. "/home/biovcu/bioetc/saved-sl2/logs7.txt" "/home/biovcu/bioetc/saved-sl2/logs8.txt"
  94. "/home/biovcu/bioetc/saved-sl2/logs8.txt" "/home/biovcu/bioetc/saved-sl2/logs9.txt"
  95. "/home/biovcu/bioetc/saved-sl2/logs10.txt" "/home/biovcu/bioetc/saved-sl2/logs11.txt"
  96. "/home/biovcu/bioetc/saved-sl2/logs12.txt"))
  97. (defun in-search-out (thing in-file)
  98. (let* ((stringed-file (file-to-string in-file :max 80000000))
  99. (string-vec (coerce (simple-string-split stringed-file #\Newline) 'vector)))
  100. (loop for string across string-vec
  101. for count from 0
  102. when (search thing string)
  103. collect
  104. (let* ((actual-error-start-index (+ count 1))
  105. (actual-error-start-string (elt string-vec actual-error-start-index)))
  106. (if (position #\> actual-error-start-string)
  107. actual-error-start-string
  108. (let ((too-long-error nil))
  109. (do ((i 1 (+ i 1))
  110. (str actual-error-start-string (elt string-vec (+ i actual-error-start-index))))
  111. ((position #\> str)
  112. (setq too-long-error (reverse (push str too-long-error))))
  113. (push str too-long-error))
  114. (string-join too-long-error #\Space)))))))
  115. (Defun errors-loop (dir-with-logs out-file)
  116. (with-open-file (o out-file :direction :output :if-exists :supersede :if-does-not-exist :create)
  117. (with-standard-io-syntax
  118. (pprint
  119. (remove-if 'null (loop for log in (directory dir-with-logs)
  120. collect
  121. (in-search-out "Actual error:" log)))
  122. o)
  123. )))
  124. (defun pesky-spaces (string)
  125. (string-join
  126. (remove
  127. ""
  128. (string-split string #\Space) :test 'string-equal) #\Space))
  129. (defun get-error-stats (&optional (regexps *error-lists*))
  130. (let ((lots-of-errors nil))
  131. (loop for file in *errors-contexts* do
  132. (with-open-file (p file)
  133. (let ((these-errors (flatten (read p))))
  134. (setq lots-of-errors (nconc lots-of-errors these-errors))
  135. )))
  136. (let ((percentage-matched
  137. (loop for regexp in regexps collect
  138. (progn
  139. (setq *string-counter* 0)
  140. (list
  141. regexp
  142. (regexp-in-list regexp
  143. (mapcar 'pesky-spaces
  144. (flatten lots-of-errors))))))))
  145. (cformatt "Total percentage matched ~$~%"
  146. (reduce '+ percentage-matched :key 'second))
  147. (setq percentage-matched (sort percentage-matched '> :key 'second))
  148. (loop for (regexp pct) in percentage-matched do
  149. (cformatt "Regexp ~S matched ~$%~%"
  150. regexp pct)))))
  151. (defun regexp-in-list (regexp ls)
  152. (let ((scanner (ppcre:create-scanner regexp))
  153. (how-many 0))
  154. (loop for error in ls do
  155. (when (ppcre:all-matches scanner error)
  156. (progn
  157. (setf
  158. (second (aref *matching-strings-array* *string-counter*)) T)
  159. (incf how-many)))
  160. (incf *string-counter*))
  161. (let ((percentage (* 100 (/ how-many (length *matching-strings-array*)))))
  162. percentage)))
  163. (defun number-of-errors (&optional (error-files *errors-contexts*))
  164. (let ((string-list nil))
  165. (loop for file in error-files
  166. sum
  167. (with-open-file (p file :direction :input)
  168. (let ((strings (flatten (read p))))
  169. (prog1
  170. (length strings)
  171. (setq string-list (nconc string-list strings))
  172. )))
  173. finally
  174. (setq *matching-strings-array*
  175. (make-array (length string-list)
  176. :initial-contents
  177. (mapcar (lambda (x) (list x nil)) (mapcar 'pesky-spaces string-list)))))))
  178. (defun top-level ()
  179. (setq *string-counter* 0)
  180. (number-of-errors)
  181. (cformatt "Number of errors: ~D" (length *matching-strings-array*))
  182. (get-error-stats))
  183. (defun collect-errors-from-logs ()
  184. (progn
  185. (errors-loop "/home/biovcu/bioetc/saved-sl2/g/" "/home/biovcu/bioetc/saved-sl2/logs1.txt")
  186. (errors-loop "/home/biovcu/bioetc/saved-sl2/h/" "/home/biovcu/bioetc/saved-sl2/logs2.txt")
  187. (errors-loop "/home/biovcu/bioetc/saved-sl2/i/" "/home/biovcu/bioetc/saved-sl2/logs3.txt")
  188. (errors-loop "/home/biovcu/bioetc/saved-sl2/j/" "/home/biovcu/bioetc/saved-sl2/logs4.txt")
  189. (errors-loop "/home/biovcu/bioetc/saved-sl2/l/" "/home/biovcu/bioetc/saved-sl2/logs5.txt")
  190. (errors-loop "/home/biovcu/bioetc/saved-sl2/m/" "/home/biovcu/bioetc/saved-sl2/logs6.txt")
  191. (errors-loop "/home/biovcu/bioetc/saved-sl2/n/" "/home/biovcu/bioetc/saved-sl2/logs7.txt")
  192. (errors-loop "/home/biovcu/bioetc/saved-sl2/o/" "/home/biovcu/bioetc/saved-sl2/logs8.txt")
  193. (errors-loop "/home/biovcu/bioetc/saved-sl2/p/" "/home/biovcu/bioetc/saved-sl2/logs9.txt")
  194. (errors-loop "/home/biovcu/bioetc/saved-sl2/q/" "/home/biovcu/bioetc/saved-sl2/logs10.txt")
  195. (errors-loop "/home/biovcu/bioetc/saved-sl2/r/" "/home/biovcu/bioetc/saved-sl2/logs11.txt")
  196. (errors-loop "/home/biovcu/bioetc/saved-sl2/s/" "/home/biovcu/bioetc/saved-sl2/logs12.txt")))