diff --git a/Dockerfile b/Dockerfile index 2ad3734..1bcb66d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ FROM python:3.10 +EXPOSE 80 WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY generateurModele.py . +COPY testFinal.py . +COPY crontab . -EXPOSE 80 +RUN chmod 0644 /app/crontab +RUN apt-get update +RUN apt-get -y install cron -ENTRYPOINT ["python","generateurModele.py"] \ No newline at end of file +ENTRYPOINT ["cron"] \ No newline at end of file diff --git a/crontab b/crontab new file mode 100644 index 0000000..8408a52 --- /dev/null +++ b/crontab @@ -0,0 +1,3 @@ +00 08 * * * python generateurModele.py +* * * * * python testFinal.py + diff --git a/file_test/Dockerfile b/file_test/Dockerfile new file mode 100644 index 0000000..2ad3734 --- /dev/null +++ b/file_test/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.10 +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY generateurModele.py . + +EXPOSE 80 + +ENTRYPOINT ["python","generateurModele.py"] \ No newline at end of file diff --git a/testFinal.py b/testFinal.py new file mode 100644 index 0000000..0ea9d41 --- /dev/null +++ b/testFinal.py @@ -0,0 +1,77 @@ + +from sklearn.linear_model import LinearRegression +import pandas as pd +import numpy as np +import requests +import logging + + +# --------------- Fonction ----------------- # +def generateJsonModel(model:LinearRegression): + listCoef = [] + listIntercept = [] + for i in range(0,len(model.coef_)): + listCoef.append(model.coef_[i][0]) + listIntercept.append(model.intercept_[i]) + json = {"coef":listCoef,"intercept":listIntercept} + return json + +def generateModele(dataJson:dict[str,str]): + # -- Préparation des données + arrayBpm = [] + arrayStartTime = [] + arrayTimeOfActivity = [] + + for data in dataJson["Data"]: + arrayBpm.append(data["BpmAvg"]) + arrayTimeOfActivity.append(data["TimeOfActivity"]) + + arrayStartTime.append(data["StartTime"]) + # -- DataFrame + data = pd.DataFrame({ + "Bpm": arrayBpm, + "TimeOfActivity": arrayTimeOfActivity + }) + # -- Régression linéaire + model = LinearRegression() + model.fit(np.array(arrayStartTime).reshape(-1,1),data) + return model + + +def getUserWithData(url:str): + response = requests.get(urlGetAllData) + if ( response.status_code != 200): + print('problème lors de l extraction des données avec l api !! -> "getUserWithData" (status_code != 200)') + exit() + return response.json + +def sendJsonToApi(url,json): + response = requests.post(url,json) + if ( response.status_code != 200): + print('Problème lors de l envoi des données avec l api !! -> "sendJsonToApi" (status_code != 200)') + exit() + return + +# ---------------- Main ------------------- # +logging.warning("RUNNNNNNNN !") + +urlGetAllData = "https://codefirst.iut.uca.fr/containers/SmartFit-smartfit_api/ia/data" + +jsonBack = { "Users" : []} +# --- Call Api +dataUser = getUserWithData(url=urlGetAllData) +for user in dataUser["Users"]: + jsonTmp = {} + + jsonTmp["Identifiant"] = user["Identifiant"] + jsonTmp["Info"] = [] + + for category in user["Info"]: + #Mettre la condition longueur ici + model = generateModele(category) + jsonTmp["Info"].append({"Category": category["Category"],"Model" : generateJsonModel(model)}) + # Add User + jsonBack["Users"].append(jsonTmp) + +# -- Send Api +sendJsonToApi(urlGetAllData,jsonBack) \ No newline at end of file