优化运维程序功能
parent
1c60fb978e
commit
cc2e412a29
@ -0,0 +1,172 @@
|
||||
package com.xypower.mpmaster;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.xypower.common.MicroPhotoContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DBHandler extends SQLiteOpenHelper {
|
||||
|
||||
// creating a constant variables for our database.
|
||||
// below variable is for our database name.
|
||||
private static final String DB_NAME = "/sdcard/" + MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/App.db";
|
||||
|
||||
// below int is our database version
|
||||
private static final int DB_VERSION = 1;
|
||||
|
||||
// below variable is for our table name.
|
||||
private static final String TABLE_NAME_SCHEDULES = "Schedules";
|
||||
|
||||
// below variable is for our table name.
|
||||
private static final String TABLE_NAME_HEARTBEATS = "Heartbeats";
|
||||
|
||||
private static final String TABLE_NAME_REBOOTS = "Reboots";
|
||||
|
||||
// creating a constructor for our database handler.
|
||||
public DBHandler(Context context) {
|
||||
super(context, DB_NAME, null, DB_VERSION);
|
||||
}
|
||||
|
||||
// below method is for creating a database by running a sqlite query
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
// on below line we are creating
|
||||
// an sqlite query and we are
|
||||
// setting our column names
|
||||
// along with their data types.
|
||||
}
|
||||
|
||||
// we have created a new method for reading all the courses.
|
||||
public boolean readStats(long startTime, long endTime, List<Pair<String, String>> stats) {
|
||||
// on below line we are creating a
|
||||
// database for reading our database.
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
|
||||
// on below line we are creating a cursor with query to read data from database.
|
||||
Cursor cursor = db.rawQuery("SELECT scheduleTime,channel,preset,scheduled,takingTime,result,retries,postTime FROM " + TABLE_NAME_SCHEDULES + " WHERE scheduleTime >=" + Long.toString(startTime) + " AND scheduleTime<=" + Long.toString(endTime), null);
|
||||
|
||||
int scheduledCount = 0;
|
||||
int takingTimes = 0;
|
||||
int retries = 0;
|
||||
int succeededPhotos = 0;
|
||||
int failedPhotos = 0;
|
||||
int failedTimes = 0;
|
||||
int scheduled = 0;
|
||||
int uploaded = 0;
|
||||
int photoResult = 0;
|
||||
long photoTime = 0;
|
||||
|
||||
// moving our cursor to first position.
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
scheduled = cursor.getInt(3);
|
||||
photoTime = cursor.getLong(4);
|
||||
if (scheduled != 0)
|
||||
{
|
||||
scheduledCount ++;
|
||||
}
|
||||
if (photoTime != 0)
|
||||
{
|
||||
takingTimes++;
|
||||
|
||||
photoResult = cursor.getInt(5);
|
||||
if (photoResult != 0)
|
||||
{
|
||||
succeededPhotos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
failedPhotos++;
|
||||
}
|
||||
retries = cursor.getInt(6);
|
||||
if (retries > 0)
|
||||
{
|
||||
failedTimes += retries - ((photoResult == 0) ? 0 : 1);
|
||||
}
|
||||
if (cursor.getInt(7) != 0)
|
||||
{
|
||||
uploaded++;
|
||||
}
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
// moving our cursor to next.
|
||||
}
|
||||
// at last closing our cursor
|
||||
// and returning our array list.
|
||||
cursor.close();
|
||||
cursor = null;
|
||||
|
||||
cursor = db.rawQuery("SELECT COUNT(hb),SUM(CASE WHEN ack=0 THEN 0 ELSE 1 END) FROM " + TABLE_NAME_HEARTBEATS + " WHERE hb >=" + Long.toString(startTime) + " AND hb<=" + Long.toString(endTime), null);
|
||||
|
||||
// moving our cursor to first position.
|
||||
int hb = 0;
|
||||
int hbAck = 0;
|
||||
if (cursor.moveToFirst()) {
|
||||
hb = cursor.getInt(0);
|
||||
hbAck = cursor.getInt(1);
|
||||
}
|
||||
// at last closing our cursor
|
||||
// and returning our array list.
|
||||
cursor.close();
|
||||
cursor = null;
|
||||
|
||||
cursor = db.rawQuery("SELECT COUNT(*),appType FROM " + TABLE_NAME_REBOOTS + " WHERE rebootTime >=" + Long.toString(startTime) + " AND rebootTime<=" + Long.toString(endTime) + " GROUP BY appType", null);
|
||||
|
||||
// moving our cursor to first position.
|
||||
int appReboots = 0;
|
||||
int systemReboots = 0;
|
||||
int appType = 0;
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
appType = cursor.getInt(1);
|
||||
if (appType == 0) {
|
||||
appReboots = cursor.getInt(0);
|
||||
} else if (appType == 1) {
|
||||
systemReboots = cursor.getInt(0);
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
// moving our cursor to next.
|
||||
}
|
||||
// at last closing our cursor
|
||||
// and returning our array list.
|
||||
cursor.close();
|
||||
cursor = null;
|
||||
|
||||
stats.add(new Pair<String, String>("numberOfHb", Integer.toString(hb)));
|
||||
stats.add(new Pair<String, String>("numberOfHbAck", Integer.toString(hbAck)));
|
||||
|
||||
stats.add(new Pair<String, String>("recv", Integer.toString(scheduledCount)));
|
||||
stats.add(new Pair<String, String>("photoTimes", Integer.toString(takingTimes)));
|
||||
stats.add(new Pair<String, String>("success", Integer.toString(succeededPhotos)));
|
||||
stats.add(new Pair<String, String>("failure", Integer.toString(succeededPhotos)));
|
||||
stats.add(new Pair<String, String>("uploads", Integer.toString(uploaded)));
|
||||
|
||||
if (systemReboots > 0) {
|
||||
stats.add(new Pair<String, String>("rebootTimes", Integer.toString(systemReboots)));
|
||||
}
|
||||
|
||||
if (appReboots > 0) {
|
||||
stats.add(new Pair<String, String>("i1RebootTimes", Integer.toString(appReboots)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// this method is called to check if the table exists already.
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue