Created
December 22, 2021 03:23
-
-
Save atroche/2b36dcc25dc111cc193ca46906b8bf23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
data = json.loads(open("segs.json").read())['data'] | |
# print(data) | |
# input | |
# { | |
# "data": { | |
# "study": { | |
# "id": "3bf069b7-f39f-4104-aec5-9765d892553a", | |
# "channelGroups": [ | |
# { | |
# "id": "de5eb9d3-a1b8-47e0-b6f8-f17d31baba69", | |
# "name": "ECG", | |
# "segments": [ | |
# { | |
# "id": "7fa13425-f261-43a9-8e86-708f42eee5ac", | |
# "startTime": 1639710291106.649, | |
# "duration": 3736 | |
# }, | |
eeg_chgrp_id = "7205d802-fae0-4555-8728-62752068e928" | |
ecg_chgrp_id = "de5eb9d3-a1b8-47e0-b6f8-f17d31baba69" | |
chgrp_to_segs_map = dict([(chgrp['id'], chgrp['segments']) for chgrp in data['study']['channelGroups']]) | |
# desired output | |
# editStudyChannelGroupSegments( | |
# studyId: "3bf069b7-f39f-4104-aec5-9765d892553a", | |
# channelGroupId: "de5eb9d3-a1b8-47e0-b6f8-f17d31baba69", | |
# segments: [ | |
# {id: "7fa13425-f261-43a9-8e86-708f42eee5ac", | |
# startTime: 1639710291106.649, | |
# duration: 3736, | |
# } | |
# ] | |
# ) | |
def stringify_seg(seg): | |
return "{" + f"""id: "{seg['id']}", startTime: {seg['startTime']}, duration: {seg['duration']}""" + "}" | |
def make_mutation(chgrp_id, segments): | |
fixed_segments = [] | |
for seg in segments: | |
if seg['duration'] < 10000: | |
seg['duration'] = seg['duration'] * 1000 | |
fixed_segments.append(seg) | |
segments_str = "[" + ",".join([stringify_seg(seg) for seg in fixed_segments]) + "]" | |
output = f""" | |
editStudyChannelGroupSegments( | |
studyId: "3bf069b7-f39f-4104-aec5-9765d892553a", | |
channelGroupId: "{chgrp_id}", | |
segments: {segments_str} | |
) | |
""" | |
return output + "{ id }" | |
# print(make_mutation(eeg_chgrp_id, chgrp_to_segs_map[eeg_chgrp_id])) | |
print(make_mutation(ecg_chgrp_id, chgrp_to_segs_map[ecg_chgrp_id])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment