schollz / find

High-precision indoor positioning framework for most wifi-enabled devices.
https://www.internalpositioning.com/
GNU Affero General Public License v3.0
5.05k stars 368 forks source link

Adding new user to an existing group. #171

Closed OlegSl closed 7 years ago

OlegSl commented 7 years ago

Hello. Now I'm working on Android mobile client for FIND. As I understand the only way to add new user to an existing group is to execute "/learn" request. Could you add new request to API? Something like

POST /username params:

group | Defines the unique group ID | Required user | Specifies a user | Required

I think this is quite useful because in this case user can just specify the name of "device" to start using previously created WiFi fingerprints map.

P.S. Thank for you work! The project you started is awesome!

OlegSl commented 7 years ago

Hello again :-) The main idea of my request is to have a possibility to track user when he send "/track" request to the FIND server. Description of use case is 1) admin creates "map" by "/learn" request; 2) admin installs mobile client on user's devices; 3) mobile client send "track" request to FIND server; 4) admin can get last known location for each user by "/location" request.

But I find out that FIND server updates user location only after "/learn" request.

So I will try to add additional logic to existing server project or use different service to store results of client "/track" request.

schollz commented 7 years ago

Short answer: new users will automatically show up in the /location list, after about 30 seconds.

Long answer: Everytime you GET /location you run getUserLocations(). This code gets the location of all the users using getUsers(). This function defaults to the users cache, if it exists it uses that. When you have a new user that is being tracked, it will start showing that user once the cache resets. Currently that is set to about 30 seconds. I suggest setting this to much shorter if you need to update quickly. The reason the cache exists is because I am getting requests on the public server at a very high rate, and I want to avoid looking up the user positions for every user (especially if they are deep in the DB) at every request.

OlegSl commented 7 years ago

Ok, based on sourcecode server should work like you described.

But try to test the following case:

1) http://ml.internalpositioning.com/location?group=PLUMPPIKE
response:
{
    "message": "Correctly found locations.",
    "success": true,
    "users": {
        "moto": [
            {
                "time": "2017-07-25 11:35:52.0977175 +0000 UTC",
                "location": "demo",
                ....
            }
        ],
        "moto2": [
            {
                "time": "2017-07-25 12:00:33.334359624 +0000 UTC",
                "location": "demo3",
                ....
            }
        ]
    }
}
2)POST https://ml.internalpositioning.com/track
{
   "group":"PLUMPPIKE",
   "location":"tracking",
   "username":"moto",
   "wifi-fingerprint":[
      // list of wifi-fingerprints
   ]
}

response:
{
    "bayes": {
        "demo": 1.2910746581693808,
        "demo2": -0.9319313760932477,
        "demo3": 0.08900201725703422,
        "exit1": -0.464441152827399,
        "exit2": 0.01629585349423146
    },
    "location": "demo",
    "message": "Current location: demo",
    "rf": {
        "demo": 1,
        "demo2": 0,
        "demo3": 0,
        "exit1": 0,
        "exit2": 0
    },
    "success": true,
    "svm": {}
}

3) http://ml.internalpositioning.com/location?group=PLUMPPIKE
Response:
....
 "users": {
        "moto": [
            {
                "time": "2017-07-27 12:45:02.800051126 +0000 UTC",
                "location": "demo",
                .....
            }
        ]
.....

"time" for "moto" user was updated as expected

4) POST https://ml.internalpositioning.com/track
{
   "group":"PLUMPPIKE",
   "location":"tracking",
   "username":"moto46",
   "wifi-fingerprint":[
      // list of wifi-fingerprints
   ]
}

Request:
{
    ...
    "location": "demo",
    "message": "Current location: demo",
    ...
    "success": true,
    "svm": {}
}

5) http://ml.internalpositioning.com/location?group=PLUMPPIKE

Response:
{
    "message": "Correctly found locations.",
    "success": true,
    "users": {
        "moto": [
            {
                "time": "2017-07-27 12:45:02.800051126 +0000 UTC",
                "location": "demo",
                .....
            }
        ],
        "moto2": [
            {
                "time": "2017-07-25 12:00:33.334359624 +0000 UTC",
                "location": "demo3",
                .....
            }
        ]
    }
}

I expect that location of new user "moto46" is available. But it isn't.

schollz commented 7 years ago

There is a problem, but I think its not with adding a new user, as I can't replicate your problem with other groups.

There seems to be a problem with your learned locations: https://ml.internalpositioning.com/dashboard/PLUMPPIKE. They aren't there anymore, did you delete them?

OlegSl commented 7 years ago

Oh.... It seems that for some requests groupName is case sensitive and for other isn't. Just compare https://ml.internalpositioning.com/dashboard/PLUMPPIKE with https://ml.internalpositioning.com/dashboard/plumppike.

I'm not sure is it "bug or feature".

Thank you for help anyway. :-)

OlegSl commented 7 years ago

Here group name is always in lowercase. Here isn't.

Unfortunately i'm not good at GoLang so I can't create a pull request to fix that problem.