{ "info": { "author": "Simples Consultoria - Luciano Pacheco", "author_email": "products@simplesconsultoria.com.br", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Introduction\n============\n\nThis package helps creates `Pivot Tables`_ using your Python objects as source.\n\nDeveloped by lucmult - Luciano Pacheco at `Simples Consultoria`_.\n\nYou don't need SQL, but can use row retrieved from your database.\n\nYou need :\n\n- A list of your objects\n- A dict mapping your object's attributes (or methods) \n- An attribute (or method) to use as column name\n\nNOTE: An attribute can be :\n\n- an attribute\n- a method (callable), without args\n- can use Zope Acquisition, but it's optional, can safely used without Zope ;-)\n\nLet's show a example.\n\nDefine your class ::\n\n >>> class Purchase(object):\n ... def __init__(self, cost=0.0, price=0.0, month='', ou=''):\n ... self.cost = cost\n ... self.price = price\n ... self.month = month\n ... self.ou = ou\n ... def gain(self):\n ... return (self.price - self.cost) / self.cost\n\nA class representing your purchases.\n\nLet's do some purchases ::\n\n >>> purchases = [Purchase(cost=5.0, price=7, month='jan', ou='NY'), \n ... Purchase(cost=5.0, price=7, month='jan', ou='NY'),\n ... Purchase(cost=14.66, price=4946.68, month='feb', ou='NY'),\n ... Purchase(cost=7.33, price=7184.90, month='mar', ou='NY'), \n ... Purchase(cost=7.33, price=7834.92, month='apr', ou='NY'),\n ... Purchase(cost=73.3, price=8692.67, month='may', ou='NY'), \n ... Purchase(cost=128.28, price=9552.14, month='jun', ou='NY'), \n ... Purchase(cost=58.64, price=8828.44, month='jul', ou='NY'), \n ... Purchase(cost=128.28, price=9652.73, month='aug', ou='NY'), ]\n\n >>> purchases += [Purchase(cost=14.66, price=463.61, month='jan', ou='RJ'), \n ... Purchase(cost=14.66, price=4946.68, month='feb', ou='RJ'),\n ... Purchase(cost=7.33, price=7184.90, month='mar', ou='RJ'), \n ... Purchase(cost=7.33, price=7834.92, month='apr', ou='RJ'),\n ... Purchase(cost=73.3, price=8692.67, month='may', ou='RJ'), \n ... Purchase(cost=128.28, price=9552.14, month='jun', ou='RJ'), \n ... Purchase(cost=58.64, price=8828.44, month='jul', ou='RJ'), \n ... Purchase(cost=128.28, price=9652.73, month='aug', ou='RJ'), ]\n\n\nNow we have a list of objects ;-).\n\nYou can use a callback function to format values to display in your genereated table ::\n\n >>> def formatter(value):\n ... if isinstance(value, float):\n ... return '%.2f' % value\n ... else:\n ... return '%s' % value\n\nIt have a built-in example to display as string ::\n\n >>> from collective.pivottable import StringTable\n >>> tbl = StringTable() \n\nDefine an attrbute to name cols ::\n\n >>> tbl.attr_to_name_col = 'month'\n\nDefine the attrs mapping and how aggregate the values ::\n\n >>> tbl.attrs_to_fill_row = [{'attr': 'cost', 'label': 'Cost Total', 'callback': formatter, 'aggr_func': Sum}, \n ... {'attr': 'price', 'label': \"Sell's Price\", 'callback': formatter , 'aggr_func': Sum}, \n ... {'attr': 'gain', 'label': 'AVG Gain %', 'callback': formatter, 'aggr_func': Avg},\n ... {'attr': 'ou', 'label': 'OU', 'callback': formatter, 'aggr_func': GroupBy}]\n\nPass your objects to tbl ::\n\n >>> tbl.objects = purchases\n\nSet a name to first col ::\n\n >>> tbl.first_col_title = 'Purchases'\n\nGet your text table ::\n\n >>> tbl.show()\n Purchases OU jan feb mar apr may jun jul aug\n Cost Total RJ 14.66 14.66 7.33 7.33 73.30 128.28 58.64 128.28\n Sell's Price RJ 463.61 4946.68 7184.90 7834.92 8692.67 9552.14 8828.44 9652.73\n AVG Gain % RJ 30.62 336.43 979.20 1067.88 117.59 73.46 149.55 74.25\n Cost Total NY 5.00 14.66 7.33 7.33 73.30 128.28 58.64 128.28\n Sell's Price NY 7 4946.68 7184.90 7834.92 8692.67 9552.14 8828.44 9652.73\n AVG Gain % NY 0.40 336.43 979.20 1067.88 117.59 73.46 149.55 74.25 \n\nOr get a list of rows and cols (main use) ::\n\n >>> for line in tbl.getAllRows():\n ... print line\n ...\n ['Purchases', 'OU', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug']\n ['Cost Total', 'RJ', '14.66', '14.66', '7.33', '7.33', '73.30', '128.28', '58.64', '128.28']\n [\"Sell's Price\", 'RJ', '463.61', '4946.68', '7184.90', '7834.92', '8692.67', '9552.14', '8828.44', '9652.73']\n ['AVG Gain %', 'RJ', '30.62', '336.43', '979.20', '1067.88', '117.59', '73.46', '149.55', '74.25']\n ['Cost Total', 'NY', '5.00', '14.66', '7.33', '7.33', '73.30', '128.28', '58.64', '128.28']\n [\"Sell's Price\", 'NY', '7', '4946.68', '7184.90', '7834.92', '8692.67', '9552.14', '8828.44', '9652.73']\n ['AVG Gain %', 'NY', '0.40', '336.43', '979.20', '1067.88', '117.59', '73.46', '149.55', '74.25']\n [] \n\nThe module aggregate_functions provides some aggregates functions, that you can case ::\n\n >>> from collective.pivottable.aggregate_functions import Avg, First, GroupBy, Last, Max, Min, Sum\n\nThe Base API to create a aggregate_function is ::\n\n >>> class Sum(object):\n ... def __init__(self):\n ... self.values = []\n ... def append(self, value):\n ... self.values.append(value)\n ... def __call__(self):\n ... return sum(self.values)\n\nIn other words, a append and a __call__, the __init__ is optional.\n\n.. _Pivot Tables: http://en.wikipedia.org/wiki/Pivot_table\n.. _Simples Consultoria: http://www.simplesconsultoria.com.br\n\n# vim:ft=doctest\n\nAggregating\n===========\n\n\n\nChecking Pivot Table\n--------------------\n\nLet's create our class to add in pivot table ::\n\n >>> class Purchase(object):\n ... def __init__(self, cost=0.0, price=0.0, month='', ou=''):\n ... self.cost = cost\n ... self.price = price\n ... self.month = month\n ... self.ou = ou\n ... def gain(self):\n ... return (self.price - self.cost) / self.cost\n ... def __repr__(self):\n ... return 'Purchase(cost=%f, price=%f, month=%s, ou=%s)' % (self.cost,\n ... self.price, self.month, self.ou) \n\n\nLet's create some purchases, for NY::\n\n >>> purchases = [Purchase(cost=5, price=7, month='jan', ou='NY'), \n ... Purchase(cost=5, price=7, month='jan', ou='NY'),\n ... Purchase(cost=14, price=4900, month='feb', ou='NY'),\n ... Purchase(cost=7, price=7000, month='mar', ou='NY'), Purchase(cost=7, price=7834, month='apr', ou='NY'),\n ... Purchase(cost=73, price=8692, month='may', ou='NY'), Purchase(cost=128, price=9552, month='jun', ou='NY'), \n ... Purchase(cost=58, price=8828, month='jul', ou='NY'), Purchase(cost=128, price=9652, month='aug', ou='NY'), ]\n\nLet's create some purchases, for RJ::\n\n >>> purchases += [Purchase(cost=14, price=463, month='jan', ou='RJ'), Purchase(cost=14, price=4946, month='feb', ou='RJ'),\n ... Purchase(cost=7, price=7184, month='mar', ou='RJ'), Purchase(cost=7, price=7834, month='apr', ou='RJ'),\n ... Purchase(cost=73, price=8692, month='may', ou='RJ'), Purchase(cost=128, price=9552, month='jun', ou='RJ'), \n ... Purchase(cost=58, price=8828, month='jul', ou='RJ'), Purchase(cost=128, price=9652, month='aug', ou='RJ'), ]\n\n\nGenerating a simple Pivot Table::\n\n >>> from pivot_table import *\n\n\n >>> fmt = PivotTable()\n >>> fmt.attr_to_name_col = 'month'\n >>> fmt.attrs_to_fill_row = [{'attr': 'cost', 'label': 'Cost Total', 'aggr_func': Sum}, \n ... {'attr': 'price', 'label': \"Sell's Price\", 'aggr_func': Sum}, \n ... {'attr': 'gain', 'label': 'AVG Gain %', 'aggr_func': Avg},\n ... {'attr': 'ou', 'label': 'OU', 'aggr_func': GroupBy}]\n >>> fmt.objects = purchases\n >>> fmt.first_col_title = 'Purchases'\n\nChecking the titles ::\n\n >>> fmt.getHeader()\n ['Purchases', 'OU', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug']\n\nChecking the rows ::\n\n >>> rows = fmt.getRows()\n\n >>> rows[0]\n ['Cost Total', 'RJ', 14, 14, 7, 7, 73, 128, 58, 128]\n >>> rows[1]\n [\"Sell's Price\", 'RJ', 463, 4946, 7184, 7834, 8692, 9552, 8828, 9652]\n >>> rows[2]\n ['AVG Gain %', 'RJ', 32.0, 352.0, 1025.0, 1118.0, 118.0, 73.0, 151.0, 74.0]\n\n >>> rows[3]\n ['Cost Total', 'NY', 10, 14, 7, 7, 73, 128, 58, 128]\n >>> rows[4]\n [\"Sell's Price\", 'NY', 14, 4900, 7000, 7834, 8692, 9552, 8828, 9652]\n >>> rows[5]\n ['AVG Gain %', 'NY', 0.0, 349.0, 999.0, 1118.0, 118.0, 73.0, 151.0, 74.0]\n\nChecking the footer ::\n\n >>> fmt.getFooter()\n []\n\nNow, new purchases\n------------------\n\nNY has purchases in jan. and feb. :: \n\n >>> purchases = [Purchase(cost=5, price=10, month='jan', ou='NY'), \n ... Purchase(cost=5, price=10, month='jan', ou='NY'),\n ... Purchase(cost=14, price=28, month='feb', ou='NY'),\n ... Purchase(cost=14, price=28, month='feb', ou='NY'),\n ... ]\n\nRJ has purchases only in feb. ::\n\n >>> purchases += [\n ... Purchase(cost=14, price=28, month='feb', ou='RJ'),\n ... Purchase(cost=14, price=28, month='feb', ou='RJ'),\n ... ]\n\nUsing the same params to Pivot Table ::\n\n >>> fmt = PivotTable()\n >>> fmt.attr_to_name_col = 'month'\n >>> fmt.attrs_to_fill_row = [{'attr': 'cost', 'label': 'Cost Total', 'aggr_func': Sum}, \n ... {'attr': 'price', 'label': \"Sell's Price\", 'aggr_func': Sum}, \n ... {'attr': 'gain', 'label': 'AVG Gain %', 'aggr_func': Avg},\n ... {'attr': 'ou', 'label': 'OU', 'aggr_func': GroupBy}]\n >>> fmt.objects = purchases\n >>> fmt.first_col_title = 'Purchases'\n\nRJ need the col jan. to be empty (None) ::\n\n >>> fmt.getHeader()\n ['Purchases', 'OU', 'jan', 'feb']\n >>> rows = fmt.getRows()\n >>> rows[0]\n ['Cost Total', 'RJ', None, 28]\n >>> rows[1]\n [\"Sell's Price\", 'RJ', None, 56]\n >>> rows[2]\n ['AVG Gain %', 'RJ', None, 1.0]\n\n >>> rows[3]\n ['Cost Total', 'NY', 10, 28]\n >>> rows[4]\n [\"Sell's Price\", 'NY', 20, 56]\n >>> rows[5]\n ['AVG Gain %', 'NY', 1.0, 1.0]\n\n\nChangelog\n=========\n\n1.1.1 - (2009-09-14)\n--------------------\n\n* fixes typos on text purchases - Thanks Leandro Lameiro :-) [lucmult]\n\n1.1 - (2009-09-07)\n------------------\n\n* fixes a bug, when a row doesn't has value in a column (like fist col), and we were using value from the next col (second col). Fixes, too, the aggregation that was broken. And add tests \\o/ [lucmult]\n\n1.0 - Initial Release\n---------------------\n\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://dev.plone.org/collective/browser/collective.pivottable", "keywords": "plone zope python pivot table pivottable", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "collective.pivottable", "package_url": "https://pypi.org/project/collective.pivottable/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/collective.pivottable/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://dev.plone.org/collective/browser/collective.pivottable" }, "release_url": "https://pypi.org/project/collective.pivottable/1.1.1/", "requires_dist": null, "requires_python": null, "summary": "A class to generate Pivot Tables based on Objects, using your attributes and/or methods, that can use Zope Acquisition to get those.", "version": "1.1.1" }, "last_serial": 788009, "releases": { "1.0": [], "1.0dev-r92234": [ { "comment_text": "", "digests": { "md5": "c535d9651bc0c5362ad7ba1ee9e37697", "sha256": "ba95c465bb95c110563ae2abd0e84548dff044243e61935160b99c498cd4c53f" }, "downloads": -1, "filename": "collective.pivottable-1.0dev_r92234-py2.4.egg", "has_sig": false, "md5_digest": "c535d9651bc0c5362ad7ba1ee9e37697", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 13998, "upload_time": "2009-07-14T01:25:30", "url": "https://files.pythonhosted.org/packages/9f/95/92124e247ddf76c4f2baf4b7ce3e3ab53134e390bdd74894ec5d7e48c979/collective.pivottable-1.0dev_r92234-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "6cfa096384e06da1d78a70d915cda895", "sha256": "9f26b37afe00bdfdbed93bceac84bdcac61600fc34b8ff73ea21bd72966d8ed0" }, "downloads": -1, "filename": "collective.pivottable-1.0dev-r92234.tar.gz", "has_sig": false, "md5_digest": "6cfa096384e06da1d78a70d915cda895", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6634, "upload_time": "2009-07-14T01:25:28", "url": "https://files.pythonhosted.org/packages/95/23/ccef4ae7085483e48c463cd7926a16dadcff9b6c649b0bdb96b82f8971b8/collective.pivottable-1.0dev-r92234.tar.gz" } ], "1.1": [], "1.1.1": [], "1.1.1dev-r97461": [ { "comment_text": "", "digests": { "md5": "a11f30c61e033fa8476e4f2d460b2236", "sha256": "274dff7bc554bbbccc06079fa7ee6dda029093c6179b0cf5f29ac7e7c0641e04" }, "downloads": -1, "filename": "collective.pivottable-1.1.1dev_r97461-py2.4.egg", "has_sig": false, "md5_digest": "a11f30c61e033fa8476e4f2d460b2236", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 16353, "upload_time": "2009-09-15T01:00:34", "url": "https://files.pythonhosted.org/packages/b5/5b/5bcc42bffb0e210cf56b042e6969018033f7b4eac90060ab0e0270fe1a09/collective.pivottable-1.1.1dev_r97461-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "7faed1483075da05acd3b7e2d8944b09", "sha256": "b25e6018aee30fc2d4441de187cbf5540617cd54e69ce5374b3f4583315e5d5a" }, "downloads": -1, "filename": "collective.pivottable-1.1.1dev-r97461.tar.gz", "has_sig": false, "md5_digest": "7faed1483075da05acd3b7e2d8944b09", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8137, "upload_time": "2009-09-15T01:00:31", "url": "https://files.pythonhosted.org/packages/5b/95/c65b939f57c988905da1fe0aa7408107101b9c6a804a0384991c322a6509/collective.pivottable-1.1.1dev-r97461.tar.gz" } ], "1.1.1dev-r97462": [ { "comment_text": "", "digests": { "md5": "243db84c6ec8d5cd962c0d0c5ad65ee4", "sha256": "2d2b5433eeba8ce2e38d64d33560923287f8986ac71bcef605a25896e9440523" }, "downloads": -1, "filename": "collective.pivottable-1.1.1dev_r97462-py2.4.egg", "has_sig": false, "md5_digest": "243db84c6ec8d5cd962c0d0c5ad65ee4", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 16345, "upload_time": "2009-09-15T01:12:55", "url": "https://files.pythonhosted.org/packages/4d/4d/cdc6300fb659507b4633b0043475e0d7019dca422cc3e5eb74560af630b1/collective.pivottable-1.1.1dev_r97462-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "0472b6c3886fb57a2bf847fba49d7060", "sha256": "6b562800577b6f1b311edb07ae712ced22a72d104a9ddbb7bdae0a7850405a31" }, "downloads": -1, "filename": "collective.pivottable-1.1.1dev-r97462.tar.gz", "has_sig": false, "md5_digest": "0472b6c3886fb57a2bf847fba49d7060", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8126, "upload_time": "2009-09-15T01:12:53", "url": "https://files.pythonhosted.org/packages/cf/99/68ead0dc680a40b6d3f41eebdc22e33971a1d12995b18994ff17d7b88f14/collective.pivottable-1.1.1dev-r97462.tar.gz" } ], "1.1dev-r96945": [ { "comment_text": "", "digests": { "md5": "8f42df95f2e57aebb0a480cb04865603", "sha256": "38543f4707db1b7aec6baaae558226c8048916adca1209e442f7aca57ef9866f" }, "downloads": -1, "filename": "collective.pivottable-1.1dev_r96945-py2.4.egg", "has_sig": false, "md5_digest": "8f42df95f2e57aebb0a480cb04865603", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 16312, "upload_time": "2009-09-07T23:00:15", "url": "https://files.pythonhosted.org/packages/90/e1/719d1f13e214c09d7fa9f5134bdadb3dc378e57187cb74dcef1b04a5e5ae/collective.pivottable-1.1dev_r96945-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "180f87cc5e508c3f0f84239a3d00eaed", "sha256": "10dbe4ee5123cbe5629891f583b6139a91e538a4c494eb7994a1549bb1a8fe11" }, "downloads": -1, "filename": "collective.pivottable-1.1dev-r96945.tar.gz", "has_sig": false, "md5_digest": "180f87cc5e508c3f0f84239a3d00eaed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8053, "upload_time": "2009-09-07T23:00:12", "url": "https://files.pythonhosted.org/packages/70/e9/04589aee06ba56669a6e7a5321a7c786bfb15c6c4f501e96fa1c64420f6b/collective.pivottable-1.1dev-r96945.tar.gz" } ] }, "urls": [] }