benjamin benjamin - 5 months ago 51
Java Question

How to calculate Profile complete percentage in a web application?

I have a Rest Based web application with Angular on front end. I want to create a profile complete percentage line. Where should I calculate its value, in back end or front end?. Is there a best practice for it?

Answer

Anyway to answer the question there is no best practice with regards to a profile complete percentage line similar to LinkedIn or what have you.

Have a look at this link

https://angular-ui.github.io/bootstrap/

and check out the the Progress Bar Directive which you could implement into your front end. My advice would be just get it working/integrate it and get a feel for how it works without worrying about how to calculate the values.

Once you understand how it works, have a think about which parts of a profile will determine what value it should add to the percentage bar.

Then take each of those parts, one step at the time, and think 'How can I write a function which can take the value of each one of those parts and calculate it into a sum total?'

Just try and break it down into as many small steps as possible and you'll work it out.

For example, say you make a call to your REST API and it returns the following JSON

{
'name'    : 'John',
'age'     :  21,
'address' : 'America'
}

You could do something like

function calculateProgressBar(JSON) {

 var total = 0;

 if(JSON.name) {
 total+=1;
 }
 if(JSON.age) {
 total+=1;
 }
 if(JSON.address) {
 total+=1;
 }

 return total;

}

Then insert total into the progress bar.

Very basic example but hopefully it points you in the right direction.

Comments