Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M320,560Q303,560 291.5,548.5Q280,537 280,520Q280,503 291.5,491.5Q303,480 320,480Q337,480 348.5,491.5Q360,503 360,520Q360,537 348.5,548.5Q337,560 320,560ZM480,560Q463,560 451.5,548.5Q440,537 440,520Q440,503 451.5,491.5Q463,480 480,480Q497,480 508.5,491.5Q520,503 520,520Q520,537 508.5,548.5Q497,560 480,560ZM640,560Q623,560 611.5,548.5Q600,537 600,520Q600,503 611.5,491.5Q623,480 640,480Q657,480 668.5,491.5Q680,503 680,520Q680,537 668.5,548.5Q657,560 640,560ZM200,880Q167,880 143.5,856.5Q120,833 120,800L120,240Q120,207 143.5,183.5Q167,160 200,160L240,160L240,80L320,80L320,160L640,160L640,80L720,80L720,160L760,160Q793,160 816.5,183.5Q840,207 840,240L840,800Q840,833 816.5,856.5Q793,880 760,880L200,880ZM200,800L760,800Q760,800 760,800Q760,800 760,800L760,400L200,400L200,800Q200,800 200,800Q200,800 200,800ZM200,320L760,320L760,240Q760,240 760,240Q760,240 760,240L200,240Q200,240 200,240Q200,240 200,240L200,320ZM200,320L200,240Q200,240 200,240Q200,240 200,240L200,240Q200,240 200,240Q200,240 200,240L200,320Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@
<string name="TestResults_Filters_Short">Filters:</string>
<string name="TestResults_Filter_Tests">Tests</string>
<string name="TestResults_Filter_Tests_Multiple">%1$d tests</string>
<string name="TestResults_Filter_Sources">Sources</string>
<string name="TestResults_Filter_Source">Source</string>
<string name="TestResults_Filter_Date">Date</string>
<string name="TestResults_Filter_Date_Any">Any date</string>
<string name="TestResults_Filter_Date_Today">Today</string>
<string name="TestResults_Filter_Date_FromSevenDaysAgo">From 7 days ago</string>
<string name="TestResults_Filter_Date_FromOneMonthAgo">From 1 month ago</string>
<string name="TestResults_Filter_Date_Custom">Custom</string>
<string name="TestResults_Filter_Date_Custom_Filled">Custom: %1$s</string>
<string name="TestResults_Filter_Date_Picker">Pick a date range</string>
<string name="TestResults_Filter_NoTestsFound">No test results found for those filters.</string>

<string name="Results_PickDateRange">Pick a date range</string>
<string name="Results_LimitedNotice">Only the last %1$d results are shown</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
package org.ooni.probe.data.models

import kotlinx.datetime.DatePeriod
import kotlinx.datetime.LocalDate
import kotlinx.datetime.minus
import org.ooni.engine.models.TaskOrigin
import org.ooni.probe.shared.today

data class ResultFilter(
val descriptors: List<Descriptor> = emptyList(),
val taskOrigin: TaskOrigin? = null,
val dates: Date = Date.AnyDate,
val limit: Long = LIMIT,
) {
val isAll get() = this == ResultFilter()

sealed class Date(
val range: ClosedRange<LocalDate>,
) {
data object AnyDate :
Date(LocalDate(2000, 1, 1)..LocalDate.today())

data object Today :
Date(LocalDate.today()..LocalDate.today())

data object FromSevenDaysAgo :
Date(LocalDate.today().minus(DatePeriod(days = 7))..LocalDate.today())

data object FromOneMonthAgo :
Date(LocalDate.today().minus(DatePeriod(months = 1))..LocalDate.today())

data class Custom(val customRange: ClosedRange<LocalDate>) : Date(customRange)
}

companion object {
const val LIMIT = 100L
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import kotlinx.datetime.atTime
import org.ooni.engine.models.TaskOrigin
import org.ooni.probe.Database
import org.ooni.probe.data.Network
Expand All @@ -28,19 +29,20 @@ class ResultRepository(
private val database: Database,
private val backgroundContext: CoroutineContext,
) {
fun list(filter: ResultFilter = ResultFilter()): Flow<List<ResultWithNetworkAndAggregates>> {
return database.resultQueries
fun list(filter: ResultFilter = ResultFilter()): Flow<List<ResultWithNetworkAndAggregates>> =
database.resultQueries
.selectAllWithNetwork(
filterByDescriptors = if (filter.descriptors.any()) 1 else 0,
descriptorsKeys = filter.descriptors.map { it.key },
filterByTaskOrigin = if (filter.taskOrigin != null) 1 else 0,
taskOrigin = filter.taskOrigin?.value,
startFrom = filter.dates.range.start.toEpoch(),
startUntil = filter.dates.range.endInclusive.atTime(23, 59, 59).toEpoch(),
limit = filter.limit,
)
.asFlow()
.mapToList(backgroundContext)
.map { list -> list.mapNotNull { it.toModel() } }
}

fun getById(resultId: ResultModel.Id): Flow<Pair<ResultModel, NetworkModel?>?> =
database.resultQueries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ fun LocalDateTime.toEpoch() = toInstant(TimeZone.currentSystemDefault()).toEpoch

fun LocalDate.toEpoch() = atStartOfDayIn(TimeZone.currentSystemDefault()).toEpochMilliseconds()

fun LocalDate.toEpochInUTC() = atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds()

fun Long.toLocalDateTime() = Instant.fromEpochMilliseconds(this).toLocalDateTime()

fun Long.toLocalDateFromUtc() = Instant.fromEpochMilliseconds(this).toLocalDateTime(TimeZone.UTC).date

fun LocalDate.Companion.today() = Clock.System.todayIn(TimeZone.currentSystemDefault())

fun LocalDateTime.Companion.now() = Clock.System.now().toLocalDateTime()
Expand Down
Loading
Loading