Skip to content

Commit

Permalink
improved package import and GH action to deploy from github
Browse files Browse the repository at this point in the history
  • Loading branch information
StigHaraldGustavsen committed Mar 9, 2024
1 parent b132bb1 commit b1be265
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/deploy_PyPI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests
on:
workflow_dispatch
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10.9']
steps:
- uses: actions/checkout@v3
name: Set up Python ${{ matrix.python-version }}

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Set up cache
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}

- name: Install and configure Poetry
run: |
pip install -U pip
pip install poetry
poetry config virtualenvs.in-project true
poetry config pypi-token.pypi ${{ secrets.PYPI }}
poetry install
- name: Run linting and other code quality checks
run: |
poetry run pre-commit run --all-files
- name: Run tests
run: export PYTHONPATH=$PYTHONPATH:$(pwd); poetry run pytest -c pyproject.toml
- name: Build
run: poetry build
- name: Depoly to PyPI
run: poetry publish
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
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/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

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

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pip install meter-proving


```python
from meter_proving.meter_proving import calculate_uncertanity
from meter_proving import calculate_uncertanity

res = calculate_uncertanity([1000.00, 1000.00, 1000.00, 1000.25, 999.75])
print(res)
Expand All @@ -18,7 +18,7 @@ print(res)
By default standard error is gotten from range of values, if this where to come from standard deviation set repetability param to false with a confidence intervall of 95% (coverage factor of almost 2), but theses can be parameterized.

```python
from meter_proving.meter_proving import calculate_uncertanity
from meter_proving import calculate_uncertanity

res = calculate_uncertanity(
[1000.00, 1000.00, 1000.00, 1000.25, 999.75],
Expand All @@ -31,7 +31,7 @@ print(res)
Standard error from standard deviation and has coverage factor of 1, witch gives a confidence interval of approx 68%

```python
from meter_proving.meter_proving import calculate_uncertanity
from meter_proving import calculate_uncertanity

res = calculate_uncertanity(
[1000.00, 1000.00, 1000.00, 1000.25, 999.75],
Expand Down
1 change: 1 addition & 0 deletions meter_proving/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = "0.1.0"
from .meter_proving import calculate_uncertanity, pdf_normal, pdf_student_t, d
10 changes: 5 additions & 5 deletions meter_proving/meter_proving.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from numba import njit, prange


def pdf_student_t(dof: int, t: np.array):
def pdf_student_t(dof: int, t: np.array) -> np.ndarray:
"""returns a np.array of len(t) of the probabilty density function of the student-t distrobution"""
numerator = gamma(((dof + 1) / 2))
denomenator = ((dof * np.pi) ** 0.5) * gamma((dof / 2))
Expand All @@ -12,7 +12,7 @@ def pdf_student_t(dof: int, t: np.array):
return (numerator / denomenator) * (x**exponent)


def pdf_normal(x: np.array, mean: float, std_dev: float):
def pdf_normal(x: np.array, mean: float, std_dev: float) -> np.ndarray:
"""returns a np.array of len(x) of the probabilty density function of the normal distrobution"""
fraction = 1 / (std_dev * (np.sqrt(2 * np.pi)))
exponent = -(0.5) * (((x - mean) / std_dev)) ** 2
Expand All @@ -21,7 +21,7 @@ def pdf_normal(x: np.array, mean: float, std_dev: float):


@njit(parallel=True)
def cal_uncerts(t: np.array, pdf: np.array, std_devs: np.array):
def cal_uncerts(t: np.array, pdf: np.array, std_devs: np.array) -> np.ndarray:
"""returns a np.array of len(std_devs) with the 2 sided cumulative probability from the mean and ourwards"""
dt = t[1] - t[0]
uncert = np.empty(len(std_devs))
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_confidence_intervall(coverage_factor: float):
]


def d(n: int):
def d(n: int) -> float:
"""
int n = the number of samples
getting the convertion factor for better estimation of standard deviation for w (range of values) of the values.
Expand All @@ -86,7 +86,7 @@ def d(n: int):
return np.sqrt(n)


def calculate_uncertanity(x, **params):
def calculate_uncertanity(x, **params) -> dict:
"""
x : list, np.ndarray of values
params:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "meter_proving"
version = "0.1.0"
version = "1.0.0"
description = "library to calculate random uncertanity of a measurment sequence"
authors = ["StigHaraldGustavsen <stighg@gmail.com>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_meter_proving.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from meter_proving.meter_proving import d, calculate_uncertanity
from meter_proving import d, calculate_uncertanity
import pytest
import numpy as np

Expand Down

0 comments on commit b1be265

Please sign in to comment.