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

packages = \
['anaximander',
 'anaximander.dataobjects',
 'anaximander.descriptors',
 'anaximander.meta',
 'anaximander.operators',
 'anaximander.utilities']

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

install_requires = \
['beartype>=0.10.4,<0.11.0',
 'frozendict>=2.3,<3.0',
 'pandas>=1.4,<2.0',
 'petl>=1.7.9,<2.0.0',
 'pydantic>=1.9,<2.0',
 'python-dotenv>=0.20.0,<0.21.0',
 'ruamel.yaml>=0.17,<0.18',
 'sortedcontainers>=2.4.0,<3.0.0']

setup_kwargs = {
    'name': 'anaximander',
    'version': '0.4a1',
    'description': 'The rapid application development framework for data-intensive Python',
    'long_description': '# Anaximander\n\nAnaximander aims to evolve into a full-fledge rapid application development framework for data-intensive backends. In its initial release, currently under development, it will take the form of a data modeling tool that facilitates storage and integration across multiple database technologies. Modern data applications are polyglot, in the sense that they use a plurality of storage engines -say a relational database for modeling entities like people, places and things, a document database for nested specifications, a columnar database for time series, and a cloud data warehouse for analytics and report generation. Anaximander allows Python developers to declare all application data models as object classes, using unifying semantics. Hence it generalizes the concept of Object-Relational Mapper to no-SQL databases, and enables programmers to work with richly featured objects that embed the application\'s domain modeling. Further, the object-oriented paradigm automatically extends to data collections, either in the form of the built-in list, set and dict primitives, or in the form of vectorized Series and Dataframes from the pandas library. For instance, if an application programmer declares a `TemperatureProbe` entity model and a `TemperatureSample` record model, then typing `nx.Set[TemperatureProbe]` or `nx.Table[TemperatureSample]` returns concrete object classes that have been programmatically generated by the framework\'s metaclasses and that carry metadata and attributes derived from the model class declarations. Among other advantages, this provides automated data validation, intuitive data exploration, and clean, expressive programming.\n\nAt the highest level, the framework considers three primary data types: entities, records and specs.\n\n- **Entities** represent discrete, identifiable application constructs such as physical assets, products, people, places, etc.\n- **Records** are purely informational objects that represent observations, such as sensor readings, sales reports, or alert notifications.\n- **Specs** are arbitrarily nested key-value mappings that capture specifications or configurations with a flexible schema, be it detailed entity attributes, schedules or model parameters.\n\nGenerally speaking, entities are relational and fit best in a relational database or an object store. Records are indexed by key and time, making them equivalent to event messages, and fit well in columnar databases or data lakes. In the data warehouse terminology, entities and records are analogous to dimensions and facts. Finally, specs are document-like objects that may be stored in a document database, a data lake, or embedded in a JSON-typed column as part of an entity table.\n\nFor a basic usage demonstration, consider an industrial IoT application in which temperature probes are deployed on manufacturing machines. The probes send regular messages containing temperature readings, which are logged and summarized on preset periodicities. Besides, a stream processor analyzes the values in near-real time to emit overheat alerts, and any such occurrence eventually gets logged as an overheat session, i.e. a time interval during which overheating conditions were met.\n\nThe following code is a partial demonstration, using the current implementation state. The most notable gaps separating it from the target release are as follows:\n\n- Model relations are still lacking, particularly the ability to link records to entities.\n- Tabular data indexing is still limited.\n- Most crucially, there is no I/O yet. The first step will be to link models to Arrow datasets so that tabular data can be imported and exported to and from the parquet format. JSON and .csv formats will also be available. Once this is done, the framework will be integrated with database engines.\n- Tabular data validation works but with a sub-optimal implementation that converts dataframes to individual records and back. This will be fixed by integrating the panderas library.\n\nInstallation is straightforward:\n\n```python\npip install anaximander\n```\n\nHere are model declarations:\n\n```python\nfrom datetime import datetime\nfrom typing import Optional\n\nimport anaximander as nx\nfrom anaximander.operators import Sessionizer\nimport numpy as np\nimport pandas as pd\n\n# =========================================================================== #\n#                              Model declarations                             #\n# =========================================================================== #\n\n# Entities are identifiable things\nclass Machine(nx.Entity):\n    id: int = nx.id()\n    machine_type: str = nx.data()\n    machine_floor: Optional[str] = nx.data()\n\n# Measurements feature units that get printed\n# The metadata is carried into model schemas that use this data type and\n# can be used by plotting libraries, or for unit conversions.\n# Also note the validation input (greater or equal to -273), using\n# Pydantic\'s notations.\nclass Temperature(nx.Measurement):\n    unit = "Celsius"\n    ge = -273\n\n# Samples are timestamped records expected to show up at a somewhat set frequency,\n# though not necessarily strictly so. In other words, the freq metadata is\n# used as a time characteristic in summarization operations, but missing or\n# irregular samples are tolerated.\n# Note that the \'machine_id\' field will eventually be replaced by a relational\n# \'machine\' field of type Machine. This functionality is still pending.\n# Also note that the temperature field defines its own validation parameters,\n# supplemental to those already defined in the Temperature class (not easy!)\nclass TemperatureSample(nx.Sample):\n    machine_id: int = nx.key()\n    timestamp: datetime = nx.timestamp(freq="5T")\n    temperature: Temperature = nx.data(ge=0, le=200)\n\n# Unlike samples, Journals are strictly periodic -by construction, since they\n# are intended as regular summaries, and hence feature a period field, whose\n# type is a pandas Period.\nclass TemperatureJournal(nx.Journal):\n    machine_id: int = nx.key()\n    period: pd.Period = nx.period(freq="1H")\n    avg_temp: Temperature = nx.data()\n    min_temp: Temperature = nx.data()\n    max_temp: Temperature = nx.data()\n\n# Spec models are intended as general-purpose nested documents, for storing\n# specifications, configuration, etc. They have no identifier because they\n# always have an \'owner\' -typically an Entity or Record object. This bit is\n# not implemented yet. If it was, the Machine model would carry an operating\n# spec as a data attribute.\n# Here the spec defines the nominal operating temperature range, and will\n# be used to compute overheat sessions.\nclass MachineOperatingSpec(nx.Spec):\n    min_temp: Temperature = nx.data()\n    max_temp: Temperature = nx.data()\n\n# Sessions are timestamped-records with two entries: a start and end times.\n# These are ubiquitous in natural data processing, particularly for aggregating\n# events, such as oveheat events in this case.\nclass OverheatSession(nx.Session):\n    machine_id: int = nx.key()\n    start_time: datetime = nx.start_time()\n    end_time: datetime = nx.end_time()\n\n# This is a very rudimentary implementation of a parametric operator that will\n# be used to compute overheat sessions. Note that the Sessionizer class reads\n# metadata from the TemperatureSample class, such as the names of the key\n# and timestamp field, as well as the timestamp frequency.\nsessionizer = Sessionizer(TemperatureSample, OverheatSession, feature="temperature")\n\n# In Anaximander, types are composable, and automatically assembled without\n# the need for a class declaration. Here we explicitly name a class for\n# tables of temperature samples. Unlike the use of generics in type annotations,\n# Table[TemperatureSample] is an actual class -which is cached once it is\n# created.\n# Table is a so-called archetype, and Table[TemperatureSample] is a concrete\n# subtype. A table instance wraps a dataframe along with metadata inherited\n# from its class -primarily the model\'s schema, which is used to conform and\n# validate the data.\nTempTable = nx.Table[TemperatureSample]\n```\n\nAnd some data inputs:\n\n```python\n# =========================================================================== #\n#                                 Data inputs                                 #\n# =========================================================================== #\n\n# Machine instance and operating spec\nm0 = Machine(id=0, machine_type="motor")\nm0_spec = MachineOperatingSpec(min_temp=40.0, max_temp=55.0)\n\n# Building a table of temperature samples\ntimes = pd.date_range(start="2022-2-18 12:00", freq="5T", periods=12)\ntemperatures = [45.0, 46.0, 45.0, 50.0, 59.0, 50.0, 48.0, 51.0, 52.0, 56.0, 58.0, 53.0]\nsample_log = TempTable(dict(machine_id=0, timestamp=times, temperature=temperatures))\n\n# Computing stats over an hour to fill a Journal instance. Note that eventually\n# this kind of summarization will be specified in model declarations and\n# carried out by operators -which will be at least partially automated, see\n# the sessionizer for a prototype.\navg_temp = round(np.mean(temperatures), 0)\nmin_temp = min(temperatures)\nmax_temp = max(temperatures)\nhourly = TemperatureJournal(\n    machine_id=0,\n    period="2022-2-18 12:00",\n    avg_temp=avg_temp,\n    min_temp=min_temp,\n    max_temp=max_temp,\n)\n\n# Computing overheat sessions\n# Note that the key and threshold will not be necessary once relations are\n# established between models -the sample log will be able to point to a machine\n# as part of its metadata, and the machine will own its operating spec,\n# providing a path to the threshold.\noverheat_sessions = sessionizer(sample_log, key=0, threshold=m0_spec.max_temp.data)\n\n```\n\nAnd some evaluations:\n\n```python\n# TempTable exposes a data frame, that is automatically indexed by key\n# and timestamp\n>>> assert isinstance(sample_log.data, pd.DataFrame)\n>>> print(sample_log)\n                                temperature\nmachine_id timestamp                       \n0          2022-02-18 12:00:00         45.0\n           2022-02-18 12:05:00         46.0\n           2022-02-18 12:10:00         45.0\n           2022-02-18 12:15:00         50.0\n           2022-02-18 12:20:00         59.0\n           2022-02-18 12:25:00         50.0\n           2022-02-18 12:30:00         48.0\n           2022-02-18 12:35:00         51.0\n           2022-02-18 12:40:00         52.0\n           2022-02-18 12:45:00         56.0\n           2022-02-18 12:50:00         58.0\n           2022-02-18 12:55:00         53.0\n```\n\n```python\n# TempTable can broken down into individual records of type TemperatureSample.\n# These feature temperature attributes with unit metadata.\n# Likewise, the temperature attribute of the TempTable is a series of\n# temperatures, and individual data points are measurements with metadata.\n>>> r0 = next(sample_log.records())\n>>> assert isinstance(r0, TemperatureSample)\n>>> print(r0.temperature)\n>>> assert next(sample_log.temperature.values()) == r0.temperature\n45.0 Celsius\n```\n\n```python\n# Temperature defines a lower bound, which is used to validate inputs\n>>> try:\n>>>     Temperature(-300)\n>>> except ValueError as e:\n>>>     print(e)\nCould not validate -300.0 as a <nxtype:Temperature> instance\n```\n\n```python\n# TemperatureSample defines its own bounds as well\n# This would also work if one tried to directly instantiate a table of\n# temperature samples from a dataframe -though in the current implementation\n# the framework converts the data frame to records and uses Pydantic, which\n# is obviously very inefficient. The target is to use the Panderas library,\n# with no change in the interface.\n>>> try:\n>>>     TemperatureSample(machine_id=m0.id, timestamp=times[0], temperature=250)\n>>> except ValueError as e:\n>>>     print(e)\nCould not validate machine_id                       0\ntimestamp      2022-02-18 12:00:00\ntemperature                  250.0\ndtype: object as a <nxtype:TemperatureSample> instance\n```\n\n```python\n# Here is a printout of our Journal instance\n>>> print(hourly)\nmachine_id                   0\nperiod        2022-02-18 12:00\navg_temp                  51.0\nmin_temp                  45.0\nmax_temp                  59.0\ndtype: object\n```\n\n```python\n# And finally a printout of our overheating sessions\' timespans, a pandas\n# IntervalIndex\n>>> print(overheat_sessions.timespans)\nIntervalIndex([[2022-02-18 12:17:30, 2022-02-18 12:22:30), [2022-02-18 12:42:30, 2022-02-18 12:52:30)], dtype=\'interval[datetime64[ns], left]\', name=\'timespan\')\n```\n',
    'author': 'Novavia Solutions',
    'author_email': 'info@novavia.us',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://www.anaximander.dev',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.10,<4.0',
}


setup(**setup_kwargs)
