Koddenbrock commited on
Commit
64877f4
·
1 Parent(s): 645c1d8

enhance delete-session functionality to optionally keep trial clicks

Browse files
Files changed (2) hide show
  1. manage_results.sh +32 -5
  2. server.js +8 -3
manage_results.sh CHANGED
@@ -20,10 +20,15 @@
20
  # real participants. Name is matched exactly.
21
  # Example: ./manage_results.sh delete-user "Mario"
22
  #
23
- # delete-session <id> Remove one specific session (and all its trial clicks)
24
- # by session UUID. Find the ID in a downloaded JSON file
25
- # under sessions[].session_id or trials[].session_id.
 
 
 
 
26
  # Example: ./manage_results.sh delete-session "3f2a1b…"
 
27
  #
28
  # PREREQUISITES
29
  # A .env file in the same directory as this script containing:
@@ -121,15 +126,37 @@ print(f\"Removed {d.get('removedSessions',0)} session(s) and {d.get('removedTria
121
 
122
  elif [[ "$cmd" == "delete-session" ]]; then
123
  session_id="${2:-}"
 
 
124
  if [[ -z "$session_id" ]]; then
125
  read -rp "Session ID to delete: " session_id
126
  fi
127
- read -rp "Delete session \"$session_id\" and all its trials? Type YES to confirm: " confirm
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  if [[ "$confirm" != "YES" ]]; then echo "Aborted."; exit 0; fi
 
129
  result=$(curl -sf -X POST \
130
  "${auth_headers[@]}" \
131
  -H "Content-Type: application/json" \
132
- -d "{\"sessionId\": \"$session_id\"}" \
133
  "$HOST/api/admin/clear-session")
134
  echo "$result" | python3 -c "
135
  import sys, json
 
20
  # real participants. Name is matched exactly.
21
  # Example: ./manage_results.sh delete-user "Mario"
22
  #
23
+ # delete-session <id> Remove one specific session by session UUID.
24
+ # Find the ID in a downloaded JSON file under
25
+ # sessions[].session_id or trials[].session_id.
26
+ # Prompts whether to also delete the raw trial clicks
27
+ # for that session (default: yes).
28
+ # --keep-trials Keep the trial clicks, remove only
29
+ # the session summary entry.
30
  # Example: ./manage_results.sh delete-session "3f2a1b…"
31
+ # Example: ./manage_results.sh delete-session "3f2a1b…" --keep-trials
32
  #
33
  # PREREQUISITES
34
  # A .env file in the same directory as this script containing:
 
126
 
127
  elif [[ "$cmd" == "delete-session" ]]; then
128
  session_id="${2:-}"
129
+ flag="${3:-}"
130
+
131
  if [[ -z "$session_id" ]]; then
132
  read -rp "Session ID to delete: " session_id
133
  fi
134
+
135
+ # Resolve --keep-trials flag (can be passed as arg or answered interactively)
136
+ if [[ "$flag" == "--keep-trials" ]]; then
137
+ delete_trials=false
138
+ else
139
+ read -rp "Also delete the raw trial clicks for this session? [Y/n] " trials_ans
140
+ if [[ "$trials_ans" =~ ^[Nn] ]]; then
141
+ delete_trials=false
142
+ else
143
+ delete_trials=true
144
+ fi
145
+ fi
146
+
147
+ if [[ "$delete_trials" == "true" ]]; then
148
+ what="session summary and all its trial clicks"
149
+ else
150
+ what="session summary only (trial clicks will be kept)"
151
+ fi
152
+
153
+ read -rp "Delete $what for \"$session_id\"? Type YES to confirm: " confirm
154
  if [[ "$confirm" != "YES" ]]; then echo "Aborted."; exit 0; fi
155
+
156
  result=$(curl -sf -X POST \
157
  "${auth_headers[@]}" \
158
  -H "Content-Type: application/json" \
159
+ -d "{\"sessionId\": \"$session_id\", \"deleteTrials\": $delete_trials}" \
160
  "$HOST/api/admin/clear-session")
161
  echo "$result" | python3 -c "
162
  import sys, json
server.js CHANGED
@@ -155,15 +155,20 @@ app.post('/api/admin/clear-user', adminAuth, (req, res) => {
155
  });
156
  });
157
 
158
- // POST /api/admin/clear-session — remove one session and its trials by session_id (admin only)
 
 
 
159
  app.post('/api/admin/clear-session', adminAuth, (req, res) => {
160
- const { sessionId } = req.body;
161
  if (!sessionId) return res.status(400).json({ error: 'sessionId required' });
162
  const data = readData();
163
  const sessionsBefore = data.sessions.length;
164
  const trialsBefore = data.trials.length;
165
  data.sessions = data.sessions.filter(s => s.session_id !== sessionId);
166
- data.trials = data.trials.filter(t => t.session_id !== sessionId);
 
 
167
  writeData(data);
168
  res.json({
169
  ok: true,
 
155
  });
156
  });
157
 
158
+ // POST /api/admin/clear-session — remove one session by session_id (admin only)
159
+ // Body: { sessionId, deleteTrials: true|false }
160
+ // deleteTrials=true → remove the session summary AND all its trial clicks
161
+ // deleteTrials=false → remove only the session summary; keep the raw trial clicks
162
  app.post('/api/admin/clear-session', adminAuth, (req, res) => {
163
+ const { sessionId, deleteTrials = true } = req.body;
164
  if (!sessionId) return res.status(400).json({ error: 'sessionId required' });
165
  const data = readData();
166
  const sessionsBefore = data.sessions.length;
167
  const trialsBefore = data.trials.length;
168
  data.sessions = data.sessions.filter(s => s.session_id !== sessionId);
169
+ if (deleteTrials) {
170
+ data.trials = data.trials.filter(t => t.session_id !== sessionId);
171
+ }
172
  writeData(data);
173
  res.json({
174
  ok: true,