Skip to main content
The Leaderboard feature provides competitive motivation and performance tracking for sales teams, ranking salespersons by their performance index and offering AI-driven target recommendations.

Overview

The leaderboard is available exclusively to Salespersons. Managers can view individual performance through the “My Team” feature and analytics dashboards.

Performance Index

Normalized metric measuring profit generation rate over time since registration

Top 10 Ranking

Displays the highest performing salespersons across the entire organization

Target Recommendation

AI algorithm suggests personalized profit targets to improve performance

Real-Time Updates

Rankings update automatically as sales are recorded

Accessing the Leaderboard

Salespersons can access the leaderboard from their dashboard:
1

Open Navigation Drawer

Tap the hamburger menu icon in the top-left corner of the Salesperson dashboard.
2

Select Leaderboard

Tap “Leaderboard” from the navigation menu:
else if (id1 == R.id.leaderboard) {
    Intent intent = new Intent(SalespersonMain.this, LeaderBoardSalesperson.class);
    startActivity(intent);
}
Source: SalespersonMain.java:459-462
3

View Rankings

The LeaderBoardSalesperson activity displays the top performers with their performance metrics.

Performance Index Calculation

The performance index is a time-normalized metric that ensures fair comparison between salespersons who joined at different times.

How It’s Calculated

1

Retrieve Total Profit

For each salesperson, calculate total profit from all sold items:
DatabaseReference databaseReference = FirebaseDatabase.getInstance()
    .getReference("Salesperson");
databaseReference.child(key).child("Inventory")
    .addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            int totalProfit = 0;
            for(DataSnapshot dataSnapshot2 : dataSnapshot.getChildren()){
                InventoryItem inventoryItem = dataSnapshot2.getValue(InventoryItem.class);
                totalProfit += inventoryItem.getSold() * inventoryItem.getProfit();
            }
        }
    });
Source: LeaderBoardSalesperson.java:168-178
2

Get Signup Timestamp

Retrieve the salesperson’s registration timestamp from the LeaderBoard node:
DatabaseReference databaseReference1 = FirebaseDatabase.getInstance()
    .getReference("LeaderBoard");
databaseReference1.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        for(DataSnapshot dataSnapshot3 : dataSnapshot.getChildren()){
            LeaderBoardObject leaderBoardObject = dataSnapshot3.getValue(LeaderBoardObject.class);
            
            if(leaderBoardObject.getSalespersonName().equals(name)){
                signupTimeInSecs = Long.parseLong(leaderBoardObject.getTimestamp());
                break;
            }
        }
    }
});
Source: LeaderBoardSalesperson.java:193-206
3

Calculate Days Active

Determine how many days the salesperson has been active:
Long currTimeInSecs = System.currentTimeMillis() / 1000;
Long timeDiff = ((Long)(currTimeInSecs - signupTimeInSecs) / 86400) + 1;
Source: LeaderBoardSalesperson.java:206
86400 is the number of seconds in a day (24 × 60 × 60). Adding 1 ensures salespersons don’t have zero days on their first day.
4

Compute Performance Index

Calculate the daily profit average:
String performanceCurr = String.valueOf((totalProfit * 1.0) / timeDiff);
int index = performanceCurr.lastIndexOf('.');
performanceCurr = performanceCurr.substring(0, index + 2);  // Round to 1 decimal
performanceIndex.add(performanceCurr);
Source: LeaderBoardSalesperson.java:207-210Formula: Performance Index = Total Profit ÷ Days Active

Performance Index Example

Salesperson A:
  • Joined: 30 days ago
  • Total Profit Generated: $15,000
  • Performance Index: 15,000÷30=15,000 ÷ 30 = **500/day**
Salesperson B:
  • Joined: 5 days ago
  • Total Profit Generated: $3,000
  • Performance Index: 3,000÷5=3,000 ÷ 5 = **600/day**
Even though Salesperson A has generated more total profit, Salesperson B ranks higher on the leaderboard because they have a better daily performance rate.

Leaderboard Display

Data Model

The leaderboard uses two key data structures:
public class LeaderBoardObject {
    private String SalespersonName;
    private String timestamp;  // Unix timestamp in seconds
    
    public LeaderBoardObject(String salespersonName, String timestamp) {
        this.SalespersonName = salespersonName;
        this.timestamp = timestamp;
    }
}
Source: LeaderBoardObject.java:7-33

Sorting and Ranking

The leaderboard sorts salespersons by performance index in descending order:
List<Pair<String,SalesPerson>> container = new ArrayList<>();
for(int i=0; i<performanceIndex.size(); i++){
    container.add(new Pair<String, SalesPerson>(performanceIndex.get(i), personArrayList.get(i)));
}

Collections.sort(container, new Comparator<Pair<String, SalesPerson>>() {
    @Override
    public int compare(Pair<String, SalesPerson> stringSalesPersonPair, Pair<String, SalesPerson> t1) {
        return -stringSalesPersonPair.first.compareTo(t1.first);  // Negative for descending
    }
});

// Extract top 10
ArrayList<String> PI = new ArrayList<>();
ArrayList<SalesPerson> SP = new ArrayList<>();
for(int i=0; i < Math.min(10, performanceIndex.size()); i++){
    PI.add(container.get(i).first);
    SP.add(container.get(i).second);
}
Source: LeaderBoardAdapter.java:53-69

Leaderboard Item Layout

Each leaderboard entry displays:

Rank

Position from 1-10

Profile Picture

Gravatar image based on email

Salesperson Name

Full name

Performance Index

