(request)
Time the different components of the forecast
Time the different components of the forecast
Time the different components of the forecast
def timeit(request):
        """
        Time the different components of the forecast
        """
        
        import timeit
        import ServerSideExtension_pb2 as SSE
        
        # Create a log file for the 
        logfile = os.path.join(os.getcwd(), 'logs', 'Prophet Performance Log.txt')

        def t1(request):
            return ProphetForQlik(request)

        def t2(predictor):
            return predictor.predict()

        def t3(forecast):
            return forecast.apply(lambda result: iter([SSE.Dual(numData=result)]))

        def t4(response_rows):
            return response_rows.apply(lambda duals: SSE.Row(duals=duals)).tolist()
        
        def dotime1():
            t = timeit.Timer("t1(request)")
            time = t.timeit(1)
            sys.stdout.write("Time taken to create an instance of ProphetForQlik: {}\n".format(time))
            with open(logfile,'a') as f:
                f.write("Time taken to create an instance of ProphetForQlik: {}\n".format(time))
            
        predictor = ProphetForQlik(request)
        
        def dotime2():
            t = timeit.Timer("t2(predictor)")
            time = t.timeit(1)
            sys.stdout.write("Time taken to calculate the forecast: {}\n".format(time))
            with open(logfile,'a') as f:
                f.write("Time taken to calculate the forecast: {}\n".format(time))
        
        forecast = predictor.predict()
        
        def dotime3():
            t = timeit.Timer("t3(forecast)")
            time = t.timeit(1)
            sys.stdout.write("Time taken to convert results to SSE.Dual: {}\n".format(time))
            with open(logfile,'a') as f:
                f.write("Time taken to convert results to SSE.Dual: {}\n".format(time))
        
        response_rows = forecast.apply(lambda result: iter([SSE.Dual(numData=result)]))
        
        def dotime4():
            t = timeit.Timer("t4(response_rows)")
            time = t.timeit(1)
            sys.stdout.write("Time taken to convert duals to SSE.Row: {}\n".format(time))
            with open(logfile,'a') as f:
                f.write("Time taken to convert duals to SSE.Row: {}\n".format(time))

        import builtins
        builtins.__dict__.update(locals())

        dotime1()
        dotime2()
        dotime3()
        dotime4()
def timeit ( request ) : import timeit import ServerSideExtension_pb2 as SSE # Create a log file for the  logfile = os . path . join ( os . getcwd ( ) , 'logs' , 'Prophet Performance Log.txt' ) def t1 ( request ) : return ProphetForQlik ( request ) def t2 ( predictor ) : return predictor . predict ( ) def t3 ( forecast ) : return forecast . apply ( lambda result : iter ( [ SSE . Dual ( numData = result ) ] ) ) def t4 ( response_rows ) : return response_rows . apply ( lambda duals : SSE . Row ( duals = duals ) ) . tolist ( ) def dotime1 ( ) : t = timeit . Timer ( "t1(request)" ) time = t . timeit ( 1 ) sys . stdout . write ( "Time taken to create an instance of ProphetForQlik: {}\n" . format ( time ) ) with open ( logfile , 'a' ) as f : f . write ( "Time taken to create an instance of ProphetForQlik: {}\n" . format ( time ) ) predictor = ProphetForQlik ( request ) def dotime2 ( ) : t = timeit . Timer ( "t2(predictor)" ) time = t . timeit ( 1 ) sys . stdout . write ( "Time taken to calculate the forecast: {}\n" . format ( time ) ) with open ( logfile , 'a' ) as f : f . write ( "Time taken to calculate the forecast: {}\n" . format ( time ) ) forecast = predictor . predict ( ) def dotime3 ( ) : t = timeit . Timer ( "t3(forecast)" ) time = t . timeit ( 1 ) sys . stdout . write ( "Time taken to convert results to SSE.Dual: {}\n" . format ( time ) ) with open ( logfile , 'a' ) as f : f . write ( "Time taken to convert results to SSE.Dual: {}\n" . format ( time ) ) response_rows = forecast . apply ( lambda result : iter ( [ SSE . Dual ( numData = result ) ] ) ) def dotime4 ( ) : t = timeit . Timer ( "t4(response_rows)" ) time = t . timeit ( 1 ) sys . stdout . write ( "Time taken to convert duals to SSE.Row: {}\n" . format ( time ) ) with open ( logfile , 'a' ) as f : f . write ( "Time taken to convert duals to SSE.Row: {}\n" . format ( time ) ) import builtins builtins . __dict__ . update ( locals ( ) ) dotime1 ( ) dotime2 ( ) dotime3 ( ) dotime4 ( )