-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_server.py
More file actions
executable file
Β·692 lines (591 loc) Β· 25.6 KB
/
demo_server.py
File metadata and controls
executable file
Β·692 lines (591 loc) Β· 25.6 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/usr/bin/env python3
"""
Public Demo Dashboard API
Flask API to serve synthetic demo data for public showcase
"""
from flask import Flask, jsonify, request, send_from_directory
import random
from datetime import datetime, timedelta
import json
app = Flask(__name__, static_folder='.')
# Generate synthetic project data for demo
def generate_demo_projects():
"""Generate synthetic project data for the demo."""
project_names = [
'openclaw-core', 'moltbot-integration', 'ai-automation', 'data-pipeline',
'workflow-engine', 'knowledge-base', 'task-orchestration', 'sync-service'
]
demo_projects = []
for name in project_names:
total_tasks = random.randint(15, 150)
completed_tasks = random.randint(0, total_tasks)
in_progress_tasks = random.randint(0, total_tasks - completed_tasks)
todo_tasks = total_tasks - completed_tasks - in_progress_tasks
demo_projects.append({
'project': name,
'total_tasks': total_tasks,
'completed_tasks': completed_tasks,
'in_progress_tasks': in_progress_tasks,
'todo_tasks': todo_tasks
})
return sorted(demo_projects, key=lambda x: x['total_tasks'], reverse=True)
def generate_demo_project_details(project_name):
"""Generate synthetic project details for demo."""
# Possible values for demo data
statuses = ['completed', 'in-progress', 'todo', 'blocked', 'review']
priorities = ['critical', 'high', 'medium', 'low']
categories = ['development', 'testing', 'documentation', 'research', 'maintenance', 'design']
# Generate random counts
total_tasks = random.randint(10, 50)
# Generate status distribution
status_counts = {}
remaining = total_tasks
for status in statuses[:-1]: # Don't assign all to the last status
if remaining <= 0:
break
count = random.randint(0, min(remaining, int(total_tasks * 0.4)))
status_counts[status] = count
remaining -= count
# Assign remaining to last status
status_counts[statuses[-1]] = remaining
# Generate priority distribution
priority_counts = {}
remaining = total_tasks
for priority in priorities[:-1]:
if remaining <= 0:
break
count = random.randint(0, min(remaining, int(total_tasks * 0.3)))
priority_counts[priority] = count
remaining -= count
priority_counts[priorities[-1]] = remaining
# Generate category distribution
category_counts = {}
remaining = total_tasks
for category in categories[:-1]:
if remaining <= 0:
break
count = random.randint(0, min(remaining, int(total_tasks * 0.3)))
category_counts[category] = count
remaining -= count
category_counts[categories[-1]] = remaining
# Generate recent tasks
recent_tasks = []
for i in range(min(10, total_tasks)):
recent_tasks.append({
'id': random.randint(1000, 9999),
'title': f'Demo task {i+1} for {project_name}',
'status': random.choice(statuses),
'priority': random.choice(priorities),
'category': random.choice(categories),
'created_date': (datetime.now() - timedelta(days=random.randint(0, 30))).strftime('%Y-%m-%d'),
'updated_date': (datetime.now() - timedelta(days=random.randint(0, 14))).strftime('%Y-%m-%d'),
'tags': ['demo', 'showcase', 'example']
})
return {
"project": project_name,
"statusCounts": status_counts,
"priorityCounts": priority_counts,
"categoryCounts": category_counts,
"recentTasks": recent_tasks,
"totalTasks": total_tasks
}
@app.route('/')
def index():
"""Serve a demo landing page."""
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenClaw Demo Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
:root {
--primary-color: #4361ee;
--secondary-color: #3f37c9;
--success-color: #4cc9f0;
--warning-color: #f72585;
--light-bg: #f8f9fa;
--dark-text: #212529;
--border-color: #dee2e6;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f7fb;
color: var(--dark-text);
line-height: 1.6;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
header {
text-align: center;
margin-bottom: 30px;
padding: 20px;
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
h1 {
margin: 0;
font-size: 2.5rem;
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
margin-top: 10px;
}
.intro {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 30px;
text-align: center;
}
.controls {
display: flex;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
align-items: center;
}
select, button {
padding: 10px 15px;
border: 1px solid var(--border-color);
border-radius: 5px;
font-size: 1rem;
}
button {
background-color: var(--primary-color);
color: white;
cursor: pointer;
border: none;
}
button:hover {
background-color: var(--secondary-color);
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.card {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
transition: transform 0.2s;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.card-title {
font-size: 1.2rem;
font-weight: 600;
margin: 0 0 15px 0;
color: var(--primary-color);
border-bottom: 2px solid var(--light-bg);
padding-bottom: 10px;
}
.chart-container {
position: relative;
height: 300px;
margin: 20px 0;
}
.project-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 15px;
}
.project-card {
background: white;
border-radius: 8px;
padding: 15px;
border-left: 4px solid var(--primary-color);
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.project-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.project-name {
font-weight: 600;
font-size: 1.1rem;
color: var(--secondary-color);
}
.task-count {
background: var(--success-color);
color: white;
padding: 3px 8px;
border-radius: 12px;
font-size: 0.9rem;
}
.progress-bar {
width: 100%;
height: 8px;
background-color: #e9ecef;
border-radius: 4px;
overflow: hidden;
margin: 10px 0;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, var(--success-color), var(--primary-color));
border-radius: 4px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-card {
background: white;
padding: 15px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.stat-value {
font-size: 2rem;
font-weight: 700;
color: var(--primary-color);
}
.stat-label {
font-size: 0.9rem;
color: #6c757d;
}
.disclaimer {
background: #fff3cd;
color: #856404;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
border-left: 4px solid #ffc107;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>OpenClaw Demo Dashboard</h1>
<div class="subtitle">Showcasing task management capabilities</div>
</header>
<div class="disclaimer">
<strong>Note:</strong> This is a demonstration system using synthetic data.
The actual OpenClaw system operates independently with real data.
</div>
<div class="intro">
<h2>Welcome to the OpenClaw Demo</h2>
<p>This dashboard showcases the task management capabilities of the OpenClaw system.</p>
<p>All data shown here is synthetic and generated for demonstration purposes only.</p>
</div>
<div class="controls">
<select id="projectSelect">
<option value="">Select a demo project...</option>
</select>
<button onclick="loadProjectData()">Load Project Data</button>
<button onclick="loadAllProjects()">Load All Projects</button>
</div>
<div id="dashboardContent" style="display: none;">
<div class="stats-grid" id="statsGrid">
<!-- Stats will be populated here -->
</div>
<div class="dashboard-grid">
<div class="card">
<h3 class="card-title">Tasks by Status</h3>
<div class="chart-container">
<canvas id="statusChart"></canvas>
</div>
</div>
<div class="card">
<h3 class="card-title">Tasks by Priority</h3>
<div class="chart-container">
<canvas id="priorityChart"></canvas>
</div>
</div>
<div class="card">
<h3 class="card-title">Tasks by Category</h3>
<div class="chart-container">
<canvas id="categoryChart"></canvas>
</div>
</div>
</div>
<div class="card">
<h3 class="card-title">Recent Tasks</h3>
<div id="recentTasksList">
<!-- Recent tasks will be populated here -->
</div>
</div>
</div>
<div id="allProjectsView" style="display: none;">
<h2 class="card-title">All Projects Overview</h2>
<div class="project-list" id="projectListView">
<!-- Project cards will be populated here -->
</div>
</div>
</div>
<script>
// Global variables to hold chart instances
let statusChart = null;
let priorityChart = null;
let categoryChart = null;
// Initialize the dashboard
document.addEventListener('DOMContentLoaded', function() {
initializeDashboard();
});
async function initializeDashboard() {
try {
// Load all projects view by default
await loadAllProjects();
} catch (error) {
console.error('Error initializing dashboard:', error);
}
}
async function loadAllProjects() {
try {
// Fetch demo projects data
const response = await fetch('/api/demo/projects');
const projects = await response.json();
// Populate project selector
populateProjectSelector(projects.map(p => p.project));
// Display all projects
displayAllProjects(projects);
document.getElementById('allProjectsView').style.display = 'block';
document.getElementById('dashboardContent').style.display = 'none';
} catch (error) {
console.error('Error loading all projects:', error);
alert('Error loading projects: ' + error.message);
}
}
function populateProjectSelector(projects) {
const select = document.getElementById('projectSelect');
select.innerHTML = '<option value="">Select a demo project...</option>';
projects.forEach(project => {
const option = document.createElement('option');
option.value = project;
option.textContent = project;
select.appendChild(option);
});
}
async function loadProjectData() {
const selectedProject = document.getElementById('projectSelect').value;
if (!selectedProject) {
alert('Please select a project first');
return;
}
try {
// Fetch demo project details
const response = await fetch('/api/demo/project/' + encodeURIComponent(selectedProject));
const projectData = await response.json();
displayProjectData(projectData);
document.getElementById('dashboardContent').style.display = 'block';
document.getElementById('allProjectsView').style.display = 'none';
} catch (error) {
console.error('Error loading project data:', error);
alert('Error loading project data: ' + error.message);
}
}
async function loadAllProjects() {
try {
// Fetch demo projects data
const response = await fetch('/api/demo/projects');
const projects = await response.json();
// Populate project selector
populateProjectSelector(projects.map(p => p.project));
// Display all projects
displayAllProjects(projects);
document.getElementById('allProjectsView').style.display = 'block';
document.getElementById('dashboardContent').style.display = 'none';
} catch (error) {
console.error('Error loading all projects:', error);
alert('Error loading projects: ' + error.message);
}
}
function displayProjectData(data) {
// Update stats
updateStats([
{ label: 'Total Tasks', value: data.totalTasks },
{ label: 'Status Types', value: Object.keys(data.statusCounts).length },
{ label: 'Priority Levels', value: Object.keys(data.priorityCounts).length },
{ label: 'Categories', value: Object.keys(data.categoryCounts).length }
]);
// Create/update charts
createOrUpdateChart('statusChart', 'bar', 'Tasks by Status', data.statusCounts);
createOrUpdateChart('priorityChart', 'doughnut', 'Tasks by Priority', data.priorityCounts);
createOrUpdateChart('categoryChart', 'bar', 'Tasks by Category', data.categoryCounts);
// Display recent tasks
displayRecentTasks(data.recentTasks);
}
function displayAllProjects(projectsData) {
const container = document.getElementById('projectListView');
container.innerHTML = '';
projectsData.forEach(project => {
const progressPercent = project.completed_tasks > 0 ?
Math.round((project.completed_tasks / project.total_tasks) * 100) : 0;
const projectCard = document.createElement('div');
projectCard.className = 'project-card';
projectCard.innerHTML = `
<div class="project-header">
<div class="project-name">${project.project}</div>
<div class="task-count">${project.total_tasks}</div>
</div>
<div>Total Tasks: ${project.total_tasks}</div>
<div>Completed: ${project.completed_tasks}</div>
<div>In Progress: ${project.in_progress_tasks}</div>
<div>To Do: ${project.todo_tasks}</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${progressPercent}%"></div>
</div>
<div>${progressPercent}% Complete</div>
`;
container.appendChild(projectCard);
});
}
function updateStats(stats) {
const container = document.getElementById('statsGrid');
container.innerHTML = '';
stats.forEach(stat => {
const statCard = document.createElement('div');
statCard.className = 'stat-card';
statCard.innerHTML = `
<div class="stat-value">${stat.value}</div>
<div class="stat-label">${stat.label}</div>
`;
container.appendChild(statCard);
});
}
function createOrUpdateChart(canvasId, chartType, title, dataObj) {
const ctx = document.getElementById(canvasId).getContext('2d');
const labels = Object.keys(dataObj);
const data = Object.values(dataObj);
// Destroy existing chart if it exists
const existingChart = Chart.getChart(canvasId);
if (existingChart) {
existingChart.destroy();
}
const chart = new Chart(ctx, {
type: chartType,
data: {
labels: labels,
datasets: [{
label: title,
data: data,
backgroundColor: [
'rgba(67, 97, 238, 0.7)',
'rgba(76, 201, 240, 0.7)',
'rgba(247, 37, 133, 0.7)',
'rgba(63, 55, 201, 0.7)',
'rgba(118, 89, 171, 0.7)',
'rgba(25, 118, 210, 0.7)'
],
borderColor: [
'rgba(67, 97, 238, 1)',
'rgba(76, 201, 240, 1)',
'rgba(247, 37, 133, 1)',
'rgba(63, 55, 201, 1)',
'rgba(118, 89, 171, 1)',
'rgba(25, 118, 210, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: title
},
legend: {
display: chartType !== 'doughnut'
}
},
scales: chartType === 'bar' ? {
y: {
beginAtZero: true,
ticks: {
precision: 0
}
}
} : {}
}
});
// Store chart reference based on chart type
if (canvasId === 'statusChart') statusChart = chart;
else if (canvasId === 'priorityChart') priorityChart = chart;
else if (canvasId === 'categoryChart') categoryChart = chart;
}
function displayRecentTasks(tasks) {
const container = document.getElementById('recentTasksList');
container.innerHTML = '';
if (tasks.length === 0) {
container.innerHTML = '<p>No recent tasks found.</p>';
return;
}
const list = document.createElement('div');
list.style.display = 'grid';
list.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))';
list.style.gap = '10px';
tasks.forEach(task => {
const taskEl = document.createElement('div');
taskEl.style.borderBottom = '1px solid #eee';
taskEl.style.padding = '10px 0';
taskEl.style.marginBottom = '10px';
taskEl.innerHTML = `
<div style="font-weight: bold;">${task.title}</div>
<div style="font-size: 0.9em; color: #666;">
ID: ${task.id} | Status: ${task.status} | Priority: ${task.priority} | Category: ${task.category}
</div>
<div style="font-size: 0.8em; color: #888;">
Created: ${task.created_date} | Updated: ${task.updated_date}
</div>
`;
list.appendChild(taskEl);
});
container.appendChild(list);
}
</script>
</body>
</html>
"""
return html_content
@app.route('/api/demo/projects')
def get_demo_projects():
"""Get synthetic project data for demo."""
try:
projects = generate_demo_projects()
return jsonify(projects)
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/api/demo/project/<project_name>')
def get_demo_project_details(project_name):
"""Get synthetic project details for demo."""
try:
project_details = generate_demo_project_details(project_name)
return jsonify(project_details)
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/demo')
def demo_page():
"""Serve the demo dashboard page."""
return index()
def main():
print("π Starting OpenClaw Public Demo Server...")
print("π Demo available at: http://localhost:5001/demo")
print("π This is a completely isolated demo system")
print("π No connection to main OpenClaw system")
app.run(debug=True, host='0.0.0.0', port=5001)
if __name__ == '__main__':
main()