Classifier debug info

pull/190/head
M66B 4 years ago
parent 07c13a6a00
commit 4d6e8c740b

@ -463,7 +463,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
private void onDebugInfo() {
new SimpleTask<Long>() {
@Override
protected Long onExecute(Context context, Bundle args) throws IOException {
protected Long onExecute(Context context, Bundle args) throws IOException, JSONException {
return Log.getDebugInfo(context, R.string.title_debug_info_remark, null, null).id;
}

@ -66,6 +66,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
@ -1219,7 +1220,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private void onDebugInfo() {
new SimpleTask<Long>() {
@Override
protected Long onExecute(Context context, Bundle args) throws IOException {
protected Long onExecute(Context context, Bundle args) throws IOException, JSONException {
return Log.getDebugInfo(context, R.string.title_debug_info_remark, null, null).id;
}

@ -1209,7 +1209,7 @@ public class Log {
}
}
static EntityMessage getDebugInfo(Context context, int title, Throwable ex, String log) throws IOException {
static EntityMessage getDebugInfo(Context context, int title, Throwable ex, String log) throws IOException, JSONException {
StringBuilder sb = new StringBuilder();
sb.append(context.getString(title)).append("\n\n\n\n");
sb.append(getAppInfo(context));
@ -1264,6 +1264,8 @@ public class Log {
attachLogcat(context, draft.id, 6);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
attachNotificationInfo(context, draft.id, 7);
if (MessageClassifier.isEnabled(context))
attachClassifierData(context, draft.id, 8);
EntityOperation.queue(context, draft, EntityOperation.ADD);
@ -1778,6 +1780,27 @@ public class Log {
db.attachment().setDownloaded(attachment.id, size);
}
private static void attachClassifierData(Context context, long id, int sequence) throws IOException, JSONException {
DB db = DB.getInstance(context);
EntityAttachment attachment = new EntityAttachment();
attachment.message = id;
attachment.sequence = sequence;
attachment.name = "classifier.json";
attachment.type = "application/json";
attachment.disposition = Part.ATTACHMENT;
attachment.size = null;
attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment);
MessageClassifier.save(context);
File source = MessageClassifier.getFile(context);
File target = attachment.getFile(context);
Helper.copy(source, target);
db.attachment().setDownloaded(attachment.id, target.length());
}
private static int write(OutputStream os, String text) throws IOException {
byte[] bytes = text.getBytes();
os.write(bytes);

@ -299,7 +299,7 @@ public class MessageClassifier {
for (int w = 0; w < jwords.length(); w++) {
JSONObject jword = (JSONObject) jwords.get(w);
long account = jword.getLong("account");
if (!wordClassFrequency.containsKey("account"))
if (!wordClassFrequency.containsKey(account))
wordClassFrequency.put(account, new HashMap<>());
String word = jword.getString("word");
Map<String, Integer> classFrequency = wordClassFrequency.get(account).get(word);
@ -326,7 +326,7 @@ public class MessageClassifier {
EntityFolder.USER.equals(folderType);
}
private static File getFile(Context context) {
static File getFile(Context context) {
return new File(context.getFilesDir(), "classifier.json");
}

Loading…
Cancel
Save