okbasto2 commited on
Commit
ba50f41
Β·
1 Parent(s): deb381a

feat: simplify state to strictly ONLINE/OFFLINE and display state directly in transitions table

Browse files
Files changed (2) hide show
  1. app.py +11 -15
  2. device_tracker/core/manager.py +4 -4
app.py CHANGED
@@ -145,7 +145,7 @@ def get_whatsapp_status_ui():
145
 
146
 
147
  def get_targets_dataframe():
148
- """Builds a formatted list of rows for the targets table (ONLINE / OFFLINE only)."""
149
  statuses = manager.get_all_status()
150
  rows = []
151
  dropdown_choices = []
@@ -158,21 +158,18 @@ def get_targets_dataframe():
158
 
159
  analysis = item.get("analysis", {})
160
  online_st = analysis.get("online_status", "OFFLINE")
161
- samples = analysis.get("total_samples", 0)
162
 
163
- # Simplified State: STRICTLY ONLINE vs OFFLINE
164
  if online_st == "ONLINE":
165
  state_disp = "🟒 ONLINE"
166
  else:
167
- if samples == 0 and is_running:
168
- state_disp = "βšͺ PROBING..."
169
- else:
170
- state_disp = "πŸ”΄ OFFLINE"
171
 
172
  last_rtt_val = analysis.get("last_rtt_ms", 0.0)
173
  avg_rtt_val = analysis.get("avg_rtt_ms", 0.0)
174
  last_rtt = f"{last_rtt_val:.1f} ms" if last_rtt_val > 0 else "β€”"
175
  avg_rtt = f"{avg_rtt_val:.1f} ms" if avg_rtt_val > 0 else "β€”"
 
176
 
177
  rows.append([f"+{phone}", name, status_badge, state_disp, last_rtt, avg_rtt, samples])
178
  dropdown_choices.append(f"+{phone} ({name})")
@@ -184,7 +181,7 @@ def get_targets_dataframe():
184
 
185
 
186
  def get_transitions_dataframe():
187
- """Fetches recent state transitions with timestamps and duration (ONLINE / OFFLINE only)."""
188
  transitions = list(manager.recent_transitions)
189
 
190
  if not transitions:
@@ -195,20 +192,19 @@ def get_transitions_dataframe():
195
  time_str = t.get("timestamp", "")
196
  phone = t.get("phone_number", "")
197
  name = t.get("target_name", "") or "β€”"
198
- prev_st = t.get("previous_state", "UNKNOWN")
199
  new_st = t.get("new_state", "UNKNOWN")
200
  duration_str = t.get("duration_str") or f"{t.get('duration_seconds', 0):.0f}s"
201
  reason = t.get("reason", "Receipt timing")
202
 
203
- # Format state change arrow
204
  if new_st == "ONLINE":
205
- event_disp = f"πŸ”΄ {prev_st} βž” 🟒 ONLINE"
206
  elif new_st == "OFFLINE":
207
- event_disp = f"🟒 {prev_st} βž” πŸ”΄ OFFLINE"
208
  else:
209
- event_disp = f"{prev_st} βž” {new_st}"
210
 
211
- rows.append([time_str, f"+{phone} ({name})", event_disp, duration_str, reason])
212
 
213
  if not rows:
214
  rows = [["β€”", "No transitions recorded yet", "β€”", "β€”", "β€”"]]
