Jump to content

Help in translating pseudo code of algorithm to PHP from a research paper.

Recommended Posts

I'm helping a friend in developing a project for our alma mater. And its based on this paper: An Enhanced Indoor Positioning Method Based on Wi-Fi RSS Fingerprinting

So far 80% of the web app is finished except for the algorithm (We have no experience with algorithms to source code translations) that needs to be implemented in the website. Inside this paper there is this algorithm that the proponents of the research used. (attached as screenshot).

The algorithm was converted to code by using MATLAB, but we are trying to use PHP with our project. Based on the pseudo code the calculation of the Euclidean Distance is the core of it. Can anyone help us with the translation just to get it started.

Share on other sites

1 and 2 would presumably be input from the web page. The rest would be something like:

for (\$m=1; \$m<=\$M; \$m++) {
for (\$l=1; \$l<=\$L; \$l++) {
for (\$j=1; \$j<=\$N; \$j++) {
#do calculation here storing it in a 2D array
}
# select minimum here (perhaps min() function)
}
}
# use array sort
# use PHP vector class
# compute distance from vectors
# echo results in desired format

Share on other sites

Based on this page, the Euclidean distance function requires 2 points (p1, p2) so a function to calculate it would be something like this:

function EuclideanDistance(\$p1x, \$p1y, \$p2x, \$p2y) {
return sqrt(pow(\$p1x - \$p2x, 2) + pow(\$p1y - \$p2y, 2));
}

Share on other sites

I assumed that they knew how to calculate the distance and just needed some pointers on how to structure the algorithm in PHP.

Share on other sites

10 hours ago, gw1500se said:

I assumed that they knew how to calculate the distance and just needed some pointers on how to structure the algorithm in PHP.

Yes! since the formula is (I assume) indicated in the pseudocode. the translation of it to PHP is what we needed. Thank you!

Share on other sites

12 hours ago, gw1500se said:

1 and 2 would presumably be input from the web page. The rest would be something like:

for (\$m=1; \$m<=\$M; \$m++) {
for (\$l=1; \$l<=\$L; \$l++) {
for (\$j=1; \$j<=\$N; \$j++) {
#do calculation here storing it in a 2D array
}
# select minimum here (perhaps min() function)
}
}
# use array sort
# use PHP vector class
# compute distance from vectors
# echo results in desired format

In our project the input will be coming from a mobile app that my friend made that scans a room. I don't if its needed but I can provide the documentation of the project here.

Share on other sites

this is some information from the project for better context.

Share on other sites

The way that the client/mobile app and the serverside routines will work, need to implement some sort of standard.  My suggestion would be that you utilize json.  So the webapp should send it's data to the web app in json format.  In PHP it is then simply a function call (json_decode) in order to convert the data into either php objects or a php array.

Share on other sites

4 minutes ago, gizmola said:

The way that the client/mobile app and the serverside routines will work, need to implement some sort of standard.  My suggestion would be that you utilize json.  So the webapp should send it's data to the web app in json format.  In PHP it is then simply a function call (json_decode) in order to convert the data into either php objects or a php array.

Hello! The php script that you sent. is there anything to add there or can we use that as is? and that will be incorporated into json? did I get that right?

Share on other sites

I think you need to start on the mobile side and, as gizmola suggested, create the json formatted data. Post a sample of that so we get a better idea of what it looks like and then we can help you go from there with the PHP side.

Share on other sites

3 minutes ago, gw1500se said:

I think you need to start on the mobile side and, as gizmola suggested, create the json formatted data. Post a sample of that so we get a better idea of what it looks like and then we can help you go from there with the PHP side.

Ok. I'll get the source code of the mobile app from my friend (because she's the one that developed it.) thanks!
and we haven't yet tested how the mobile app and the web app will 'meet'

Edited by -franciskane-
Share on other sites

22 hours ago, gw1500se said:

I think you need to start on the mobile side and, as gizmola suggested, create the json formatted data. Post a sample of that so we get a better idea of what it looks like and then we can help you go from there with the PHP side.

Hello my friend said the she wrote the mobile app's source code in unity

Share on other sites

Language doesn't matter. What I want to see is the JSON output or whatever she programmed to be passed to the PHP script. It would be preferable if she programmed it to output it in JSON.

Edited by gw1500se
Share on other sites

4 hours ago, gw1500se said:

Language doesn't matter. What I want to see is the JSON output or whatever she programmed to be passed to the PHP script. It would be preferable if she programmed it to output it in JSON.

To elaborate a bit, talk to your clientside developer and ask her for some test output.  If she is not already outputting the collected data in json, then you want to ask her to modify that.  She will need to change the app eventually to send output to the domain/url of the production server anyway.  Ideally the url to send data would be configurable in the client so that you can have multiple server side environments   (dev, test, prod).  Development is the one you are currently working on now.  Test would be for automated testing, and prod is of course production.

Share on other sites

On 8/15/2020 at 11:34 PM, gw1500se said:

Language doesn't matter. What I want to see is the JSON output or whatever she programmed to be passed to the PHP script. It would be preferable if she programmed it to output it in JSON.

Hello I have the c# files. but I cant upload them here. and from browsing those files I can't find any json file so maybe that she hasn't finished that part. I thought that I can finish first this algorithm then try to connect the website to the mobile app. but I guess my reasoning is wrong.

Edited by -franciskane-
Additional information
Share on other sites

She may have finished but where/what is the output she plans to pass to the PHP script?

Share on other sites

20 minutes ago, gw1500se said:

She may have finished but where/what is the output she plans to pass to the PHP script?

I don't know if this is something but I browsed the files and I found this file named 'JsonHelper.cs'.

Share on other sites

No, we need to see the actual output and how it plans to call the PHP script. However, it does look like JSON was the intention.

Share on other sites

20 hours ago, gw1500se said:

No, we need to see the actual output and how it plans to call the PHP script. However, it does look like JSON was the intention.

Ohh. Ok I get it. We aren't on that phase yet because of the pandemic. My friend can't go to our alma mater yet to test the QR Scanner. We are hoping to finish everything first before she can test the mobile app and the website. then debug.

Share on other sites

She can't make up test data?

Share on other sites

On 8/19/2020 at 9:18 PM, gw1500se said:

She can't make up test data?

The only part the we can make test data for (that I know of) is the login credentials from the db of the website that will also be used by the mobile app. And I wouldn't know how would you test a qr scanner without being there.

Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
×
• Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.