Skip to content

Commit ec1c7e9

Browse files
committed
better debug
2 parents 48d7c32 + d1a05e4 commit ec1c7e9

25 files changed

+161
-32
lines changed

Makefile

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ PYTHON=venv/bin/python
1515
PIP_INSTALL=venv/bin/pip install --no-warn-script-location
1616
ROOT_ETC=etc
1717
DEPLOY_ETC=deploy/etc
18-
DBMAINT=-m deploy.app.dbmaint
18+
APP_ETC=$(DEPLOY_ETC)
19+
DBMAINT=dbutil.py
1920

2021
# Note: PLANTTRACER_CREDENTIALS must be set
2122

@@ -65,6 +66,7 @@ check:
6566
PYLINT_OPTS:=--output-format=parseable --rcfile .pylintrc --fail-under=$(PYLINT_THRESHOLD) --verbose
6667
pylint: $(REQ)
6768
$(PYTHON) -m pylint $(PYLINT_OPTS) deploy
69+
$(PYTHON) -m pylint $(PYLINT_OPTS) *.py
6870

6971
pylint-tests: $(REQ)
7072
$(PYTHON) -m pylint $(PYLINT_OPTS) --init-hook="import sys;sys.path.append('tests');import conftest" tests
@@ -150,13 +152,13 @@ pytest-coverage: $(REQ)
150152

151153
run-local:
152154
@echo run bottle locally, storing new data in database
153-
$(PY) bottle_app.py --storelocal
155+
$(PYTHON) standalone.py --storelocal
154156

155157
run-local-demo:
156158
@echo run bottle locally in demo mode, using local database
157-
DEMO_MODE=1 $(PY) bottle_app.py --storelocal
159+
DEMO_MODE=1 $(PYTHON) standalone.py --storelocal
158160

159-
DEBUG:=$(PY) bottle_app.py --loglevel DEBUG
161+
DEBUG:=$(PYTHON) standalone.py --loglevel DEBUG
160162
debug:
161163
make debug-local
162164

@@ -207,8 +209,10 @@ jscoverage:
207209
PLANTTRACER_LOCALDB_NAME ?= actions_test
208210

209211
create_localdb:
210-
@echo Creating local database, exercise the upgrade code and write credentials to $(PLANTTRACER_CREDENTIALS) using $(ROOT_ETC)/github_actions_mysql_rootconfig.ini
212+
@echo Creating local database, exercise the upgrade code and write credentials
213+
@echo to $(PLANTTRACER_CREDENTIALS) using $(ROOT_ETC)/github_actions_mysql_rootconfig.ini
211214
@echo $(PLANTTRACER_CREDENTIALS) will be used automatically by other tests
215+
pwd
212216
mkdir -p $(ROOT_ETC)
213217
ls -l $(ROOT_ETC)
214218
$(PYTHON) $(DBMAINT) --create_client=$$MYSQL_ROOT_PASSWORD --writeconfig $(ROOT_ETC)/github_actions_mysql_rootconfig.ini

dbutil.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
"""
2+
dbutil.py - CLI for dbmaint module.
3+
"""
4+
15
import sys
26
import os
37
import configparser
8+
import uuid
49

510
from deploy.app import clogging
611
from deploy.app import dbmaint
712
from deploy.app import db
813
from deploy.app import dbfile
914
from deploy.app import paths
15+
from deploy.app.constants import C
1016

1117

