-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools.py
More file actions
166 lines (112 loc) · 3.21 KB
/
Copy pathtools.py
File metadata and controls
166 lines (112 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 27 15:49:25 2018
@author: januszhou
"""
import numpy as np
from datetime import datetime
# ok, let's try to build up some tools first
# maybe we should make things as a class
def get_birthday(pid):
# assume that we have defensive code
birthday_raw = pid[6:14]
# if we want to parse the IDs
birthday = datetime.strptime(birthday_raw, '%Y%m%d')
# return with python datetime type
return(birthday)
def get_age(pid):
now = datetime.now()
birthday = get_birthday(pid)
age = now.year - birthday.year
return(age)
def get_zodiac(birth_date):
# assuming the input is python date type
day = birth_date.day
month = birth_date.month
if month == 12:
astro_sign = 'Sagittarius' if (day < 22) else 'Capricorn'
elif month == 1:
astro_sign = 'Capricorn' if (day < 20) else 'Aquarius'
elif month == 2:
astro_sign = 'Aquarius' if (day < 19) else 'Pisces'
elif month == 3:
astro_sign = 'Pisces' if (day < 21) else 'Aries'
elif month == 4:
astro_sign = 'Aries' if (day < 20) else 'Taurus'
elif month == 5:
astro_sign = 'Taurus' if (day < 21) else 'Gemini'
elif month == 6:
astro_sign = 'Gemini' if (day < 21) else 'Cancer'
elif month == 7:
astro_sign = 'Cancer' if (day < 23) else 'Leo'
elif month == 8:
astro_sign = 'Leo' if (day < 23) else 'Virgo'
elif month == 9:
astro_sign = 'Virgo' if (day < 23) else 'Libra'
elif month == 10:
astro_sign = 'Libra' if (day < 23) else 'Scorpio'
elif month == 11:
astro_sign = 'Scorpio' if (day < 22) else 'Sagittarius'
return(astro_sign)
def get_animal_zodiac(year):
zodiacYear = year % 12
if zodiacYear == 0:
return("Monkey")
elif zodiacYear == 1:
return("Rooster")
elif zodiacYear == 2:
return("Dog")
elif zodiacYear == 3:
return("Pig")
elif zodiacYear == 4:
return("Rat")
elif zodiacYear == 5:
return("Ox")
elif zodiacYear == 6:
return("Tiger")
elif zodiacYear == 7:
return("Rabbit")
elif zodiacYear == 8:
return("Dragon")
elif zodiacYear == 9:
return("Snake")
elif zodiacYear == 10:
return("Horse")
else:
return("Sheep")
def get_gender(pid):
# assuming pid is a string with 18 digits
if len(pid) != 18:
raise ValueError('The input pid does not have 18 digits!')
gender_code = int(pid[16]) % 2
if gender_code:
return('Male')
else:
return('Female')
def id_upgrade(old_pid):
# input has to be the old 15 digits pid
if len(old_pid) != 15:
raise ValueError('The input old pid does not have 15 digits!')
temp_pid = old_pid[:6] + '19' + old_pid[6:]
last_digit = get_last_digit(temp_pid)
new_pid = temp_pid + last_digit
return(new_pid)
def is_valid_id(pid):
status = False
if pid[-1] == get_last_digit(pid[:-1]):
status = True
return(status)
def get_last_digit(pid_without_tail):
multiplier = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
base_numbers = [int(i) for i in pid_without_tail]
product = np.dot(np.asarray(multiplier), np.asarray(base_numbers))
remainder = product % 12
verification_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
return(verification_code[remainder])
def get_area_code(pid):
return(pid[:6])
# need to wrap the area name lookup
def get_place_of_birth(pid):
# first 6 digits
# TODO
pass