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

Results: Show success, anomaly and failed counts on items #346

Merged
merged 3 commits into from
Jan 6, 2025
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
10 changes: 10 additions & 0 deletions composeApp/src/commonMain/composeResources/drawable/ic_world.xml
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="#FFFFFFFF"
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,473 799.5,465.5Q799,458 799,453Q794,482 772,501Q750,520 720,520L640,520Q607,520 583.5,496.5Q560,473 560,440L560,400L400,400L400,320Q400,287 423.5,263.5Q447,240 480,240L520,240L520,240Q520,217 532.5,199.5Q545,182 563,171Q543,166 522.5,163Q502,160 480,160Q346,160 253,253Q160,346 160,480Q160,480 160,480Q160,480 160,480L360,480Q426,480 473,527Q520,574 520,640L520,680L400,680L400,790Q420,795 439.5,797.5Q459,800 480,800Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
<string name="TestResults_Overview_Hero_Tests">Tests</string>
<string name="TestResults_Overview_Hero_Networks">Networks</string>
<string name="TestResults_Overview_Hero_DataUsage">Data Usage</string>
<string name="TestResults_Overview_Websites_Blocked_Singular">%1$s blocked</string>
<string name="TestResults_Overview_Websites_Blocked_Plural">%1$s blocked</string>
<string name="TestResults_Overview_Websites_Tested_Singular">%1$s tested</string>
<string name="TestResults_Overview_Websites_Tested_Plural">%1$s tested</string>
<string name="TestResults_Overview_InstantMessaging_Blocked_Singular">%1$s blocked</string>
<string name="TestResults_Overview_InstantMessaging_Blocked_Plural">%1$s blocked</string>
<string name="TestResults_Overview_InstantMessaging_Available_Singular">%1$s accessible</string>
<string name="TestResults_Overview_InstantMessaging_Available_Plural">%1$s accessible</string>
<string name="TestResults_Overview_Circumvention_Blocked_Singular">%1$s blocked</string>
<string name="TestResults_Overview_Circumvention_Blocked_Plural">%1$s blocked</string>
<string name="TestResults_Overview_Circumvention_Available_Singular">%1$s available</string>
<string name="TestResults_Overview_Circumvention_Available_Plural">%1$s available</string>
<string name="TestResults_Summary_Hero_DateAndTime">Date &amp; Time</string>
<string name="TestResults_Summary_Hero_Network">Network</string>
<string name="TestResults_Summary_Hero_Country">Country</string>
Expand Down Expand Up @@ -302,13 +314,13 @@
<string name="AddDescriptor_Toasts_Unsupported_Url">Unsupported URL</string>

<string name="Measurement_Title">Measurement</string>

<string name="Measurements_Count_One">%1$d measurement</string>
<string name="Measurements_Count_Other">%1$d measurements</string>

<string name="Measurements_Failed">Failed</string>
<string name="Measurements_Ok">OK</string>
<string name="Measurements_Anomaly">Anomaly</string>
<string name="Measurements_Count_One">%1$d measured</string>
<string name="Measurements_Count_Other">%1$d measured</string>
<string name="Measurements_Failed_One">%1$d failed</string>
<string name="Measurements_Failed_Other">%1$d failed</string>

<string name="Results_TestType_All">All Types</string>
<string name="Results_TaskOrigin_All">All Sources</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<resources>
<string name="shareEmailTo" translatable="false">[email protected]</string>
<string name="shareSubject" translatable="false">[bug-report] OONI Probe %1$s</string>
<string name="version" translatable="false">%1$s: %2$s</string>

<plurals name="Common_Minutes" translatable="false">
<item quantity="one">@string/Common_Minutes_One</item>
<item quantity="other">@string/Common_Minutes_Other</item>
</plurals>
<plurals name="Common_Hours" translatable="false">
<item quantity="one">@string/Common_Hour_One</item>
<item quantity="other">@string/Common_Hour_Other</item>
</plurals>

<plurals name="Dashboard_RunTests_RunButton_Label" translatable="false">
<item quantity="one">@string/Dashboard_RunTests_RunButton_Label_One</item>
<item quantity="other">@string/Dashboard_RunTests_RunButton_Label_Other</item>
</plurals>

