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

Places survey #917

Merged

Conversation

sebastianbarry
Copy link
Contributor

No description provided.

sebastianbarry and others added 24 commits December 20, 2022 15:10
I manually picked out the files which were important to the time-use/places button and time-use enketo survey to this branch
Removed the time-use-survey-form-v9 file from the json, as this will be read in from the nrel-openpath-deploy-configs repo

dynamic-config.js
- Changed the download URL to be my version of the deploy configs so it can read in the new config data for survey data path and survey info

service.js
- Reads in the formpath, if formpath already exists locally (i.e. demo-survey-v2.json) use that; otherwise, read in the survey path from my nrel-openpath-deploy-configs
…y path exists

Using the deploy-configs that contain info about the survey data, we can perform javascript on them to make them behave properly. For example,

enketo-time-use.js
- Added DynamicConfig
- Read from DynamicConfig to get the config details as an object
- Use the config details to see whether time_use_survey_path is empty or not, and skip if it is empty
service.js
- Added DynamicConfig library
- Removed the ENKETO_SURVEY_CONFIG_PATH since we are getting the path from the dynamic config now
- Added the DynamicConfig get text which gets the config.surveys data to be used
- Removed the _lazyLoadConfig http request now that we are getting the survey json path from the dynamic config data

answer.js
- Added DynamicConfig library
- Removed the ENKETO_SURVEY_CONFIG_PATH since we are getting the path from the dynamic config now
- Added the DynamicConfig get text which gets the config.surveys data to be used
- Removed the _lazyLoadConfig http request now that we are getting the survey json path from the dynamic config data

enketo-time-use.js
- Fixed the location of the formPath file since it was changed in nrel_openpath_deploy_configs

Removed enketoSurveyConfig.json.sample because we no longer need it due to the data being in nrel_openpath_deploy_configs
service.js
- Added DynamicConfig library
- Removed the ENKETO_SURVEY_CONFIG_PATH since we are getting the path from the dynamic config now
- Added the DynamicConfig get text which gets the config.surveys data to be used
- Removed the _lazyLoadConfig http request now that we are getting the survey json path from the dynamic config data

answer.js
- Added DynamicConfig library
- Removed the ENKETO_SURVEY_CONFIG_PATH since we are getting the path from the dynamic config now
- Added the DynamicConfig get text which gets the config.surveys data to be used
- Removed the _lazyLoadConfig http request now that we are getting the survey json path from the dynamic config data

enketo-time-use.js
- Fixed the location of the formPath file since it was changed in nrel_openpath_deploy_configs

Removed enketoSurveyConfig.json.sample because we no longer need it due to the data being in nrel_openpath_deploy_configs
…rveys-data

dynamic_config.js
- changed the URL to reflect the new branch location

enketo-time-use.js
- removed the check that checks to make sure that the timeusesurvey is activated (this is the old way that we were doing it)

service.js
- Fixed the filepaths to reflect the new filePath field in surveys in the dynamic config
Prepare label screen directives for dynamic surveys + notes
Touch ups for dynamic surveys implementation
- Added a try/catch around the entire init function because there was a single "undefined" error causing the profile screen to not load
service.js
- Because when using trip confirm survey, _state.opts.trip.data.properties does not automatically have start_ts and end_ts. Added start_ts and end_ts entering into the data
@sebastianbarry
Copy link
Contributor Author

I found the point where start_ts and end_ts were not being entered into the enketo survey for the trip-level object for trip_user_input/trip confirm survey. I made a case for this where the start_ts and end_ts don't get entered, and made sure they do get entered:

Before

Screen Shot 2023-01-04 at 9 56 17 AM

After

Screen Shot 2023-01-04 at 10 21 00 AM

As you can see, now the trips get removed from the to-label filter when you've labeled them, and they don't come back after hitting the refresh 🔄 button!

@shankari
Copy link
Contributor

shankari commented Jan 4, 2023

I'm glad you were able to fix that - it will unblock me as well.
However, I don't understand the change. As the comment at the top says, the

        // The trip structure is different between the diary and label screens
        // one has the timestamps in properties and the other does not
        // let's support both so we can label from either screen

If you try to label the trip from the diary, for example, it will have data.properties filled out

That's why I have the line

        let tsObj = _state.opts.trip.data? _state.opts.trip.data.properties : _state.opts.trip;

From your screenshots, it looks like the trip has data with features but no properties.
Is this from the label screen or the diary screen?
I wonder if this is a regression triggered by the changes in https://github.com/e-mission/e-mission-phone/blob/master/www/js/diary/infinite_scroll_list.js#L344

  • can you test with a change prior to the diary/label refactor? (e.g. git checkout 82c997cb32b6ca23c31a75f2f78ce643951d1d45) and confirm that the code works even without your changes?
  • if so, the fix might be to change Timeline.confirmedTrip2Geojson to actually fill in the properties correctly instead of adding additional hacks. that would also allow us to remove the original hack above (let tsObj = ...)

@sebastianbarry
Copy link
Contributor Author

My previous screenshots were from the Label screen.

When labeling from the Diary screen, _scope.opts.trip.properties does in fact have start_ts and end_ts, unlike labeling from the Label screen:

image

I will no do the following:

  • can you test with a change prior to the diary/label refactor? (e.g. git checkout 82c997c) and confirm that the code works even without your changes?
  • if so, the fix might be to change Timeline.confirmedTrip2Geojson to actually fill in the properties correctly instead of adding additional hacks. that would also allow us to remove the original hack above (let tsObj = ...)

