Created
November 8, 2012 08:47
-
-
Save metametaclass/4037621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns main | |
(:use [clojure.string :only [trim split]]) | |
(:import (java.io BufferedReader FileReader))) | |
(defn process-file-by-desc | |
"Process large file line-by-line with specified process functions" | |
([file-name process-list separator] | |
(let [zero (map first process-list) | |
oper (map second process-list) | |
line-preprocess (map #(get % 2) process-list) | |
parse-line (fn [line] (split (trim line) separator)) | |
line-func (fn [acc [line splitted-line]] | |
(vec | |
(map (fn [accItem operItem preprocItem] ; parts of process-list | |
(operItem accItem (preprocItem line splitted-line))) | |
acc oper line-preprocess)))] | |
(println zero) | |
(println oper) | |
(println line-preprocess) | |
(with-open [rdr (BufferedReader. (FileReader. file-name))] | |
(->> rdr | |
(line-seq) | |
(map (juxt identity parse-line)) | |
(reduce line-func zero))))) | |
([file-name process-list] (process-file-by-desc file-name process-list #" "))) | |
(defn- parseInt | |
[str] | |
(Integer/parseInt str)) | |
(def process-libtorrent-logs | |
[[0 + (fn [_ [_ _ read bytes _]] | |
(if (= read "read") | |
(parseInt bytes) | |
0)) ] | |
]) | |
(def total | |
(process-file-by-desc | |
"193.160.231.33_read_bytes.log" | |
process-libtorrent-logs | |
)) | |
(println total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment