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

feat: Show performance metrics on performance items #360

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="18dp"
android:height="18dp"
android:viewportWidth="19"
android:viewportHeight="19">
<path
android:name="path"
android:fillColor="#FF000000"
android:pathData="M 2.8 5 L 2.8 16.2 L 14 16.2 L 14 17.8 L 2.8 17.8 C 2.379 17.79 1.978 17.618 1.68 17.32 C 1.382 17.022 1.21 16.621 1.2 16.2 L 1.2 5 Z M 15.6 1.8 C 16.021 1.81 16.422 1.982 16.72 2.28 C 17.018 2.578 17.19 2.979 17.2 3.4 L 17.2 13 C 17.19 13.421 17.018 13.822 16.72 14.12 C 16.422 14.418 16.021 14.59 15.6 14.6 L 6 14.6 C 5.579 14.59 5.178 14.418 4.88 14.12 C 4.582 13.822 4.41 13.421 4.4 13 L 4.4 3.4 C 4.41 2.979 4.582 2.578 4.88 2.28 C 5.178 1.982 5.579 1.81 6 1.8 Z M 9.2 11.8 L 14 8.2 L 9.2 4.6 Z"
android:strokeWidth="1" />
</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 All @@ -58,6 +70,12 @@
<string name="TestResults_NotAvailable">N/A</string>
<string name="TestResults_Summary_Performance_Hero_Upload">Upload</string>
<string name="TestResults_Summary_Performance_Hero_Download">Download</string>


<string name="TestResults_Gbps">Gbit/s</string>
<string name="TestResults_Mbps">Mbit/s</string>
<string name="TestResults_Kbps">kbit/s</string>

<string name="Modal_ReRun_Title">Re-run test</string>
<string name="Modal_ReRun_Websites_Title">You are about to re-test %1$s websites.</string>
<string name="Modal_ReRun_Websites_Run">Run</string>
Expand Down Expand Up @@ -302,13 +320,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,74 @@
<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>

<string name="r240p" translatable="false">240p</string>
<string name="r360p" translatable="false">360p</string>
<string name="r480p" translatable="false">480p</string>
<string name="r720p" translatable="false">720p</string>
<string name="r720p_ext" translatable="false">720p (HD)</string>
<string name="r1080p" translatable="false">1080p</string>
<string name="r1080p_ext" translatable="false">1080p (full HD)</string>
<string name="r1440p" translatable="false">1440p</string>
<string name="r1440p_ext" translatable="false">1440p (2k)</string>
<string name="r2160p" translatable="false">2160p</string>
<string name="r2160p_ext" translatable="false">2160p (4k)</string>

<string name="twoParam" translatable="false">%1$s %2$s</string>

</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
@@ -1,12 +1,43 @@
package org.ooni.probe.data.models

import androidx.compose.runtime.Composable
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.twoParam
import org.jetbrains.compose.resources.stringResource
import org.ooni.engine.models.TestType

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 testKeys: List<TestKeysWithResultId>?,
) {
val idOrThrow get() = result.idOrThrow
val idOrThrow
get() = result.idOrThrow

val videoQuality
get() = testKeys?.firstOrNull { TestType.Dash.name == it.testName }?.testKeys?.getVideoQuality(extended = false)

val upload
@Composable
get() = testKeys?.firstOrNull { TestType.Ndt.name == it.testName }?.testKeys?.let { testKey ->
return@let testKey.summary?.upload?.let {
val upload = setFractionalDigits(getScaledValue(it))
val unit = getUnit(it)
stringResource(Res.string.twoParam, upload, stringResource(unit))
}
}

val download
@Composable
get() = testKeys?.firstOrNull { TestType.Ndt.name == it.testName }?.testKeys?.let { testKey ->
return@let testKey.summary?.download?.let {
val download = setFractionalDigits(getScaledValue(it))
val unit = getUnit(it)
stringResource(Res.string.twoParam, download, stringResource(unit))
}
}
}
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
@@ -0,0 +1,96 @@
package org.ooni.probe.data.models

import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.TestResults_Gbps
import ooniprobe.composeapp.generated.resources.TestResults_Kbps
import ooniprobe.composeapp.generated.resources.TestResults_Mbps
import ooniprobe.composeapp.generated.resources.TestResults_NotAvailable
import ooniprobe.composeapp.generated.resources.r1080p
import ooniprobe.composeapp.generated.resources.r1080p_ext
import ooniprobe.composeapp.generated.resources.r1440p
import ooniprobe.composeapp.generated.resources.r1440p_ext
import ooniprobe.composeapp.generated.resources.r2160p
import ooniprobe.composeapp.generated.resources.r2160p_ext
import ooniprobe.composeapp.generated.resources.r240p
import ooniprobe.composeapp.generated.resources.r360p
import ooniprobe.composeapp.generated.resources.r480p
import ooniprobe.composeapp.generated.resources.r720p
import ooniprobe.composeapp.generated.resources.r720p_ext
import org.jetbrains.compose.resources.StringResource
import org.ooni.engine.models.TestKeys
import org.ooni.probe.ui.shared.format

data class TestKeysWithResultId(
val id: MeasurementModel.Id,
val testName: String?,
val testKeys: TestKeys?,
val resultId: ResultModel.Id,
val testGroupName: String?,
val descriptorRunId: InstalledTestDescriptorModel.Id?,
)

fun TestKeys.getVideoQuality(extended: Boolean): StringResource {
return simple?.medianBitrate?.let {
return minimumBitrateForVideo(it, extended)
} ?: Res.string.TestResults_NotAvailable
}

private fun minimumBitrateForVideo(
videoQuality: Double,
extended: Boolean,
): StringResource {
return if (videoQuality < 600) {
Res.string.r240p
} else if (videoQuality < 1000) {
Res.string.r360p
} else if (videoQuality < 2500) {
Res.string.r480p
} else if (videoQuality < 5000) {
if (extended) {
Res.string.r720p_ext
} else {
Res.string.r720p
}
} else if (videoQuality < 8000) {
if (extended) {
Res.string.r1080p_ext
} else {
Res.string.r1080p
}
} else if (videoQuality < 16000) {
if (extended) {
Res.string.r1440p_ext
} else {
Res.string.r1440p
}
} else if (extended) {
Res.string.r2160p_ext
} else {
Res.string.r2160p
}
}

fun getScaledValue(value: Double): Double {
return if (value < 1000) {
value
} else if (value < 1000 * 1000) {
value / 1000
} else {
value / 1000 * 1000
}
}

fun setFractionalDigits(value: Double): String {
return if (value < 10) value.format(1) else value.format(2)
}

fun getUnit(value: Double): StringResource {
// We assume there is no Tbit/s (for now!)
return if (value < 1000) {
Res.string.TestResults_Kbps
} else if (value < 1000 * 1000) {
Res.string.TestResults_Mbps
} else {
Res.string.TestResults_Gbps
}
}
Loading
Loading