forked from Py-Contributors/RandomProfileGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
158 lines (110 loc) Β· 4.15 KB
/
Copy pathutils.py
File metadata and controls
158 lines (110 loc) Β· 4.15 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
import math
import sys
from datetime import datetime
import random
import os
import json
sys.path.append('.')
from random_profile.enums.gender import Gender
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ASSETS_DIR = os.path.join(ROOT_DIR, "random_profile", "assets")
def load_json(file_name: str) -> dict:
""" function to load json file into dict
args:
file_name (str): file name to load
returns:
dict: dict of data from file
"""
with open(file_name, "r") as f:
data = json.load(f)
return data
# radius of the earh in meters
M_PER_DEGREE = 111319.5
def generate_random_gender() -> Gender:
return random.choice(list(Gender))
def load_txt_file(file_name: str) -> list:
""" function to load txt file into list
args:
file_name (str): file name to load
returns:
list: list of data from file
"""
with open(file_name, "r") as f:
data = f.read().splitlines()
return data
def ipv4_gen() -> str:
return f"{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}"
def generate_dob_age() -> tuple:
month = random.randint(1, 12)
if month == 2: # if month is feb
day = random.randint(1, 28)
elif month in [4, 6, 9, 11]: # if month has 30 days
day = random.randint(1, 30)
elif month in [1, 3, 5, 7, 8, 10, 12]: # if month has 31 days
day = random.randint(1, 31)
current_year = datetime.now().year
year = random.randint(current_year - 80, current_year - 18)
dob = datetime(day=day, month=month, year=year)
age = (datetime.now() - dob).days // 365
dob = dob.strftime("%d/%m/%Y")
return dob, age
def generate_random_height_weight() -> tuple:
height = random.randint(140, 200)
if height < 150:
weight = random.randint(40, 60)
elif height < 160:
weight = random.randint(50, 70)
elif height < 170:
weight = random.randint(60, 80)
elif height < 180:
weight = random.randint(70, 90)
elif height < 190:
weight = random.randint(80, 100)
elif height <= 200:
weight = random.randint(90, 110)
return height, weight
def generate_random_card() -> dict:
card_type = random.choice(("Credit", "Debit"))
number = f"{random.randint(1, 9999):04}-{random.randint(1, 9999):04}-{random.randint(1, 9999):04}-{random.randint(1, 9999):04}"
expiration_year = random.randint(datetime.today().year, datetime.today().year + 10)
expiration_month = random.randint(1, 12)
expiration = f"{expiration_month:02}/{str(expiration_year)[-2:]}"
card = {
"type": card_type,
"number": number,
"expiration": expiration
}
return card
def generate_random_job_level(age: int, levels) -> str:
levels_with_ranges = [level.split(';') for level in levels]
applicable_level = list(filter(lambda level: (int(level[1]) <= age <= int(level[2])), levels_with_ranges))
level = ""
try:
level = applicable_level[0][0]
except Exception:
print(applicable_level)
print(age)
return level
def random_coords_from_point(lat: float, lon: float, max_distance: float = 1000) -> tuple:
angle = random.random() * 2 * math.pi
offset = random.random() * max_distance
lat_ = lat + math.cos(angle) * offset / M_PER_DEGREE
lon_ = lon + math.sin(angle) * offset / M_PER_DEGREE
return lat_, lon_
def generate_random_city_coords(cities) -> tuple:
city = random.choice(cities)
city_data = city.split(';')
name = city_data[0]
lat = float(city_data[1])
lon = float(city_data[2])
coords = random_coords_from_point(lat, lon)
return name, coords
def decdeg2dms(dd):
mult = -1 if dd < 0 else 1
mnt, sec = divmod(abs(dd) * 3600, 60)
deg, mnt = divmod(mnt, 60)
return mult * deg, mult * mnt, mult * sec
def coords_string(coords: tuple) -> str:
dms_lat = decdeg2dms(abs(coords[0]))
dms_lon = decdeg2dms(abs(coords[1]))
return f"{dms_lat[0]:.0f}Β° {dms_lat[1]:.0f}' {dms_lat[2]:.4f}'' {'N' if coords[0] > 0 else 'S'} {dms_lon[0]:.0f}Β° {dms_lon[1]:.0f}' {dms_lon[2]:.4f}'' {'E' if coords[1] > 0 else 'W'}"