forked from fecgov/openFEC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.py
68 lines (53 loc) · 2.05 KB
/
flow.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
57
58
59
60
61
62
63
64
65
66
67
68
import os
import networkx as nx
here, _ = os.path.split(__file__)
home = os.path.join(here, os.pardir)
script_path = os.path.join(home, 'data', 'sql_updates')
def get_graph():
"""Build a `DiGraph` that captures dependencies between database migration
tasks. Each node represents a migration script, and each edge represents
a dependency between tasks. Tasks can be ordered using topological sort.
"""
graph = nx.DiGraph()
for path in os.listdir(script_path):
name, ext = os.path.splitext(path)
if ext == '.sql':
graph.add_node(name)
graph.add_edge('candidate_history', 'candidate_detail')
graph.add_edge('candidate_detail', 'candidate_election')
graph.add_edges_from([
('candidate_history', 'candidate_history_latest'),
('candidate_election', 'candidate_history_latest')
])
graph.add_edge('committee_history', 'committee_detail')
graph.add_edges_from([
('candidate_history', 'filings'),
('committee_history', 'filings'),
])
graph.add_edges_from([
('candidate_history', 'candidate_flags'),
('candidate_aggregates', 'candidate_flags'),
])
graph.add_edges_from([
('totals_house_senate', 'totals_combined'),
('totals_presidential', 'totals_combined'),
('totals_pac_party', 'totals_combined'),
])
graph.add_edges_from([
('committee_detail', 'committee_fulltext'),
('totals_combined', 'committee_fulltext'),
])
graph.add_edge('committee_detail', 'totals_party')
graph.add_edge('committee_detail', 'totals_pac')
graph.add_edges_from([
('candidate_detail', 'candidate_fulltext'),
('totals_combined', 'candidate_fulltext'),
])
graph.add_edge('totals_combined', 'sched_a_by_size_merged')
graph.add_edges_from([
('totals_house_senate', 'candidate_aggregates'),
('totals_presidential', 'candidate_aggregates'),
('candidate_election', 'candidate_aggregates'),
('cand_cmte_linkage', 'candidate_aggregates'),
])
return graph