Mercurial > sqlpython
changeset 156:4927f901a634
adding bar charts
author | catherine@dellzilla |
---|---|
date | Mon, 29 Sep 2008 14:50:31 -0400 |
parents | d504e9760dad |
children | c03574f007df |
files | setup.py sqlpython/__init__.py sqlpython/editplot.bash sqlpython/editplot.py sqlpython/plothandler.py sqlpython/sqlpyPlus.py sqlpython/sqlpython.py |
diffstat | 7 files changed, 36 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Mon Sep 29 13:27:41 2008 -0400 +++ b/setup.py Mon Sep 29 14:50:31 2008 -0400 @@ -16,7 +16,6 @@ author_email="luca.canali@cern.ch", url="https://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython", packages=find_packages(), - #py_modules = ['mysqlpy','completion','sqlpyPlus','sqlpython','pexpecter','output_templates','plothandler'], include_package_data=True, install_requires=['pyparsing','cmd2>=0.3.7','cx_Oracle','genshi'], keywords = 'client oracle database', @@ -24,6 +23,7 @@ platforms = ['any'], entry_points = """ [console_scripts] - sqlpython = mysqlpy:run""" + sqlpython = sqlpython.mysqlpy:run + editplot_sqlpython = sqlpython.editplot.bash""" )
--- a/sqlpython/__init__.py Mon Sep 29 13:27:41 2008 -0400 +++ b/sqlpython/__init__.py Mon Sep 29 14:50:31 2008 -0400 @@ -1,3 +1,3 @@ import mysqlpy -__all__ = ["sqlpython", "sqlpyPlus", "pexpecter", "mysqlpy", "output_templates", "plothandler", "editplot"] +__all__ = ["sqlpython", "sqlpyPlus", "pexpecter", "mysqlpy", "output_templates", "plothandler", ] __version__ = '1.5.0' \ No newline at end of file
--- a/sqlpython/editplot.bash Mon Sep 29 13:27:41 2008 -0400 +++ b/sqlpython/editplot.bash Mon Sep 29 14:50:31 2008 -0400 @@ -1,1 +1,1 @@ -ipython -pylab editplot.py \ No newline at end of file +ipython -pylab -c "import sqlpython.plothandler; sqlpython.plothandler.Plot().unshelve()" \ No newline at end of file
--- a/sqlpython/editplot.py Mon Sep 29 13:27:41 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/usr/bin/python -import plothandler -plothandler.Plot().unshelve() \ No newline at end of file
--- a/sqlpython/plothandler.py Mon Sep 29 13:27:41 2008 -0400 +++ b/sqlpython/plothandler.py Mon Sep 29 14:50:31 2008 -0400 @@ -9,7 +9,8 @@ self.legends = [] self.yserieslists = [] self.xticks = [] - def build(self, sqlSession): + def build(self, sqlSession, outformat): + self.outformat = outformat self.title = sqlSession.tblname self.xlabel = sqlSession.curs.description[0][0] self.datatypes = [d[1] for d in sqlSession.curs.description] @@ -26,7 +27,7 @@ self.xticks = [r[0] for r in sqlSession.rows] def shelve(self): s = shelve.open(shelvename,'c') - for k in ('xvalues xticks yserieslists title legends xlabel'.split()): + for k in ('xvalues xticks yserieslists title legends xlabel outformat'.split()): s[k] = getattr(self, k) s.close() # reading pickles fails with EOF error, don't understand @@ -34,19 +35,36 @@ s = shelve.open(shelvename) self.__dict__.update(s) s.close() - self.draw() - def draw(self): + self.draw() + def bar(self): + barEdges = pylab.arange(len(self.xvalues)) + width = 0.5 + for yseries in self.yserieslists: + pylab.bar(barEdges, yseries, width=width) + if self.xticks: + pylab.xticks(barEdges + (0.5 * width), self.xticks) + def line(self, markers): + for yseries in self.yserieslists: + pylab.plot(self.xvalues, yseries, markers) + if self.xticks: + pylab.xticks(self.xvalues, self.xticks) + def draw(self, chartGuts, markers=None): if not self.yserieslists: print 'At least one quantitative column needed to plot.' return None - for yseries in self.yserieslists: - pylab.plot(self.xvalues, yseries, '-o') - if self.xticks: - pylab.xticks(self.xvalues, self.xticks) + if self.outformat == '\\p': + self.line('-o') + elif self.outformat == '\\P': + self.line('-') + else: + self.bar() pylab.xlabel(self.xlabel) pylab.title(self.title) pylab.legend(self.legends) pylab.show() + print 'You can edit this plot from the command prompt (outside sqlpython) by running' + print "ipython -pylab -c 'import sqlpython.plothandler; sqlpython.plothandler.Plot().unshelve()'" + # there's got to be a way to install a shell script like that through setuptools... but how? except ImportError: class Plot(object):
--- a/sqlpython/sqlpyPlus.py Mon Sep 29 13:27:41 2008 -0400 +++ b/sqlpython/sqlpyPlus.py Mon Sep 29 14:50:31 2008 -0400 @@ -439,10 +439,10 @@ transpr[x][0] = rname newdesc[0][0] = 'COLUMN NAME' result = '\n' + sqlpython.pmatrix(transpr,newdesc) - elif outformat == '\\p': + elif outformat in ('\\p', '\\P', '\\b'): plot = Plot() - plot.build(self) - plot.shelve() + plot.build(self, outformat) + plot.shelve() plot.draw() return '' else: @@ -499,7 +499,7 @@ return completions rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') - rawTerminators = '; \\s \\S \\c \\C \\t \\i \\p ' + ' '.join(output_templates.keys()) + rawTerminators = '; \\s \\S \\c \\C \\t \\i \\p \\P \\b ' + ' '.join(output_templates.keys()) terminatorPattern = (pyparsing.oneOf(rawTerminators) ^ pyparsing.Literal('\n/') ^ \ (pyparsing.Literal('\nEOF') + pyparsing.stringEnd)) \
--- a/sqlpython/sqlpython.py Mon Sep 29 13:27:41 2008 -0400 +++ b/sqlpython/sqlpython.py Mon Sep 29 14:50:31 2008 -0400 @@ -108,7 +108,8 @@ \\t transposed \\x XML \\p plot, with markers -\\P plot, continuous lines""" +\\P plot, lines only +\\b bar graph""" print self.do_terminators.__doc__ terminatorSearchString = '|'.join('\\' + d.split()[0] for d in do_terminators.__doc__.splitlines())