Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thepabloaguilar committed Apr 11, 2021
0 parents commit 3065201
Show file tree
Hide file tree
Showing 40 changed files with 2,710 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Check http://editorconfig.org for more information
# This is the main config file for this project:
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
indent_style = space
insert_final_newline = true
indent_size = 2

[*.py]
indent_size = 4

[*.go]
indent_style = tab
indent_size = 4
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: test

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.7', '3.8', '3.9']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python_version }}

- name: Install Poetry
run: |
curl -sSL "https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
# Adding `poetry` to `$PATH`:
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
- name: Run tests
run: |
poetry run flake8 .
poetry run mypy floc
poetry run pytest
poetry run poetry check
poetry run pip check
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
file: ./coverage.xml
86 changes: 86 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
*.h

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Sphinx documentation
docs/_build/

# pyenv
.python-version

# vscode
.vscode/

# Jetbrains
.idea/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/


# Allow shared lib inside our package
!floc/floc_go/floc_go.h
!floc/floc_go/floc_go.so
12 changes: 12 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

python:
version: 3.8
install:
- requirements: docs/requirements.txt

sphinx:
configuration: docs/conf.py
fail_on_warning: true

formats: all
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Version 0.1.0

Initial release.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Pablo Henrique Aguilar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: gen-flocgo
gen-flocgo:
@cd floc_simulator;go build -buildmode=c-shared -o ../floc/floc_go/floc_go.so;cd ..

.PHONY: gen-flocgo-root
gen-flocgo-root:
@cd floc_simulator;go build -buildmode=c-shared -o ../floc_go.so;cd ..
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# FLoC

<p align="center">
<a href="https://github.com/thepabloaguilar/floc/actions?query=workflow%3Atest"><img alt="Build Status" src="https://github.com/thepabloaguilar/floc/workflows/test/badge.svg?branch=main"></a>
<a href="https://floc.readthedocs.io/en/latest/?badge=latest"><img alt="Documentation Status" src="https://readthedocs.org/projects/floc/badge/?version=latest"></a>
<a href="https://pypi.org/project/floc/"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/floc.svg"></a>
<a href="https://codecov.io/gh/thepabloaguilar/floc"><img alt="Coverage Status" src="https://codecov.io/gh/thepabloaguilar/floc/branch/main/graph/badge.svg"></a>
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/License-MIT-yellow.svg"></a>
<a href="http://mypy-lang.org/"><img alt="Checked with mypy" src="https://img.shields.io/badge/mypy-checked-2a6db2"></a>
<a href="https://github.com/wemake-services/wemake-python-styleguide"><img alt="wemake python styleguide" src="https://img.shields.io/badge/style-wemake-000000.svg"></a>
</p>

---

## Introduction

This is a Python wrapper of [this](https://github.com/shigeki/floc_simulator) implementation for FLoC written in go!

It's easy to calculate the CohortID using this lib, see the example below:

```python
>>> from floc import simulate
>>> host_list = [
... 'www.nikkei.com',
... 'jovi0608.hatenablog.com',
... 'www.nikkansports.com',
... 'www.yahoo.co.jp',
... 'www.sponichi.co.jp',
... 'www.cnn.co.jp',
... 'floc.glitch.me',
... 'html5.ohtsu.org',
... ]
>>> simulate(host_list)
21454
```

By default, we'll use the `SortingLshClusters` from FLoC's `1.0.6` version. If you want to use other, just pass it to the function:

```python
>>> from floc import simulate
>>> host_list = [
... 'www.nikkei.com',
... 'jovi0608.hatenablog.com',
... 'www.nikkansports.com',
... 'www.yahoo.co.jp',
... 'www.sponichi.co.jp',
... 'www.cnn.co.jp',
... 'floc.glitch.me',
... 'html5.ohtsu.org',
... ]
>>> sorting_cluster_data = "" # READ THE DATA FROM SOMEWHERE
>>> simulate(host_list, sorting_cluster_data)
21454
```

We also expose some other functions, see the documentation [here](https://floc.readthedocs.io)
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
39 changes: 39 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
API Reference
=============


Hashes
------

.. automodule:: floc.hashes
:members:

.. autofunction:: floc.hashes.cityhash
.. autofunction:: floc.hashes.cityhash_with_seeds
.. autofunction:: floc.hashes.cityhash_with_seed
.. autofunction:: floc.hashes.sim_hash_string

Simulate
--------

.. automodule:: floc.simulate
:members:

.. function:: floc.simulate.simulate

Sorting
--------

.. automodule:: floc.sorting
:members:

.. autofunction:: floc.sorting.apply_sorting_lsh

Go Types
--------

.. automodule:: floc.go_types
:members:
:special-members:

.. autofunction:: floc.go_types.covert_str_list_to_go_slice
Loading

0 comments on commit 3065201

Please sign in to comment.