<plurals name="TestResults_Overview_Websites_Blocked" translatable="false">
<item quantity="one">@string/TestResults_Overview_Websites_Blocked_Singular</item>
<item quantity="other">@string/TestResults_Overview_Websites_Blocked_Plural</item>
</plurals>

<plurals name="TestResults_Overview_Websites_Tested" translatable="false">
<item quantity="one">@string/TestResults_Overview_Websites_Tested_Singular</item>
<item quantity="other">@string/TestResults_Overview_Websites_Tested_Plural</item>
</plurals>

<plurals name="TestResults_Overview_InstantMessaging_Blocked" translatable="false">
<item quantity="one">@string/TestResults_Overview_InstantMessaging_Blocked_Singular</item>
<item quantity="other">@string/TestResults_Overview_InstantMessaging_Blocked_Plural</item>
</plurals>

<plurals name="TestResults_Overview_InstantMessaging_Available" translatable="false">
<item quantity="one">@string/TestResults_Overview_InstantMessaging_Available_Singular</item>
<item quantity="other">@string/TestResults_Overview_InstantMessaging_Available_Plural</item>
</plurals>

<plurals name="TestResults_Overview_Circumvention_Blocked" translatable="false">
<item quantity="one">@string/TestResults_Overview_Circumvention_Blocked_Singular</item>
<item quantity="other">@string/TestResults_Overview_Circumvention_Blocked_Plural</item>
</plurals>

<plurals name="TestResults_Overview_Circumvention_Available" translatable="false">
<item quantity="one">@string/TestResults_Overview_Circumvention_Available_Singular</item>
<item quantity="other">@string/TestResults_Overview_Circumvention_Available_Plural</item>
</plurals>

<plurals name="Measurements_Count" translatable="false">
<item quantity="one">@string/Measurements_Count_One</item>
<item quantity="other">@string/Measurements_Count_Other</item>
</plurals>

<plurals name="Measurements_Failed" translatable="false">
<item quantity="one">@string/Measurements_Failed_One</item>
<item quantity="other">@string/Measurements_Failed_Other</item>
</plurals>
</resources>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.ooni.engine.models

import kotlin.reflect.KClass

