-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathas_sensordata.py
96 lines (81 loc) · 3.43 KB
/
as_sensordata.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
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
"""Helper methods for converting event data from other sources
to the DevEventTracker format. Typically you would do this to allow
interpersing different event types (e.g. Submissions, method
modifications, etc.) into a larger set of DevEventTracker events.
"""
import pandas as pd
import load_datasets
def method_mods_to_edits(df=None, filepath=None, testonly=False):
"""Convert method modification events, as emitted by the
project at https://github.com/ayaankazerouni/incremental-testing,
to the sensordata format.
Args:
df (pd.DataFrame): A dataframe of method modification events
filepath (str): Path to a CSV file containing method modification
events
testonly (bool): Only convert and return changes to test methods?
Returns:
The same DataFrame, possibly with only test changes, with columns
in the sensordata format (see :attr:`utils.DEFAULT_FIELDNAMES`).
"""
if df is None and filepath is None:
raise ValueError('Either df or filepath must be specified.')
if df is None:
df = pd.read_csv(filepath)
if testonly:
df = df[df['Type'] == 'MODIFY_TESTING_METHOD']
df = df.apply(__sensordata_from_method_mod, axis=1) \
.drop_duplicates(subset=['userName', 'assignment', 'time',
'Class-Name', 'Unit-Name', 'edit_size'])
return df
def __sensordata_from_method_mod(mod):
modtype = mod['Type']
method_id = mod['methodId']
on_test_case = 0
if modtype == 'MODIFY_TESTING_METHOD':
on_test_case = 1
method_id = mod['testMethodId']
class_name = method_id.split(',')[0]
method_name = method_id.split(',')[1]
return pd.Series({
'userName': mod['userName'],
'Type': 'Edit',
'Subtype': 'Commit',
'Unit-Name': method_name,
'Unit-Type': 'Method',
'Class-Name': class_name,
'studentProjectUuid': mod['project'],
'commitHash': mod['commitHash'],
'edit_size': mod['modsToMethod'],
'assignment': mod['assignment'],
'time': mod['time'],
'onTestCase': on_test_case
})
def submissions_to_sensordata(df=None, submissionpath=None, **kwargs):
"""Convert submissions to the DevEventTracker format.
Args:
df (pd.DataFrame): A DataFrame of submissions, as returned
by :meth:`load_datasets.load_submission_data`
submissionpath (str): A path to a CSV containing submission information
kwargs (dict): Other keyword arguments passed to :meth:`load_datasets.load_submission_data`
Returns:
The submissions in the same format as DevEventTracker data
"""
if df is None and submissionpath is None:
raise ValueError('Either df or submissionpath must be specified.')
if df is None:
onlyfinal = kwargs.get('onlyfinal', True)
pluscols = kwargs.get('pluscols', [])
df = load_datasets.load_submission_data(webcat_path=submissionpath, onlyfinal=onlyfinal,
pluscols=pluscols)
return df.reset_index().apply(__sensordata_from_sub, axis=1)
def __sensordata_from_sub(sub):
return pd.Series({
'userName': sub['userName'],
'Type': 'Submission',
'Subtype': sub['submissionNo'],
'assignment': sub['assignment'],
'time': sub['submissionTimeRaw'],
'score': sub['score'],
'elementsCovered': sub['elementsCovered']
})