From 6aa099d4ec1056f16bb8458053e881cde7574a1c Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 3 May 2020 17:44:34 -0400 Subject: [PATCH] Added a lot of documentaion --- .gitlab-ci.yml | 8 ++++--- MetaStalk/__init__.py | 3 +++ MetaStalk/main.py | 42 ++++++++++++++++++++++++++++++----- MetaStalk/modules/DateTime.py | 16 +++++++++++-- MetaStalk/modules/GPSCheck.py | 13 +++++++++-- MetaStalk/modules/PieChart.py | 32 +++++++++++++++++++++----- MetaStalk/modules/Stats.py | 14 ++++++++++-- MetaStalk/tests/test_main.py | 8 ++++--- MetaStalk/utils/logger.py | 17 +++++++++++--- MetaStalk/utils/web.py | 12 +++++++++- 10 files changed, 137 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d73dc35..7d68123 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,22 +21,24 @@ license_scanning: - tags - master +# This job will fail until tests are implemented Coverage: image: python:3.7 - stage: Test_Build + stage: test coverage: '/TOTAL\s*\d*\s*\d*\s*(\d*)%/' artifacts: paths: - MetaStalk.log - htmlcov/* + allow_failure: true before_script: - pip install -U pip coverage -r requirements.txt --quiet - curl https://deepsource.io/cli | sh - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; chmod +x ./cc-test-reporter; ./cc-test-reporter before-build script: - pip install dist/*.whl - - coverage run -a --source . metastalk ./ExamplePhotos/ -t -d - - coverage run -a --source . metastalk ./ExamplePhotos/Panasonic_DMC-FZ30.jpg ./ExamplePhotos/DSCN0010.jpg -t -d + - coverage run -a --source . ./MetaStalk/main.py ./ExamplePhotos/ -t -d + - coverage run -a --source . ./MetaStalk/main.py ./ExamplePhotos/Panasonic_DMC-FZ30.jpg ./ExamplePhotos/DSCN0010.jpg -t -d after_script: - coverage report - coverage html diff --git a/MetaStalk/__init__.py b/MetaStalk/__init__.py index 81b9960..dc1c04f 100644 --- a/MetaStalk/__init__.py +++ b/MetaStalk/__init__.py @@ -1,3 +1,6 @@ """MetaStalk +--- +MetaStalk is a program that parse image metadata and creates charts from it. """ __version__ = "v2.0.0" +__author__ = "Cyb3r Jak3" diff --git a/MetaStalk/main.py b/MetaStalk/main.py index eebfe99..68736a2 100644 --- a/MetaStalk/main.py +++ b/MetaStalk/main.py @@ -17,7 +17,11 @@ def start(): - """ Sets up MetaStalk and parses arguments""" + """start + + Sets up MetaStalk and parses arguments. + Will raise an IOError if no path is passed. + """ parser = argparse.ArgumentParser(prog="MetaStalk", description="Tool to graph " "image metadata.") @@ -43,8 +47,14 @@ def start(): def run(args, log: logging.Logger): - """Process files and generates graphs""" + """run + + Process files and generates graphs + Arguments: + args {argparse.Namespace} -- The arguments from start() + log {logging.Logger} -- Logger + """ for path in args.files: isdir = os.path.isdir(path) log.debug("Detected path as a directory") @@ -67,8 +77,18 @@ def run(args, log: logging.Logger): utils.graph(plots, t_start, args.test) -def directory_search(files: list, log: logging.Logger): - """ Used to append all file in a directory """ +def directory_search(files: list, log: logging.Logger) -> (list, list): + """directory_search + + Used to append all files in a directory from args. + + Arguments: + files {list} -- List of directories to parse + log {logging.Logger} -- Logger + + Returns: + valid, invalid -- List of photos with metadata and ones without + """ valid, invalid = [], [] for item in os.listdir(files): item_path = os.path.join(files, item) @@ -85,8 +105,18 @@ def directory_search(files: list, log: logging.Logger): return valid, invalid -def file_search(files: list, log: logging.Logger): - """ Used to append files if the path is not a directory """ +def file_search(files: list, log: logging.Logger) -> (list, list): + """file_search + + Used to append files if the path is not a directory. + + Arguments: + files {list} -- List of files to parse + log {logging.Logger} -- Logger + + Returns: + valid, invalid -- List of photos with metadata and ones without + """ valid, invalid = [], [] for _, item in enumerate(files): parser = createParser(item) diff --git a/MetaStalk/modules/DateTime.py b/MetaStalk/modules/DateTime.py index d2017c1..edf587b 100644 --- a/MetaStalk/modules/DateTime.py +++ b/MetaStalk/modules/DateTime.py @@ -5,8 +5,20 @@ log = logging.getLogger("MetaStalk") -def date_time(photos): - """Makes a table with gps timestamp of photos""" +def date_time(photos: list) -> go.Figure(): + """date_time + + Makes a table with timestamp of photos. + There are three name that DateTime data can be under `Creation date`, + `Date-time original`, `Date-time digitized` and a column in made + for each type. + + Arguments: + photos {list} -- A list of dictionaries with phot information. + + Returns: + go.Figure -- A plotly Table with the DateTime data. + """ log.info("Starting DateTime Charts") datetime = [] datetime_original = [] diff --git a/MetaStalk/modules/GPSCheck.py b/MetaStalk/modules/GPSCheck.py index 5ce4da4..5552fce 100644 --- a/MetaStalk/modules/GPSCheck.py +++ b/MetaStalk/modules/GPSCheck.py @@ -5,8 +5,17 @@ log = logging.getLogger("MetaStalk") -def GPS_Check(photos: list): - """Takes a list of photos and creates a geo plot of them""" +def GPS_Check(photos: list) -> px.scatter_mapbox: + """GPS_Check + + Takes a list of photos and creates a geo plot of them + + Arguments: + photos {list} -- A list of dictionaries with phot information. + + Returns: + px.scatter_mapbox -- Map plot with photos plotted. + """ log.info("Starting GPS Chart") lats = [] longs = [] diff --git a/MetaStalk/modules/PieChart.py b/MetaStalk/modules/PieChart.py index 4981e65..1837283 100644 --- a/MetaStalk/modules/PieChart.py +++ b/MetaStalk/modules/PieChart.py @@ -5,8 +5,18 @@ log = logging.getLogger("MetaStalk") -def create_chart(table, pietype): - """Creates the pie chart""" +def create_chart(table: list, pielabel: str) -> go.Figure(): + """create_chart + + Creates the pie chart by frequency of items in a dictionary. + + Arguments: + table {list} -- [description] + pielabel {str} -- The label of the pie chart. + + Returns: + go.Figure -- A plotly PieChart + """ freq = {} for item in table: if item in freq: @@ -16,20 +26,30 @@ def create_chart(table, pietype): (labels, values) = ([], []) for key, value in freq.items(): - if pietype == "Camera focal": + if pielabel == "Camera focal": labels.append("Length: {}".format(key)) else: labels.append(key) values.append(value) fig = go.Figure(data=[go.Pie(labels=labels, values=values)]) - fig.update_layout(title="{} Information".format(pietype)) + fig.update_layout(title="{} Information".format(pielabel)) return fig -def PieChart(photos: list, pietype: str): - """Gets information and makes a pie chart""" +def PieChart(photos: list, pietype: str) -> go.Figure(): + """PieChart + + Parses information and returns a pie chart + + Arguments: + photos {list} -- A list of dictionaries with phot information. + pietype {str} -- The type of metadata for the pie chart + + Returns: + go.Figure -- A plotly PieChart + """ log.info("Staring %s Chart", pietype) table = [] diff --git a/MetaStalk/modules/Stats.py b/MetaStalk/modules/Stats.py index cc398be..68c631b 100644 --- a/MetaStalk/modules/Stats.py +++ b/MetaStalk/modules/Stats.py @@ -6,8 +6,18 @@ log = logging.getLogger("MetaStalk") -def Stats(photos: list, invalid: list): - """Creates the table of photos""" +def Stats(photos: list, invalid: list) -> go.Figure(): + """Stats + + Creates the table of photos showing ones with metadata and ones without + + Arguments: + photos {list} -- List of photos with metadata. + invalid {list} -- List of photos without metadata. + + Returns: + go.Figure() -- A plotly table + """ log.info("Staring Stats") log.debug("There are %s photos with metadata and %s without", len(photos), len(invalid)) diff --git a/MetaStalk/tests/test_main.py b/MetaStalk/tests/test_main.py index 7abaf09..e6aab5e 100644 --- a/MetaStalk/tests/test_main.py +++ b/MetaStalk/tests/test_main.py @@ -1,9 +1,11 @@ -"""Test suite for PyStalk""" +"""Test suite for MetaStalk +Currently unused but planned. +""" import pytest -import PyStalk +import MetaStalk def empty_directory_test(): """Shows result for empty directory""" with pytest.raises(FileNotFoundError): - PyStalk.run() + MetaStalk.run() diff --git a/MetaStalk/utils/logger.py b/MetaStalk/utils/logger.py index df8f176..8746960 100644 --- a/MetaStalk/utils/logger.py +++ b/MetaStalk/utils/logger.py @@ -2,9 +2,20 @@ import logging -def make_logger(name, log_level): - """Creates the logger. - Might look to make this happen in the main script +def make_logger(name: str, log_level: int) -> logging.Logger: + """make_logger + + Creates the logger. + + Might look to make this happen in the main script + + + Arguments: + name {str} -- name of the logger + log_level {int} -- Verbosity of the logger + + Returns: + logging.Logger -- The logger that gets used. """ logger = logging.getLogger(name) logger.setLevel(log_level) diff --git a/MetaStalk/utils/web.py b/MetaStalk/utils/web.py index 772026a..fcbdcd9 100644 --- a/MetaStalk/utils/web.py +++ b/MetaStalk/utils/web.py @@ -11,7 +11,17 @@ def graph(plots: dict, t_start: float, test=False): - """Creates the graphs""" + """graph + + Displays all the plots that are passed to it. + + Arguments: + plots {dict} -- All the plot that get displayed + t_start {float} -- The start time of MetaStalk + + Keyword Arguments: + test {bool} -- Whether or not to show the web page (default: {False}) + """ external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) app.title = "MetaStalk"