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

New state structure. #5007

Merged
merged 36 commits into from Jun 12, 2018
Merged

New state structure. #5007

merged 36 commits into from Jun 12, 2018

Conversation

DubeySandeep
Copy link
Member

@DubeySandeep DubeySandeep commented May 31, 2018

Explanation

This PR changes the state structure.

  • Replaces audio_translations to content_id in SubtitledHtml.
  • Adds Content_ids_to _audio_translation to connect audio translations with SubtitledHtml.

(Doc can be found here)

CheckList:

  • Make backend structure for the new state.
  • Add state migration function.
  • New cmd for content_ids_to_audio_translations.
  • Changes in SubtitledHtmlObjectFactory and StateObjectFactory compaitible with backend changes
  • Make new structure work for Exploration player.
  • Making other part of StateObject (Feedbacks, Hints, Solution) interact with ConentIdsToAUdioTranslations.
  • Adding command to send change list to the backend.
  • Make frontend AudioTranslationBar and player work.
  • Making test files compatible with the changes.
  • Adding new test cases related to the changes made.

@seanlip
Copy link
Member

seanlip commented May 31, 2018

Hi @DubeySandeep, please note merge conflicts.

Also, might be worth making a note of what remaining work is needed on this PR in the form of a checklist? This helps the reviewer understand what the current status is, so they don't comment on stuff you are planning to do anyway.

Copy link
Contributor

@tjiang11 tjiang11 left a comment

Choose a reason for hiding this comment

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

Thanks @DubeySandeep ! I left some comments, I think it looks pretty good overall, but it's pretty clear this needs some tests.

I also tried running it and it errors out. It seems like a circular dependency has been introduced by the id services. Could you take a look at that? Thanks!

"""Initializes a SubtitledHtml domain object.

Args:
content_id: str. An id for the object.
Copy link
Contributor

Choose a reason for hiding this comment

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

This description is extremely vague. Perhaps something more like "A unique id referring to the audio translations for this content."?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -934,7 +910,7 @@ def __init__(self, hint_content):
"""Constructs a Hint domain object.

Args:
hint_content: SubtitledHtml. The hint text and audio translations.
hint_content: SubtitledHtml. The hint text and content_id.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "The hint text and ID referring to the audio translations for this content."?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -504,23 +506,20 @@ class SubtitledHtml(object):
"""Value object representing subtitled HTML."""

