File size: 2,244 Bytes
a97e60d
 
 
 
 
 
 
 
 
 
 
 
b55f93a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a97e60d
b55f93a
a97e60d
b55f93a
 
 
 
 
 
 
 
 
 
 
 
 
a97e60d
b55f93a
 
 
 
 
a97e60d
b55f93a
 
 
 
 
 
 
a97e60d
b55f93a
 
 
 
 
a97e60d
b55f93a
 
 
 
c4dc0b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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

@UserGetLocationRouter.post("/GetMapLocations")
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()
        print(DataCollected)
        if len(DataCollected)==0:
            return {
            "Status":True,
            "Data":{

                "PositionData":[],
                "Time":[],
                "Mean":[51.505, -0.09]
                
            }
                }
        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}