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

Replace suggestLoiTaskType with DataCollectionStrategy #2108

Merged
merged 25 commits into from
Dec 15, 2023
Merged

Conversation

gino-m
Copy link
Collaborator

@gino-m gino-m commented Dec 11, 2023

Fixes #2097

@gino-m
Copy link
Collaborator Author

gino-m commented Dec 13, 2023

This is now working, modulo:

Will mark "Ready for review" once those are fixed and/or out for review. @rfontanarosa FYI.

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (f05948f) 52.01% compared to head (0af709f) 52.11%.

Files Patch % Lines
...nd/domain/usecases/submission/SubmitDataUseCase.kt 30.00% 6 Missing and 1 partial ⚠️
...persistence/remote/firebase/schema/JobConverter.kt 0.00% 5 Missing ⚠️
...ersistence/remote/firebase/schema/TaskConverter.kt 0.00% 3 Missing ⚠️
...in/java/com/google/android/ground/model/job/Job.kt 71.42% 2 Missing ⚠️
...istence/remote/firebase/schema/TaskNestedObject.kt 0.00% 2 Missing ⚠️
...ground/persistence/sync/LocalMutationSyncWorker.kt 66.66% 2 Missing ⚠️
...round/ui/datacollection/DataCollectionViewModel.kt 33.33% 0 Missing and 2 partials ⚠️
...d/persistence/local/room/converter/ConverterExt.kt 90.00% 0 Missing and 1 partial ⚠️
...sistence/remote/firebase/schema/JobNestedObject.kt 0.00% 1 Missing ⚠️
...ome/mapcontainer/HomeScreenMapContainerFragment.kt 0.00% 0 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2108      +/-   ##
============================================
+ Coverage     52.01%   52.11%   +0.09%     
- Complexity     1213     1215       +2     
============================================
  Files           311      311              
  Lines          6102     6104       +2     
  Branches        645      644       -1     
============================================
+ Hits           3174     3181       +7     
+ Misses         2581     2578       -3     
+ Partials        347      345       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gino-m gino-m marked this pull request as ready for review December 14, 2023 21:36
…o gino-m/2097/1

# Conflicts:
#	ground/src/main/java/com/google/android/ground/persistence/sync/LocalMutationSyncWorker.kt
@gino-m gino-m requested a review from scolsen December 15, 2023 20:08
@gino-m
Copy link
Collaborator Author

gino-m commented Dec 15, 2023

@scolsen PTAL

@rfontanarosa FYI

Copy link
Contributor

@scolsen scolsen left a comment

Choose a reason for hiding this comment

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

couple of small comments but lgtm

data class Job(
val id: String,
val style: Style? = null,
val name: String? = null,
val tasks: Map<String, Task> = mapOf(),
val suggestLoiTaskType: Task.Type? = null,
val strategy: DataCollectionStrategy = DataCollectionStrategy.MIXED
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a default? Don't we need this to be defined by survey organizers? Shouldn't it be a required argument, and shouldn't we error out if it's not available/provided?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default value was mainly for tests, but that's probably the wrong reason. Updating now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doing this turned out to be more disruptive than I expected; basically we end up needing to defined it in all tests even where it's not relevant. Ideally we'd have a custom constructor with default values for tests, but since we don't have yet that we can apply UNKNOWN as a default based on your next suggestion

) {
enum class DataCollectionStrategy {
PREDEFINED,
Copy link
Contributor

Choose a reason for hiding this comment

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

So far, it's been helpful to have UNKNOWN for cases in when the web app evolves before the android app/field names change. Not sure if you want to add one here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think UNKNOWN is useful for serialized representations like protos, but for model objects less so; if the strategy is invalid in remote or local data store, by the time to deserialize we should either have chosen a fall-back value, or thrown an error.

@@ -112,7 +113,7 @@ fun JobEntityAndRelations.toModelObject(): Job {
jobEntity.style?.toModelObject(),
jobEntity.name,
taskMap.toPersistentMap(),
jobEntity.suggestLoiTaskType?.let { Task.Type.valueOf(it) }
jobEntity.strategy.let { DataCollectionStrategy.valueOf(it) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just DataCollectionStrategy.valueOf(jobEntity.strategy)?

Or. like other entities, I might expect to see jobEntity.strategy.toModelObject()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why not just DataCollectionStrategy.valueOf(jobEntity.strategy)?

Because strategy might be null, and Enum.valueOf() doesn't accept nulls

Or. like other entities, I might expect to see jobEntity.strategy.toModelObject()

Because in jobEntity strategy is a String, and defining fun String.?toModelObject() would be too broad.

@@ -24,5 +25,5 @@ data class JobNestedObject(
val defaultStyle: StyleNestedObject? = null,
val name: String? = null,
val tasks: Map<String, TaskNestedObject>? = null,
val suggestLoiTaskType: String? = null
val strategy: String = MIXED.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry that this default value and the default value for the Job model object could get out of sync. I think removing a default from the model might be one way to avoid that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. Done!

addAll(job.tasksSorted)
}
// LOI creation task is included only on "new data collection site" flow..
val tasks: List<Task> = job.tasksSorted.filter { loiId == null || !it.isAddLoiTask }
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this filter a little tricky to understand. Seems like we're getting tasks that either have no LOI Id or that are explicitly not add LOI tasks. The latter makes sense given the comment, but I don't understand why we filter for tasks with loiId == null

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're including all tasks when loiId = null. I can rewrite this, lmkwyt.

@gino-m gino-m merged commit 18d518c into master Dec 15, 2023
4 checks passed
@gino-m gino-m deleted the gino-m/2097/1 branch December 15, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Replace suggestLoiTaskType with special LOI task
3 participants