Skip to content

Commit

Permalink
update progress bar styling
Browse files Browse the repository at this point in the history
  • Loading branch information
jennchenn committed Jul 12, 2021
1 parent d1d96c2 commit ef89942
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 69 deletions.
3 changes: 1 addition & 2 deletions backend/python/app/graphql/types/story_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class StoryTranslationContentResponseDTO(graphene.ObjectType):
id = graphene.Int(required=True)
line_index = graphene.Int(required=True)
translation_content = graphene.String(required=True)
percentage_complete = graphene.Int()


class StoryTranslationResponseDTO(graphene.ObjectType):
Expand All @@ -74,4 +73,4 @@ class StoryTranslationResponseDTO(graphene.ObjectType):
description = graphene.String(required=True)
youtube_link = graphene.String(required=True)
level = graphene.Int(required=True)
percentage_complete = graphene.Int()
num_translated_lines = graphene.Int()
76 changes: 9 additions & 67 deletions backend/python/app/services/implementations/story_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def get_story_translation(self, id):
# TODO: Condense into singular query
translation = StoryTranslation.query.get(id)

# story_details = Story.query.
story_details = (
(
db.session.query(
Expand All @@ -147,8 +146,8 @@ def get_story_translation(self, id):
._asdict()
)

story_details["percentage_complete"] = self._get_translation_progress(
story_details["story_id"], id
story_details["num_translated_lines"] = self._get_num_translated_lines(
translation.translation_contents
)
response = {
**translation.to_dict(include_relationships=True),
Expand Down Expand Up @@ -180,42 +179,21 @@ def assign_user_as_reviewer(self, user, story_translation):

def update_story_translation_content(self, story_translation_content):
try:
old_translation_content = (
db.session.query(
StoryTranslation.id,
StoryTranslation.story_id,
StoryTranslationContent.translation_content,
StoryTranslationContent.line_index,
)
.join(
StoryTranslation,
StoryTranslation.id == StoryTranslationContent.story_translation_id,
)
.filter(StoryTranslationContent.id == story_translation_content.id)
.one()
)
story_translation = StoryTranslationContent.query.filter_by(
id=story_translation_content.id
).first()

if not old_translation_content:
if not story_translation:
raise Exception(
"story_translation_content_id {id} not found".format(
id=story_translation_content.id
)
)

story_translation = StoryTranslationContent.query.filter_by(
id=story_translation_content.id
).first()

story_translation.translation_content = (
story_translation_content.translation_content
)
db.session.commit()

percentage_complete = self._get_translation_progress(
old_translation_content.story_id, old_translation_content.id
)

db.session.commit()
except Exception as error:
reason = getattr(error, "message", None)
self.logger.error(
Expand All @@ -227,9 +205,8 @@ def update_story_translation_content(self, story_translation_content):

return StoryTranslationContentResponseDTO(
story_translation_content.id,
old_translation_content.line_index,
story_translation.line_index,
story_translation_content.translation_content,
percentage_complete,
)

def update_story_translation_contents(self, story_translation_contents):
Expand Down Expand Up @@ -275,40 +252,5 @@ def get_story_translations_available_for_review(self, language, level):
self.logger.error(str(error))
raise error

def _get_translation_progress(self, story_id, translation_id):
try:
num_translated_lines = self._get_num_translated_lines(translation_id)
num_story_lines = self._get_num_story_lines(story_id)
if num_translated_lines == 0 or num_story_lines == 0:
return 0
percentage_complete = round(num_translated_lines / num_story_lines, 2) * 100
return percentage_complete

except Exception as error:
self.logger.error(str(error))
raise error

def _get_num_translated_lines(self, translation_id):
try:
return (
db.session.query(StoryTranslationContent)
.filter(
StoryTranslationContent.story_translation_id == translation_id,
StoryTranslationContent.translation_content != "",
)
.count()
)
except Exception as error:
self.logger.error(str(error))
raise error

def _get_num_story_lines(self, story_id):
try:
return (
db.session.query(StoryContent)
.filter(StoryContent.story_id == story_id)
.count()
)
except Exception as error:
self.logger.error(str(error))
raise error
def _get_num_translated_lines(self, translation_contents):
return sum(1 for _ in translation_contents if _.translation_content)
2 changes: 2 additions & 0 deletions frontend/src/components/pages/TranslationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type TranslationPageProps = {

const TranslationPage = () => {
const { storyId, storyTranslationId } = useParams<TranslationPageProps>();
// TODO: set percentageComplete based on return from get translation query,
// and update when edits made to page
// const [percentageComplete, setPercentageComplete] = useState(0);
const [percentageComplete] = useState(25);
if (storyId === undefined || storyTranslationId === undefined) {
Expand Down

0 comments on commit ef89942

Please sign in to comment.