Skip to content

Commit

Permalink
Added a lot of documentaion
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyb3r-Jak3 committed May 3, 2020
1 parent c208b01 commit 6aa099d
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 28 deletions.
8 changes: 5 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions MetaStalk/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 36 additions & 6 deletions MetaStalk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions MetaStalk/modules/DateTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
13 changes: 11 additions & 2 deletions MetaStalk/modules/GPSCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
32 changes: 26 additions & 6 deletions MetaStalk/modules/PieChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = []

Expand Down
14 changes: 12 additions & 2 deletions MetaStalk/modules/Stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions MetaStalk/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 14 additions & 3 deletions MetaStalk/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion MetaStalk/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6aa099d

Please sign in to comment.