Skip to content

Commit

Permalink
The most basic functionality is present; graphs may be created from t…
Browse files Browse the repository at this point in the history
…he cli
  • Loading branch information
christophertubbs committed Nov 14, 2020
1 parent 3303474 commit 90b3bc5
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 18 deletions.
Empty file added __init__.py
Empty file.
4 changes: 4 additions & 0 deletions plotting/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ class PlotArguments(object):
def __init__(
self,
data: pandas.DataFrame,
plot_type: str,
title: str = None,
x_title: str = None,
y_title: str = None,
x_axis: str = None,
group: str = None,
trace_columns: [list, tuple, str] = None,
**kwargs
):
self.data = data
self.plot_type = plot_type
self.title = title
self.x_title = x_title
self.y_title = y_title
self.x_axis = x_axis
self.group = group
self.trace_columns = trace_columns

def validate(self) -> list:
Expand Down
13 changes: 13 additions & 0 deletions plotting/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/env python

import plotting.arguments as arguments
import plotting.line as line_graphs
import plotting.plot as plots


def get_plot(plot_arguments: arguments.PlotArguments) -> plots.Plot:
if plot_arguments.plot_type.lower() == 'line':
if plot_arguments.group is None:
return line_graphs.LinePlot(plot_arguments)
return line_graphs.AnimatedLinePlot(plot_arguments)
raise Exception("{} is not a valid plot type".format(plot_arguments.plot_type))
4 changes: 1 addition & 3 deletions plotting/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import plotly.graph_objects as go

import plotting.plot as plot
import plotting.exceptions as exceptions
from plotting import arguments as arguments


class LinePlot(plot.Plot):
Expand All @@ -29,7 +27,7 @@ def plot(self) -> go.Figure:
figure.add_trace(
go.Scatter(
x=self.args.data[self.args.x_axis],
y=self.args.data[trace]
y=trace
)
)

Expand Down
2 changes: 1 addition & 1 deletion plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def plot(self) -> go.Figure:
def validate(self):
invalid_arguments = self.args.validate()

if len(invalid_arguments) == 0:
if len(invalid_arguments) > 0:
raise exceptions.MissingArgumentException(invalid_arguments)
27 changes: 27 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
attrs==20.3.0
certifi==2020.11.8
cftime==1.2.1
click==7.1.2
click-plugins==1.1.1
cligj==0.7.0
cycler==0.10.0
Cython==0.29.21
Fiona==1.8.17
geopandas==0.8.1
kiwisolver==1.3.1
matplotlib==3.3.2
munch==2.5.0
netCDF4==1.5.4
numpy==1.19.4
pandas==1.1.4
Pillow==8.0.1
plotly==4.12.0
pyparsing==2.4.7
pyproj==3.0.0.post1
python-dateutil==2.8.1
pytz==2020.4
retrying==1.3.3
scipy==1.5.4
Shapely==1.7.1
six==1.15.0
xarray==0.16.1
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup
from setuptools import find_packages

setup(
name='Plot4OF',
version='0.1',
packages=find_packages(),
url='https://github.com/christophertubbs/Plot4OF',
license='GPL 3.0',
author='Christopher Tubbs',
author_email='[email protected]',
description='Plots for Old Farts - A simple tool for generating basic graphs without the manual use of code or tools like excel '
)
72 changes: 58 additions & 14 deletions ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

from argparse import ArgumentParser

import pandas

import plotting.arguments as arguments
import plotting.factory as plot_factory

__PLOT_TYPES = [
"line",
]

def create_commandline_parser() -> ArgumentParser:
"""
Expand All @@ -13,27 +21,63 @@ def create_commandline_parser() -> ArgumentParser:
:rtype: ArgumentParser
:return: An argument parser used to collect the inputs to the script
"""
parser = ArgumentParser("This is the default description of a python script")
# parser.add_argument(
# -o,
# metavar="example",
# dest="example",
# type=str,
# default="ex",
# help="This is an example argument used for an example"
# )
parser = ArgumentParser("Plot CSV data plainly")
parser.add_argument(
"-t",
metavar="type",
dest="type",
type=str,
choices=__PLOT_TYPES,
default=__PLOT_TYPES[0],
help="The type of plot to create"
)
parser.add_argument("-T", metavar="title", dest="title", default=None, type=str, help="A title for the plot")
parser.add_argument("-x", metavar="name", dest="xtitle", default=None, type=str, help="The title on the x axis")
parser.add_argument("-y", metavar="name", dest="ytitle", default=None, type=str, help="The title on the y axis")
parser.add_argument("-g", metavar="group", type=str, default=None, dest="group", help="A field to group on")
parser.add_argument("target", type=str, help="The file to plot")
parser.add_argument("xaxis", type=str, help="The column to use as the x-axis")
parser.add_argument("columns", type=str, nargs="+", help="Values to plot on the y-axis")

return parser


def get_plot_arguments() -> arguments.PlotArguments:
parameters = create_commandline_parser().parse_args()
frame = pandas.read_csv(parameters.target)

is_animated = parameters.group is not None

if parameters.type in ['line']:
if is_animated:
plot_arguments = arguments.AnimatedPlotArguments(
group=parameters.group,
data=frame,
plot_type=parameters.type
)
else:
plot_arguments = arguments.PlotArguments(data=frame, plot_type=parameters.type)
else:
raise Exception("This tool cannot plot {} graphs".format(parameters.type))

plot_arguments.title = parameters.title
plot_arguments.x_axis = parameters.xaxis
plot_arguments.trace_columns = parameters.columns
plot_arguments.y_title = parameters.ytitle
plot_arguments.x_title = parameters.xtitle
plot_arguments.group = parameters.group

return plot_arguments


def main():
"""
This is the entry point to the script's execution
"""
parser = create_commandline_parser()
parameters = parser.parse_args()


# Run the following if this script was called directly
plot_arguments = get_plot_arguments()
graph = plot_factory.get_plot(plot_arguments)
plot = graph.plot()
plot.show()


if __name__ == "__main__":
Expand Down

0 comments on commit 90b3bc5

Please sign in to comment.