Spaces:
Sleeping
Sleeping
Update Logic/Locations/GetMapOfuser.py
Browse files- Logic/Locations/GetMapOfuser.py +73 -73
Logic/Locations/GetMapOfuser.py
CHANGED
@@ -1,74 +1,74 @@
|
|
1 |
-
from fastapi import APIRouter
|
2 |
-
import sqlite3
|
3 |
-
from numpy import array,mean
|
4 |
-
from pydantic import BaseModel
|
5 |
-
UserGetLocationRouter=APIRouter(prefix="/Location")
|
6 |
-
class DataType(BaseModel):
|
7 |
-
Email:str
|
8 |
-
Password:str
|
9 |
-
Day:str
|
10 |
-
|
11 |
-
@UserGetLocationRouter.post("/GetMapLocations")
|
12 |
-
def adduser(Data:DataType):
|
13 |
-
try:
|
14 |
-
Email=Data.Email
|
15 |
-
Password=Data.Password
|
16 |
-
Day=Data.Day
|
17 |
-
State=False
|
18 |
-
|
19 |
-
# pwd_context=CryptContext(schemes=["bcrypt"],deprecated="auto")
|
20 |
-
|
21 |
-
|
22 |
-
connect=sqlite3.connect("DataBase/DataBase.bd")
|
23 |
-
cursor=connect.execute(f'''
|
24 |
-
SELECT UserId,Password FROM Users where Email='{Email}'
|
25 |
-
''')
|
26 |
-
Data=cursor.fetchall()
|
27 |
-
if len(Data) !=0 :
|
28 |
-
if Data[0][0]==None:
|
29 |
-
return {"Status":False,"Message":"User Is Not Defined Before"}
|
30 |
-
HasedPassword=Data[0][1]
|
31 |
-
UserId=Data[0][0]
|
32 |
-
State=Password==HasedPassword
|
33 |
-
if State:
|
34 |
-
cursor=connect.execute(f'''
|
35 |
-
SELECT Longtude , Lattitude,Houre FROM TrackeringPoints WHERE Day='{Day}' and UserId={UserId}
|
36 |
-
''')
|
37 |
-
DataCollected=cursor.fetchall()
|
38 |
-
# cursor2=connect.execute(f'''
|
39 |
-
# SELECT AVG(Longtude) , AVG(Lattitude) TrackeringPoints WHERE Day='{Day}' and UserId={UserId}
|
40 |
-
# ''')
|
41 |
-
|
42 |
-
|
43 |
-
# PositionsMean=cursor2.fetchall()
|
44 |
-
connect.close()
|
45 |
-
if len(DataCollected)==0:
|
46 |
-
return {
|
47 |
-
"Status":True,
|
48 |
-
"Data":{
|
49 |
-
|
50 |
-
"PositionData":[],
|
51 |
-
"Time":[],
|
52 |
-
"Mean":[
|
53 |
-
|
54 |
-
}
|
55 |
-
}
|
56 |
-
PositionData=[ [ item[0],item[1]]for item in DataCollected]
|
57 |
-
PositionsMean=mean(array(PositionData),axis=0)
|
58 |
-
Houre=[ item[2] for item in DataCollected]
|
59 |
-
|
60 |
-
return {
|
61 |
-
"Status":True,
|
62 |
-
"Data":{
|
63 |
-
|
64 |
-
"PositionData":PositionData,
|
65 |
-
"Time":Houre,
|
66 |
-
"Mean":PositionsMean
|
67 |
-
|
68 |
-
}
|
69 |
-
}
|
70 |
-
else:
|
71 |
-
return {"State":False}
|
72 |
-
except Exception as e :
|
73 |
-
return {"Status":False,"Message":e}
|
74 |
|
|
|
1 |
+
from fastapi import APIRouter
|
2 |
+
import sqlite3
|
3 |
+
from numpy import array,mean
|
4 |
+
from pydantic import BaseModel
|
5 |
+
UserGetLocationRouter=APIRouter(prefix="/Location")
|
6 |
+
class DataType(BaseModel):
|
7 |
+
Email:str
|
8 |
+
Password:str
|
9 |
+
Day:str
|
10 |
+
|
11 |
+
@UserGetLocationRouter.post("/GetMapLocations")
|
12 |
+
def adduser(Data:DataType):
|
13 |
+
try:
|
14 |
+
Email=Data.Email
|
15 |
+
Password=Data.Password
|
16 |
+
Day=Data.Day
|
17 |
+
State=False
|
18 |
+
|
19 |
+
# pwd_context=CryptContext(schemes=["bcrypt"],deprecated="auto")
|
20 |
+
|
21 |
+
|
22 |
+
connect=sqlite3.connect("DataBase/DataBase.bd")
|
23 |
+
cursor=connect.execute(f'''
|
24 |
+
SELECT UserId,Password FROM Users where Email='{Email}'
|
25 |
+
''')
|
26 |
+
Data=cursor.fetchall()
|
27 |
+
if len(Data) !=0 :
|
28 |
+
if Data[0][0]==None:
|
29 |
+
return {"Status":False,"Message":"User Is Not Defined Before"}
|
30 |
+
HasedPassword=Data[0][1]
|
31 |
+
UserId=Data[0][0]
|
32 |
+
State=Password==HasedPassword
|
33 |
+
if State:
|
34 |
+
cursor=connect.execute(f'''
|
35 |
+
SELECT Longtude , Lattitude,Houre FROM TrackeringPoints WHERE Day='{Day}' and UserId={UserId}
|
36 |
+
''')
|
37 |
+
DataCollected=cursor.fetchall()
|
38 |
+
# cursor2=connect.execute(f'''
|
39 |
+
# SELECT AVG(Longtude) , AVG(Lattitude) TrackeringPoints WHERE Day='{Day}' and UserId={UserId}
|
40 |
+
# ''')
|
41 |
+
|
42 |
+
|
43 |
+
# PositionsMean=cursor2.fetchall()
|
44 |
+
connect.close()
|
45 |
+
if len(DataCollected)==0:
|
46 |
+
return {
|
47 |
+
"Status":True,
|
48 |
+
"Data":{
|
49 |
+
|
50 |
+
"PositionData":[],
|
51 |
+
"Time":[],
|
52 |
+
"Mean":[51.505, -0.09]
|
53 |
+
|
54 |
+
}
|
55 |
+
}
|
56 |
+
PositionData=[ [ item[0],item[1]]for item in DataCollected]
|
57 |
+
PositionsMean=mean(array(PositionData),axis=0)
|
58 |
+
Houre=[ item[2] for item in DataCollected]
|
59 |
+
|
60 |
+
return {
|
61 |
+
"Status":True,
|
62 |
+
"Data":{
|
63 |
+
|
64 |
+
"PositionData":PositionData,
|
65 |
+
"Time":Houre,
|
66 |
+
"Mean":PositionsMean
|
67 |
+
|
68 |
+
}
|
69 |
+
}
|
70 |
+
else:
|
71 |
+
return {"State":False}
|
72 |
+
except Exception as e :
|
73 |
+
return {"Status":False,"Message":e}
|
74 |
|