Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uvad,test and update setup.py #7

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main", "dev"]
pull_request:
branches: [ "main", "dev" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10.8', '3.11', '3.12']

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

# - name: Install setuptools Cython numpy
# run: pip install setuptools Cython==3.0.8 numpy==1.25.2

- name: install dependence
working-directory: ./
run: |
poetry lock --no-update
poetry install

- name: compile cython
working-directory: ./
run: poetry run python setup.py build_ext --inplace


- name: run the test script
working-directory: ./
run: |
pip install pytest
poetry run python anomaly-detector/tests/test_demo.py
poetry run python anomaly-detector/tests/test_uvad.py

- name: Analyze code with pylint
run: |
pip install pylint
pylint --exit-zero $(git ls-files '*.py')

test_on_setup_whl:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10.8', '3.11', '3.12' ]
steps:
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

# - name: Install setuptools Cython numpy
# run: pip install setuptools Cython==3.0.8 numpy==1.25.2

- name: install dependence
working-directory: ./
run: |
poetry lock --no-update
poetry install

- name: gen .whl file by setup.py
working-directory: ./
run: poetry run python setup.py sdist bdist_wheel

- name: install .whl file
run: poetry run pip install dist/*.whl

- name: run the test script
working-directory: ./
run: |
pip install pytest
poetry run python anomaly-detector/tests/test_demo.py
poetry run python anomaly-detector/tests/test_uvad.py


# test_on_setup:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4

# - name: install package by setup.py
# run: pip install .

# - name: run the test script
# working-directory: anomaly-detector/tests
# run: |
# pip install pytest
# python test_demo.py
97 changes: 0 additions & 97 deletions .github/workflows/tests.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,7 @@ FodyWeavers.xsd

mlruns/
mlartifacts/
model/
model/
venv/

.idea/
18 changes: 18 additions & 0 deletions .script/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/mirror/docker/library/python:3.11

ARG DEBIAN_FRONTEND=noninteractive

ADD requirements.txt .

RUN apt-get update -qq && \
apt-get upgrade -y && \
apt-get install -y r-base r-base-dev --fix-missing && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install --upgrade pip
RUN pip3 install setuptools --upgrade
RUN pip3 install -r requirements.txt
RUN apt-get clean

WORKDIR /anomaly-detector
COPY . .
RUN python3 setup.py build_ext --inplace
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
recursive-include ./anomaly-detector/*.pyx
recursive-include ./anomaly-detector/*.c
recursive-include ./anomaly-detector/*.h
recursive-include ./anomaly-detector/*.py
recursive-include ./anomaly-detector/*.txt
recursive-include ./anomaly-detector/anomaly_detector/univariate *
include ./setup.py
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# Environment
python = 3.11

R >= 4.0

# Getting Started

<!-- ## Clone the Repository -->

```bash
git clone https://github.com/microsoft/anomaly-detector.git
cd anomaly-detector
```

<!-- ## Install -->


```bash
pip install -r requirements.txt
python setup.py build_ext --inplace
```

build

python setup.py sdist bdist_wheel

## Using Docker (Optional)

```bash
docker build -t your_image_name -f .script/Dockerfile .
```


# Test

```bash
cd anomaly-detector
python tests/uvad_test.py
```

# Project

> This repo has been populated by an initial template to help get you started. Please
Expand Down
1 change: 1 addition & 0 deletions anomaly-detector/anomaly_detector/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .multivariate.model import MultivariateAnomalyDetector
from .univariate.univariate_anomaly_detection import UnivariateAnomalyDetector
11 changes: 11 additions & 0 deletions anomaly-detector/anomaly_detector/common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def __repr__(self):
def to_dict(self):
return {"code": self.code, "message": self.message}

class AnomalyDetectionRequestError(Exception):
"""Raised when an error occurs in the request."""
def __init__(self, error_msg, error_code=None):
if isinstance(error_msg, type(b'')):
error_msg = error_msg.decode('UTF-8', 'replace')

super(AnomalyDetectionRequestError, self).__init__(
error_msg
)
self.message = error_msg
self.code = error_code

class DataFormatError(AnomalyDetectorException):
pass
Expand Down
5 changes: 5 additions & 0 deletions anomaly-detector/anomaly_detector/univariate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .util import fit_trend
from .util import get_period_pattern
from .model.detect_model import AnomalyDetectionModel
from .resource.error_message import InvalidJsonFormat, CustomSupportRequired
from .period import period_detection
Loading
Loading