diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 81704ec..5b98320 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: Run Tests on: push: - branches: main + branches: + - "**" pull_request: branches: main diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 381a794..88b1258 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,6 +1,10 @@ name: Publish RetailTree Python package distribution to PyPI -on: push +on: + workflow_run: + workflows: ["Run Tests"] + types: + - completed jobs: build: @@ -8,86 +12,86 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - name: Install pypa/build - run: >- - python3 -m - pip install - build - --user - - name: Build a binary wheel and a source tarball - run: python3 -m build - - name: Store the distribution packages - uses: actions/upload-artifact@v4 - with: - name: python-package-distributions - path: dist/ + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ publish-to-pypi: name: >- Publish RetailTree Python package distribution to PyPI - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - - build + - build runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/retailtree permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing + id-token: write # IMPORTANT: mandatory for trusted publishing steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 github-release: name: >- Sign the Python 🐍 distribution 📦 with Sigstore and upload them to GitHub Release needs: - - publish-to-pypi + - publish-to-pypi runs-on: ubuntu-latest permissions: - contents: write # IMPORTANT: mandatory for making GitHub Releases - id-token: write # IMPORTANT: mandatory for sigstore + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Sign the dists with Sigstore - uses: sigstore/gh-action-sigstore-python@v2.1.1 - with: - inputs: >- - ./dist/*.tar.gz - ./dist/*.whl - - name: Create GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - run: >- - gh release create - '${{ github.ref_name }}' - --repo '${{ github.repository }}' - --notes "" - - name: Upload artifact signatures to GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - # Upload to GitHub Release using the `gh` CLI. - # `dist/` contains the built packages, and the - # sigstore-produced signatures and certificates. - run: >- - gh release upload - '${{ github.ref_name }}' dist/** - --repo '${{ github.repository }}' + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/README.md b/README.md index ce0f922..de5a035 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,24 @@ RetailTree is a Python library designed for efficient management and querying of You can install retailTree via pip: -``` +```python pip install retailtree ``` # Usage -``` -# Import necessary modules and functions +### Import necessary modules and functions + +```python +# Imports from retailtree import RetailTree, Annotation from retailtree.utils.dist_func import manhattan, euclidean import json +``` + +### Sample Usage 1: Creating Annotations with Annotation Class using a sample JSON file +```python # Define the path to the JSON file containing annotations file_path = './tests/test_data/test_data.json' @@ -42,21 +48,48 @@ for ann in annotations: ann_obj = Annotation(id=ann['id'], x_min=ann['x_min'], y_min=ann['y_min'], x_max=ann['x_max'], y_max=ann['y_max']) # Add the created Annotation object to the RetailTree rt.add_annotation(ann_obj) +``` -# Build the spatial tree structure using the euclidean distance function -rt.build_tree(dist_func=euclidean) +# OR + +### Sample Usage 2: Creating Annotations with Annotation Class + +```python +# Create annotation object +ann1 = Annotation(id=1, x_min=2, y_min=1, x_max=3, y_max=2) +ann2 = Annotation(id=2, x_min=1, y_min=2, x_max=2, y_max=3) +ann3 = Annotation(id=3, x_min=2, y_min=2, x_max=3, y_max=3) +ann4 = Annotation(id=4, x_min=3, y_min=2, x_max=4, y_max=3) +ann5 = Annotation(id=5, x_min=2, y_min=3, x_max=3, y_max=4) +annotations = [ann1, ann2, ann3, ann4, ann5] -# Retrieve and print annotations within a radius of 1 from the annotation with id=3 +# Create retailtree object +rt = RetailTree() + +# Adding annotations to retailtree +for ann in annotations: + rt.add_annotation(ann) +``` + +## Building the Tree and Querying + +### Building the Tree + +```python +# Build the retail tree structure using the euclidean distance function +rt.build_tree(dist_func=euclidean) +``` +### Querying the Tree +```python +# Retrieve and print annotations within a radius. print(rt.neighbors(id=3, radius=1)) -# Retrieve and print the Top, Bottom, Left, and Right neighboring annotations -# of the annotation with id=3 within a radius of 1 and a minimum overlap of 0.5 +# Retrieve and print the Top, Bottom, Left, and Right neighboring annotations. print(rt.TBLR(id=3, radius=1, overlap=0.5)) -# Retrieve and print neighboring annotations of the annotation with id=3 -# within a radius of 1 and angle range from 0 to 180 degrees -print(rt.neighbors_wa(id=3, radius=1, amin=0, amax=180)) +# Retrieve and print neighboring annotations of the annotation. +print(rt.neighbors_wa(id=3, radius=2, amin=0, amax=180)) -# Retrieve and print the coordinates of the annotation with id=3 +# Retrieve and print the coordinates of the annotation. print(rt.get(id=3).get_coords()) ```