-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.py
56 lines (40 loc) · 1.9 KB
/
playground.py
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
import datetime
def parse_expenses(expense_string):
"""Parse the list of expenses and return the list of triples (date, value, currency).
Ignore lines starting with #.
Parse the date using datetime.
Example expenses string:
2016-01-02 -34.01 USD
2016-01-03 2.59 DKK
2016-01-03 -2.72 EUR
"""
expenses = []
for line in expense_string.splitlines():
if line.startswith('#'):
continue
date, value, currency = line.split()
date = datetime.datetime.strptime(date, '%Y-%m-%d')
value = float(value)
expenses.append((date, value, currency))
return expenses
def over_sixty(date):
"""if else statement to check if value is more than 60 days old. If it is, return True, else return False"""
if date < datetime.datetime.now() - datetime.timedelta(days=60):
return True
else:
return False
"""if else statement to check if value is more than 60 days old. If it is, return True, else return False"""
"""Create a new datapoint which will indicate whether a candidate has updated their data
in the last 60 days or not. This will be used to filter out candidates who have not updated
their data in the last 60 days.
"""
"""Create a new COLUMN in the table called 'OwnDate' which will
indicate whether a candidate has updated their data in the last 60 days or not.
"""
def add_updated_cv_from_sixty_days(NC_AssociateInbox_table:str):
query_updated_cv = f”””select OwnDate from {TARGET_SCHEMA}.{NC_AssociateInbox_table}"""
df = spark.sql(query_updated_cv)
df = df.withColumn(“UpdateData”), when(df.”UpdateData”.isNull(), “No").otherwise(“Yes”)) # datediff(df.”UpdateData”, current_timestamp()) > 60)
df_add_regulated
# when(date_diff(df.”UpdateData”, current_timestamp()) > 60, “No”).otherwise(“Yes”))
# don't forget to import date_diff from pyspark.sql.functions