Skip to content

Commit

Permalink
Fix oppia#7019: Add skill_id to Misconception and replace tagged_misc…
Browse files Browse the repository at this point in the history
…onception_id with tagged_skill_misconception_id in AnswerGroup (oppia#7141)

* add skill_id to misconception and change tagged_misconception_id to tagged_skill_misconception_id

* lint

* lint

* lint

* lint

* lint

* backend fix

* backend fix

* lint

* lint

* fixed backend error

* review changes and backend coverage

* lint

* fixed backend error

* revert Misconception changes

* review changes and frontend fix

* lint

* lint

* backend fix

* review changes

* backend fix

* backend error fix

* lint

* review changes

* fixed backend errors due to newest changes

* lint

* lint
  • Loading branch information
sophiewu6 authored and seanlip committed Jul 24, 2019
1 parent f8d9919 commit 482d2eb
Show file tree
Hide file tree
Showing 33 changed files with 648 additions and 152 deletions.
31 changes: 31 additions & 0 deletions core/domain/draft_upgrade_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ def try_upgrading_draft_to_exp_version(
class DraftUpgradeUtil(object):
"""Wrapper class that contains util functions to upgrade drafts."""

@classmethod
def _convert_states_v29_dict_to_v30_dict(cls, draft_change_list):
"""Converts draft change list from state version 29 to 30. State
version 30 replaces tagged_misconception_id with
tagged_skill_misconception_id.
Args:
draft_change_list: list(ExplorationChange). The list of
ExplorationChange domain objects to upgrade.
Returns:
list(ExplorationChange). The converted draft_change_list.
"""
for i, change in enumerate(draft_change_list):
if (change.cmd == exp_domain.CMD_EDIT_STATE_PROPERTY and
change.property_name ==
exp_domain.STATE_PROPERTY_INTERACTION_ANSWER_GROUPS):
draft_change_list[i] = exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_ANSWER_GROUPS),
'state_name': change.state_name,
'new_value': {
'rule_specs': change.new_value['rule_specs'],
'outcome': change.new_value['outcome'],
'training_data': change.new_value['training_data'],
'tagged_skill_misconception_id': None
}
})
return draft_change_list

@classmethod
def _convert_states_v28_dict_to_v29_dict(cls, draft_change_list):
"""Converts draft change list from state version 28 to 29. State
Expand Down
68 changes: 68 additions & 0 deletions core/domain/draft_upgrade_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,74 @@ def test_convert_to_latest_schema_version_implemented(self):
msg='Current schema version is %d but DraftUpgradeUtil.%s is '
'unimplemented.' % (state_schema_version, conversion_fn_name))

def test_convert_states_v29_dict_to_v30_dict(self):
draft_change_list = [
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': 'answer_groups',
'state_name': 'State 1',
'new_value': {
'rule_specs': [{
'rule_type': 'Equals',
'inputs': {'x': [
'<p>This is value1 for ItemSelection</p>'
]}
}, {
'rule_type': 'Equals',
'inputs': {'x': [
'<p>This is value2 for ItemSelection</p>'
]}
}],
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback',
'html': '<p>Outcome for state1</p>'
},
'param_changes': [],
'labelled_as_correct': False,
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'training_data': [],
'tagged_misconception_id': None
}
})]
self.assertEqual(
draft_upgrade_services.DraftUpgradeUtil._convert_states_v29_dict_to_v30_dict( # pylint: disable=protected-access,line-too-long
draft_change_list)[0].to_dict(),
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': 'answer_groups',
'state_name': 'State 1',
'new_value': {
'rule_specs': [{
'rule_type': 'Equals',
'inputs': {'x': [
'<p>This is value1 for ItemSelection</p>'
]}
}, {
'rule_type': 'Equals',
'inputs': {'x': [
'<p>This is value2 for ItemSelection</p>'
]}
}],
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback',
'html': '<p>Outcome for state1</p>'
},
'param_changes': [],
'labelled_as_correct': False,
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'training_data': [],
'tagged_skill_misconception_id': None
}
}).to_dict())

def test_convert_states_v28_dict_to_v29_dict(self):
draft_change_list = [
exp_domain.ExplorationChange({
Expand Down
54 changes: 52 additions & 2 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ def _convert_states_v28_dict_to_v29_dict(cls, states_dict):
Args:
states_dict: dict. A dict where each key-value pair represents,
respectively, a state name and a dict used to initalize a
respectively, a state name and a dict used to initialize a
State domain object.
Returns:
Expand All @@ -2186,6 +2186,28 @@ def _convert_states_v28_dict_to_v29_dict(cls, states_dict):
state_dict['solicit_answer_details'] = False
return states_dict

@classmethod
def _convert_states_v29_dict_to_v30_dict(cls, states_dict):
"""Converts from version 29 to 30. Version 30 replaces
tagged_misconception_id with tagged_skill_misconception_id, which
contains the skill id and misconception id of the tagged misconception,
connected by '-'.
Args:
states_dict: dict. A dict where each key-value pair represents,
respectively, a state name and a dict used to initialize a
State domain object.
Returns:
dict. The converted states_dict.
"""
for state_dict in states_dict.itervalues():
answer_groups = state_dict['interaction']['answer_groups']
for answer_group in answer_groups:
answer_group['tagged_skill_misconception_id'] = None
del answer_group['tagged_misconception_id']
return states_dict

@classmethod
def update_states_from_model(
cls, versioned_exploration_states, current_states_schema_version,
Expand Down Expand Up @@ -2221,7 +2243,7 @@ def update_states_from_model(
# incompatible changes are made to the exploration schema in the YAML
# definitions, this version number must be changed and a migration process
# put in place.
CURRENT_EXP_SCHEMA_VERSION = 34
CURRENT_EXP_SCHEMA_VERSION = 35
LAST_UNTITLED_SCHEMA_VERSION = 9

@classmethod
Expand Down Expand Up @@ -2835,6 +2857,29 @@ def _convert_v33_dict_to_v34_dict(cls, exploration_dict):

return exploration_dict

@classmethod
def _convert_v34_dict_to_v35_dict(cls, exploration_dict):
"""Converts a v34 exploration dict into a v35 exploration dict.
Replaces tagged_misconception_id with tagged_skill_misconception_id,
which contains the skill id and misconception id of the tagged
misconception, connected by '-'.
Args:
exploration_dict: dict. The dict representation of an exploration
with schema version v34.
Returns:
dict. The dict representation of the Exploration domain object,
following schema version v35.
"""
exploration_dict['schema_version'] = 35

exploration_dict['states'] = cls._convert_states_v29_dict_to_v30_dict(
exploration_dict['states'])
exploration_dict['states_schema_version'] = 30

return exploration_dict

@classmethod
def _migrate_to_latest_yaml_version(
cls, yaml_content, exp_id, title=None, category=None):
Expand Down Expand Up @@ -3038,6 +3083,11 @@ def _migrate_to_latest_yaml_version(
exploration_dict)
exploration_schema_version = 34

if exploration_schema_version == 34:
exploration_dict = cls._convert_v34_dict_to_v35_dict(
exploration_dict)
exploration_schema_version = 35

return (exploration_dict, initial_schema_version)

@classmethod
Expand Down
Loading

0 comments on commit 482d2eb

Please sign in to comment.