4 Commits

Author SHA1 Message Date
106877a073 feat: init Learning class and add drop_empty_price function 2026-03-28 15:51:46 +01:00
Loïc GUEZO
416cfcbf8b Add Python package ecosystem to Dependabot config
Configure Dependabot for Python package updates.
2026-03-27 22:11:53 +01:00
32c5310e37 fix: mettre à jour les tests pytest 2026-03-27 22:06:36 +01:00
9dfc7457a0 fix(scraper.py): retirer commentaire code et print 2026-03-27 22:06:06 +01:00
8 changed files with 78 additions and 39 deletions

18
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
day: "saturday"
open-pull-requests-limit: 5
groups:
python-dependencies:
patterns:
- "*"

View File

@@ -19,15 +19,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Python 3.10 - name: Set up Python 3.x
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
python-version: "3.10" python-version: "3.x"
- name: install dependencies - name: install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install ".[test,doc]" pip install ".[test]"
- name: Lint with flake8 - name: Lint with flake8
run: | run: |

View File

@@ -32,15 +32,14 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Python 3.10 - name: Set up Python 3.x
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.10' python-version: '3.x'
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
# Installe le projet en mode éditable avec les extras de doc
pip install -e ".[doc]" pip install -e ".[doc]"
- name: Setup Pages - name: Setup Pages

View File

@@ -6,8 +6,13 @@ dependencies = [
"beautifulsoup4==4.14.3", "beautifulsoup4==4.14.3",
"pandas==2.3.3", "pandas==2.3.3",
"tqdm==4.67.3", "tqdm==4.67.3",
"scikit-learn==1.7.2"
] ]
[tool.pytest.ini_options]
pythonpath = "src"
testpaths = ["tests"]
[project.optional-dependencies] [project.optional-dependencies]
test = ["pytest==8.4.2", "requests-mock==1.12.1", "flake8==7.3.0"] test = ["pytest==8.4.2", "requests-mock==1.12.1", "flake8==7.3.0"]
doc = ["mkdocs<2.0.0", "mkdocs-material==9.6.23", "mkdocstrings[python]"] doc = ["mkdocs<2.0.0", "mkdocs-material==9.6.23", "mkdocstrings[python]"]

View File

@@ -92,18 +92,24 @@ class Cleaning:
self._vins = self._vins.join(appellation_dummies) self._vins = self._vins.join(appellation_dummies)
return self return self
def drop_empty_price(self) -> "Cleaning":
self._vins = self._vins.dropna(subset=["Prix"])
return self
def main() -> None: def main() -> None:
if len(argv) != 2: if len(argv) != 2:
raise ValueError(f"Usage: {argv[0]} <filename.csv>") raise ValueError(f"Usage: {argv[0]} <filename.csv>")
filename = argv[1] filename = argv[1]
cleaning: Cleaning = Cleaning(filename) cleaning: Cleaning = (
cleaning.drop_empty_appellation() \ Cleaning(filename)
.fill_missing_scores() \ .drop_empty_appellation()
.encode_appellation() \ .fill_missing_scores()
.getVins() \ .encode_appellation()
.to_csv("clean.csv", index=False) .drop_empty_price()
)
cleaning.getVins().to_csv("clean.csv", index=False)
if __name__ == "__main__": if __name__ == "__main__":

31
src/learning.py Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env python3
from typing import Any, Callable
from pandas import DataFrame
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
class Learning:
def __init__(self, vins: DataFrame, target: str) -> None:
self.X = vins.drop(target, axis=1)
self.y = vins[target]
self.X_train, self.X_test, self.y_train, self.y_test = train_test_split(
self.X, self.y, test_size=0.25, random_state=49
)
def evaluate(
self,
estimator,
pretreatment=None,
fn_score=lambda m, xt, yt: m.score(xt, yt),
):
pipeline = make_pipeline(pretreatment, estimator) if pretreatment else estimator
pipeline.fit(self.X_train, self.y_train)
score = fn_score(pipeline, self.X_test, self.y_test)
prediction = pipeline.predict(self.X_test)
return score, prediction

View File

@@ -377,18 +377,10 @@ class Scraper:
try: try:
data: dict[str, object] = self.getjsondata(subdir).getdata() data: dict[str, object] = self.getjsondata(subdir).getdata()
# Changement dans la maniere du site stocke ses données.
#
# for element in ["initialReduxState", "categ", "content"]:
# data = cast(dict[str, object], data.get(element))
# print(data)
products: list[dict[str, Any]] = cast( products: list[dict[str, Any]] = cast(
list[dict[str, Any]], data.get("products") list[dict[str, Any]], data.get("products")
) )
print(products)
return products return products
except (JSONDecodeError, HTTPError): except (JSONDecodeError, HTTPError):

View File

@@ -185,17 +185,11 @@ def mock_site():
{dumps({ {dumps({
"props": { "props": {
"pageProps": { "pageProps": {
"initialReduxState": { "products": [
"categ": { {"seoKeyword": "/nino-negri-5-stelle-sfursat-2022.html",},
"content": { {"seoKeyword": "/poubelle",},
"products": [ {"seoKeyword": "/",}
{"seoKeyword": "/nino-negri-5-stelle-sfursat-2022.html",}, ]
{"seoKeyword": "/poubelle",},
{"seoKeyword": "/",}
]
}
}
}
} }
} }
} }
@@ -213,14 +207,8 @@ def mock_site():
{dumps({ {dumps({
"props": { "props": {
"pageProps": { "pageProps": {
"initialReduxState": { "products": [
"categ": { ]
"content": {
"products": [
]
}
}
}
} }
} }
} }