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

Added roll number parsing and fixed get_dept bugs #3

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ eg) 2021PECCB101
PEC - Panimalar Engineering College
CB - Department (Computer Science and Business Systems)
101 - Roll Number of Student


### Release Steps

- change version number in pyproject.toml
- add modules to pyproject.toml
- add dependencies if any
- add new functions in readme
Binary file added src/rollno/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added src/rollno/__pycache__/module.cpython-310.pyc
Binary file not shown.
65 changes: 54 additions & 11 deletions src/rollno/module.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import regex


# Regex for rollno
regex_rollno = r'^(20[1-3]{1}[0-9]{1})(PEC)([A-Z]{2})([0-9]{3})$'

def isvalid(rollno):
"""
Check if rollno is valid (eg. 2021PECCB001)
Returns True if valid, False otherwise
"""

# Regex for rollno
regex_rollno = r'^20[1-3]{1}[0-9]{1}(PEC)[A-Z]{2}[0-9]{3}$'


# Check if rollno is valid
if regex.match(regex_rollno, rollno.strip().upper()):
Expand All @@ -18,25 +19,62 @@ def isvalid(rollno):
return False


def getdeptcode(rollno):
def parse(rollno, required):

"""
Parse rollno
Returns parsed rollno if valid, None otherwise
"""

# Check if rollno is valid
if isvalid(rollno):

# Match regex
re = regex.match(regex_rollno, rollno.strip().upper())


# Return required
if required == 'year':
# Get year
year = re.group(1)
return year

elif required == 'college_code':
# Get college code
college_code = re.group(2)
return college_code
elif required == 'department_code':
# Get department code
department_code = re.group(3)
return department_code
elif required == 'shortrollno':
# Get shortrollno
shortrollno = re.group(4)
return shortrollno
else:
return None
else:
return None


def get_dept_code(rollno):
"""
Get department code from rollno
Returns department code if valid, None otherwise
"""

# Check if rollno is valid
if isvalid(rollno):

# Get department code
department_code=rollno[5:7]
department_code = parse(rollno, 'department_code')

return department_code
else:
return None




def getdept(rollno):
def get_dept(rollno):
"""
Get department from rollno
Returns department if valid, None otherwise
Expand All @@ -50,17 +88,22 @@ def getdept(rollno):
'IT': 'Information Technology',
'EC': 'Electronics and Communication Engineering',
'EE': 'Electrical and Electronics Engineering',
'CE': 'Computer Science and Engineering',
'CC': 'Computer Science and Communication Engineering',
'CE': 'Civil Engineering',
'CC': 'Computer and Communication Engineering',
'ME': 'Mechanical Engineering',
'AD': 'Artificial Intelligence and Data Science'
}

# Get department code
department_code=getdeptcode(rollno)
department_code = parse(rollno, 'department_code')


# Get department name and return
department= departments[department_code]
try:
department= departments[department_code]
except KeyError:
return None

return department
else:
return None
Loading