# -*- coding: utf-8 -*-
from setuptools import setup

package_dir = \
{'': 'src'}

packages = \
['apteco', 'apteco.data']

package_data = \
{'': ['*']}

install_requires = \
['apteco-api>=0.2.1,<0.3.0',
 'numpy>=1.18,<2.0',
 'pandas>=1.0,<2.0',
 'pysimplegui>=4.0,<5.0']

setup_kwargs = {
    'name': 'apteco',
    'version': '0.8.0',
    'description': 'A Python package for interacting with Apteco Marketing Suite resources via the Apteco API.',
    'long_description': '**************\n  Quickstart\n**************\n\nRequirements\n============\n\n* Python 3.6+\n* Access to an installation of the Apteco API\n\nThe Apteco API (which also goes under the name **Orbit API**)\nis part of the Apteco Orbit™ installation.\nIf you have access to Apteco Orbit™, you also have access to the Apteco API!\nIf you\'re not sure about this, contact whoever administers your Apteco software,\nor get in touch with Apteco support (support@apteco.com).\n\nInstallation\n============\n\nYou can install the package the usual way from PyPI using ``pip``:\n\n.. code-block:: console\n\n   python -m pip install apteco\n\nLogging in\n==========\n\nYour login credentials are the same username and password\nyou would use to log in to Apteco Orbit™:\n\n.. code-block:: python\n\n    >>> from apteco import login\n    >>> my_session = login("https://my-site.com/OrbitAPI", "my_data_view", "my_system", "jdoe")\n\nYou will be asked to enter your password in the terminal, which won\'t be echoed.\nIf Python is unable to ask for your password in this way,\nit will provide a pop-up box instead.\nThis might appear in the background,\nso check your taskbar for a new window if nothing seems to be happening.\n\nIf you don\'t want to enter your password every time,\nthere\'s also a ``login_with_password`` function which takes your password\nas a fifth argument:\n\n.. code-block:: python\n\n    >>> from apteco import login_with_password\n    >>> my_session = login_with_password(\n    ...     "https://my-site.com/OrbitAPI",\n    ...     "my_data_view",\n    ...     "my_system",\n    ...     "jdoe",\n    ...     "password",  # password is in plain sight in the code!\n    ... )\n\nTables\n======\n\nTables are accessed through the ``tables`` attribute on the ``Session`` object.\nYou can retrieve a table using its name:\n\n.. code-block:: python\n\n    >>> bookings = my_session.tables["Bookings"]\n\n``Table`` objects have properties for various metadata:\n\n.. code-block:: python\n\n    >>> print(\n    ...     f"There are {bookings.total_records:,}"\n    ...     f" {bookings.plural.lower()}"\n    ...     f" in the system."\n    ... )\n    There are 2,130,081 bookings in the system.\n\nVariables\n=========\n\nVariables are accessed through the ``variables`` attribute\non the ``Session`` object.\nYou can retrieve a variable using its name or description:\n\n.. code-block:: python\n\n    >>> occupation = my_session.variables["peOccu"]  # name\n    >>> cost = my_session.variables["Cost"]  # description\n\nEach table also has a ``variables`` attribute\nfor accessing the variables on that table:\n\n.. code-block:: python\n\n    >>> occupation = people.variables["peOccu"]\n    >>> cost = bookings.variables["Cost"]\n\nFor convenience you can access variables by indexing into the ``Table`` itself:\n\n.. code-block:: python\n\n    >>> occupation = people["peOccu"]\n    >>> cost = bookings["Cost"]\n\n``Variable`` objects have attributes with various metadata:\n\n.. code-block:: python\n\n    >>> occupation.type\n    <VariableType.SELECTOR: \'Selector\'>\n    >>> cost.description\n    \'Cost\'\n\nCreating selections\n===================\n\nYou can use the Python operators with ``Variable`` objects to build selections\nbased on criteria and return a count:\n\n.. code-block:: python\n\n    >>> sweden = bookings["Destination"] == "29"\n    >>> sweden.count()\n    25207\n\nYou can specify multiple values using any *iterable*:\n\n.. code-block:: python\n\n    >>> people = my_session.tables["People"]\n    >>> high_earners = people["Income"] == (f"{i:02}" for i in range(7, 12))\n    >>> high_earners.count()\n    7114\n\nYou can use other operators as well; for example, to exclude values:\n\n.. code-block:: python\n\n    >>> households = my_session.tables["Households"]\n    >>> uk_only = households["Region"] != "14"  # 14 is Channel Islands\n    >>> uk_only.count()\n    741572\n\nOr to allow a range of values:\n\n.. code-block:: python\n\n    >>> low_profit = bookings["Profit"] <= 25\n    >>> low_profit.count()\n    211328\n\n.. code-block:: python\n\n    >>> second_half_of_alphabet = people["Surname"] >= "N"\n    >>> second_half_of_alphabet.count()\n    410954\n\nDate and DateTime variables use the built-in ``datetime`` module:\n\n.. code-block:: python\n\n    >>> from datetime import date, datetime\n    >>> bookings_before_2019 = bookings["Booking Date"] <= date(2018, 12, 31)\n    >>> bookings_before_2019.count()\n    972439\n\nYou can take advantage of functionality available in other Python packages:\n\n.. code-block:: python\n\n    >>> from dateutil.relativedelta import relativedelta\n    >>> under_30 = people["DOB"] >= date.today() - relativedelta(years=30)\n    >>> under_30.count()\n    207737\n\nCombining selections\n====================\n\nYou can use the ``&`` ``|`` operators to combine selection criteria:\n\n.. code-block:: python\n\n    >>> sweden = bookings["Destination"] == "29"\n    >>> cost_at_least_2k = bookings["Cost"] >= 2000\n    >>> expensive_sweden = sweden & cost_at_least_2k\n    >>> expensive_sweden.count()\n    632\n    >>> student = people["Occupation"] == "4"\n    >>> under_21 = people["DOB"] >= date.today() - relativedelta(years=21)\n    >>> eligible_for_discount = student | under_21\n    >>> eligible_for_discount.count()\n    188364\n\nThe ``~`` operator negates a selection:\n\n.. code-block:: python\n\n    >>> pay_full_price = ~eligible_for_discount\n    >>> pay_full_price.count()\n    968189\n\nYou can join clauses from different tables and it will automatically handle\nthe required table changes:\n\n.. code-block:: python\n\n    >>> high_affordability = high_earners | cost_at_least_2k  # will resolve to people\n    >>> high_affordability.count()\n    56096\n    >>> high_affordability.table_name\n    \'People\'\n\nThe left-most clause determines the resolve table:\n\n.. code-block:: python\n\n    >>> female = people["Gender"] == "F"\n    >>> usa = bookings["Destination"] == "38"\n    >>> female.table_name\n    \'People\'\n    >>> usa.table_name\n    \'Bookings\'\n    >>> (female & usa).table_name\n    \'People\'\n    >>> (usa & female).table_name\n    \'Bookings\'\n\nYou can manually set the resolve table using the ``*`` operator:\n\n.. code-block:: python\n\n    >>> bookings_by_under_21s = bookings * under_21\n    >>> bookings_by_under_21s.count()\n    135100\n    >>> bookings_by_under_21s.table_name\n    \'Bookings\'\n\nCompound clauses follow Python operator precedence:\n\n.. code-block:: python\n\n    >>> student_or_young_female = student | female & under_21\n    >>> student_or_young_female.count()\n    166708\n    >>> student_or_female_must_be_young = (student | female) & under_21\n    >>> student_or_female_must_be_young.count()\n    49225\n\nBe especially careful where compound clauses involve table changes:\n\n.. code-block:: python\n\n    >>> women_to_sweden = female & sweden\n    >>> women_to_sweden.count()  # selection on People table\n    8674\n    >>> audience_1 = bookings * (female & sweden)\n    >>> audience_1.count()  # bookings by women who\'ve been to sweden\n    23553\n    >>> audience_2 = (bookings * female) & sweden\n    >>> audience_2.count()  # bookings made by a woman, with destination of sweden\n    8687\n\nCreating data grids\n===================\n\nYou can create a data grid from a table:\n\n.. code-block:: python\n\n    >>> urn = bookings["Booking URN"]\n    >>> dest = bookings["Destination"]\n    >>> occupation = people["Occupation"]\n    >>> town = households["Town"]\n    >>> datagrid = bookings.datagrid([urn, dest, cost, occupation, town])\n\nConvert it to a Pandas DataFrame:\n\n.. code-block:: python\n\n    >>> datagrid.to_df()\n        Booking URN    Destination     Cost       Occupation        Town\n    0      10001265         France  1392.35  Sales Executive    Aberdeen\n    1      10001266         France   780.34  Sales Executive    Aberdeen\n    2      10011532        Germany   181.68    Manual Worker      Alford\n    3      10011533        Germany   300.67    Manual Worker      Alford\n    4      10015830   Unclassified   228.70  Sales Executive     Macduff\n    ..          ...            ...      ...              ...         ...\n    995    10996176  United States   241.24     Professional  Glenrothes\n    996    10996177         Greece   343.23          Manager  Glenrothes\n    997    10996178  United States   636.22          Manager  Glenrothes\n    998    10996179  United States   356.21          Manager  Glenrothes\n    999    10996180  United States   438.20          Manager  Glenrothes\n\n    [1000 rows x 5 columns]\n\nYou can use a base selection to filter the records:\n\n.. code-block:: python\n\n    >>> sweden = dest == "29"\n    >>> sweden_datagrid = sweden.datagrid([urn, dest, cost, occupation, town])\n    >>> sweden_datagrid.to_df()\n        Booking URN Destination     Cost       Occupation           Town\n    0      10172319      Sweden  1201.81  Sales Executive         Bolton\n    1      10384970      Sweden   344.30          Manager     Chelmsford\n    2      10421011      Sweden   322.89  Sales Executive        Croydon\n    3      10425298      Sweden   880.02          Student  South Croydon\n    4      10479109      Sweden   172.91    Retail Worker       Nantwich\n    ..          ...         ...      ...              ...            ...\n    995    11471824      Sweden   118.76  Sales Executive    King\'s Lynn\n    996    11576762      Sweden   652.38    Public Sector        Redhill\n    997    11576764      Sweden   183.36    Public Sector        Redhill\n    998    11682962      Sweden  1166.38          Manager         London\n    999    11754655      Sweden   192.45  Sales Executive          Ascot\n\n    [1000 rows x 5 columns]\n\nYou can filter using a selection from a different table:\n\n.. code-block:: python\n\n    >>> manchester = households["Region"] == "13"\n    >>> manc_datagrid = manchester.datagrid(\n    ...     [urn, dest, cost, occupation, town], table=bookings\n    ... )\n    >>> manc_datagrid.to_df()\n        Booking URN    Destination     Cost       Occupation         Town\n    0      10172319         Sweden  1201.81  Sales Executive       Bolton\n    1      10172320  United States  1616.80  Sales Executive       Bolton\n    2      10173729         France   581.71          Student       Bolton\n    3      10173730         France  2224.70          Student       Bolton\n    4      10177047         France   686.53  Sales Executive       Bolton\n    ..          ...            ...      ...              ...          ...\n    995    11739340      Australia   316.60     Professional  Stalybridge\n    996    11739342   Unclassified   316.58  Sales Executive  Stalybridge\n    997    12087034         Greece  1305.66    Public Sector   Altrincham\n    998    12087035  United States   585.65    Public Sector   Altrincham\n    999    12087036      Australia   496.64    Public Sector   Altrincham\n\n    [1000 rows x 5 columns]\n\nCreating cubes\n==============\n\nYou can create a cube from a table:\n\n.. code-block:: python\n\n    >>> occupation = people["Occupation"]\n    >>> income = people["Income"]\n    >>> gender = people["Gender"]\n    >>> cube = people.cube([occupation, income, gender])\n\nConvert it to a Pandas DataFrame:\n\n.. code-block:: python\n\n    >>> df = cube.to_df()\n    >>> df.head(10)\n                                   People\n    Occupation    Income  Gender\n    Manual Worker <£10k   Female    15624\n                          Male       5321\n                          Unknown       5\n                  £10-20k Female    43051\n                          Male       5992\n                          Unknown      25\n                  £20-30k Female     1498\n                          Male        649\n                          Unknown      14\n                  £30-40k Female      675\n\nYou can pivot the dimensions to make it easier to read:\n\n.. code-block:: python\n\n    >>> df.unstack(level=0)\n                       People          ...\n    Occupation       Director Manager  ... Student Unemployed\n    Income   Gender                    ...\n    <£10k    Female      1279    4649  ...   28002      21385\n             Male         832    2926  ...   14296       8386\n             Unknown        4      16  ...      10        155\n    £10-20k  Female      4116   16665  ...   39462      17230\n             Male        2139    9123  ...   17917       4532\n             Unknown        9      47  ...      25        368\n    £100k+   Female         2       1  ...       2          0\n             Male           1       0  ...       3          0\n             Unknown        1       0  ...       1          0\n    £20-30k  Female      1267    6238  ...    6669       5747\n             Male        1050    5315  ...    5274       1345\n             Unknown        5      45  ...      22        236\n    £30-40k  Female      1591    6621  ...    5690       3117\n             Male        1940    9713  ...    6345       1049\n             Unknown       46     140  ...      63        519\n    £40-50k  Female       265     965  ...     587        262\n             Male         518    1800  ...     943        115\n             Unknown       22      58  ...      29        110\n    £50-60k  Female       336     806  ...     425        277\n             Male         607    1677  ...     692         69\n             Unknown       47      88  ...      64         89\n    £60-70k  Female        40     112  ...      54         58\n             Male          96     220  ...      95          8\n             Unknown       11      16  ...      17         17\n    £70-80k  Female        44      96  ...      42         27\n             Male         102     179  ...      63          5\n             Unknown       12      22  ...      15          5\n    £80-90k  Female        11      11  ...       3          0\n             Male          14      13  ...      16          0\n             Unknown        4       3  ...       5          0\n    £90-100k Female         1       0  ...       1          1\n             Male          11       7  ...       4          0\n             Unknown        3       6  ...       9          0\n\n    [33 rows x 10 columns]\n\nYou can use a base selection to filter the records:\n\n.. code-block:: python\n\n    >>> occupation = people["Occupation"]\n    >>> region = households["Region"]\n    >>> student = occupation == "4"\n    >>> student_cube = student.cube([occupation, dest, region])\n    >>> student_df = student_cube.to_df()\n    >>> student_df.head()\n                                                                     People\n    Occupation    Destination Region\n    Manual Worker Australia   North                                       0\n                              North West (Excluding Gtr Manchester)       0\n                              South East (Outside M25 )                   0\n                              South West                                  0\n                              East Midlands                               0\n\nSelecting only cells where ``Occupation`` is *Student*,\nand pivoting ``Destination`` dimension:\n\n.. code-block:: python\n\n    >>> student_df.loc["Student"].unstack(level=0)\n                                             People          ...\n    Destination                           Australia Denmark  ... Sweden United States\n    Region                                                   ...\n    Channel Islands                              46       1  ...     10            81\n    East Anglia                                 989       0  ...    109           905\n    East Midlands                              1956       0  ...    174          1762\n    Greater Manchester                         1197       1  ...    147          1089\n    North                                       959       2  ...    115           869\n    North West (Excluding Gtr Manchester)      1594       2  ...    177          1429\n    Northern Ireland                            467       0  ...     42           492\n    Scotland                                   2061       1  ...    224          1964\n    South East (Inside M25 )                   3935       0  ...    390          3580\n    South East (Outside M25 )                  6255       1  ...    608          5587\n    South West                                 2310       0  ...    182          2037\n    Wales                                       974       0  ...    122           860\n    West Midlands                              2643       0  ...    288          2362\n    Yorkshire and Humber                       2295       0  ...    249          2089\n\n    [14 rows x 19 columns]\n\nYou can use a selection from a different table to filter the records in the cube:\n\n.. code-block:: python\n\n    >>> manchester = region == "13"\n    >>> manc_cube = manchester.cube([occupation, dest, region], table=bookings)\n    >>> manc_cube.to_df()\n                                                                      Bookings\n    Occupation    Destination  Region\n    Manual Worker Australia    North                                         0\n                               North West (Excluding Gtr Manchester)         0\n                               South East (Outside M25 )                     0\n                               South West                                    0\n                               East Midlands                                 0\n                                                                        ...\n    Retired       South Africa Scotland                                      0\n                               Wales                                         0\n                               Northern Ireland                              0\n                               Greater Manchester                            0\n                               Channel Islands                               0\n\n    [2660 rows x 1 columns]\n\nYou can find the complete documentation\nincluding a more thorough `tutorial <https://help.apteco.com/python/tutorial.html>`_\non the `Apteco website <https://help.apteco.com/python/index.html>`_.',
    'author': 'Apteco Ltd',
    'author_email': 'support@apteco.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://help.apteco.com/python/index.html',
    'package_dir': package_dir,
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6.1,<4.0.0',
}


setup(**setup_kwargs)
