Class: Vodstamp
- Inherits:
-
Object
- Object
- Vodstamp
- Defined in:
- lib/vodstamp.rb
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
-
#all(args) ⇒ Object
def.
-
#build(args) ⇒ Object
def.
-
#build_timestamps(rawlog, rawsplits, offset) ⇒ Object
Working Methods ###########################################################.
-
#err(msg) ⇒ Object
def.
-
#filter(args) ⇒ Object
def.
-
#filter_chatlog(all_messages, rawlog, source = nil) ⇒ Object
def.
-
#msg(msg) ⇒ Object
def.
-
#readable_time(time) ⇒ Object
Helpers ###################################################################.
-
#version(args) ⇒ Object
Commands ##################################################################.
Instance Method Details
#all(args) ⇒ Object
def
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vodstamp.rb', line 11 def all(args) msg "filtering all from [#{args[0]}] to [#{args[1]}]" inputfile = File.(args[0]); outputfile = File.(args[1]); if ! File.exist? inputfile err "The file [#{inputfile}] does not exist." end rawlog = File.read inputfile rawlog = rawlog.split "\n" log = filter_chatlog true, rawlog, arg[2] File.write(outputfile, log.join("\n")) msg "fin" end |
#build(args) ⇒ Object
def
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vodstamp.rb', line 49 def build(args) msg "building from [#{args[0]}] to [#{args[1]}] with splits [#{args[2]}] and offset of #{args[3]} seconds" inputfile = File.(args[0]); outputfile = File.(args[1]); splitsfile = File.(args[2]); if ! File.exist? inputfile err "The file [#{inputfile}] does not exist." end if ! File.exist? splitsfile err "The file [#{splitsfile}] does not exist." end rawlog = File.read inputfile rawlog = rawlog.split "\n" rawsplits = File.read splitsfile rawsplits = rawsplits.split "\n" = rawlog, rawsplits, args[3].to_i File.write(outputfile, .join("\n")) msg "fin" end |
#build_timestamps(rawlog, rawsplits, offset) ⇒ Object
Working Methods ###########################################################
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vodstamp.rb', line 78 def (rawlog, rawsplits, offset) # parse timestamps logpattern = /[a-zA-Z]+ [0-9]+ ([0-9]{2}):([0-9]{2}):([0-9]{2}) <([a-zA-Z0-9_-]+)> \[timestamp\] (T-([0-9]{2}):([0-9]{2}) (.*)|ignore last|todo|realign)/ log = []; diff = nil rawlog.each do |line| match = logpattern.match(line) next if match[6] == nil # get data h = match[1].to_i m = match[2].to_i s = match[3].to_i om = match[6].to_i os = match[7].to_i = match[8] # convert to seconds time_s = s + m * 60 + h * 60 * 60 offset_s = os + om * 60 if diff === nil diff = time_s - offset_s end time_s = time_s - offset_s - diff log.push({ time: time_s, msg: }) end#each # parse splits splitpattern = /([a-zA-Z0-9 ]+)\. ([0-9]{2}):([0-9]{2}):([0-9]{2})/ splits = [] rawsplits.each do |line| match = splitpattern.match(line) h = match[2].to_i m = match[3].to_i s = match[4].to_i # convert to seconds time_s = s + m * 60 + h * 60 * 60 splits.push({ time: time_s, name: match[1] }) end#each # generate timestamps times = [] splitidx = 0 this_split = splits[splitidx] split_max_time = this_split[:time] split_diff = -offset times.push([]); log.each do |entry| if offset + entry[:time] > split_max_time split_diff += this_split[:time] splitidx += 1 this_split = splits[splitidx] split_max_time += this_split[:time] times.push([]) end times[splitidx].push({ time: entry[:time] - split_diff, msg: entry[:msg] }) end#each = [] idx = 0 print " " # progress prefix times.each do |stamps| .push " -- #{splits[idx][:name]} -- " stamps.each do |time| minutes = (time[:time] / 60).to_i seconds = time[:time] - minutes * 60 .push readable_time(time[:time]) + " #{time[:msg]}" print '.' # progress indicator end#each idx += 1 end#each puts return ; end |
#err(msg) ⇒ Object
def
198 199 200 201 |
# File 'lib/vodstamp.rb', line 198 def err(msg) puts " Err: #{msg}" exit end |
#filter(args) ⇒ Object
def
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vodstamp.rb', line 30 def filter(args) msg "filtering [#{args[0]}] to [#{args[1]}] using source [#{args[2]}]" inputfile = File.(args[0]); outputfile = File.(args[1]); if ! File.exist? inputfile err "The file [#{inputfile}] does not exist." end rawlog = File.read inputfile rawlog = rawlog.split "\n" filter_chatlog false, rawlog, args[2] File.write(outputfile, log.join("\n")) msg "fin" end |
#filter_chatlog(all_messages, rawlog, source = nil) ⇒ Object
def
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/vodstamp.rb', line 155 def filter_chatlog(, rawlog, source = nil) log = [] if logpattern = /.* \[timestamp\] .*/ else # only correct ones logpattern = /[a-zA-Z]+ [0-9]+ ([0-9]{2}):([0-9]{2}):([0-9]{2}) <([a-zA-Z0-9_-]+)> \[timestamp\] (T-([0-9]{2}):([0-9]{2}) .*|ignore last|todo|realign)/ end ignorepattern = /\[timestamp\] ignore last/ print " " # progress prefix rawlog.each do |line| if (match = logpattern.match(line)) != nil if || match[4] == source if ! && ignorepattern.match(line) != nil log.pop print ',' # indicate backtracking else # normal line log.push line print '.' # indicate progress end end end end#each puts # new line at end of progress return log end |
#msg(msg) ⇒ Object
def
203 204 205 |
# File 'lib/vodstamp.rb', line 203 def msg(msg) puts " #{msg}" end |
#readable_time(time) ⇒ Object
Helpers ###################################################################
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/vodstamp.rb', line 187 def readable_time(time) hours = (time / 3600).to_i minutes = ((time - hours) / 60).to_i seconds = time - hours * 3600 - minutes * 60 if hours != 0 return ('%02d' % hours) + ':' + ('%02d' % minutes) + ':' + ('%02d' % seconds) else return ('%02d' % minutes) + ':' + ('%02d' % seconds) end end |