-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebsocket_functions.py
130 lines (110 loc) · 3.92 KB
/
websocket_functions.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
def send_message(group_name, message):
"""
General function to send a WS message
@param group_name: Channel dest to send te message
@param message: Message to send
"""
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(group_name, {
"type": "send_message",
"message": message
})
def send_update_experiments_command(user_id: int):
"""
Sends a message indicating that an Experiment's state update has occurred
@param user_id: Experiment's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_experiments'
}
send_message(user_group_name, message)
def send_update_cgds_studies_command():
"""
Sends a message indicating that an CGDSStudy's state update has occurred
"""
user_group_name = "admin_notifications"
message = {
'command': 'update_cgds_studies'
}
send_message(user_group_name, message)
def send_update_biomarkers_command(user_id: int):
"""
Sends a message indicating that an Biomarker's state update has occurred
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_biomarkers'
}
send_message(user_group_name, message)
def send_update_user_file_command(user_id: int):
"""
Sends a message indicating that an user file's state update has occurred
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_user_files'
}
send_message(user_group_name, message)
def send_update_stat_validations_command(user_id: int):
"""
Sends a message indicating that an StatisticalValidation state update has occurred
@param user_id: StatisticalValidation's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_statistical_validations'
}
send_message(user_group_name, message)
def send_update_trained_models_command(user_id: int):
"""
Sends a message indicating that a TrainedModel state update has occurred
@param user_id: TrainedModel's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_trained_models'
}
send_message(user_group_name, message)
def send_update_prediction_experiment_command(user_id: int):
"""
Sends a message indicating that a InferenceExperiment state update has occurred
@param user_id: InferenceExperiment's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_prediction_experiment'
}
send_message(user_group_name, message)
def send_update_cluster_label_set_command(user_id: int):
"""
Sends a message indicating that a ClusterLabelsSet state update has occurred
@param user_id: ClusterLabelsSet's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_cluster_labels_sets'
}
send_message(user_group_name, message)
def send_update_institutions_command(user_id: int):
"""
Sends a message indicating that a Institution state update has occurred
@param user_id: Institution's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_institutions'
}
send_message(user_group_name, message)
def send_update_user_for_institution_command(user_id: int):
"""
Sends a message indicating that a Institution_user state update has occurred
@param user_id: Institution's user's id to send the WS message
"""
user_group_name = f'notifications_{user_id}'
message = {
'command': 'update_user_for_institution'
}
send_message(user_group_name, message)