sealed class TestGroup(
vararg tests: KClass<out TestType>,
) {
val tests: List<KClass<out TestType>> = tests.toList()

data object Websites : TestGroup(TestType.WebConnectivity::class)

data object InstantMessaging : TestGroup(
TestType.Whatsapp::class,
TestType.Telegram::class,
TestType.FacebookMessenger::class,
TestType.Signal::class,
)

data object Circumvention : TestGroup(
TestType.Psiphon::class,
TestType.Tor::class,
)

data object Performance : TestGroup(
TestType.Ndt::class,
TestType.Dash::class,
TestType.HttpHeaderFieldManipulation::class,
TestType.HttpInvalidRequestLine::class,
)

data object Experimental : TestGroup(TestType.Experimental::class)

data object Unknown : TestGroup()

companion object {
fun fromTests(tests: List<TestType>): TestGroup {
if (tests.isEmpty()) return Unknown

return listOf(
Websites,
InstantMessaging,
Circumvention,
Performance,
Experimental,
)
.firstOrNull { group ->
tests.all { test -> group.tests.any { it.isInstance(test) } }
}
?: Unknown
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.ooni.probe.data.models

data class MeasurementCounts(
val done: Long,
val failed: Long,
val anomaly: Long,
) {
val success get() = done - failed - anomaly
val tested get() = done - failed
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ data class ResultListItem(
val result: ResultModel,
val descriptor: Descriptor,
val network: NetworkModel?,
val measurementsCount: Long,
val measurementCounts: MeasurementCounts,
val allMeasurementsUploaded: Boolean,
val anyMeasurementUploadFailed: Boolean,
) {
val idOrThrow get() = result.idOrThrow
val idOrThrow
get() = result.idOrThrow
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ooni.probe.data.models
data class ResultWithNetworkAndAggregates(
val result: ResultModel,
val network: NetworkModel?,
val measurementsCount: Long,
val measurementCounts: MeasurementCounts,
val allMeasurementsUploaded: Boolean,
val anyMeasurementUploadFailed: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.ooni.probe.data.Result
import org.ooni.probe.data.SelectAllWithNetwork
import org.ooni.probe.data.SelectByIdWithNetwork
import org.ooni.probe.data.models.InstalledTestDescriptorModel
import org.ooni.probe.data.models.MeasurementCounts
import org.ooni.probe.data.models.NetworkModel
import org.ooni.probe.data.models.ResultFilter
import org.ooni.probe.data.models.ResultModel
Expand Down Expand Up @@ -151,7 +152,7 @@ class ResultRepository(
private fun SelectAllWithNetwork.toModel(): ResultWithNetworkAndAggregates? {
return ResultWithNetworkAndAggregates(
result = Result(
id = id,
id = id ?: return null,
test_group_name = test_group_name,
start_time = start_time,
is_viewed = is_viewed,
Expand All @@ -163,7 +164,7 @@ class ResultRepository(
network_id = network_id,
descriptor_runId = descriptor_runId,
).toModel() ?: return null,
network = id_?.let { networkId ->
network = network_id_inner?.let { networkId ->
Network(
id = networkId,
network_name = network_name,
Expand All @@ -173,7 +174,11 @@ class ResultRepository(
network_type = network_type,
).toModel()
},
measurementsCount = measurementsCount,
measurementCounts = MeasurementCounts(
done = doneMeasurementsCount ?: 0,
failed = failedMeasurementsCount ?: 0,
anomaly = anomalyMeasurementsCount ?: 0,
),
allMeasurementsUploaded = allMeasurementsUploaded,
anyMeasurementUploadFailed = anyMeasurementUploadFailed,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GetResults(
result = item.result,
descriptor = descriptors.forResult(item.result) ?: return@mapNotNull null,
network = item.network,
measurementsCount = item.measurementsCount,
measurementCounts = item.measurementCounts,
allMeasurementsUploaded = item.allMeasurementsUploaded,
anyMeasurementUploadFailed = item.anyMeasurementUploadFailed,
)
Expand Down
103 changes: 76 additions & 27 deletions composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,43 @@ import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Lab
import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Label_Other
import ooniprobe.composeapp.generated.resources.Measurements_Count_One
import ooniprobe.composeapp.generated.resources.Measurements_Count_Other
import ooniprobe.composeapp.generated.resources.Measurements_Failed_One
import ooniprobe.composeapp.generated.resources.Measurements_Failed_Other
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Circumvention_Available_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Circumvention_Available_Singular
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Circumvention_Blocked_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Circumvention_Blocked_Singular
import ooniprobe.composeapp.generated.resources.TestResults_Overview_InstantMessaging_Available_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_InstantMessaging_Available_Singular
import ooniprobe.composeapp.generated.resources.TestResults_Overview_InstantMessaging_Blocked_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_InstantMessaging_Blocked_Singular
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Websites_Blocked_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Websites_Blocked_Singular
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Websites_Tested_Plural
import ooniprobe.composeapp.generated.resources.TestResults_Overview_Websites_Tested_Singular
import org.jetbrains.compose.resources.PluralStringResource
import org.jetbrains.compose.resources.getPluralString
import org.jetbrains.compose.resources.getString
import org.jetbrains.compose.resources.pluralStringResource
import org.jetbrains.compose.resources.stringResource

val stringMap = mapOf(
"@string/Common_Minutes_One" to Res.string.Common_Minutes_One,
"@string/Common_Minutes_Other" to Res.string.Common_Minutes_Other,
"@string/Common_Hour_One" to Res.string.Common_Hour_One,
"@string/Common_Hour_Other" to Res.string.Common_Hour_Other,
"@string/Dashboard_RunTests_RunButton_Label_One" to Res.string.Dashboard_RunTests_RunButton_Label_One,
"@string/Dashboard_RunTests_RunButton_Label_Other" to Res.string.Dashboard_RunTests_RunButton_Label_Other,
"@string/Measurements_Count_One" to Res.string.Measurements_Count_One,
"@string/Measurements_Count_Other" to Res.string.Measurements_Count_Other,
)

@Composable
fun stringMonthArrayResource(): List<String> {
return listOf(
stringResource(Res.string.Common_Months_January),
stringResource(Res.string.Common_Months_February),
stringResource(Res.string.Common_Months_March),
stringResource(Res.string.Common_Months_April),
stringResource(Res.string.Common_Months_May),
stringResource(Res.string.Common_Months_June),
stringResource(Res.string.Common_Months_July),
stringResource(Res.string.Common_Months_August),
stringResource(Res.string.Common_Months_September),
stringResource(Res.string.Common_Months_October),
stringResource(Res.string.Common_Months_November),
stringResource(Res.string.Common_Months_December),
)
}
fun stringMonthArrayResource(): List<String> =
listOf(
Res.string.Common_Months_January,
Res.string.Common_Months_February,
Res.string.Common_Months_March,
Res.string.Common_Months_April,
Res.string.Common_Months_May,
Res.string.Common_Months_June,
Res.string.Common_Months_July,
Res.string.Common_Months_August,
Res.string.Common_Months_September,
Res.string.Common_Months_October,
Res.string.Common_Months_November,
Res.string.Common_Months_December,
).map { stringResource(it) }

@Composable
fun pluralStringResourceItem(
Expand All @@ -77,3 +79,50 @@ suspend fun getPluralStringResourceItem(
return getString(it, *formatArgs)
} ?: ""
}

private val stringMap = mapOf(
"@string/Common_Minutes_One"
to Res.string.Common_Minutes_One,
"@string/Common_Minutes_Other"
to Res.string.Common_Minutes_Other,
"@string/Common_Hour_One"
to Res.string.Common_Hour_One,
"@string/Common_Hour_Other"
to Res.string.Common_Hour_Other,
"@string/Dashboard_RunTests_RunButton_Label_One"
to Res.string.Dashboard_RunTests_RunButton_Label_One,
"@string/Dashboard_RunTests_RunButton_Label_Other"
to Res.string.Dashboard_RunTests_RunButton_Label_Other,
"@string/Measurements_Count_One"
to Res.string.Measurements_Count_One,
"@string/Measurements_Count_Other"
to Res.string.Measurements_Count_Other,
"@string/Measurements_Failed_One"
to Res.string.Measurements_Failed_One,
"@string/Measurements_Failed_Other"
to Res.string.Measurements_Failed_Other,
"@string/TestResults_Overview_Websites_Blocked_Singular"
to Res.string.TestResults_Overview_Websites_Blocked_Singular,
"@string/TestResults_Overview_Websites_Blocked_Plural"
to Res.string.TestResults_Overview_Websites_Blocked_Plural,
"@string/TestResults_Overview_Websites_Tested_Singular"
to Res.string.TestResults_Overview_Websites_Tested_Singular,
"@string/TestResults_Overview_Websites_Tested_Plural"
to Res.string.TestResults_Overview_Websites_Tested_Plural,
"@string/TestResults_Overview_InstantMessaging_Blocked_Singular"
to Res.string.TestResults_Overview_InstantMessaging_Blocked_Singular,
"@string/TestResults_Overview_InstantMessaging_Blocked_Plural"
to Res.string.TestResults_Overview_InstantMessaging_Blocked_Plural,
"@string/TestResults_Overview_InstantMessaging_Available_Singular"
to Res.string.TestResults_Overview_InstantMessaging_Available_Singular,
"@string/TestResults_Overview_InstantMessaging_Available_Plural"
to Res.string.TestResults_Overview_InstantMessaging_Available_Plural,
"@string/TestResults_Overview_Circumvention_Blocked_Singular"
to Res.string.TestResults_Overview_Circumvention_Blocked_Singular,
"@string/TestResults_Overview_Circumvention_Blocked_Plural"
to Res.string.TestResults_Overview_Circumvention_Blocked_Plural,
"@string/TestResults_Overview_Circumvention_Available_Singular"
to Res.string.TestResults_Overview_Circumvention_Available_Singular,
"@string/TestResults_Overview_Circumvention_Available_Plural"
to Res.string.TestResults_Overview_Circumvention_Available_Plural,
)
Loading