-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fe6d7b
commit 91ce923
Showing
4 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
"""Random PINFL generation module.""" | ||
|
||
import random | ||
import datetime | ||
|
||
|
||
class PinflUtilitiesGenerator: | ||
def generate_pinfl(self, gender, birth_date): | ||
century = str(self.gender_date_index(gender, birth_date)) | ||
"""Random PINFL generation.""" | ||
|
||
def generate(self, gender, birth_date): | ||
"""PINFL generation function.""" | ||
|
||
century = str(self._gender_date_index(gender, birth_date)) | ||
|
||
month = str(birth_date.month).zfill(2) | ||
day = str(birth_date.day).zfill(2) | ||
decade = str(birth_date.year % 100) | ||
|
||
area_code = str(random.randint(1, 999)).zfill(3) | ||
serial_number = str(random.randint(1, 999)).zfill(3) | ||
pinfl_digits = [ | ||
|
||
digits = [ | ||
str(digit) | ||
for digit in century + day + month + decade + area_code + serial_number | ||
] | ||
check_digit = self._calculate_check_digit(pinfl_digits) | ||
return "".join(pinfl_digits) + str(check_digit) | ||
|
||
def gender_date_index(self, gender, birth_date): | ||
check_digit = self._calculate_check_digit(digits) | ||
return "".join(digits) + str(check_digit) | ||
|
||
def generate_pinfl(self, gender, birth_date): | ||
"""Generate PINFL.""" | ||
|
||
return self.generate(gender, birth_date) | ||
|
||
def _gender_date_index(self, gender, birth_date): | ||
gender_shift_number = 1 if gender == "female" else 0 | ||
return (birth_date.year // 100) - 17 + gender_shift_number | ||
|
||
def _calculate_check_digit(self, pinfl_digits): | ||
def _calculate_check_digit(self, digits): | ||
weight_func = [7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7] | ||
sum_digits = sum( | ||
int(digit) * weight for digit, weight in zip(pinfl_digits, weight_func) | ||
int(digit) * weight for digit, weight in zip(digits, weight_func) | ||
) | ||
return sum_digits % 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters