Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

[BM-667] Feedback - baby device side #263

Open
wants to merge 1 commit into
base: BM-667_User_feedback
Choose a base branch
from

Conversation

gabrysgab
Copy link

Task

Description

Added checking the frequency of feedback requests
Added sending feedback requests with the notifications
Added tests

Added checking the frequency of feedback requests
Added sending feedback requests with the notifications
Added tests
@gabrysgab gabrysgab changed the base branch from master to BM-667_User_feedback February 18, 2020 15:32
@@ -47,6 +47,11 @@ class BabyMonitorMessagingService : FirebaseMessagingService() {
message.data
)
NotificationType.LOW_BATTERY_NOTIFICATION -> handleLowBatteryNotification(message.data)
NotificationType.CRY_NOTIFICATION_WITH_FEEDBACK_REQUEST,
NotificationType.NOISE_NOTIFICATION_WITH_FEEDBACK_REQUEST -> {
// TODO handle notification with feedback request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This comment contains text that has been defined as forbidden in detekt.

@@ -15,14 +17,30 @@ class NotifyBabyEventUseCase(
private val babyEvents: PublishSubject<BabyEvent> = PublishSubject.create()

private fun fetchClientsAndPostNotification(babyEvent: BabyEvent): Completable {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The function fetchClientsAndPostNotification appears to be too complex.

Timber.d("Notification posted: $response.")
}
.ignoreElement()
}

private fun updateFeedbackData(notificationData: NotificationData) {
feedbackFrequencyUseCase.notificationSent()
if (notificationData.feedbackRecordingFile.isNotEmpty())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Multi-line if statement was found that does not have braces. These should be added to improve readability.

private fun updateFeedbackData(notificationData: NotificationData) {
feedbackFrequencyUseCase.notificationSent()
if (notificationData.feedbackRecordingFile.isNotEmpty())
feedbackFrequencyUseCase.feedbackRequestSent()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Missing { … }

title: String,
text: String,
notificationType: NotificationType
notificationData: NotificationData
): Single<Response> {
return checkIdCall(firebaseToken)
.flatMap { isAndroid ->
return@flatMap notificationCall(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Expression with labels increase complexity and affect maintainability.

Timber.d("Sound Db: $decibels")
return@fromCallable decibels.roundToInt()
Timber.d("Max Db: $maxDecibels")
return@fromCallable maxDecibels?.roundToInt() ?: 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Expression with labels increase complexity and affect maintainability.

}

private fun mapToDecibels(shorts: List<Short>): Double {
var totalSquared = 0.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Unexpected indentation (7) (it should be 8)

@@ -26,10 +29,11 @@ class RecordingController @Inject constructor(
.map {
val data = when {
isMachineLearningWithEnoughData(it) -> RecordingData.MachineLearning(
it.first.takeLast(MachineLearning.DATA_SIZE * 2).toByteArray(),
it.first.takeLast(FeedbackController.DATA_SIZE * 2).toByteArray(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This expression contains a magic number. Consider defining it to a well named constant.

it.second.takeLast(MachineLearning.DATA_SIZE).toShortArray()
)
isNoiseDetectionWithEnoughData(it) -> RecordingData.NoiseDetection(
it.first.takeLast(FeedbackController.DATA_SIZE * 2).toByteArray(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This expression contains a magic number. Consider defining it to a well named constant.

) = Single.fromCallable {
// TODO add metadata to the recordings (should be consulted with ML dev)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This comment contains text that has been defined as forbidden in detekt.

.subscribeOn(Schedulers.io())
.subscribeBy(
onSuccess = { savedRecordingData ->
Timber.i("Recording saved: ${savedRecordingData.fileName}" +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Replace String concatenation with Timber’s string formatting

.subscribeOn(Schedulers.io())
.subscribeBy(
onSuccess = { savedRecordingData ->
Timber.i("Recording saved: ${savedRecordingData.fileName}" +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Multiple occurrences of the same string literal within a single file detected.

.subscribeBy(
onSuccess = { savedRecordingData ->
Timber.i("Recording saved: ${savedRecordingData.fileName}" +
" should ask for feedback: ${savedRecordingData.shouldAskForFeedback}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Multiple occurrences of the same string literal within a single file detected.

.subscribeOn(Schedulers.io())
.subscribeBy(
onSuccess = { savedRecordingData ->
Timber.i("Recording saved: ${savedRecordingData.fileName}" +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Replace String concatenation with Timber’s string formatting

@@ -23,9 +24,9 @@ class NotifyLowBatteryUseCaseTest {
notifyLowBatteryUseCase.notifyLowBattery(title, text)

verify(notificationSender).broadcastNotificationToFcm(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Unexpected indentation (11) (it should be 12)

@netguru-hound
Copy link

6 Warnings
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/application/firebase/FirebaseSharedPreferencesWrapper.kt#L12 - Unexpected indentation (expected 4, actual 8)
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/feature/firebasenotification/FirebaseNotificationSender.kt#L77 - Multiple occurrences of the same string literal within a single file detected.
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/feature/firebasenotification/FirebaseNotificationSender.kt#L83 - Expression with labels increase complexity and affect maintainability.
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/feature/recording/RecordingController.kt#L64 - This expression contains a magic number. Consider defining it to a well named constant.
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/feature/settings/ConfigurationViewModel.kt#L1 - Trailing space(s)
⚠️ app/src/main/kotlin/co/netguru/baby/monitor/client/feature/settings/ConfigurationViewModel.kt#L96 - Unexpected newline before “:”
1 Message
📖 🔗 BM-667

JaCoCO Code Coverage 20.09% ✅

Class Covered Meta Status
co/netguru/baby/monitor/client/feature/batterylevel/NotifyLowBatteryUseCase 100% 0%
co/netguru/baby/monitor/client/common/TimestampProvider 0% 0%
co/netguru/baby/monitor/client/feature/babynotification/NotifyBabyEventUseCase 40% 0%
co/netguru/baby/monitor/client/feature/babynotification/BabyMonitorMessagingService 0% 0%
co/netguru/baby/monitor/client/application/firebase/FirebaseRepository 0% 0%
co/netguru/baby/monitor/client/application/firebase/FirebaseSharedPreferencesWrapper 0% 0%
co/netguru/baby/monitor/client/feature/settings/ConfigurationViewModel 93% 0%
co/netguru/baby/monitor/client/feature/noisedetection/NoiseDetector 0% 0%
co/netguru/baby/monitor/client/application/di/SharedPreferencesModule 0% 0%
co/netguru/baby/monitor/client/feature/voiceAnalysis/VoiceAnalysisController 38% 0%
co/netguru/baby/monitor/client/feature/voiceAnalysis/VoiceAnalysisService 0% 0%
co/netguru/baby/monitor/client/feature/recording/RecordingFileController 0% 0%
co/netguru/baby/monitor/client/feature/recording/RecordingController 100% 0%
co/netguru/baby/monitor/client/feature/firebasenotification/Message 0% 0%
co/netguru/baby/monitor/client/feature/firebasenotification/FirebaseNotificationSender 0% 0%
co/netguru/baby/monitor/client/feature/feedback/FeedbackController 100% 0%
co/netguru/baby/monitor/client/feature/feedback/SavedRecordingDetails 100% 0%
co/netguru/baby/monitor/client/feature/feedback/FeedbackFrequencyUseCase 83% 0%

APK file size

size
30.4MB

Number of method references

Dex file count
classes.dex 47245

Generated by 🚫 Danger

Comment on lines +15 to +19
fun shouldAskForFeedback(): Boolean {
val currentCounter = sharedPreferences.getInt(NOTIFICATION_COUNTER_KEY, 0)
val lastFeedbackTimestamp = sharedPreferences.getLong(FEEDBACK_TIMESTAMP_KEY, 0)
return enoughTimePassed(lastFeedbackTimestamp) && currentCounter > NO_FEEDBACK_COUNTER_LIMIT
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it could be modeled with rx. Something like this, perhaps?

fun feedbackRecordings(recordings: Observable<Recording>) =
    Observable.interval(DELAY_HOURS, TimeUnit.HOURS)
        .withLatestFrom(recordings) { _, recording -> recording }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants