Skip to content

Commit

Permalink
Link alerts (#138)
Browse files Browse the repository at this point in the history
* Add report id to alerts

* Rename public report in public symptoms

* Rename PublicReport in PublicSymptoms
  • Loading branch information
ivnsch authored Jul 28, 2020
1 parent d0e37d3 commit 1662de4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.coepi.core.jni.JniAlert
import org.coepi.core.jni.JniAlertsArrayResult
import org.coepi.core.jni.JniApi
import org.coepi.core.jni.JniOneAlertResult
import org.coepi.core.jni.JniPublicReport
import org.coepi.core.jni.JniPublicSymptoms
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -36,7 +36,7 @@ class JNIInterfaceTests {
assertEquals(
JniOneAlertResult(
1, "", JniAlert(
"123", JniPublicReport(
"123", JniPublicSymptoms(
reportTime = 234324,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand All @@ -63,7 +63,7 @@ class JNIInterfaceTests {
JniAlertsArrayResult(
1, "", arrayOf(
JniAlert(
"123", JniPublicReport(
"123", JniPublicSymptoms(
reportTime = 131321,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand All @@ -78,7 +78,7 @@ class JNIInterfaceTests {
), 1592567315, 1592567335, 1.2f, 2.1f
),
JniAlert(
"343356", JniPublicReport(
"343356", JniPublicSymptoms(
reportTime = 32516899200,
earliestSymptomTime = 1590356601,
feverSeverity = 1,
Expand Down
4 changes: 2 additions & 2 deletions android/core/core/src/main/java/org/coepi/core/jni/JniApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ data class JniAlertsArrayResult(

data class JniAlert(
var id: String,
var report: JniPublicReport,
var report: JniPublicSymptoms,
var contactStart: Long,
var contactEnd: Long,
var minDistance: Float,
var avgDistance: Float
)

data class JniPublicReport(
data class JniPublicSymptoms(
val reportTime: Long,
val earliestSymptomTime: Long, // -1 -> no input
val feverSeverity: Int,
Expand Down
39 changes: 20 additions & 19 deletions src/android/android_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
errors::ServicesError,
expect_log,
reporting::{
public_report::{CoughSeverity, FeverSeverity, PublicReport},
public_symptoms::{CoughSeverity, FeverSeverity, PublicSymptoms},
symptom_inputs::UserInput,
},
reports_interval::UnixTime,
Expand Down Expand Up @@ -565,7 +565,7 @@ fn register_callback_internal(callback: Box<dyn LogCallbackWrapper>) {

// To prefill the JNI array (TODO can this be skipped?)
fn placeholder_alert() -> Alert {
let report = PublicReport {
let symptoms = PublicSymptoms {
report_time: UnixTime { value: 0 },
earliest_symptom_time: UserInput::Some(UnixTime { value: 0 }),
fever_severity: FeverSeverity::None,
Expand All @@ -581,7 +581,8 @@ fn placeholder_alert() -> Alert {

Alert {
id: "0".to_owned(),
report,
report_id: "0".to_owned(),
symptoms,
contact_start: 0,
contact_end: 0,
min_distance: 0.0,
Expand All @@ -590,41 +591,41 @@ fn placeholder_alert() -> Alert {
}

pub fn alert_to_jobject(alert: Alert, env: &JNIEnv) -> Result<jobject, ServicesError> {
let jni_public_report_class = env.find_class("org/coepi/core/jni/JniPublicReport")?;
let jni_public_symptoms_class = env.find_class("org/coepi/core/jni/JniPublicSymptoms")?;

let report_time_j_value = JValue::from(alert.report.report_time.value as i64);
let report_time_j_value = JValue::from(alert.symptoms.report_time.value as i64);

let earliest_time = match &alert.report.earliest_symptom_time {
let earliest_time = match &alert.symptoms.earliest_symptom_time {
UserInput::Some(time) => time.value as i64,
UserInput::None => -1,
};
let earliest_time_j_value = JValue::from(earliest_time);

let fever_severity = match &alert.report.fever_severity {
let fever_severity = match &alert.symptoms.fever_severity {
FeverSeverity::None => 0,
FeverSeverity::Mild => 1,
FeverSeverity::Serious => 2,
};
let fever_severity_j_value = JValue::from(fever_severity);

let cough_severity = match &alert.report.cough_severity {
let cough_severity = match &alert.symptoms.cough_severity {
CoughSeverity::None => 0,
CoughSeverity::Existing => 1,
CoughSeverity::Wet => 2,
CoughSeverity::Dry => 3,
};
let cough_severity_j_value = JValue::from(cough_severity);

let breathlessness_j_value = JValue::from(alert.report.breathlessness);
let muscle_aches_j_value = JValue::from(alert.report.muscle_aches);
let loss_smell_or_taste_j_value = JValue::from(alert.report.loss_smell_or_taste);
let diarrhea_j_value = JValue::from(alert.report.diarrhea);
let runny_nose_j_value = JValue::from(alert.report.runny_nose);
let other_j_value = JValue::from(alert.report.other);
let no_symptoms_j_value = JValue::from(alert.report.no_symptoms);
let breathlessness_j_value = JValue::from(alert.symptoms.breathlessness);
let muscle_aches_j_value = JValue::from(alert.symptoms.muscle_aches);
let loss_smell_or_taste_j_value = JValue::from(alert.symptoms.loss_smell_or_taste);
let diarrhea_j_value = JValue::from(alert.symptoms.diarrhea);
let runny_nose_j_value = JValue::from(alert.symptoms.runny_nose);
let other_j_value = JValue::from(alert.symptoms.other);
let no_symptoms_j_value = JValue::from(alert.symptoms.no_symptoms);

let jni_public_report_obj = env.new_object(
jni_public_report_class,
let jni_public_symptoms_obj = env.new_object(
jni_public_symptoms_class,
"(JJIIZZZZZZZ)V",
&[
report_time_j_value,
Expand Down Expand Up @@ -654,10 +655,10 @@ pub fn alert_to_jobject(alert: Alert, env: &JNIEnv) -> Result<jobject, ServicesE
let result: Result<jobject, jni::errors::Error> = env
.new_object(
jni_alert_class,
"(Ljava/lang/String;Lorg/coepi/core/jni/JniPublicReport;JJFF)V",
"(Ljava/lang/String;Lorg/coepi/core/jni/JniPublicSymptoms;JJFF)V",
&[
id_j_value,
JValue::from(jni_public_report_obj),
JValue::from(jni_public_symptoms_obj),
contact_start_j_value,
contact_end_j_value,
min_distance_j_value,
Expand Down
7 changes: 4 additions & 3 deletions src/android/jni_domain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::android_interface::{alert_to_jobject, jni_obj_result};
use crate::{
expect_log,
reporting::{
public_report::{CoughSeverity, FeverSeverity, PublicReport},
public_symptoms::{CoughSeverity, FeverSeverity, PublicSymptoms},
symptom_inputs::UserInput,
},
reports_interval::UnixTime,
Expand Down Expand Up @@ -64,7 +64,7 @@ pub unsafe extern "C" fn Java_org_coepi_core_jni_JniApi_testReturnMultipleAlerts
}

fn create_test_alert(id: &str, report_time: u64) -> Alert {
let report = PublicReport {
let symptoms = PublicSymptoms {
report_time: UnixTime { value: report_time },
earliest_symptom_time: UserInput::Some(UnixTime { value: 1590356601 }),
fever_severity: FeverSeverity::Mild,
Expand All @@ -80,7 +80,8 @@ fn create_test_alert(id: &str, report_time: u64) -> Alert {

Alert {
id: id.to_owned(),
report,
report_id: id.to_owned(), // re-use alert id, not particular reason other than we don't need separate id for now
symptoms,
contact_start: 1592567315,
contact_end: 1592567335,
min_distance: 1.2,
Expand Down
Loading

0 comments on commit 1662de4

Please sign in to comment.