From bc43df4104ea4e6882be03085bbe94a5cf922c9c Mon Sep 17 00:00:00 2001 From: SKai Date: Thu, 2 May 2019 23:19:49 +0000 Subject: [PATCH] improved logging --- dev_autopilot.ipynb | 100 ++++++++++++++++++++++---------------------- dev_autopilot.py | 100 ++++++++++++++++++++++---------------------- 2 files changed, 102 insertions(+), 98 deletions(-) diff --git a/dev_autopilot.ipynb b/dev_autopilot.ipynb index 927cd9c..25b5673 100644 --- a/dev_autopilot.ipynb +++ b/dev_autopilot.ipynb @@ -45,7 +45,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -140,7 +140,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -280,7 +280,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -303,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -368,7 +368,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -393,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -431,7 +431,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -448,7 +448,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -461,7 +461,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -484,7 +484,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -521,7 +521,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -541,7 +541,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -598,7 +598,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -614,7 +614,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -640,7 +640,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -656,7 +656,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -682,7 +682,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -698,7 +698,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -724,7 +724,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -740,7 +740,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -766,7 +766,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -782,7 +782,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -798,7 +798,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -815,7 +815,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -849,7 +849,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -865,7 +865,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -924,7 +924,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -940,7 +940,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -979,7 +979,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -1003,7 +1003,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -1036,7 +1036,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -1053,7 +1053,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -1099,7 +1099,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -1116,7 +1116,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -1132,7 +1132,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -1236,7 +1236,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -1253,7 +1253,7 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -1288,7 +1288,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -1305,7 +1305,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -1333,7 +1333,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -1350,7 +1350,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -1370,7 +1370,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -1408,12 +1408,14 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "def autopilot():\n", " logging.info('\\n'+200*'-'+'\\n'+'---- AUTOPILOT START '+179*'-'+'\\n'+200*'-')\n", + " logging.info('get_latest_log='+str(get_latest_log(PATH_LOG_FILES)))\n", + " logging.debug('ship='+str(ship()))\n", "# if ship()['target']:\n", "# undock()\n", " while ship()['target']:\n", @@ -1432,7 +1434,7 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ diff --git a/dev_autopilot.py b/dev_autopilot.py index 139bce2..b33a2d2 100644 --- a/dev_autopilot.py +++ b/dev_autopilot.py @@ -22,7 +22,7 @@ # ## Imports -# In[55]: +# In[1]: import sys @@ -42,7 +42,7 @@ import logging -# In[56]: +# In[2]: def resource_path(relative_path): @@ -58,14 +58,14 @@ def resource_path(relative_path): # ## Constants -# In[57]: +# In[3]: logging.basicConfig(filename='autopilot.log', level=logging.DEBUG) logging.info('\n'+200*'-'+'\n'+'---- AUTOPILOT DATA '+180*'-'+'\n'+200*'-') -# In[58]: +# In[4]: PATH_LOG_FILES = None @@ -90,7 +90,7 @@ def resource_path(relative_path): # ### Get latest log file -# In[59]: +# In[5]: def get_latest_log(path_logs=None): @@ -104,7 +104,7 @@ def get_latest_log(path_logs=None): return latest_log -# In[60]: +# In[6]: logging.info('get_latest_log='+str(get_latest_log(PATH_LOG_FILES))) @@ -112,7 +112,7 @@ def get_latest_log(path_logs=None): # ### Extract ship info from log -# In[61]: +# In[7]: def ship(): @@ -214,7 +214,7 @@ def ship(): return ship -# In[62]: +# In[8]: logging.debug('ship='+str(ship())) @@ -224,7 +224,7 @@ def ship(): # ### Get necessary keybinds -# In[63]: +# In[9]: def get_bindings(path_bindings=None): @@ -286,7 +286,7 @@ def get_bindings(path_bindings=None): return direct_input_keys -# In[64]: +# In[10]: keys = get_bindings(PATH_KEYBINDINGS) @@ -298,7 +298,7 @@ def get_bindings(path_bindings=None): # ### Send input -# In[65]: +# In[11]: def send(key, hold=None, repeat=1, repeat_delay=None, state=None): @@ -333,7 +333,7 @@ def send(key, hold=None, repeat=1, repeat_delay=None, state=None): sleep(KEY_REPEAT_DELAY) -# In[66]: +# In[12]: # sleep(3) @@ -342,7 +342,7 @@ def send(key, hold=None, repeat=1, repeat_delay=None, state=None): # ### Clear input -# In[67]: +# In[13]: def clear_input(to_clear=None): @@ -352,7 +352,7 @@ def clear_input(to_clear=None): logging.debug('clear_input') -# In[68]: +# In[14]: # clear_input(keys) @@ -362,7 +362,7 @@ def clear_input(to_clear=None): # ### Tkinter test -# In[69]: +# In[15]: # import tkinter as tk @@ -386,7 +386,7 @@ def clear_input(to_clear=None): # ### Get screen -# In[70]: +# In[16]: def get_screen(x_left, y_top, x_right, y_bot): @@ -398,7 +398,7 @@ def get_screen(x_left, y_top, x_right, y_bot): # ### HSV slider tool -# In[71]: +# In[17]: def callback(x): @@ -452,7 +452,7 @@ def hsv_slider(): break -# In[72]: +# In[18]: # hsv_slider() @@ -460,7 +460,7 @@ def hsv_slider(): # ### Filter sun -# In[73]: +# In[19]: def filter_sun(image=None, testing=False): @@ -483,7 +483,7 @@ def filter_sun(image=None, testing=False): return filtered -# In[74]: +# In[20]: # filter_sun(testing=True) @@ -491,7 +491,7 @@ def filter_sun(image=None, testing=False): # ### Filter orange -# In[75]: +# In[21]: def filter_orange(image=None, testing=False): @@ -514,7 +514,7 @@ def filter_orange(image=None, testing=False): return filtered -# In[76]: +# In[22]: # filter_orange(testing=True) @@ -522,7 +522,7 @@ def filter_orange(image=None, testing=False): # ### Filter orange2 -# In[77]: +# In[23]: def filter_orange2(image=None, testing=False): @@ -545,7 +545,7 @@ def filter_orange2(image=None, testing=False): return filtered -# In[78]: +# In[24]: # filter_orange2(testing=True) @@ -553,7 +553,7 @@ def filter_orange2(image=None, testing=False): # ### Filter blue -# In[79]: +# In[25]: def filter_blue(image=None, testing=False): @@ -576,7 +576,7 @@ def filter_blue(image=None, testing=False): return filtered -# In[80]: +# In[26]: # filter_blue(testing=True) @@ -584,7 +584,7 @@ def filter_blue(image=None, testing=False): # ### Get sun -# In[81]: +# In[27]: def sun_percent(): @@ -597,7 +597,7 @@ def sun_percent(): return result * 100 -# In[82]: +# In[28]: # sleep(3) @@ -606,7 +606,7 @@ def sun_percent(): # ### Get compass image -# In[83]: +# In[29]: def get_compass_image(testing=False): @@ -637,7 +637,7 @@ def get_compass_image(testing=False): return compass_image, compass_width+(2*doubt), compass_height+(2*doubt) -# In[84]: +# In[30]: # get_compass_image(testing=True) @@ -645,7 +645,7 @@ def get_compass_image(testing=False): # ### Get navpoint offset -# In[85]: +# In[31]: same_last_count = 0 @@ -700,7 +700,7 @@ def get_navpoint_offset(testing=False, last=None): -# In[86]: +# In[32]: # get_navpoint_offset(testing=True) @@ -708,7 +708,7 @@ def get_navpoint_offset(testing=False, last=None): # ### Get destination offset -# In[87]: +# In[33]: def get_destination_offset(testing=False): @@ -744,7 +744,7 @@ def get_destination_offset(testing=False): return result -# In[88]: +# In[34]: # sleep(3) @@ -755,7 +755,7 @@ def get_destination_offset(testing=False): # ### Undock -# In[89]: +# In[35]: def undock(): @@ -785,7 +785,7 @@ def undock(): return True -# In[90]: +# In[36]: # sleep(3) @@ -794,7 +794,7 @@ def undock(): # ### Dock -# In[91]: +# In[37]: def dock(): @@ -837,7 +837,7 @@ def dock(): return True -# In[92]: +# In[38]: # sleep(3) @@ -846,7 +846,7 @@ def dock(): # ### Align -# In[93]: +# In[39]: def x_angle(point=None): @@ -859,7 +859,7 @@ def x_angle(point=None): return -90 - result -# In[94]: +# In[40]: def align(): @@ -952,7 +952,7 @@ def align(): logging.debug('align=complete') -# In[95]: +# In[41]: # sleep(3) @@ -961,7 +961,7 @@ def align(): # ### Jump -# In[96]: +# In[42]: def jump(): @@ -993,7 +993,7 @@ def jump(): raise Exception("jump failure") -# In[97]: +# In[43]: # sleep(3) @@ -1002,7 +1002,7 @@ def jump(): # ### Refuel -# In[98]: +# In[44]: def refuel(): @@ -1027,7 +1027,7 @@ def refuel(): return True -# In[99]: +# In[45]: # sleep(3) @@ -1036,7 +1036,7 @@ def refuel(): # ### Position -# In[100]: +# In[46]: def position(): @@ -1053,7 +1053,7 @@ def position(): return True -# In[101]: +# In[47]: # sleep(3) @@ -1078,11 +1078,13 @@ def position(): # # 'in-docking' -# In[102]: +# In[48]: def autopilot(): logging.info('\n'+200*'-'+'\n'+'---- AUTOPILOT START '+179*'-'+'\n'+200*'-') + logging.info('get_latest_log='+str(get_latest_log(PATH_LOG_FILES))) + logging.debug('ship='+str(ship())) # if ship()['target']: # undock() while ship()['target']: @@ -1099,7 +1101,7 @@ def autopilot(): logging.info('\n'+200*'-'+'\n'+'---- AUTOPILOT END '+181*'-'+'\n'+200*'-') -# In[103]: +# In[49]: # sleep(3)