Daily profit average
Implementation:
SalesPerson salesPerson = SP.get(position);
holder.performanceIndex.setText(PI.get(position));
holder.name.setText(salesPerson.getName());
holder.rank.setText(String.valueOf(position+1) + ".");
ImageSetter.setImage(context, holder.imageView, salesPerson.getEmailId(), holder.progressBar);
Source: LeaderBoardAdapter.java:71-75

Target Recommendation Algorithm

The leaderboard includes an intelligent recommendation system that suggests personalized profit targets.

How It Works

1

Access Recommendation

Tap the floating action button (FAB) on the leaderboard screen:
fabButton = findViewById(R.id.fabButton);
fabButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // Calculate and show target
    }
});
Source: LeaderBoardSalesperson.java:63-68
2

Find Current Salesperson

The system identifies your current performance index:
String currName = salesPerson.getName();
int i;
for(i=0; i<SalespersonList.size(); i++){
    if(SalespersonList.get(i).getName().equals(currName))
        break;
}
Double PiCurr = Double.parseDouble(performanceIndex.get(i));
Source: LeaderBoardSalesperson.java:91-100
3

Find Top Performer

Retrieve the highest performance index:
ArrayList<Double> arrayList = new ArrayList<>();
for(int i=0; i<performanceIndex.size(); i++){
    arrayList.add(Double.parseDouble(performanceIndex.get(i)));
}
Double PiTopper = Collections.max(arrayList);
Source: LeaderBoardSalesperson.java:85-92
4

Calculate Target

The algorithm calculates your target profit:
Double targetProfit = (PiCurr + (PiTopper - PiCurr)) * 1.10;
target.setText(String.valueOf(targetProfit));
Source: LeaderBoardSalesperson.java:106-107Formula: Target = (Current PI + Gap to Top) × 1.10
The 1.10 multiplier adds a 10% stretch goal to encourage continuous improvement.
5

Display Recommendation

A circular progress animation shows your target in a dialog:
CircleProgressbar circleProgressbar = mView.findViewById(R.id.circular_progress);
circleProgressbar.setForegroundProgressColor(getResources().getColor(R.color.colorPrimary));
circleProgressbar.setProgressWithAnimation(100, 1000);  // 1 second animation

final AlertDialog dialog = mBuilder.create();
dialog.show();
Source: LeaderBoardSalesperson.java:109-122

Target Example

Your Current Performance:
  • Performance Index: $400/day
Top Performer:
  • Performance Index: $600/day
Your Calculated Target:
  • Gap to Top: 600600 - 400 = $200
  • Catch Up Target: 400+400 + 200 = $600
  • Stretch Goal: 600×1.10=600 × 1.10 = **660/day**
The system recommends you aim for $660/day to not only reach the current top performer but exceed them by 10%.

User Interface

Loading State

While calculating performance indices and rankings:
progressBar = findViewById(R.id.leaderboard_progress);
progressBar.setVisibility(View.VISIBLE);
// ... calculations ...
progressBar.setVisibility(View.GONE);
Source: LeaderBoardSalesperson.java:59-213

RecyclerView Implementation

The leaderboard uses a RecyclerView for smooth scrolling:
mRecyclerView = findViewById(R.id.leaderboard_recycler_view);
mAdapter = new LeaderBoardAdapter(getApplicationContext(), SalespersonList, performanceIndex);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
Source: LeaderBoardSalesperson.java:231-235

Real-Time Updates

The leaderboard recalculates rankings whenever:
  • A salesperson records a new sale
  • Inventory items are updated
  • You navigate to the leaderboard screen
Rankings update automatically when you open the leaderboard. No manual refresh is needed.

Common Use Cases

  1. Open the navigation drawer
  2. Tap “Leaderboard”
  3. Scroll through the top 10 list
  4. Find your name and rank
  5. Compare your performance index with others
  1. View the leaderboard
  2. Tap the FAB button
  3. Review your recommended target
  4. Note the target profit per day
  5. Calculate how many sales you need to reach the target
  6. Track progress by checking the leaderboard regularly
  1. Check the leaderboard daily
  2. Identify salespersons just above your rank
  3. Calculate the performance index gap
  4. Focus on closing deals to increase your daily average
  5. Monitor your climb in the rankings
As a new salesperson:
  1. Your initial performance index may be volatile
  2. Focus on consistent sales over your first month
  3. Your index will stabilize as you accumulate more days
  4. Don’t be discouraged by veterans with lower daily rates but higher total sales
  5. Use the target recommendation to guide your efforts

Performance Tips

Consistency Wins

Maintain steady sales every day rather than sporadic high-volume days for better performance index

High-Margin Items

Focus on items with higher profit margins to boost your daily average faster

Early Sales

Log sales early in the day to see your ranking improve in real-time

Target Focused

Use the recommendation algorithm weekly to set realistic short-term goals

Understanding the Algorithm

Time normalization ensures fair competition:Without normalization: A salesperson who joined 2 years ago will always rank higher than a new hire, regardless of current performance.With normalization: A new salesperson with strong daily sales can quickly rise in rankings, while veterans must maintain high performance to stay on top.This creates a meritocratic system that rewards current performance rather than tenure.
The recommendation algorithm adds 10% to prevent complacency:
  • Motivation: Encourages exceeding the current top performer
  • Growth Mindset: Promotes continuous improvement
  • Realistic: 10% is challenging but achievable
  • Team Elevation: As individuals improve, the entire team’s performance rises

Limitations

The leaderboard only displays the top 10 performers. If you’re ranked 11th or lower, you won’t appear on the list but can still use the target recommendation feature.
Rankings are calculated synchronously when the leaderboard loads. In large teams, there may be a brief loading period while performance indices are computed.

Build docs developers (and LLMs) love