Skip to content

Commit

Permalink
Updated resut list logic to determine in progress test
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Feb 20, 2024
1 parent feb06f6 commit 007f12a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openobservatory.ooniprobe.item.*;
import org.openobservatory.ooniprobe.model.database.Network;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.model.database.ResultExtensions;
import org.openobservatory.ooniprobe.model.database.Result_Table;
import org.openobservatory.ooniprobe.test.suite.*;

Expand Down Expand Up @@ -162,9 +163,11 @@ void queryList() {
for (DatedResults group : list) {
items.add(new DateItem(group.getGroupedDate()));
for (Result result : group.getResultsList()) {
if (result.countTotalMeasurements() == 0)
if (ResultExtensions.getStatus(result) == -1){
items.add(new ProgressItem(result, this, this));
} else if (result.countTotalMeasurements() == 0) {
items.add(new FailedItem(result, this, this));
else {
} else {
switch (result.test_group_name) {
case WebsitesSuite.NAME:
items.add(new WebsiteItem(result, this, this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import org.openobservatory.ooniprobe.databinding.ItemFailedBinding;
import org.openobservatory.ooniprobe.model.database.Result;

import java.util.Date;
import java.util.Locale;
import static java.util.concurrent.TimeUnit.*;

import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;

Expand All @@ -41,24 +39,13 @@ public FailedItem(Result extra, View.OnClickListener onClickListener, View.OnLon
viewHolder.binding.icon.setImageResource(extra.getTestSuite().getIcon());
viewHolder.binding.testName.setText(extra.getTestSuite().getTitle());
String failure_msg = viewHolder.itemView.getContext().getString(R.string.TestResults_Overview_Error);
if (extra.failure_msg != null) {
if (extra.failure_msg != null)
failure_msg += " - " + extra.failure_msg;
} else {
// NOTE: If the test is running for more than 5 minutes, we assume it's stuck or failed,
// and we show the default error message.
long MAX_DURATION = MILLISECONDS.convert(5, MINUTES);
long duration = new Date().getTime() - extra.start_time.getTime();
if (duration < MAX_DURATION) {
failure_msg = viewHolder.itemView.getContext()
.getString(R.string.Dashboard_Running_Running)
.replace(":","");
}
}
viewHolder.binding.subtitle.setText(failure_msg);
viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time));
}

class ViewHolder extends RecyclerView.ViewHolder {
public class ViewHolder extends RecyclerView.ViewHolder {
ItemFailedBinding binding;

ViewHolder(ItemFailedBinding binding) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openobservatory.ooniprobe.item

import android.view.View
import org.openobservatory.ooniprobe.R
import org.openobservatory.ooniprobe.model.database.Result

class ProgressItem(
result: Result,
onClickListener: View.OnClickListener,
onLongClickListener: View.OnLongClickListener
) : FailedItem(result, onClickListener, onLongClickListener) {
override fun onBindViewHolder(viewHolder: ViewHolder) {
super.onBindViewHolder(viewHolder)
viewHolder.binding.subtitle.text = viewHolder.itemView.context
.getString(R.string.Dashboard_Running_Running)
.replace(":", "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.openobservatory.ooniprobe.model.database

import com.raizlabs.android.dbflow.config.FlowManager
import com.raizlabs.android.dbflow.structure.database.FlowCursor
import org.openobservatory.ooniprobe.common.AppDatabase


class ResultExtensions {

companion object {

@JvmStatic
fun Result.getStatus(): Int {
val queryById = """
SELECT
CASE
WHEN COUNT(m.result_id) = 0 THEN -1
ELSE SUM(CASE WHEN m.is_done = 0 THEN 1 ELSE 0 END)
END AS in_progress_count
FROM
Result r
LEFT JOIN
Measurement m ON r.id = m.result_id
WHERE
r.id = ?
""".trimIndent()
val cursor: FlowCursor = FlowManager.getDatabase(AppDatabase::class.java)
.writableDatabase
.rawQuery(queryById, arrayOf(id.toString()))

var inProgressCount = 0
if (cursor.moveToFirst()) {
cursor.getColumnIndex("in_progress_count").let {
if (it == -1) {
return@let
}
inProgressCount = cursor.getInt(it)
}
}
cursor.close()
return inProgressCount
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ private void runTest(AbstractTest... tests) {
currentTest.run(app, app.getPreferenceManager(),app.getLogger(), app.getGson(), result, i, this);
}
}
if (result.countTotalMeasurements() == tests.length) {
result.is_done = true;
result.save();
}
} catch (Exception e) {
publishProgress(ERR, app.getString(R.string.Modal_Error_CantDownloadURLs));
e.printStackTrace();
Expand Down

0 comments on commit 007f12a

Please sign in to comment.