Search in sources :

Example 1 with Reports

use of edu.berkeley.cs.amplab.carat.thrift.Reports in project carat by amplab.

the class CaratApplication method setReportData.

public static void setReportData() {
    final Reports r = storage.getReports();
    Log.d(TAG, "Got reports.");
    long freshness = CaratApplication.storage.getFreshness();
    long l = System.currentTimeMillis() - freshness;
    final long h = l / 3600000;
    final long min = (l - h * 3600000) / 60000;
    double bl = 0;
    double error = 0;
    if (r != null) {
        Log.d(TAG, "r (reports) not null.");
        // Try exact battery life
        if (r.jScoreWith != null) {
            // Log.d(TAG, "jscoreWith not null.");
            double exp = r.jScoreWith.expectedValue;
            if (exp > 0.0) {
                bl = 100 / exp;
                error = 100 / (exp + r.jScoreWith.error);
            } else if (r.getModel() != null) {
                exp = r.getModel().expectedValue;
                Log.d(TAG, "Model expected value: " + exp);
                if (exp > 0.0) {
                    bl = 100 / exp;
                    error = 100 / (exp + r.getModel().error);
                }
            }
        // If not possible, try model battery life
        }
    }
    // Only take the error part
    error = bl - error;
    int blh = (int) (bl / 3600);
    bl -= blh * 3600;
    int blmin = (int) (bl / 60);
    int errorH = 0;
    int errorMin = 0;
    if (error > 7200) {
        errorH = (int) (error / 3600);
        error -= errorH * 3600;
    }
    errorMin = (int) (error / 60);
    final String blS = blh + "h " + blmin + "m ± " + (errorH > 0 ? errorH + "h " : "") + errorMin + " m";
    /*
		 * we removed direct manipulation of MyDevice fragment,
		 * and moved the data pertaining to this fragment to a class field, called myDeviceData.
		 * In the onResume() method of MyDeviceFragment, we fetch this data and show (see setViewData())
		 * The reason for this movement is that we migrated from tabs to fragments.
		 * We cannot change a fragment's view while it's not in the foreground
		 * (fragments get replaced by a fragment transaction:
		 * the parent activity which hosts a frame-layout
		 * (a placeholder for fragment's layout), replaces the frame-layout with
		 * the new fragment's layout)
		 */
    SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getMainActivity());
    String caratId = p.getString(Constants.REGISTERED_UUID, "0");
    myDeviceData.setAllFields(freshness, h, min, caratId, blS);
}
Also used : SharedPreferences(android.content.SharedPreferences) Reports(edu.berkeley.cs.amplab.carat.thrift.Reports)

Example 2 with Reports

use of edu.berkeley.cs.amplab.carat.thrift.Reports in project carat by amplab.

the class CaratApplication method getJscore.

public static int getJscore() {
    final Reports reports = storage.getReports();
    int jscore = 0;
    if (reports != null) {
        jscore = ((int) (reports.getJScore() * 100));
    }
    return jscore;
}
Also used : Reports(edu.berkeley.cs.amplab.carat.thrift.Reports)

Example 3 with Reports

use of edu.berkeley.cs.amplab.carat.thrift.Reports in project carat by amplab.

the class CommunicationManager method refreshMainReports.

private boolean refreshMainReports(String uuid, String os, String model) {
    if (System.currentTimeMillis() - CaratApplication.storage.getFreshness() < Constants.FRESHNESS_TIMEOUT)
        return false;
    CaratService.Client instance = null;
    try {
        instance = ProtocolClient.open(a.getApplicationContext());
        Reports r = instance.getReports(uuid, getFeatures("Model", model, "OS", os));
        // ProtocolClient.close();
        if (r != null) {
            Log.d("CommunicationManager.refreshMainReports()", "got the main report (action list)" + ", model=" + r.getModel() + ", jscore=" + r.getJScore() + ". Storing the report in the databse");
            CaratApplication.storage.writeReports(r);
        } else {
            Log.d("CommunicationManager.refreshMainReports()", "the fetched MAIN report is null");
        }
        // Assume freshness written by caller.
        // s.writeFreshness();
        safeClose(instance);
        return true;
    } catch (Throwable th) {
        Log.e(TAG, "Error refreshing main reports.", th);
        safeClose(instance);
    }
    return false;
}
Also used : CaratService(edu.berkeley.cs.amplab.carat.thrift.CaratService) Reports(edu.berkeley.cs.amplab.carat.thrift.Reports)

Example 4 with Reports

use of edu.berkeley.cs.amplab.carat.thrift.Reports in project carat by amplab.

