Skip to content

Instantly share code, notes, and snippets.

@anandwana001
Created August 23, 2021 05:41
Show Gist options
  • Save anandwana001/e8607e5705b69f95c104b6c6e73c2f68 to your computer and use it in GitHub Desktop.
Save anandwana001/e8607e5705b69f95c104b6c6e73c2f68 to your computer and use it in GitHub Desktop.
@classmethod
def create_default_exploration(
cls, exploration_id, title=feconf.DEFAULT_EXPLORATION_TITLE,
init_state_name=feconf.DEFAULT_INIT_STATE_NAME,
category=feconf.DEFAULT_EXPLORATION_CATEGORY,
objective=feconf.DEFAULT_EXPLORATION_OBJECTIVE,
language_code=constants.DEFAULT_LANGUAGE_CODE):
.
.
.
.
exploration = cls(
exploration_id, title, category, objective, language_code, [], '',
'', feconf.CURRENT_STATE_SCHEMA_VERSION,
init_state_name, states_dict, {}, [], 0,
feconf.DEFAULT_AUTO_TTS_ENABLED, False)
exp_android_proto = cls.to_exploration_proto(
cls, exploration_id, title, 0, init_state_name, exploration.states)
exp_android_proto_size = int(exp_android_proto.ByteSize())
cls.update_proto_size_in_bytes(cls, exp_android_proto_size)
return exploration
def to_exploration_proto(
self, exploration_id, title, version, init_state_name, states):
"""Calculate the exploration size by setting exploration proto.
Args:
exploration_id: str. The id of the exploration.
title: str. The exploration title.
version: int. The version of the exploration.
init_state_name: str. The name of the initial state.
Returns:
exploration_proto: Exploration. The exploration
proto object.
"""
state_protos=self.to_state_proto(states)
exploration_proto = exploration_pb2.Exploration(
id=exploration_id,
content_version=version,
init_state_name=init_state_name,
title=title,
states=state_protos
)
print("------------------")
print(exploration_proto)
print("------------------")
return exploration_proto
def to_state_proto(self, states):
state_protos = {}
for (state_name, state) in states.items():
state_proto = state_pb2.State(
content=self.to_subtitled_html_proto(
self, state.content
),
recorded_voiceovers=self.to_recorded_voiceover_proto(
self, state.recorded_voiceovers)
)
state_protos[state_name] = state_proto
return state_protos
# This method is already there is file
def apply_change_list(exploration_id, change_list):
exploration = exp_fetchers.get_exploration_by_id(exploration_id)
.
.
.
exp_android_proto = exploration.to_exploration_proto(
exploration_id, exploration.title, exploration.version,
exploration.init_state_name, exploration.states)
exp_android_proto_size = int(exp_android_proto.ByteSize())
exploration.update_proto_size_in_bytes(exp_android_proto_size)
return exploration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment