import time
import copy
from tabulate import tabulate

# LogStorage - read and do basic processing of incoming data
class LogStorage:
    def __init__(self):
        self.spans = []
        self.annotations = []

        self.minNumOfSpansToFlush = 1
        self.minNumOfAnnotationsToFlush = 1

    def push(self, row):
        # process row to attach data to span / annotation
        self.process(row)

        if len(self.spans) >= self.minNumOfSpansToFlush:
            self.flushSpans()

        if len(self.annotations) >= self.minNumOfAnnotationsToFlush:
            self.flushAnnotations()

    def process(self, row):
        # process row data
        if row['request_type'] == 'c':
            print 'Client Request, process client start and client recieve'
            print row['timestamp-abs-Start'] + ', ' + row['timestamp-abs-Resp']
        elif row['request_type'] == 'b':
            print 'Backend Request, process client start, server recieve, server send, client recieve'
            print

    def flushSpans(self):
        print self.spans
        self.spans = []

    def flushAnnotations(self):
        print self.annotations
        self.annotations = []

@@ -648,16 +648,147 @@
 ow data%0A
+%0A        if 'debug' not in row:%0A            row%5B'debug'%5D = 0%0A%0A        if 'parent_id' not in row:%0A            row%5B'parent_id'%5D = 0%0A%0A
         
@@ -834,151 +834,655 @@
     
-print 'C
+# c
 lient 
-R
+r
 equest
-, process client start and client recieve'%0A            print row%5B'timestamp-abs-Start'%5D + ', ' + row%5B'timestamp-abs-Resp'%5D
+ considered for, span processing%0A            span = %7B%5C%0A                'span_id': row%5B'span_id'%5D, %5C%0A                'parent_id': row%5B'parent_id'%5D, %5C%0A                'trace_id': row%5B'trace_id'%5D, %5C%0A                'span_name': row%5B'span_name'%5D, %5C%0A                'debug': row%5B'debug'%5D, %5C%0A                'duration': row%5B'timestamp-duration-Start'%5D, %5C%0A                'created_ts': row%5B'timestamp-abs-Start'%5D%0A            %7D%0A%0A            self.spans.append( copy.copy(span) )%0A%0A            span%5B'duration'%5D = row%5B'timestamp-duration-Resp'%5D%0A            span%5B'created_ts'%5D = row%5B'timestamp-abs-Resp'%5D%0A%0A            self.spans.append( span )%0A
 %0A   

add spans to logmanager