efidgy


Nameefidgy JSON
Version 0.15 PyPI version JSON
download
home_pagehttps://efidgy.com/
SummaryPython bindings to efidgy services.
upload_time2023-02-03 18:42:51
maintainer
docs_urlNone
authorVasily Stepanov
requires_python>=3.6
licenseGPL3
keywords efidgy logistics optimization dispatcing vrp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # efidgy

Python bindings to efidgy services.


## Overview


### Environment

Environment in terms of efidgy package is a set of settings to work with efidgy backend.
Theese settings includes **customer code** and **access token** that will be used to communicate with backend.


### Unit System

If you will not set the unit system directly, efidgy will use current user settings: [console.efidgy.com/profile](https://console.efidgy.com/profile)

Anyway, it is a good practice to define the unit system in your code:

``` python
efidgy.env = efidgy.env.override(
    unit_system=efidgy.models.UnitSystem.IMPERIAL,
)
```


### Credentials

efidgy.env is initialized with settings fetched from the shell environment. The following environment variables are used:

 * EFIDGY_ACCESS_TOKEN -- You can get one at [console.efidgy.com/profile/company](https://console.efidgy.com/profile/company)
 * EFIDGY_CUSTOMER_CODE -- See [console.efidgy.com/profile/tokens](https://console.efidgy.com/profile/tokens)

You can always override code and/or token with the code like this:

``` python
efidgy.env = efidgy.env.override(
    code='hardcoded customer code',
)
```


## API documentation

Find out more at: [efidgy.com/docs](https://efidgy.com/docs)


## Sample usage

``` sh
export EFIDGY_CUSTOMER_CODE=code  # https://console.efidgy.com/profile/company
export EFIDGY_ACCESS_TOKEN=token  # https://console.efidgy.com/profile/tokens
```


### Sync API

``` python
import datetime
import efidgy


def create_project():
    project = efidgy.models.Project.service.create(
        name='Demo',
        currency='USD',
        project_type=efidgy.models.ProjectTypeCode.IDD_OR,
        shared_mode=efidgy.models.SharedMode.PRIVATE,
    )

    store_address = '6133 Broadway Terr., Oakland, CA 94618, USA'
    lat, lon = efidgy.tools.geocode(store_address)
    store = efidgy.models.idd_or.Store.service.create(
        project=project,
        address=store_address,
        lat=lat,
        lon=lon,
        name='Delivery Inc.',
        open_time=datetime.time(8, 0),
        close_time=datetime.time(18, 0),
    )

    efidgy.models.idd_or.Vehicle.service.create(
        project=project,
        store=store,
        name='Gary Bailey',
        fuel_consumption=11.76,
        fuel_price=3.25,
        salary_per_duration=21,
        duration_limit=datetime.timedelta(hours=9),
    )

    order_address = '1 Downey Pl, Oakland, CA 94610, USA'
    lat, lon = efidgy.tools.geocode(order_address)
    efidgy.models.idd_or.Order.service.create(
        project=project,
        store=store,
        name='#00001',
        address=order_address,
        lat=lat,
        lon=lon,
        ready_time=datetime.time(8, 0),
        delivery_time_from=datetime.time(12, 0),
        delivery_time_to=datetime.time(16, 0),
        load_duration=datetime.timedelta(minutes=1),
        unload_duration=datetime.timedelta(minutes=5),
        items=1,
        volume=3.53,
        weight=22.05,
    )

    return project


def solve(project):
    project.computate()

    solutions = efidgy.models.Solution.service.all(
        project=project,
    )

    if not solutions:
        return None

    return solutions[0]


def report(project, solution):
    print('Total Cost: {cost:.2f}{currency}'.format(
        cost=solution.cost,
        currency=project.currency.symbol,
    ))

    vehicles = efidgy.models.idd_or.Vehicle.service.all(
        project=project,
        solution=solution,
    )

    for vehicle in vehicles:
        print('{vehicle} Schedule'.format(
            vehicle=vehicle.name,
        ))
        if vehicle.route is not None:
            arr = vehicle.route.start_time
            for schedule in vehicle.route.schedule:
                dep = schedule.departure_time
                print('{at}\t{arr}\t{dep}'.format(
                    at=schedule.start_point.name,
                    arr=arr,
                    dep=dep,
                ))
                arr = schedule.arrival_time
            if vehicle.route.schedule:
                print('{at}\t{arr}\t{dep}'.format(
                    at=vehicle.route.schedule[-1].end_point.name,
                    arr=vehicle.route.schedule[-1].arrival_time,
                    dep='',
                ))


def main():
    project = create_project()
    solution = solve(project)
    if solution:
        report(project, solution)


if __name__ == '__main__':
    main()
```


### Output
```
Total Cost: 12.51$
Gary Bailey Schedule
Delivery Inc.   15:45:00        15:46:00
#00001          15:55:00        16:00:00
Delivery Inc.   16:09:00
```


### Async API

``` python
import datetime
import asyncio
import efidgy.asyncapi as efidgy


async def create_project():
    project = await efidgy.models.Project.service.create(
        name='Demo',
        currency='USD',
        project_type=efidgy.models.ProjectTypeCode.IDD_OR,
        shared_mode=efidgy.models.SharedMode.PRIVATE,
    )

    store_address = '6133 Broadway Terr., Oakland, CA 94618, USA'
    lat, lon = await efidgy.tools.geocode(store_address)
    store = await efidgy.models.idd_or.Store.service.create(
        project=project,
        address=store_address,
        lat=lat,
        lon=lon,
        name='Delivery Inc.',
        open_time=datetime.time(8, 0),
        close_time=datetime.time(18, 0),
    )

    await efidgy.models.idd_or.Vehicle.service.create(
        project=project,
        store=store,
        name='Gary Bailey',
        fuel_consumption=11.76,
        fuel_price=3.25,
        salary_per_duration=21,
        duration_limit=datetime.timedelta(hours=9),
    )

    order_address = '1 Downey Pl, Oakland, CA 94610, USA'
    lat, lon = await efidgy.tools.geocode(order_address)
    await efidgy.models.idd_or.Order.service.create(
        project=project,
        store=store,
        name='#00001',
        address=order_address,
        lat=lat,
        lon=lon,
        ready_time=datetime.time(8, 0),
        delivery_time_from=datetime.time(12, 0),
        delivery_time_to=datetime.time(16, 0),
        load_duration=datetime.timedelta(minutes=1),
        unload_duration=datetime.timedelta(minutes=5),
        items=1,
        volume=3.53,
        weight=22.05,
    )

    return project


async def solve(project):
    await project.computate()

    solutions = await efidgy.models.Solution.service.all(
        project=project,
    )

    if not solutions:
        return None

    return solutions[0]


async def report(project, solution):
    print('Total Cost: {cost:.2f}{currency}'.format(
        cost=solution.cost,
        currency=project.currency.symbol,
    ))

    vehicles = await efidgy.models.idd_or.Vehicle.service.all(
        project=project,
        solution=solution,
    )

    for vehicle in vehicles:
        print('{vehicle} Schedule'.format(
            vehicle=vehicle.name,
        ))
        if vehicle.route is not None:
            arr = vehicle.route.start_time
            for schedule in vehicle.route.schedule:
                dep = schedule.departure_time
                print('{at}\t{arr}\t{dep}'.format(
                    at=schedule.start_point.name,
                    arr=arr,
                    dep=dep,
                ))
                arr = schedule.arrival_time
            if vehicle.route.schedule:
                print('{at}\t{arr}\t{dep}'.format(
                    at=vehicle.route.schedule[-1].end_point.name,
                    arr=vehicle.route.schedule[-1].arrival_time,
                    dep='',
                ))


async def main():
    project = await create_project()
    solution = await solve(project)
    if solution:
        await report(project, solution)


if __name__ == '__main__':
    asyncio.run(main())
```


### Output
```
Total Cost: 12.51$
Gary Bailey Schedule
Delivery Inc.   15:45:00        15:46:00
#00001          15:55:00        16:00:00
Delivery Inc.   16:09:00
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://efidgy.com/",
    "name": "efidgy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "efidgy logistics optimization dispatcing vrp",
    "author": "Vasily Stepanov",
    "author_email": "vasily.stepanov@efidgy.com",
    "download_url": "https://files.pythonhosted.org/packages/0e/0f/5445c420d3da7792183f01270cc6e43891f15d6f79bec591ee6dd9899569/efidgy-0.15.tar.gz",
    "platform": null,
    "description": "# efidgy\n\nPython bindings to efidgy services.\n\n\n## Overview\n\n\n### Environment\n\nEnvironment in terms of efidgy package is a set of settings to work with efidgy backend.\nTheese settings includes **customer code** and **access token** that will be used to communicate with backend.\n\n\n### Unit System\n\nIf you will not set the unit system directly, efidgy will use current user settings: [console.efidgy.com/profile](https://console.efidgy.com/profile)\n\nAnyway, it is a good practice to define the unit system in your code:\n\n``` python\nefidgy.env = efidgy.env.override(\n    unit_system=efidgy.models.UnitSystem.IMPERIAL,\n)\n```\n\n\n### Credentials\n\nefidgy.env is initialized with settings fetched from the shell environment. The following environment variables are used:\n\n * EFIDGY_ACCESS_TOKEN -- You can get one at [console.efidgy.com/profile/company](https://console.efidgy.com/profile/company)\n * EFIDGY_CUSTOMER_CODE -- See [console.efidgy.com/profile/tokens](https://console.efidgy.com/profile/tokens)\n\nYou can always override code and/or token with the code like this:\n\n``` python\nefidgy.env = efidgy.env.override(\n    code='hardcoded customer code',\n)\n```\n\n\n## API documentation\n\nFind out more at: [efidgy.com/docs](https://efidgy.com/docs)\n\n\n## Sample usage\n\n``` sh\nexport EFIDGY_CUSTOMER_CODE=code  # https://console.efidgy.com/profile/company\nexport EFIDGY_ACCESS_TOKEN=token  # https://console.efidgy.com/profile/tokens\n```\n\n\n### Sync API\n\n``` python\nimport datetime\nimport efidgy\n\n\ndef create_project():\n    project = efidgy.models.Project.service.create(\n        name='Demo',\n        currency='USD',\n        project_type=efidgy.models.ProjectTypeCode.IDD_OR,\n        shared_mode=efidgy.models.SharedMode.PRIVATE,\n    )\n\n    store_address = '6133 Broadway Terr., Oakland, CA 94618, USA'\n    lat, lon = efidgy.tools.geocode(store_address)\n    store = efidgy.models.idd_or.Store.service.create(\n        project=project,\n        address=store_address,\n        lat=lat,\n        lon=lon,\n        name='Delivery Inc.',\n        open_time=datetime.time(8, 0),\n        close_time=datetime.time(18, 0),\n    )\n\n    efidgy.models.idd_or.Vehicle.service.create(\n        project=project,\n        store=store,\n        name='Gary Bailey',\n        fuel_consumption=11.76,\n        fuel_price=3.25,\n        salary_per_duration=21,\n        duration_limit=datetime.timedelta(hours=9),\n    )\n\n    order_address = '1 Downey Pl, Oakland, CA 94610, USA'\n    lat, lon = efidgy.tools.geocode(order_address)\n    efidgy.models.idd_or.Order.service.create(\n        project=project,\n        store=store,\n        name='#00001',\n        address=order_address,\n        lat=lat,\n        lon=lon,\n        ready_time=datetime.time(8, 0),\n        delivery_time_from=datetime.time(12, 0),\n        delivery_time_to=datetime.time(16, 0),\n        load_duration=datetime.timedelta(minutes=1),\n        unload_duration=datetime.timedelta(minutes=5),\n        items=1,\n        volume=3.53,\n        weight=22.05,\n    )\n\n    return project\n\n\ndef solve(project):\n    project.computate()\n\n    solutions = efidgy.models.Solution.service.all(\n        project=project,\n    )\n\n    if not solutions:\n        return None\n\n    return solutions[0]\n\n\ndef report(project, solution):\n    print('Total Cost: {cost:.2f}{currency}'.format(\n        cost=solution.cost,\n        currency=project.currency.symbol,\n    ))\n\n    vehicles = efidgy.models.idd_or.Vehicle.service.all(\n        project=project,\n        solution=solution,\n    )\n\n    for vehicle in vehicles:\n        print('{vehicle} Schedule'.format(\n            vehicle=vehicle.name,\n        ))\n        if vehicle.route is not None:\n            arr = vehicle.route.start_time\n            for schedule in vehicle.route.schedule:\n                dep = schedule.departure_time\n                print('{at}\\t{arr}\\t{dep}'.format(\n                    at=schedule.start_point.name,\n                    arr=arr,\n                    dep=dep,\n                ))\n                arr = schedule.arrival_time\n            if vehicle.route.schedule:\n                print('{at}\\t{arr}\\t{dep}'.format(\n                    at=vehicle.route.schedule[-1].end_point.name,\n                    arr=vehicle.route.schedule[-1].arrival_time,\n                    dep='',\n                ))\n\n\ndef main():\n    project = create_project()\n    solution = solve(project)\n    if solution:\n        report(project, solution)\n\n\nif __name__ == '__main__':\n    main()\n```\n\n\n### Output\n```\nTotal Cost: 12.51$\nGary Bailey Schedule\nDelivery Inc.   15:45:00        15:46:00\n#00001          15:55:00        16:00:00\nDelivery Inc.   16:09:00\n```\n\n\n### Async API\n\n``` python\nimport datetime\nimport asyncio\nimport efidgy.asyncapi as efidgy\n\n\nasync def create_project():\n    project = await efidgy.models.Project.service.create(\n        name='Demo',\n        currency='USD',\n        project_type=efidgy.models.ProjectTypeCode.IDD_OR,\n        shared_mode=efidgy.models.SharedMode.PRIVATE,\n    )\n\n    store_address = '6133 Broadway Terr., Oakland, CA 94618, USA'\n    lat, lon = await efidgy.tools.geocode(store_address)\n    store = await efidgy.models.idd_or.Store.service.create(\n        project=project,\n        address=store_address,\n        lat=lat,\n        lon=lon,\n        name='Delivery Inc.',\n        open_time=datetime.time(8, 0),\n        close_time=datetime.time(18, 0),\n    )\n\n    await efidgy.models.idd_or.Vehicle.service.create(\n        project=project,\n        store=store,\n        name='Gary Bailey',\n        fuel_consumption=11.76,\n        fuel_price=3.25,\n        salary_per_duration=21,\n        duration_limit=datetime.timedelta(hours=9),\n    )\n\n    order_address = '1 Downey Pl, Oakland, CA 94610, USA'\n    lat, lon = await efidgy.tools.geocode(order_address)\n    await efidgy.models.idd_or.Order.service.create(\n        project=project,\n        store=store,\n        name='#00001',\n        address=order_address,\n        lat=lat,\n        lon=lon,\n        ready_time=datetime.time(8, 0),\n        delivery_time_from=datetime.time(12, 0),\n        delivery_time_to=datetime.time(16, 0),\n        load_duration=datetime.timedelta(minutes=1),\n        unload_duration=datetime.timedelta(minutes=5),\n        items=1,\n        volume=3.53,\n        weight=22.05,\n    )\n\n    return project\n\n\nasync def solve(project):\n    await project.computate()\n\n    solutions = await efidgy.models.Solution.service.all(\n        project=project,\n    )\n\n    if not solutions:\n        return None\n\n    return solutions[0]\n\n\nasync def report(project, solution):\n    print('Total Cost: {cost:.2f}{currency}'.format(\n        cost=solution.cost,\n        currency=project.currency.symbol,\n    ))\n\n    vehicles = await efidgy.models.idd_or.Vehicle.service.all(\n        project=project,\n        solution=solution,\n    )\n\n    for vehicle in vehicles:\n        print('{vehicle} Schedule'.format(\n            vehicle=vehicle.name,\n        ))\n        if vehicle.route is not None:\n            arr = vehicle.route.start_time\n            for schedule in vehicle.route.schedule:\n                dep = schedule.departure_time\n                print('{at}\\t{arr}\\t{dep}'.format(\n                    at=schedule.start_point.name,\n                    arr=arr,\n                    dep=dep,\n                ))\n                arr = schedule.arrival_time\n            if vehicle.route.schedule:\n                print('{at}\\t{arr}\\t{dep}'.format(\n                    at=vehicle.route.schedule[-1].end_point.name,\n                    arr=vehicle.route.schedule[-1].arrival_time,\n                    dep='',\n                ))\n\n\nasync def main():\n    project = await create_project()\n    solution = await solve(project)\n    if solution:\n        await report(project, solution)\n\n\nif __name__ == '__main__':\n    asyncio.run(main())\n```\n\n\n### Output\n```\nTotal Cost: 12.51$\nGary Bailey Schedule\nDelivery Inc.   15:45:00        15:46:00\n#00001          15:55:00        16:00:00\nDelivery Inc.   16:09:00\n```\n\n",
    "bugtrack_url": null,
    "license": "GPL3",
    "summary": "Python bindings to efidgy services.",
    "version": "0.15",
    "split_keywords": [
        "efidgy",
        "logistics",
        "optimization",
        "dispatcing",
        "vrp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4226fbee6a0c5b9e757c2082b0418b0e24634df8fd97f10be2d8c5b590e19a7f",
                "md5": "9b56c80996977c88aafc3a557c31fe8b",
                "sha256": "7da4d85d53eb86e1bfcd3704a393c444499ff178847380290889d83731b6119f"
            },
            "downloads": -1,
            "filename": "efidgy-0.15-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b56c80996977c88aafc3a557c31fe8b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 29466,
            "upload_time": "2023-02-03T18:42:49",
            "upload_time_iso_8601": "2023-02-03T18:42:49.328580Z",
            "url": "https://files.pythonhosted.org/packages/42/26/fbee6a0c5b9e757c2082b0418b0e24634df8fd97f10be2d8c5b590e19a7f/efidgy-0.15-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e0f5445c420d3da7792183f01270cc6e43891f15d6f79bec591ee6dd9899569",
                "md5": "b54e88a4e155930a7edc66baa7023f02",
                "sha256": "14a4539003c48f517015cc0442cd9b75de8cecb86080d332b87d060b7b855a26"
            },
            "downloads": -1,
            "filename": "efidgy-0.15.tar.gz",
            "has_sig": false,
            "md5_digest": "b54e88a4e155930a7edc66baa7023f02",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 27428,
            "upload_time": "2023-02-03T18:42:51",
            "upload_time_iso_8601": "2023-02-03T18:42:51.046954Z",
            "url": "https://files.pythonhosted.org/packages/0e/0f/5445c420d3da7792183f01270cc6e43891f15d6f79bec591ee6dd9899569/efidgy-0.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-03 18:42:51",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "efidgy"
}
        
Elapsed time: 0.06402s