S2-group / NAPPA

Implementation of a navigation-aware technique for personalized prefetching of network requests of Android apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extract Link Analysis Ranking computation from ActivityGraph

github-actions opened this issue · comments

The computation of Link Analysis Ranking (LAR) rankings in this class add cluster, difficult the implementation of plug-and-play components and reduce the source readability.

The following strategies run their calculations here

  • PageRank
  • PageRank + Greedy
  • HITS
  • HITS + PPM
  • SALSA

Extracting the management of LAR data from this class will largely increase its readability.
While performing the extraction, an aspect to consider is that the implemented algorithms run the scores for all activities in the graph and runs a single interaction only.

Take the method updateNodes as an example:

public boolean updateNodes(String activityName) {
boolean shouldPrefetch = false;
float dump = 0.85f;
float initialPageRank = 0.25f;
float initialAuthority = 1f;
float initialHub = 1f;
float initialAuthorityS = 1f;
float initialHubS = 1f;
ActivityNode temp = new ActivityNode(activityName);
// verify if this activity has already been added to the graph
final String tempActivityName = temp.activityName;
if (nodeList.contains(temp)) {
temp = nodeList.get(nodeList.lastIndexOf(temp));
} else {
temp.pageRank = initialPageRank;
temp.authority = initialAuthority;
temp.hub = initialHub;
temp.authorityS = initialAuthorityS;
temp.hubS = initialHubS;
nodeList.add(temp);
poolExecutor.schedule(() -> {
NappaDB.getInstance().activityDao().insertLAR(new LARData(tempActivityName, initialPageRank, initialAuthority, initialHub, initialAuthorityS, initialHubS));
}, 0, TimeUnit.SECONDS);
Log.d(LOG_TAG, "LARDataUpdate " + "node " + temp.activityName + " added to nodelist");
Log.d(LOG_TAG, "LARDataUpdate " + " Pagerank: " + temp.pageRank + " HITS-Authority: " + temp.authority + " HITS-Hub: " + temp.hub + " SALSA-Authority: " + temp.authorityS + " SALSA-Hub: " + temp.hubS);
}
if (current != null) {
shouldPrefetch = current.addSuccessor(temp);
nodeList.set(nodeList.lastIndexOf(temp), temp);
//updates
updateLAR(activityName);
temp = nodeList.get(nodeList.lastIndexOf(temp));
Log.d(LOG_TAG, "LARDataCalculatedUpdate " + temp.activityName + " Pagerank: " + temp.pageRank + " HITS-Authority: " + temp.authority + " HITS-Hub: " + temp.hub + " SALSA-Authority: " + temp.authorityS + " SALSA-Hub: " + temp.hubS);
}
current = temp;
return shouldPrefetch;
}

Without LARs operations and doing a cleanup, this method would be something like:

    public boolean updateNodes(String activityName) {
        boolean shouldPrefetch = false;
        ActivityNode node = new ActivityNode(activityName);

        // verify if this activity has already been added to the graph
        int nodeIdx = nodeList.lastIndexOf(node);
        if (nodeIdx != -1) node = nodeList.get(nodeIdx);
        else nodeList.add(node);
        
        if (current != null) {
            shouldPrefetch = current.addSuccessor(node);
            if (nodeIdx == -1) nodeIdx = nodeList.size() - 1;
            nodeList.set(nodeIdx, node);
        }
        current = node;
        
        return shouldPrefetch;
    }