-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunion_demo.py
More file actions
65 lines (47 loc) · 2.32 KB
/
Copy pathunion_demo.py
File metadata and controls
65 lines (47 loc) · 2.32 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
import coolNewLanguage.src as hilt
import pandas as pd
tool = hilt.Tool('UnionRegistrations')
tool.tables['University Roster'] = pd.DataFrame(
columns=['Name', 'Email', 'Grad Year'])
tool.tables['Union Roster'] = pd.DataFrame(
columns=['Name', 'Email', 'Grad Year'])
def file_upload():
file_path = hilt.FileUploadComponent(
expected_ext="csv", label="Input a CSV file", replace_existing=True)
name_input = hilt.UserInputComponent(str, "Name your CSV file: ")
if tool.user_input_received():
hilt.results.show_results((file_path.value, "Uploaded file path: "))
df = pd.read_csv(file_path.value)
tool.tables[name_input.value] = df
tool.add_stage('File Upload', file_upload)
def extend_roster():
roster_selector = hilt.SelectorComponent(
options=['University Roster', 'Union Roster'], label='Choose a roster to extend:')
name_col = hilt.ColumnSelectorComponent(
"Choose the column with names:")
email_col = hilt.ColumnSelectorComponent(
"Choose the column with emails:")
grad_year_col = hilt.ColumnSelectorComponent(
"Choose the column with grad years:")
if tool.user_input_received():
roster_name = roster_selector.value
names, emails, grad_years = name_col.value, email_col.value, grad_year_col.value
new_rows = pd.DataFrame({'Name': names.to_numpy().flatten(),
'Email': emails.to_numpy().flatten(),
'Grad Year': grad_years.to_numpy().flatten()})
tool.tables[roster_name] = pd.concat(
[tool.tables[roster_name], new_rows], ignore_index=True)
hilt.approvals.get_user_approvals()
hilt.results.show_results(
(tool.tables[roster_name], "Extended roster: "))
tool.add_stage('Extend Roster', extend_roster)
def compute_matches():
hilt.SubmitComponent("Compute Matches")
if tool.user_input_received():
year_email_matches = tool.tables['University Roster'].merge(tool.tables['Union Roster'], on=[
'Email', 'Grad Year'], how='inner', suffixes=['_university', '_union'])
tool.tables['Matches'] = year_email_matches
hilt.approvals.get_user_approvals()
hilt.results.show_results((tool.tables['Matches'], "Matches: "))
tool.add_stage('Compute Matches', compute_matches)
tool.run()