fix 'add details' btn not appearing.
 -'surveyOpt' needs to recompute after dynamic config is loaded
fix text overlapping over 'add details' btn
 -changed the bottom 'diary-infos' to be vertically centered
@sebastianbarry
Copy link
Contributor Author

  • can you test with a change prior to the diary/label refactor? (e.g. git checkout 82c997c) and confirm that the code works even without your changes?

The code works in this way:

Old Label Screen:

  • _state.opts.trip.data.properties is still undefined (the same behavior as our current commit)
  • _state.opts.trip.data? evaluates to false, so _state.opts.trip is used instead of _state.opts.trip.data.properties
  • _state.opts.trip contains the start_ts and the stop_ts

Screen Shot 2023-01-04 at 12 40 25 PM

Old Diary Screen:

  • _state.opts.trip.data.properties is defined and contains start_ts and end_ts
  • _state.opts.trip.data? evaluates to true, so _state.opts.trip.data.properties is used

Screen Shot 2023-01-04 at 12 35 29 PM


That being said, the solution appears to be:

  1. Find wherever _state.opts.trip.data is defined, make sure that the start_ts and end_ts are added here.

@shankari you had mentioned:

if so, the fix might be to change Timeline.confirmedTrip2Geojson to actually fill in the properties correctly instead of adding additional hacks. that would also allow us to remove the original hack above (let tsObj = ...)

@shankari
Copy link
Contributor

shankari commented Jan 4, 2023

@sebastianbarry

Given this:

_state.opts.trip.data? evaluates to false, so _state.opts.trip is used instead of _state.opts.trip.data.properties

This is clearly a regression caused by the changes to unify the diary and label screens.

Not sure why this is your proposed solution:

Find wherever _state.opts.trip.data is defined, make sure that the start_ts and end_ts are added here.

instead of my proposal to change Timeline.confirmedTrip2Geojson

Can you indicate why your proposed solution is better?
Do you (and @JGreenlee) understand the cause of the regression?

-if the config has "autoRefresh": true, then it will be checked for updates on every app launch
-the same source URL is checked every time
-the newly retrieved config will be applied only if the "version" is different
@JGreenlee
Copy link
Collaborator

We can now have the dynamic config checked for updates on launch!

dev-emulator-program.nrel-op.json

{
    "version": 1,
    "autoRefresh": true,
    ...
}

If the above config is loaded into the app (from github) and then it is incremented to version 2, the app will load the new version on its next launch. If autoRefresh is not given, the default behavior is the same.
This will be helpful for development, and potentially for deployers as well

We should now update the docs to explain this
@sebastianbarry Do you want to update the readme you made? Or if you'd rather give me write access to sebastianbarry/e-mission-docs I can do it later

- additions will now immediately show up on whatever trip was happening at the time, according to the addition's start timestamp
since entries are being sorted we can no longer use the $index that angularjs provides - we need to lookup the index for the entry being deleted
this seems more logical, clear, and versatile for other use cases
hack for enketo to preserve prefilled timezone
Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

This is looking pretty good to me so far. The two issue that I see are:

  • the matching code is not correct
  • the HTML file still has a lot of style-based function calls that should be replaced with variables instead.

www/js/survey/enketo/service.js Outdated Show resolved Hide resolved
www/js/survey/enketo/enketo-add-note-button.js Outdated Show resolved Hide resolved
www/js/survey/input-matcher.js Outdated Show resolved Hide resolved
www/js/diary/infinite_scroll_list.js Outdated Show resolved Hide resolved
www/js/diary/infinite_scroll_place_item.js Show resolved Hide resolved
www/js/survey/enketo/answer.js Outdated Show resolved Hide resolved
www/js/survey/enketo/answer.js Outdated Show resolved Hide resolved
www/templates/diary/trip_list_item.html Show resolved Hide resolved
www/templates/diary/trip_list_item.html Show resolved Hide resolved
sebastianbarry and others added 10 commits February 1, 2023 08:30
The "undefined" error that this solved temporarily as a band-aid fix was fixed in commit e-mission@e474945
answer.js
- Removed the case when the labelVars type is not supported to return an empty string
- Replaced it with a throw new Error that identifies the label type is not supported and it says specifically which one it is
milliseconds were used at one point of testing, but .unix() is now used which returns seconds
- to more closely parallel the server code, the user input filter function has been moved to a separate function called validUserInputForTrip()
- both getUserInputForTrip() and getTripAdditionsForTrip() will now use validUserInputForTrip()
- the survey is only precise to the minute, while trips are precise to milliseconds
- if the start/end timestamps resolved from the survey response are within the same minute as the trip start/end, we will use the exact trip start/end
- this is to avoid addition timestamps being slightly off because of truncation issues
- if the label takes up >2 lines, it should show "..." and not overflow to next entry
- this is for the "enketo.noteAddition" emit coming from enketo-add-note-button.js. when we locate the trip on which to display a brand new addition, we should use the now-standardized validUserInputForTrip function
Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

Only high level issue that is left is to avoid using functions for classes/conditionals etc in the HTML

www/js/diary/infinite_scroll_list.js Outdated Show resolved Hide resolved
www/js/survey/enketo/answer.js Show resolved Hide resolved
www/js/survey/enketo/answer.js Outdated Show resolved Hide resolved
Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

I don't see any pending issues for the trip code.

www/js/diary/infinite_scroll_place_item.js Show resolved Hide resolved
@shankari shankari merged commit d459d9a into e-mission:survey_refactor_expansion Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants