Browse Source

add performance measurements

Eren Yilmaz 6 years ago
parent
commit
e1c90ab7e5
2 changed files with 20 additions and 9 deletions
  1. 15 9
      client_controller.py
  2. 5 0
      run_server.py

+ 15 - 9
client_controller.py

@@ -134,13 +134,13 @@ def help():
         params = signature(method).parameters
         command_table.append([cmd] + [p for p in params])
 
-    print(_my_tabulate(command_table,tablefmt='pipe',headers=['command',
-                                                              'param 1',
-                                                              'param 2',
-                                                              'param 3',
-                                                              'param 4',
-                                                              'param 5',
-                                                              ]))
+    print(_my_tabulate(command_table, tablefmt='pipe', headers=['command',
+                                                                'param 1',
+                                                                'param 2',
+                                                                'param 3',
+                                                                'param 4',
+                                                                'param 5',
+                                                                ]))
     print('NOTE:')
     print('  All parameters for all commands are optional!')
     print('  Commands can be combined in one line with ; between them.')
@@ -231,7 +231,7 @@ def buy(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
     if limit is not None and \
             float(limit) <= 0 and \
             input(input('Are you sure you want to use such a low limit (limit=' + str(
-            limit) + '? (type in "yes" or something else):') != 'yes'):
+                limit) + '? (type in "yes" or something else):') != 'yes'):
         print('Order was not placed.')
         return
 
@@ -278,7 +278,7 @@ def sell(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
     if limit is not None and \
             float(limit) <= 0 and \
             input(input('Are you sure you want to use such a low limit (limit=' + str(
-            limit) + '? (type in "yes" or something else):') != 'yes'):
+                limit) + '? (type in "yes" or something else):') != 'yes'):
         print('Order was not placed.')
         return
 
@@ -381,6 +381,12 @@ def tradables():
         print(_my_tabulate(response['data'],
                            headers=['Name', 'Course', 'Market Cap.'],
                            tablefmt="pipe"))
+        world_wealth = 0
+        for row in response['data']:
+            if row[2] is not None:
+                world_wealth += row[2]
+        print('Estimated worldwide wealth:', world_wealth)
+
     else:
         if 'error_message' in response:
             print('Data access failed with message:', response['error_message'])

+ 5 - 0
run_server.py

@@ -1,4 +1,5 @@
 import sqlite3
+import time
 
 import connection
 import server_controller
@@ -28,8 +29,10 @@ if __name__ == '__main__':
 
     @route('/<path>', method='POST')
     def process(path):
+        start = time.clock()
         path = path.strip().lower()
         if path not in valid_routes:
+            print('Processing time:', time.clock() - start)
             return not_found()
         response.content_type = 'application/json'
         method_to_call = getattr(server_controller, path)
@@ -40,10 +43,12 @@ if __name__ == '__main__':
                 model.connection.commit()
             else:
                 model.connection.rollback()
+            print('Processing time:', time.clock() - start)
             return resp
         except sqlite3.IntegrityError as e:
             print(e)
             model.connection.rollback()
+            print('Processing time:', time.clock() - start)
             return server_controller.bad_request('Action violates database constraints.')