cron
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
9b8595d92b
commit
de23e4785d
@ -1,10 +1,15 @@
|
|||||||
FROM python:3.10
|
FROM python:3.10
|
||||||
|
EXPOSE 80
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
COPY generateurModele.py .
|
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"]
|
ENTRYPOINT ["cron"]
|
@ -0,0 +1,3 @@
|
|||||||
|
00 08 * * * python generateurModele.py
|
||||||
|
* * * * * python testFinal.py
|
||||||
|
|
@ -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"]
|
@ -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)
|
Loading…
Reference in new issue