Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter | |
| import sqlite3 | |
| from numpy import array,mean | |
| from pydantic import BaseModel | |
| UserGetLocationRouter=APIRouter(prefix="/Location") | |
| class DataType(BaseModel): | |
| Email:str | |
| Password:str | |
| Day:str | |
| def adduser(Data:DataType): | |
| try: | |
| Email=Data.Email | |
| Password=Data.Password | |
| Day=Data.Day | |
| State=False | |
| # pwd_context=CryptContext(schemes=["bcrypt"],deprecated="auto") | |
| connect=sqlite3.connect("DataBase/DataBase.bd") | |
| cursor=connect.execute(f''' | |
| SELECT UserId,Password FROM Users where Email='{Email}' | |
| ''') | |
| Data=cursor.fetchall() | |
| if len(Data) !=0 : | |
| if Data[0][0]==None: | |
| return {"Status":False,"Message":"User Is Not Defined Before"} | |
| HasedPassword=Data[0][1] | |
| UserId=Data[0][0] | |
| State=Password==HasedPassword | |
| if State: | |
| cursor=connect.execute(f''' | |
| SELECT Longtude , Lattitude,Houre FROM TrackeringPoints WHERE Day='{Day}' and UserId={UserId} | |
| ''') | |
| DataCollected=cursor.fetchall() | |
| # cursor2=connect.execute(f''' | |
| # SELECT AVG(Longtude) , AVG(Lattitude) TrackeringPoints WHERE Day='{Day}' and UserId={UserId} | |
| # ''') | |
| # PositionsMean=cursor2.fetchall() | |
| connect.close() | |
| if len(DataCollected)==0: | |
| return { | |
| "Status":True, | |
| "Data":{ | |
| "PositionData":[], | |
| "Time":[], | |
| "Mean":[12.3,50] | |
| } | |
| } | |
| PositionData=[ [ item[0],item[1]]for item in DataCollected] | |
| PositionsMean=mean(array(PositionData),axis=0) | |
| Houre=[ item[2] for item in DataCollected] | |
| return { | |
| "Status":True, | |
| "Data":{ | |
| "PositionData":PositionData, | |
| "Time":Houre, | |
| "Mean":PositionsMean | |
| } | |
| } | |
| else: | |
| return {"State":False} | |
| except Exception as e : | |
| return {"Status":False,"Message":e} | |