@@ -447,7 +443,7 @@ with gr.Blocks(
447
  gr.Markdown("---")
448
  gr.Markdown("### ⏱ State Transitions & Timestamps History")
449
  transitions_table = gr.Dataframe(
450
- headers=["Timestamp", "Target", "State Transition", "Duration in State", "Telemetry Detail"],
451
  datatype=["str", "str", "str", "str", "str"],
452
  value=get_transitions_dataframe(),
453
  interactive=False,
 
145
 
146
 
147
  def get_targets_dataframe():
148
+ """Builds a formatted list of rows for the targets table (strictly ONLINE / OFFLINE)."""
149
  statuses = manager.get_all_status()
150
  rows = []
151
  dropdown_choices = []
 
158
 
159
  analysis = item.get("analysis", {})
160
  online_st = analysis.get("online_status", "OFFLINE")
 
161
 
162
+ # Strictly ONLINE or OFFLINE (no probing state displayed)
163
  if online_st == "ONLINE":
164
  state_disp = "🟒 ONLINE"
165
  else:
166
+ state_disp = "πŸ”΄ OFFLINE"
 
 
 
167
 
168
  last_rtt_val = analysis.get("last_rtt_ms", 0.0)
169
  avg_rtt_val = analysis.get("avg_rtt_ms", 0.0)
170
  last_rtt = f"{last_rtt_val:.1f} ms" if last_rtt_val > 0 else "β€”"
171
  avg_rtt = f"{avg_rtt_val:.1f} ms" if avg_rtt_val > 0 else "β€”"
172
+ samples = analysis.get("total_samples", 0)
173
 
174
  rows.append([f"+{phone}", name, status_badge, state_disp, last_rtt, avg_rtt, samples])
175
  dropdown_choices.append(f"+{phone} ({name})")
 
181
 
182
 
183
  def get_transitions_dataframe():
184
+ """Fetches recent state transitions with timestamps and duration (directly displaying ONLINE / OFFLINE)."""
185
  transitions = list(manager.recent_transitions)
186
 
187
  if not transitions:
 
192
  time_str = t.get("timestamp", "")
193
  phone = t.get("phone_number", "")
194
  name = t.get("target_name", "") or "β€”"
 
195
  new_st = t.get("new_state", "UNKNOWN")
196
  duration_str = t.get("duration_str") or f"{t.get('duration_seconds', 0):.0f}s"
197
  reason = t.get("reason", "Receipt timing")
198
 
199
+ # Display state directly without arrows
200
  if new_st == "ONLINE":
201
+ state_disp = "🟒 ONLINE"
202
  elif new_st == "OFFLINE":
203
+ state_disp = "πŸ”΄ OFFLINE"
204
  else:
205
+ state_disp = new_st
206
 
207
+ rows.append([time_str, f"+{phone} ({name})", state_disp, duration_str, reason])
208
 
209
  if not rows:
210
  rows = [["β€”", "No transitions recorded yet", "β€”", "β€”", "β€”"]]
 
443
  gr.Markdown("---")
444
  gr.Markdown("### ⏱ State Transitions & Timestamps History")
445
  transitions_table = gr.Dataframe(
446
+ headers=["Timestamp", "Target", "Current State", "Duration in State", "Telemetry Detail"],
447
  datatype=["str", "str", "str", "str", "str"],
448
  value=get_transitions_dataframe(),
449
  interactive=False,
device_tracker/core/manager.py CHANGED
@@ -258,13 +258,13 @@ class TargetManager:
258
  "timestamp": now.strftime("%Y-%m-%d %H:%M:%S"),
259
  "phone_number": clean_number,
260
  "target_name": session.name,
261
- "transition_type": "INITIAL_DETECTION",
262
- "previous_state": "PROBING",
263
  "new_state": curr_online,
264
- "duration_str": "0s",
265
  "duration_seconds": 0.0,
266
  "confidence": 1.0,
267
- "reason": f"First Probe RTT {analysis.last_rtt_ms:.1f}ms" if curr_online == "ONLINE" else "Initial Probe",
268
  })
269
 
270
  async def stop_target(self, phone_number: str) -> bool:
 
258
  "timestamp": now.strftime("%Y-%m-%d %H:%M:%S"),
259
  "phone_number": clean_number,
260
  "target_name": session.name,
261
+ "transition_type": "ONLINE_STATUS",
262
+ "previous_state": "β€”",
263
  "new_state": curr_online,
264
+ "duration_str": "β€”",
265
  "duration_seconds": 0.0,
266
  "confidence": 1.0,
267
+ "reason": f"RTT {analysis.last_rtt_ms:.1f}ms" if curr_online == "ONLINE" else "Receipt timeout",
268
  })
269
 
270
  async def stop_target(self, phone_number: str) -> bool: