def OnInit(self):
     start = None
     clock = 0
     a_u = []
     a_t = []
     b = open(sys.argv[1], 'r').read()
     if b[0] == '(':
         a_t, a_u = eval(b)
     else:
         last_t = -1
         for l in b.split('\n'):
             try:
                 t, u, clock = l.split(' ')
             except:
                 try:
                     t, u = l.split(' ')
                 except:
                     break
             clock = float(clock)
             if start == None:
                 start = clock
             #elif clock < (start + (60 * 70)):
             #    continue
             #elif clock > (start + (60 * 90)):
             #    print clock
             #    break
             t = round(float(t))
             if t == last_t:
                 continue
             u = round(float(u))
             a_t.append(t)
             a_u.append(u)
             last_t = t
     a_t, a_u = filter_points.filter_points(a_t, a_u)
     print filter_points.standard_deviation(a_t)
     f = create_plotwindow(a_u, a_t)
     self.SetTopWindow(f)
     #u_plotwindow.area_expose_cb(u_plotwindow.u_area, None)
     
     return True
    def draw_points(self, area, a, b):
        if len(a) < 3:
            return
        x1 = a[-1]
        y1 = b[-1]
        w, h = area.GetSize()
        a, b, ma, mb = self.scale_points(a, b, w, h)
        c = zip(a, b)
        c = filter_points.remove_dupes(c)
        
        area.Clear()
        area.SetPen(wx.Pen((0,0,0)))
       
        area.DrawPoints(c)

##        try:
##            rc = c#random.sample(c, 1000)
##            ra = [ x for x, y in rc ]
##            rb = [ y for x, y in rc ]
##
##            #a, b, c = matfunc.polyfit((ra, rb))
##            #lines = self.get_lines(w, a, b, c)
##            #a, b, c, d = matfunc.polyfit((ra, rb), 3)
##            a, b = matfunc.polyfit((ra, rb), 1)
##            lines = self.get_lines1(w, a, b)
##            area.DrawLines(lines)
##            #area.draw_lines(area.gc, lines)
##        except Exception, e:# ZeroDivisionError:
##            print e
##            pass


        u = SizedList(10)
        t = SizedList(10)
        points = []
        for (x,y) in c:
            u.append(x)
            t.append(y)

            #x2 = float(sum(u)) / float(len(u))
            x2 = x
            y2 = h - filter_points.standard_deviation(t)
            #y2 = float(sum(t)) / float(len(t))
            points.append((x2,y2))
                    
        #area.draw_lines(area.gc, points)
        area.SetPen(wx.Pen((255,0,0)))
        area.DrawPoints(points)

        def avg_atan2_p(a, b):
            atan = 0
            x = 0
            y = 0
            as = 0
            t = float(len(a))
            for p1, p2 in zip(a, b):
                atan += math.atan2(p1, p2) / t
                try:
                    as += math.sqrt(p1**2 + p2**2) / t
                except ZeroDivisionError, e:
                    print e