the class AppDetailsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View detailsPage = inflater.inflate(R.layout.graph, container, false);
    DrawView drawView = new DrawView(getActivity());
    if (isApp) {
        drawView.setParams(fullObject, detailsPage);
        setBenefitTextView(detailsPage, fullObject.getBenefitText());
    } else {
        // isOS or isModel
        Reports reports = CaratApplication.storage.getReports();
        if (reports != null) {
            Tracker tracker = Tracker.getInstance();
            if (isOs) {
                setOsWidgets(detailsPage, drawView, reports, tracker);
            } else {
                // isModel
                setModelWidgets(detailsPage, drawView, reports, tracker);
            }
            // common piece of code for both OS and Model
            setBenefitWidget(detailsPage);
        }
        Log.d("NullReports", "Reports are null!!!");
    }
    // common piece of code for App, OS, and Model
    setDescriptionWidgets(detailsPage);
    // layout file
    return detailsPage;
}
Also used : Tracker(edu.berkeley.cs.amplab.carat.android.utils.Tracker) DrawView(edu.berkeley.cs.amplab.carat.android.ui.DrawView) Reports(edu.berkeley.cs.amplab.carat.thrift.Reports) DrawView(edu.berkeley.cs.amplab.carat.android.ui.DrawView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with Reports

use of edu.berkeley.cs.amplab.carat.thrift.Reports in project carat by amplab.

the class CommunicationManager method refreshAllReports.

/**
	 * Used by UiRefreshThread which needs to know about exceptions.
	 * 
	 * @throws TException
	 */
public void refreshAllReports() {
    registerLocal();
    // Do not refresh if not connected
    if (!SamplingLibrary.networkAvailable(a.getApplicationContext()))
        return;
    if (System.currentTimeMillis() - CaratApplication.storage.getFreshness() < Constants.FRESHNESS_TIMEOUT)
        return;
    // Establish connection
    if (register) {
        CaratService.Client instance = null;
        try {
            instance = ProtocolClient.open(a.getApplicationContext());
            registerOnFirstRun(instance);
            safeClose(instance);
        } catch (Throwable th) {
            Log.e(TAG, "Error refreshing main reports.", th);
            safeClose(instance);
        }
    }
    String uuId = p.getString(CaratApplication.getRegisteredUuid(), null);
    String model = SamplingLibrary.getModel();
    String OS = SamplingLibrary.getOsVersion();
    // NOTE: Fake data for simulator
    if (model.equals("sdk")) {
        // My S3
        uuId = "97c542cd8e99d948";
        model = "GT-I9300";
        OS = "4.0.4";
    }
    Log.d(TAG, "Getting reports for " + uuId + " model=" + model + " os=" + OS);
    FlurryAgent.logEvent("Getting reports for " + uuId + "," + model + "," + OS);
    int progress = 0;
    String[] titles = CaratApplication.getTitles();
    if (titles != null) {
        String[] temp = Arrays.copyOfRange(titles, 2, 5);
        titles = temp;
    }
    CaratApplication.setActionProgress(progress, titles[0], false);
    boolean success = refreshMainReports(uuId, OS, model);
    if (success) {
        progress += 20;
        CaratApplication.setActionProgress(progress, titles[1], false);
        Log.d(TAG, "Successfully got main report");
    } else {
        CaratApplication.setActionProgress(progress, titles[0], true);
        Log.d(TAG, "Failed getting main report");
    }
    success = refreshBugReports(uuId, model);
    if (success) {
        progress += 20;
        CaratApplication.setActionProgress(progress, titles[2], false);
        Log.d(TAG, "Successfully got bug report");
    } else {
        CaratApplication.setActionProgress(progress, titles[1], true);
        Log.d(TAG, "Failed getting bug report");
    }
    //		success = refreshSettingsReports(uuId, model);
    //		
    //		if (success) {
    //			progress += 20;
    //			CaratApplication.setActionProgress(progress, a.getString(R.string.tab_hogs), false);
    //			Log.d(TAG, "Successfully got settings report");
    //		} else {
    //			CaratApplication.setActionProgress(progress, a.getString(R.string.tab_settings), true);
    //			Log.d(TAG, "Failed getting settings report");
    //		}
    success = refreshHogReports(uuId, model);
    boolean bl = true;
    if (System.currentTimeMillis() - CaratApplication.storage.getBlacklistFreshness() < Constants.FRESHNESS_TIMEOUT_BLACKLIST)
        bl = false;
    if (success) {
        // changed to 40
        progress += 40;
        CaratApplication.setActionProgress(progress, bl ? a.getString(R.string.blacklist) : a.getString(R.string.finishing), false);
        Log.d(TAG, "Successfully got hog report");
    } else {
        CaratApplication.setActionProgress(progress, titles[2], true);
        Log.d(TAG, "Failed getting hog report");
    }
    // NOTE: Check for having a J-Score, and in case there is none, send the
    // new message
    Reports r = CaratApplication.storage.getReports();
    if (r == null || r.jScoreWith == null || r.jScoreWith.expectedValue <= 0) {
        success = getQuickHogsAndMaybeRegister(uuId, OS, model);
        if (success)
            Log.d(TAG, "Got quickHogs.");
        else
            Log.d(TAG, "Failed getting GuickHogs.");
    }
    if (bl) {
        refreshBlacklist();
        refreshQuestionnaireLink();
    }
    CaratApplication.storage.writeFreshness();
    Log.d(TAG, "Wrote freshness");
}
Also used : CaratService(edu.berkeley.cs.amplab.carat.thrift.CaratService) Reports(edu.berkeley.cs.amplab.carat.thrift.Reports)

Aggregations

Reports (edu.berkeley.cs.amplab.carat.thrift.Reports)5 CaratService (edu.berkeley.cs.amplab.carat.thrift.CaratService)2 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 TextView (android.widget.TextView)1 DrawView (edu.berkeley.cs.amplab.carat.android.ui.DrawView)1 Tracker (edu.berkeley.cs.amplab.carat.android.utils.Tracker)1