DEFAULT_SUBTITLED_HTML_DICT = {
'html': '',
'audio_translations': {}
'content_id': feconf.DEFAULT_OUTCOME_CONTENT_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this DEFAULT_OUTCOME_CONTENT_ID specifically?

@@ -987,8 +963,8 @@ def __init__(
False if is one of possible answer.
correct_answer: str. The correct answer; this answer enables the
learner to progress to the next card.
explanation: SubtitledHtml. Contains text and audio translations for
the solution's explanation.
explanation: SubtitledHtml. Contains text and text id to link audio
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this comment similar/consistent with the other ones, such as hint_content in hint

if default_outcome:
default_outcome.feedback.audio_translations = {}
for content_id in state.content_ids_to_audio_translations:
state.content_ids_to_audio_translations[content_id] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it matter that the content_id is still present within the different components?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I didn't understand this one. Can you please explain a bit more?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nevermind, realized this shouldn't matter, I think

@@ -221,6 +221,7 @@
<script src="{{TEMPLATE_DIR_PREFIX}}/services/CodeNormalizerService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/services/ComputeGraphService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/services/EditabilityService.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/services/GenerateContendIdService.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

ContentIdService*

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I have also misspelled the filename.
Done!

function(stateContentIdsToAudioTranslationsService) {
var generateRandomString = function() {
randomString = '';
while (randomStringlength != 6){
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is randomStringLength defined?

Also capitalize the l in length

}
};
var _generateUniqueId = function() {
var ContentIdList = Object.keys(
Copy link
Contributor

Choose a reason for hiding this comment

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

contentIdList (camel case)

while (ContentIdList.indexOf(uniqueId) >= 0) {
uniqueId = generateRandomString();
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this function return something?

utils.py Outdated
old_ids.
"""
new_id = generate_random_string(6)
while(new_id in old_id):
Copy link
Contributor

Choose a reason for hiding this comment

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

old_ids?**

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -54,7 +54,8 @@

<div ng-if="stateHintsService.savedMemento[getIndexPlusOne() - 1] && !stateHintsService.savedMemento[getIndexPlusOne() - 1].isEmpty()">
<audio-translations-editor component-name="<[COMPONENT_NAME_HINT]>"
subtitled-html="stateHintsService.displayed[getIndexPlusOne() - 1].hintContent"
content-ids-to-audio-translations="stateContentIdsToAudioTranslationsService.displayed"
Copy link
Member Author

Choose a reason for hiding this comment

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

@seanlip, Can we remove this (also on-change) as this will be same in all other places?

@@ -54,7 +54,8 @@

<div ng-if="stateHintsService.savedMemento[getIndexPlusOne() - 1] && !stateHintsService.savedMemento[getIndexPlusOne() - 1].isEmpty()">
<audio-translations-editor component-name="<[COMPONENT_NAME_HINT]>"
subtitled-html="stateHintsService.displayed[getIndexPlusOne() - 1].hintContent"
content-ids-to-audio-translations="stateContentIdsToAudioTranslationsService.displayed"
conten-id="stateHintsService.displayed[getIndexPlusOne() - 1].hintContent.getContentId()"
on-start-edit="onAudioTranslationsStartEditAction"
on-change="onAudioTranslationsEdited">
Copy link
Member Author

Choose a reason for hiding this comment

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

@seanlip, onAudioTranslationsEdited we'll have to save the changes in stateContentIdsToAudioTranslationsService.saveDisplayedValue(); everywhere.

$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
AlertsService.clearWarnings();
};
}
]
}).result.then(function() {
// TODO(SD): Clean Hints and Responses to resolve #4634.
Copy link
Member Author

Choose a reason for hiding this comment

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

@seanlip, is this an expected behavior?
We don't clean the stateHintsService while deleting an interaction? (I'll have to do the same thing for the audio part)

Copy link
Member

Choose a reason for hiding this comment

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

(Hm, looks like my comment showed up in the main thread. I'll reply inline.)

Yep I think it is expected. Scenario: creator wants to ask exactly the same question, but using a different interaction (eg number with units instead of just a number).

Copy link
Member Author

Choose a reason for hiding this comment

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

@seanlip,

  • Create an exploration add textInput interaction.
  • Add hint.
  • Delete Interaction
  • Add end exploration interaction.
  • Preview
  • Hint appears in "End exploration" card.

Is this expected?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, that's a good point. I didn't think of that scenario. It makes sense for hints not to appear when the state does not have an interaction to which answers are submittable in the first place.

Could you please file a bug for this? I am open to fixing it in this PR or fixing it in a separate PR, and I think the latter might be better since this PR is getting large, but your call.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! (I have created an issue for now #5063 I'll fix this in another PR)

@DubeySandeep
Copy link
Member Author

@tjiang11, can you PTAL? I'll be modifying/writing tests after this.

@seanlip
Copy link
Member

seanlip commented Jun 4, 2018 via email

@DubeySandeep DubeySandeep changed the title [WIP] New state structure. New state structure. Jun 9, 2018
@codecov-io
Copy link

codecov-io commented Jun 9, 2018

Codecov Report

Merging #5007 into develop will increase coverage by 0.02%.
The diff coverage is 58.69%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5007      +/-   ##
===========================================
+ Coverage     45.2%   45.22%   +0.02%     
===========================================
  Files          409      411       +2     
  Lines        23891    23993     +102     
  Branches      3861     3858       -3     
===========================================
+ Hits         10800    10851      +51     
- Misses       13091    13142      +51
Impacted Files Coverage Δ
...head/pages/exploration_editor/ChangeListService.js 74.19% <ø> (ø) ⬆️
...v/head/domain/exploration/SolutionObjectFactory.js 81.39% <ø> (ø) ⬆️
...mplates/dev/head/components/HintEditorDirective.js 2.43% <0%> (+0.05%) ⬆️
.../pages/exploration_editor/editor_tab/StateHints.js 0.95% <0%> (-0.12%) ⬇️
.../exploration_player/HintAndSolutionModalService.js 2.43% <0%> (-0.27%) ⬇️
...ates/dev/head/components/OutcomeEditorDirective.js 1.03% <0%> (ø) ⬆️
...d/components/SolutionExplanationEditorDirective.js 2.56% <0%> (-0.22%) ⬇️
...es/exploration_editor/editor_tab/StateResponses.js 2.59% <0%> (-0.07%) ⬇️
...ev/head/pages/exploration_player/PlayerServices.js 0.88% <0%> (-0.02%) ⬇️
...ges/exploration_editor/ExplorationStatesService.js 44.62% <0%> (-1.49%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2edb01...be7480a. Read the comment docs.

if not set(content_id_list) <= set(available_content_ids):
raise utils.ValidationError(
'Expected state content_ids_to_audio_translations to have all '
'of the listed content ids %s' % content_id_list)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth making a test to test this case? Same with the duplicate content ids case

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -203,7 +239,10 @@ describe('States object factory', function() {
customization_args: {},
default_outcome: {
dest: 'new state',
feedback: [],
feedback: {
contnet_id: 'default_outcome',
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and in about 20 other places, content*

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -29,9 +29,9 @@ oppia.directive('hintEditor', [
'/components/hint_editor_directive.html'),
controller: [
'$scope', '$uibModal', 'EditabilityService', 'stateHintsService',
'COMPONENT_NAME_HINT',
'stateContentIdsToAudioTranslationsService', 'COMPONENT_NAME_HINT',
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you still planning on renaming to AudioAssets?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but I didn't find any other name, as these are not the audio assets these are just the metadata for audio files and their status. So maybe we can leave it as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sgtm

return new Outcome(
dest,
SubtitledHtmlObjectFactory.createDefault(feedbackText),
SubtitledHtmlObjectFactory.createDefault(feedbackText, feedbacktextId),
Copy link
Contributor

Choose a reason for hiding this comment

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

feedbackTextId (camel case)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -115,10 +117,13 @@ oppia.controller('StateHints', [
$scope.hintIndex = stateHintsService.displayed.length + 1;

$scope.saveHint = function() {
var contentId = GenerateContentIdService.generateUniqueId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of generateUniqueId, we should call it something more like getNextId? Unique Id makes it sound like it's a random string. Up to you though I'm ultimately okay with either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@tjiang11 tjiang11 merged commit 150a076 into oppia:develop Jun 12, 2018
hoangviet1993 pushed a commit to hoangviet1993/oppia that referenced this pull request Jun 20, 2018
* Changes in exp_domain for new state structure

* Made changes in exp_services

* changes made in SubtitledHtmlObjectFactory

* changes made in SubtitledHtmlObjectFactory

* Made changes in backend exp_domain for state validation and conversion

* Added new GenerateContendIdService

* Added domain object for contentIdsToAudioTranslations

* Added changes to support exploration player for new changes

* Fixed lint issues andmade few changes.

* Exploration editor and player started working

* Minor changes to make AudioTranslationBar double binded.

* Added review changes.

* Change branch

* exp_services_test fix

* Fixed other backend test from core.domain

* Fixed frontend tests

* Lint fix

* Fixed e2e test(1)

* Fixed backend tests

* Added Spec files for ContentIdsToAudioTranslationsObjectFactory

* Added Spec file for GenerateContentIdService

* Added validators for citat in sate.validator and fixed tests

* Removed DEFAULT_OUTCOME_CONTENT_ID

* minor changes

* Added e2e review comments changes

* Changed all contnet to content

* Added review changes

* resolved lint errors for docsting
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.

None yet

4 participants