-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_sankey_diagram.py
More file actions
109 lines (95 loc) · 4.52 KB
/
Copy pathgenerate_sankey_diagram.py
File metadata and controls
109 lines (95 loc) · 4.52 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
import os
import pandas as pd
import holoviews as hv
from holoviews import opts
hv.extension('matplotlib')
episoden_colors = [
"#8dd3c7",
"#ffffb3",
"#bebada",
"#fb8072",
"#80b1d3",
"#fdb462",
"#b3de69",
"#fccde5",
"#d9d9d9",
"#bc80bd",
"#ccebc5",
"#ffed6f"
]
strategies = {'follow control flow': "Follow control flow",
'follow data flow': 'Follow data flow',
'configuration': "Program comprehension",
'hotspot': "Program comprehension", 'accept/reject hypothesis': "Scientific strategy",
'scanning': "Inspect source code", 'planning': "Planning",
'follow intuition': "Intuition", 'code reading': "Inspect source code",
'state/test hypothesis': "Scientific strategy",
'bug report': "Program comprehension", 'simulate execution': "Simulation"}
def read_data(path):
df = pd.read_csv(os.path.join(path, "actions-by-participant.csv"))
to_replace = {'Cause-effect chain starts': None,
'Changes location in code/graph because of a method-call': "follow control flow",
'Changes location in code/graph because of a variable': "follow data flow",
'Configuration': "configuration",
'Hotspot': "hotspot",
'Open Codewindow (from Code Window)': None,
'Open Codewindow (from Graph)': None,
'Open Method inside window (click on graph)': None,
'Open Method inside window (click on window)': None,
'P ist lost und braucht Hilfe': None,
'Player Movement': None,
'Reposition Windows': None,
'accept hypothesis': "accept/reject hypothesis",
'browsing/scrolling/scanning': "scanning",
'deducting from prior knowledge': None,
'expresses a plan or series of tasks that they want to do': "planning",
'expresses insight/statement/assumption\nbased on a feeling/experience/intuition': "follow intuition",
'plan successfully executed': None,
'reject hypothesis': "accept/reject hypothesis",
'specific code area, detailed reading': "code reading",
'state & test hypothesis': "state/test hypothesis",
'inducting from code bases': None,
'Bug report': "bug report",
'Close Codewindow': None,
'problem formulation': None,
'browsing/scrolling/scanning\n(attention on code window)': "scanning",
'simulates execution': "simulate execution",
'browsing/scrolling/scanning\n(attention on code window)\n(some expression about source code)': "scanning",
'Cause-effect chain end': None}
df["Action"] = df["Action"].replace(to_replace)
df = df[[True if a else False for a in df["Action"]]]
return df
def plot_sankey(df, out_path):
strategies_actions = [{"source": v, "target": k,
"value": sum(df[df["Action"] == k]["Marker"]) if sum(df[df["Action"] == k]["Marker"]) else 1}
for k, v in strategies.items()]
actions_participant = [{"source": r["Action"], "target": r["Participant"], "value": r["Marker"]} for _, r in
df.iterrows()]
unused = [{"source": action, "target": "unused", "value": 1} for action in
pd.DataFrame(strategies_actions)["target"] if
action not in list(pd.DataFrame(actions_participant)["source"])]
nodes_gray = list(set(strategies.keys())) + list(set(strategies.values()))
nodes_colors = ["P" + str(x) for x in range(1, 13)]
color_mapping = {s: "#d1cdcd" for s in nodes_gray} | {nodes_colors[i]: episoden_colors[i] for i in
range(len(nodes_colors))}
# print(color_mapping)
edges = pd.DataFrame(strategies_actions + actions_participant + unused)
sankey = hv.Sankey(edges)
sankey.opts(
opts.Sankey(
edge_color='target',
cmap=color_mapping,
node_color="index",
label_position='left',
fig_inches=(20, 3),
# node_padding=20,
)
)
hv.save(sankey, os.path.join(out_path, 'sankey_plot_overview.pdf'), fmt='pdf', dpi=300)
return
def gen_sankey():
path = './data/user study'
out_path = './output'
df = read_data(path)
plot_sankey(df, out_path)
return