Skip to content

Commit

Permalink
Merge pull request #3 from thecoding-society/rollno
Browse files Browse the repository at this point in the history
Added roll number parsing and fixed get_dept bugs
  • Loading branch information
aviiciii authored Jan 20, 2023
2 parents d7ac236 + 6f99ac7 commit 5b004cd
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 97 deletions.
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

0 comments on commit 5b004cd

Please sign in to comment.