Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify insertEventLog usage #583

Open
E3V3A opened this issue Jul 30, 2015 · 3 comments
Open

Simplify insertEventLog usage #583

E3V3A opened this issue Jul 30, 2015 · 3 comments

Comments

@E3V3A
Copy link
Contributor

E3V3A commented Jul 30, 2015

Currently the insertEventLog function looks like this:

dbHelper.insertEventLog(
    MiscUtils.getCurrentTimeStamp(),        // time
    mMonitorCell.getLAC(),                  // LAC
    mMonitorCell.getCID(),                  // CID
    mMonitorCell.getPSC(),                  // PSC
    String.valueOf(mMonitorCell.getLat()),  // gpsd_lat
    String.valueOf(mMonitorCell.getLon()),  // gpsd_lon
    (int)mMonitorCell.getAccuracy(),        // gpsd_accu
    1,                                      // DF_id
    "Changing LAC"                          // DF_desc
);

However, this is highly inefficient as we need to always load all items that can be automatically loaded within function. The only variables we need to supply should be DF_id and DF_desc.

Like this: insertEventLog(1, "Changing LAC");

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@E3V3A
Copy link
Contributor Author

E3V3A commented Jul 31, 2015

@banjaxbanjo What do I need to do to change this? I.e. the correct dependencies to implement the getters directly into the insertEventLog?

@E3V3A
Copy link
Contributor Author

E3V3A commented Aug 2, 2015

I'm thinking something like this:

// Defining a new simple version of insertEventLog:
public void sinsertEventLog(int DF_id, String DF_desc){

        time      = MiscUtils.getCurrentTimeStamp() );          // time
        lac       = mMonitorCell.getLAC();                      // LAC
        cid       = mMonitorCell.getCID();                      // CID
        psc       = mMonitorCell.getPSC();                      // PSC [UMTS,LTE]
        gpsd_lat  = String.valueOf(mMonitorCell.getLat());      // gpsd_lat
        gpsd_lon  = String.valueOf(mMonitorCell.getLon());      // gpsd_lon
        gpsd_accu = (int)mMonitorCell.getAccuracy();            // gpsd_accu

        // skip CID/LAC of "-1" (due to crappy API, Roaming or Air-Plane Mode)
        if (cid != -1 OR lac !=-1) {
                // Check if LAST entry is the same!
                String query = String.format(
                    "SELECT * from EventLog WHERE _id=(SELECT max(_id) from EventLog) AND CID=%d AND LAC=%d AND PSC=%d AND DF_id=%d",
                    cid, lac, psc, DF_id);
                Cursor cursor = mDb.rawQuery(query,null);

                // WARNING: By skipping duplicate events, we might be missing counts of Type-0 SMS etc.
                boolean insertData = true;
                if (cursor.getCount() > 0) { insertData = false; }
                cursor.close();

                if(insertData){
                        ContentValues eventLog = new ContentValues();

                        eventLog.put("time", time );                    // time
                        eventLog.put("LAC", lac );                      // LAC
                        eventLog.put("CID", cid );                      // CID
                        eventLog.put("PSC", psc );                      // PSC
                        eventLog.put("gpsd_lat", gpsd_lat );            // gpsd_lat
                        eventLog.put("gpsd_lon", gpsd_lon );            // gpsd_lon
                        eventLog.put("gpsd_accu", gpsd_accu );          // gpsd_accu
                        eventLog.put("DF_id", DF_id);                   // DF_id
                        eventLog.put("DF_description", DF_desc);        // DF_desc

                        mDb.insert("EventLog", null, eventLog);
                        Log.i(TAG, mTAG + ":insertEventLog(): Added New Event: id=" +DF_id+ " time=" +time+ " cid=" +cid);
                } else {
                        // TODO This may need to be removed as it may spam the logcat buffer...
                        //Log.v(TAG, mTAG + ":insertEventLog(): Skipped inserting duplicate event");
                }
        }
        // TODO This may need to be removed as it may spam the logcat buffer...
        //Log.v(TAG, mTAG + ":insertEventLog(): Skipped inserting bad CID/LAC data");
}

@banjaxbanjo Do you think that would work?

@SecUpwN
Copy link
Member

SecUpwN commented Aug 9, 2015

@E3V3A, am I right if I assume that you already implemented this? If so, please close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants