Skip to content

Commit

Permalink
Merge pull request #14 from jvachier/jv/ruff
Browse files Browse the repository at this point in the history
Ruff.
  • Loading branch information
jvachier authored Feb 11, 2024
2 parents b57b352 + 46b3f76 commit b604dcd
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 156 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Install dependencies
run: |
make install
- name: Black
# - name: Black
# run: |
# make black
- name: Ruff
run: |
make black
make ruff
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@
*.bin
*.h5
*.keras
*.pyc
*.so
*.pylintrc

*data/
*videos/
*pickle_files/
*.pyc
*predictions/

*__pycache__/
__pycache__/
*.so
*.pylintrc
*.ruff_cache/


# Ignore specific file
test.mp4
*.mp4

# Ignore all executable files
*.o
Expand All @@ -38,5 +43,4 @@ test.mp4
*.ipynb

# Ignore all json file
*.json

*.json
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ lint:

black:
python -m black src/


ruff:
ruff check src/
ruff check --fix src/
ruff format src/
280 changes: 176 additions & 104 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "kth machine learning"
version = "1.2.2"
version = "1.3.4"
description = ""
authors = ["Jeremy Vachier"]
readme = "README.md"
Expand All @@ -19,10 +19,9 @@ statsmodels = "^0.14.1"
pylint = "^3.0.3"
scikit-optimize = "^0.9.0"
black = "^24.1.1"
ruff = "^0.2.1"
pyarrow = "^15.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pylint.main]
load-plugins = "pylint_actions"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ datetime == 5.4
statsmodels == 0.14.1
pylint == 3.0.3
scikit-optimize == 0.9.0
black == 24.1.1
black == 24.1.1
ruff == 0.2.1
77 changes: 77 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# Same as Black.
line-length = 88
indent-width = 4

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[lint.isort]
case-sensitive = true
from-first = false

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
17 changes: 8 additions & 9 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os.path
from argparse import ArgumentParser

from keras.models import load_model

from src.modules import data_preparation
from src.modules import models
from src.modules import loading
from src.modules import data_preparation, loading, models


def main() -> None:
Expand All @@ -21,7 +20,7 @@ def main() -> None:

print("Loading data\n")

load = loading.Loading_files()
load = loading.LoadingFiles()

if os.path.isfile("./pickle_files/loading/telemetry") is False:
(
Expand All @@ -40,13 +39,13 @@ def main() -> None:
df_maintenance,
) = load.load_db_file()

data = data_preparation.Data_Preparation(
data = data_preparation.DataPreparation(
df_telemetry,
df_maintenance,
df_errors,
df_failures,
)
load_data = data_preparation.Load_Save()
load_data = data_preparation.LoadSave()

if os.path.isfile("./pickle_files/data_preparation/data_set") is False:
data.date_to_time()
Expand All @@ -60,7 +59,7 @@ def main() -> None:
print("Models prediction\n")
model = models.Predictions(data_set_prepared)

save_model = models.Save_Load_models()
save_model = models.SaveLoadmodels()

x_train, x_test, y_train, y_test = model.train_split()
clf_rfc = model.model_rf(25, 10, "sqrt", 4)
Expand Down Expand Up @@ -102,10 +101,10 @@ def main() -> None:
print("\n")
print("Models Anomaly Detection\n")

anomaly_isolation = models.Anomaly_detection_isolationforest(
anomaly_isolation = models.AnomalyDetectionIsolationforest(
df_telemetry, "pressure", 1
)
anomaly_autoencoder = models.Anomaly_detection_autoencoder(
anomaly_autoencoder = models.AnomalyDetectionAutoencoder(
df_telemetry, "pressure", 1, 5
)

Expand Down
7 changes: 4 additions & 3 deletions src/modules/data_preparation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dataclasses import dataclass
import pickle
from dataclasses import dataclass

import pandas as pd


@dataclass(slots=True)
class Data_Preparation:
class DataPreparation:
"""
Class to prepare data to be ingested by the model
Input:
Expand Down Expand Up @@ -84,7 +85,7 @@ def _merge1(self, features1: pd.DataFrame, feature2: pd.DataFrame) -> pd.DataFra


@dataclass(slots=True)
class Load_Save:
class LoadSave:
"""
Class to load and save the prepared data into a pickle format: data_set
Two functions:
Expand Down
7 changes: 4 additions & 3 deletions src/modules/loading.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Tuple
from dataclasses import dataclass
import pickle
from dataclasses import dataclass
from typing import Tuple

import pandas as pd


@dataclass(slots=True)
class Loading_files:
class LoadingFiles:
"""
Class to load and save required data into a pickle format
"""
Expand Down
39 changes: 16 additions & 23 deletions src/modules/models.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
import os.path
import pickle
from dataclasses import dataclass
from typing import Tuple

import pickle
import os.path

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


import numpy as np
import pandas as pd
import tensorflow as tf
from keras.layers import Dense, Input
from keras.models import Model
from keras.optimizers.legacy import Adam
from sklearn import metrics
from sklearn.ensemble import IsolationForest, RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import (
precision_recall_fscore_support,
RocCurveDisplay,
)
from sklearn.ensemble import IsolationForest, RandomForestClassifier
from sklearn.model_selection import learning_curve, train_test_split
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split, learning_curve
from sklearn.pipeline import make_pipeline, Pipeline
from sklearn.linear_model import LogisticRegression

from sklearn import metrics

from skopt.searchcv import BayesSearchCV

import tensorflow as tf
from keras.layers import Input, Dense
from keras.models import Model
from keras.optimizers.legacy import Adam


@dataclass(slots=True)
class Predictions:
Expand Down Expand Up @@ -294,7 +287,7 @@ def visualization_accuracy(


@dataclass(slots=True)
class Save_Load_models:
class SaveLoadmodels:
def save_model_sklearn(
self, name: str, model: object, prediction: np.array, prediction_proba: np.array
) -> None:
Expand Down Expand Up @@ -325,7 +318,7 @@ def load_model_sklearn(self, name: str) -> Tuple[object, np.array, np.array]:


@dataclass(slots=True)
class Anomaly_detection_isolationforest:
class AnomalyDetectionIsolationforest:
data: pd.DataFrame
name: str
machine_name: int
Expand Down Expand Up @@ -363,7 +356,7 @@ def visulaization_isolationforest(self) -> None:


@dataclass(slots=True)
class Anomaly_detection_autoencoder:
class AnomalyDetectionAutoencoder:
data: pd.DataFrame
name: str
machine_name: int
Expand Down

0 comments on commit b604dcd

Please sign in to comment.