Skip to content

fix: rewrite course string parser#90

Merged
madhavarshney merged 7 commits intomasterfrom
fix/75-course-string-parser
Aug 10, 2020
Merged

fix: rewrite course string parser#90
madhavarshney merged 7 commits intomasterfrom
fix/75-course-string-parser

Conversation

@madhavarshney
Copy link
Copy Markdown
Member

@madhavarshney madhavarshney commented Aug 9, 2020

Fixes #75.

@madhavarshney madhavarshney added bug Something isn't working enhancement New feature or request labels Aug 9, 2020
@madhavarshney madhavarshney marked this pull request as ready for review August 10, 2020 04:57
@madhavarshney madhavarshney requested a review from phi-line August 10, 2020 04:57
pylint = "*"
colorama = "*"
snapshottest = "*"
click = "*"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Was already used by flask

print(e.message, '-', e.details)


class TestParseCourseString(TestCase):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

great tests 👍

if len(without_dept) < 6 or len(without_dept) > 8:
raise ValidationError(
f"Invalid course + section string ('{without_dept}')",
'Length is not between 6-8 chars'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why does length have to be between 6-8 chars?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are there valid cases more or less than that count?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The fundamental assumptions that are made throughout this parser are as follows:

F 1AHL 01Z

First char - campus
Next four char - course (may start with 0's and/or end with .)
All chars afterwards - section (max 3 chars)

Therefore, the string needs to be at least 6 chars and no more than 8 chars. In practice, all course strings are between 7-8 chars.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for clarifying 👍

section = without_dept[5:]

# Extract flags by filtering nonalphabets from the class section string
flags = set(filter(str.isalpha, section))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is a filter to get rid of .?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, that is done through the regex. This chooses alphabets from the section string (ex. 1HZ => {'H', 'Z'}).


# The last chars are the class section + flags
# ex. `01Z` or `5ZH`
section = without_dept[5:]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we storing variant from section?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That will be done in #80

Copy link
Copy Markdown
Collaborator

@phi-line phi-line left a comment

Choose a reason for hiding this comment

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

looks good! thanks for PR

- Document methodology for parsing course string
- More tests
- Minor changes
@madhavarshney madhavarshney merged commit dc685e4 into master Aug 10, 2020
@madhavarshney madhavarshney deleted the fix/75-course-string-parser branch August 10, 2020 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Querying with course modifiers

2 participants