1218
if __name__ == "__main__":
@@ -83,7 +89,7 @@
8389
ath = dbfile.DBMySQLAuth.FromConfigFile(args.rootconfig, 'client')
8490
with dbfile.DBMySQL( ath ) as droot:
8591
if args.createdb:
86-
createdb(droot=droot, createdb_name = args.createdb,
92+
dbmaint.createdb(droot=droot, createdb_name = args.createdb,
8793
write_config_fname=args.writeconfig, schema=args.schema)
8894
sys.exit(0)
8995

@@ -92,7 +98,7 @@
9298
dbreader_user = 'dbreader_' + args.dropdb
9399
dbwriter_user = 'dbwriter_' + args.dropdb
94100
c = droot.cursor()
95-
for ipaddr in hostnames():
101+
for ipaddr in dbmaint.hostnames():
96102
c.execute(f'DROP USER IF EXISTS `{dbreader_user}`@`{ipaddr}`')
97103
c.execute(f'DROP USER IF EXISTS `{dbwriter_user}`@`{ipaddr}`')
98104
c.execute(f'DROP DATABASE IF EXISTS {args.dropdb}')

deploy/app/bottle_app.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from logging.config import dictConfig
1212

1313
from flask import Flask, request, render_template, jsonify, make_response
14-
from flask.logging import default_handler
1514

1615
# Bottle creates a large number of no-member errors, so we just remove the warning
1716
# pylint: disable=no-member
@@ -195,7 +194,9 @@ def func_upload():
195194

196195
@app.route('/debug', methods=GET)
197196
def app_debug():
198-
return render_template('debug.html', routes=app.url_map)
197+
python_keys = {"path":sys.path,
198+
"sys.version":sys.version}
199+
return render_template('debug.html', routes=app.url_map, python_keys = python_keys, environ=os.environ)
199200

200201
@app.route('/demo_tracer1.html', methods=GET)
201202
def demo_tracer1():

deploy/app/templates/debug.html

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
</head>
1818

1919
<body lang='en-US' style='background:white'>
20+
<h1>Environment</h1>
21+
<pre>
22+
{% for k,v in environ | dictsort -%}
23+
{{k}}={{v}}
24+
{% endfor %}
25+
</pre>
26+
</table>
27+
<h1>Python Runtime</h1>
28+
<table>
29+
{% for k,v in python_keys.items() %}
30+
<tr><th>{{k}}</th><td style='max-width: 600px; word-wrap: break-word;'> {{ v }} </td></tr>
31+
{% endfor %}
32+
</table>
2033
<h1>Routes</h1>
2134
<pre>
2235
{{routes}}

docs/DeveloperSetup.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ Requirements and Preparation
88

99
* Python3.11. Verify that typing 'python' gives you python3.11. If it doesn't, make sure that your PATH is up-to-date.
1010

11-
* HomeBrew. If installing on a MacOS machine, `HomeBrew <https://brew.sh>`_ must be installed prior to performing the steps below.
12-
11+
* Package installer
12+
* Homebrew. If installing on a MacOS machine, `HomeBrew <https://brew.sh>`_ must be installed prior to performing the steps below.
13+
* Chocolatey. If installing on a Windows machine, the Chocolatey package manager is recommended.
14+
1315
Setup Steps
1416
-----------
1517

1618
#. Clone the Plant Tracer webapp into a directory that will be the local repository, for example::
1719

18-
git clone --recurse-submodules https://github.com/Plant-Tracer/webapp.git webapp
20+
git clone https://github.com/Plant-Tracer/webapp.git webapp
1921

2022
#. Change to the local repository directory::
2123

@@ -84,27 +86,27 @@ Running Locally Quick Start
8486

8587
.. code-block::
8688
87-
make run-local # Ctrl-C to quit
89+
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini make run-local # Ctrl-C to quit
8890
8991
#. To run a Plant-Tracer/webapp server process locally, examine the debug-* targets in Makefile. The general form is:
9092

9193
.. code-block::
9294
93-
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini python bottle_app.py [arguments]
95+
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini python standalone.py [arguments]
9496
9597
#. A specific case: running with movies stored in MySQL rather than S3:
9698

9799
.. code-block::
98100
99-
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini python bottle_app.py --storelocal
101+
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini python standalone.py --storelocal
100102
101103
#. Another case: running in demo mode, with movies stored in MySQL rather than S3:
102104

103105
* Note: there must be no user logged in for demo mode to take effect. May have to clear browser cookies.
104106

105107
.. code-block::
106108
107-
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini DEMO_MODE=1 python bottle_app.py --storelocal
109+
PLANTTRACER_CREDENTIALS=${MY_INI_FILES}/credentials-myconfig.ini DEMO_MODE=1 python standablone.py --storelocal
108110
109111
#. Sometimes, it is necessary to manually clear the cookies that Plant-Tracer/webapp creates in a browser. These cookies are of the form "api_key-"+my_database_name. Here is an example:
110112

docs/UserTutorial.rst

+104-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,105 @@
1-
How to Use Plant Tracer
2-
=======================
1+
Plant Tracer Web App Tutorial
2+
=============================
33

4-
* Coming soon
4+
Welcome and Registration
5+
-------------------------
6+
- Go to `dev.planttracer.com/register`.
7+
- Register for an account using your Course Key provided by your instructor.
8+
- Alternately, you can register for a demo course which is called "dev" (enter "dev" in the box labeled Course Key.
9+
- Enter your full name, email address, and Course Key.
10+
11+
.. image:: tutorial_images/register.png
12+
:alt: Plant Tracer Registration
13+
14+
- Look for an email from `[email protected]`. Click on the second link to view movies. The first link will allow you to upload movies.
15+
16+
.. image:: tutorial_images/admin_email_link.png
17+
:alt: email from Plant Tracer
18+
19+
Viewing movies
20+
--------------
21+
- The second link in the email will bring you to the Welcome page.
22+
- Click on "Movies" in the menu bar at the top of the page to see a list of movies to analyze.
23+
24+
.. image:: tutorial_images/welcome_page.png
25+
:alt: Selecting a sample movie on Plant Tracer
26+
27+
- Click on the analyze button to see the tracked movie.
28+
29+
.. image:: tutorial_images/choose_analyze.png
30+
:alt: Selecting a sample movie on Plant Tracer
31+
32+
Uploading Movies (optional)
33+
---------------------------
34+
- From the menu bar at the top select Upload.
35+
- Enter the title of the file and a description of the movie.
36+
- Choose a file to upload. Your movie file must be 256MB or less. If your file is larger than 256MB, you must use some other tool to reduce the file size prior to uploading.
37+
38+
.. image:: tutorial_images/upload_movie.png
39+
:alt: Uploading Movies on Plant Tracer
40+
41+
Tracking the Uploaded Movie
42+
---------------------------
43+
- Once the file is uploaded, you can choose to track it.
44+
- In the bottom left of the page, click on the button labeled "Track the uploaded movie".
45+
46+
.. image:: tutorial_images/track_uploaded_movie.png
47+
:alt: Tracking uploaded movie on Plant Tracer
48+
49+
- PlantTracer places three markers on newly uploaded movies automatically. They initially appear on the left side of the movie frame. These also appear in the Marker Table to the right (or beneath) the video frame.
50+
- PlantTracer will attempt to track the motion of whatever part of the image a marker is placed over, frame by frame.
51+
- It is the user's job to position the markers appropriately. To move a marker, click on it, and drag it to the desired location.
52+
- You may use the Marker Table to add and delete markers whose names have meaning for your motion analysis. There may be any number of markers. Markers may not be renamed, so if you want to rename a marker, delete it and add another with the name you want.
53+
- PlantTracer will attempt to track the motion related to every marker.
54+
- Typically, the apex of some part of the plant is tracked. So, to do that, move the Apex marker, for example, to the top of the vertical stem.
55+
- Marker that have names of the form RulerXXmm are special. XX is any non-negative integer. These markers are intended to be used for distance calibration. Using the default Ruler markers, if the image has a ruler in it, move the Ruler0mm marker to the beginning of the ruler in the image, and move the Ruler10mm marker to the 10mm mark on the ruler. In this way, PlantTracer can report analysis results in millimeters rather than numbers of pixels in the image.
56+
- There can be any number of RulerXXmm markers, but PlantTracer will only use the RulerXXmm markers with the lowest and highest XX values in its calculations, and ignores any intermediate RulerXXmm markers for purposes of distance calculations. PlantTracer only uses mm distances.
57+
- If there are fewer than two RulerXXmm markers on a given analysis, then analysis results are calclulated and presented using units of pixels.
58+
59+
.. image:: tutorial_images/moving_marker.png
60+
:alt: Tracking uploaded movie on Plant Tracer
61+
62+
- The Apex marker, and ruler markers need to be moved to the appropriate location.
63+
64+
.. image:: tutorial_images/placed_markers.png
65+
:alt: Tracking uploaded movie on Plant Tracer
66+
67+
Viewing the trace of a Movie
68+
----------------------------
69+
- Once the tracked movie has loaded you will see the image of the first frame, the data table and the graphs of the movement.
70+
71+
.. image:: tutorial_images/analyzed_movie.png
72+
:alt: Viewing the tracked movie, data and graphs on Plant Tracer
73+
74+
- Click on the play button to view the movement of the apex in all frames of the movie.
75+
76+
.. image:: tutorial_images/play_button.png
77+
:alt: Viewing the traced movie on Plant Tracer
78+
79+
Interpreting and Reading Results
80+
--------------------------------
81+
- Use the arrow buttons just below the tracked movie to play, or navigate to a particular frame.
82+
- Graphs help visualize the horizontal (x position) and vertical (y position).
83+
- When you are satisfied with the tracking, you can press the button "Download Trackpoints".
84+
- At this point, you are ready to use a spreadsheet to analyze and graph the data.
85+
86+
.. image:: tutorial_images/download_trackpoints.png
87+
:alt: Reading Results in Plant Tracer
88+
89+
Further Adjustments to Tracking
90+
-------------------------------
91+
- You can enlarge the image of the movie to better view the markers and tracing.
92+
93+
.. image:: tutorial_images/movie_size_adjustment.png
94+
:alt: Adjusting the Zoom in Plant Tracer
95+
96+
- You have the option of re-tracking the movie from that frame.
97+
98+
.. image:: tutorial_images/fall_off_apex.png
99+
:alt: Other Adjustments in Plant Tracer
100+
101+
- Use the arrow buttons just below the original movie to navigate to the frame where tracking was lost.
102+
- Then move the apex marker to the correct position. Now press the button "re-track movie".
103+
104+
.. image:: tutorial_images/retrack_movie.png
105+
:alt: Retrack Movie in Plant Tracer

docs/mv1.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Configuration on mv1:
22

3-
Host | gunicorn port | app dir | app name
4-
mv1.planttracer.com | 8000 | /home/ec2-user/webapp/deploy/ | app.app
5-
app.planttracer.com | 8010 | /home/ec2-user/webapp/deploy/ | app.app
6-
demo1.planttracer.com | 8020 | /home/ec2-user/webapp/deploy/ | app.app
7-
dev-slg.planttracer.com | 8030| /home/ec2-user/slg-dev/deploy/ | app.app
3+
Host | gunicorn port | app dir | app name
4+
mv1.planttracer.com | 8000 | /home/ec2-user/webapp/deploy/ | app.app
5+
app.planttracer.com | 8010 | /home/ec2-user/webapp/deploy/ | app.app
6+
demo1.planttracer.com | 8020 | /home/ec2-user/webapp/deploy/ | app.app
7+
dev-slg.planttracer.com | 8030 | /home/ec2-user/slg-dev/deploy/ | app.app

docs/tutorial_images/admin_email.png

170 KB
Loading
168 KB
Loading
351 KB
Loading
231 KB
Loading
458 KB
Loading
822 KB
Loading
443 KB
Loading
486 KB
Loading
517 KB
Loading

docs/tutorial_images/play_button.png

334 KB
Loading

docs/tutorial_images/register.png

101 KB
Loading
367 KB
Loading
364 KB
Loading
399 KB
Loading

docs/tutorial_images/upload_movie.png

124 KB
Loading

docs/tutorial_images/welcome_page.png

84.6 KB
Loading

etc/planttracer-template.service

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ ExecStart={base}/venv/bin/gunicorn -w 2 -b 127.0.0.1:{port} \
1616
--reload deploy.app.bottle_app:app
1717

1818
Restart=always
19-
RestartSec=5
20-
StandardOutput=append:/home/ec2-user/logs/planttracer-{name}-error.log
21-
StandardError=append:/home/ec2-user/logs/planttracer-{name}-error.log
19+
RestartSec=1
20+
StandardOutput=append:/home/ec2-user/logs/planttracer-{name}-stdout.log
21+
StandardError=append:/home/ec2-user/logs/planttracer-{name}-stderr.log
2222
[Install]
2323
WantedBy=multi-user.target

standalone.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
#!/usr/bin/env python3.11
1+
"""
2+
CLI for running standalone webserver.
3+
"""
24

35
################################################################
46
# Bottle App
57
##
68

79
import sys
810
import os
9-
import uvicorn
1011
import argparse
12+
import logging
1113

12-
import deploy.app.clogging as clogging
14+
from deploy.app import clogging
1315
from deploy.app.constants import C
16+
from deploy.app import db_object
1417

1518
if __name__ == "__main__":
1619
parser = argparse.ArgumentParser(description="Run Bottle App with Bottle's built-in server unless a command is given",
@@ -27,7 +30,7 @@
2730
sys.exit(1)
2831

2932
if args.info:
30-
for name in logging.root.manager.loggerDict:
33+
for name in logging.root.manager.loggerDict: # pylint: disable=no-member
3134
print("Logger: ",name)
3235
sys.exit(0)
3336

@@ -45,5 +48,4 @@
4548

4649
cmd = f'gunicorn --bind 127.0.0.1:{args.port} --workers 2 --reload --log-level DEBUG deploy.app.bottle_app:app '
4750
print(cmd)
48-
exit(0)
4951
os.system(cmd)

0 commit comments

Comments
 (0)