Class: EventChart
- Inherits:
-
Object
- Object
- EventChart
- Defined in:
- lib/eventchart.js.rb
Instance Method Summary collapse
-
#exuz(rootPath) ⇒ Object
解压.
-
#initialize ⇒ EventChart
constructor
A new instance of EventChart.
-
#reportEvent(eventType, event) ⇒ Object
解压.
-
#scheduleWriteEventTimer ⇒ Object
Schedule a timer to wirte evnetys.
-
#writeEvents ⇒ Object
def exuz(rootPath).
Constructor Details
#initialize ⇒ EventChart
Returns a new instance of EventChart.
10 11 12 13 14 |
# File 'lib/eventchart.js.rb', line 10 def initialize @events=[] # Event list @lastTimerTime=Time.now end |
Instance Method Details
#exuz(rootPath) ⇒ Object
解压
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 |
# File 'lib/eventchart.js.rb', line 54 def exuz(rootPath) result = true # 解压结果 currentBlockFile = File.new(rootPath, 'rb') # 打开文件 @wholeFileContent = currentBlockFile.read # 读取全部内容 currentBlockFile.close # 关闭文件 wholeCborByteArray = @wholeFileContent # 从第5个到末尾 begin # 可能出错。 = {:tolerant => true} wholeCbor = CBOR.decode(wholeCborByteArray, ) # 解码 #puts wholeCbor x=1..wholeCbor.length y=wholeCbor.map { |event| event["optimisticScore"] } y1=wholeCbor.map { |event| event["speciesScore"] } #puts x #puts y xString="" x.each { |value| xString=xString+"#{value}," } xString="[#{xString}]" #puts xString yString="" y.each { |value| yString=yString+"#{value}," } yString="[#{yString}]" #puts yString yString1="" y1.each { |value| yString1=yString1+"#{value}," } yString1="[#{yString1}]" #puts yString1 result =true # 解压成功 rescue EOFError => e # 文件内容提前到末尾。一般是压缩包文件未传输完全 。 #puts "Error: the exz file may be incomplete." # 报告错误。文件可能不完整。 result = false # 失败 end #begin # 可能出错。 wholeCbor end |
#reportEvent(eventType, event) ⇒ Object
解压
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eventchart.js.rb', line 30 def reportEvent(eventType, event) event['eventType']=eventType @events << event #EventMachine.add_timer(10) { writeEvents } scheduleWriteEventTimer # Schedule a timer to wirte evnetys. end |
#scheduleWriteEventTimer ⇒ Object
Schedule a timer to wirte evnetys.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eventchart.js.rb', line 17 def scheduleWriteEventTimer time=Time.now if (time-@lastTimerTime)>1 # 1 timer 1 second at most @timer&.cancel # Cancel existing timer. @timer = EventMachine::Timer.new(10) { writeEvents } @lastTimerTime= time end #if (time-@lastTimerTime)>1 # 1 timer 1 second at most end |
#writeEvents ⇒ Object
def exuz(rootPath)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/eventchart.js.rb', line 41 def writeEvents compressed= @events.to_cbor datastore= "events.cx" # 配置文件路径 extremeZipOutputFile = File.new(datastore, 'wb') # 创建文件 extremeZipOutputFile.syswrite(compressed) # 写入文件 extremeZipOutputFile.close # 关闭文件 @events.clear end |