Skip to content

Commit

Permalink
fix: thelook_ecommerce - adds age field for users (GoogleCloudPlatfor…
Browse files Browse the repository at this point in the history
  • Loading branch information
adlersantos authored Mar 2, 2022
1 parent a1323d1 commit f0806c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def generate_locations() -> typing.List[str]:
SECONDS_IN_MINUTE = 60
MINUTES_IN_HOUR = 60
MINUTES_IN_DAY = 1440
MIN_AGE = 12
MAX_AGE = 71

products = generate_products()
logging.info("generating products helper dict")
Expand Down Expand Up @@ -393,6 +395,7 @@ class Users(DataUtil):
first_name: str = dataclasses.field(init=False)
last_name: str = dataclasses.field(init=False)
email: str = dataclasses.field(init=False)
age: int = dataclasses.field(init=False)
gender: str = dataclasses.field(init=False)
state: str = dataclasses.field(init=False)
street_address: str = dataclasses.field(init=False)
Expand Down Expand Up @@ -428,6 +431,7 @@ def __post_init__(self):
self.latitude = address.latitude
self.longitude = address.longitude
self.email = f"{self.first_name.lower()}{self.last_name.lower()}@{fake.safe_domain_name()}"
self.age = random.randrange(MIN_AGE, MAX_AGE)
# weight newer users/orders
choice = random.choices([0, 1], weights=[0.975, 0.025])[0]
if choice == 0:
Expand All @@ -446,7 +450,7 @@ def __post_init__(self):
orders.append(dataclasses.asdict(Order(user=self)))

def __str__(self):
return f"{self.id}, {self.first_name}, {self.last_name}, {self.email}, {self.gender}, {self.state}, {self.street_address}, {self.postal_code}, {self.city}, {self.traffic_source}, {self.created_at}"
return f"{self.id}, {self.first_name}, {self.last_name}, {self.email}, {self.age}, {self.gender}, {self.state}, {self.street_address}, {self.postal_code}, {self.city}, {self.traffic_source}, {self.created_at}"


@dataclasses.dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ dag:
- name: "email"
type: "STRING"
mode: "NULLABLE"
- name: "age"
type: "INTEGER"
mode: "NULLABLE"
- name: "gender"
type: "STRING"
mode: "NULLABLE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
{"name": "first_name", "type": "STRING", "mode": "NULLABLE"},
{"name": "last_name", "type": "STRING", "mode": "NULLABLE"},
{"name": "email", "type": "STRING", "mode": "NULLABLE"},
{"name": "age", "type": "INTEGER", "mode": "NULLABLE"},
{"name": "gender", "type": "STRING", "mode": "NULLABLE"},
{"name": "state", "type": "STRING", "mode": "NULLABLE"},
{"name": "street_address", "type": "STRING", "mode": "NULLABLE"},
Expand Down

0 comments on commit f0806c6

Please sign in to comment.