forked from LumenTix-HQ/lumentix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo-scheduling-optimization.js
More file actions
480 lines (391 loc) · 17.3 KB
/
Copy pathdemo-scheduling-optimization.js
File metadata and controls
480 lines (391 loc) · 17.3 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
#!/usr/bin/env node
// Simple demonstration of AI-powered event scheduling optimization
// This script shows the core concepts without requiring the full backend setup
const { EventCategory } = {
EventCategory: {
CONFERENCE: 'CONFERENCE',
WORKSHOP: 'WORKSHOP',
NETWORKING: 'NETWORKING',
CONCERT: 'CONCERT',
SPORTS: 'SPORTS',
OTHER: 'OTHER'
}
};
class SchedulingOptimizationDemo {
constructor() {
this.historicalData = this.generateMockHistoricalData();
}
generateMockHistoricalData() {
const data = [];
const categories = Object.values(EventCategory);
const locations = ['San Francisco', 'New York', 'Austin', 'Seattle', 'Boston'];
// Generate 100 mock historical events
for (let i = 0; i < 100; i++) {
const startDate = new Date(2024, Math.floor(Math.random() * 12), Math.floor(Math.random() * 28) + 1);
data.push({
id: i + 1,
category: categories[Math.floor(Math.random() * categories.length)],
location: locations[Math.floor(Math.random() * locations.length)],
startDate,
endDate: new Date(startDate.getTime() + (2 + Math.random() * 6) * 60 * 60 * 1000),
ticketsSold: Math.floor(Math.random() * 200) + 20,
revenue: Math.floor(Math.random() * 10000) + 1000,
maxAttendees: Math.floor(Math.random() * 300) + 50
});
}
return data;
}
analyzeOptimalTiming(category, location, duration, targetAudience) {
console.log('\n🤖 AI-Powered Event Scheduling Analysis');
console.log('=' .repeat(50));
console.log(`Category: ${category}`);
console.log(`Location: ${location}`);
console.log(`Duration: ${duration} hours`);
console.log(`Target Audience: ${targetAudience || 'General'}`);
// Analyze historical data
const relevantEvents = this.historicalData.filter(event =>
event.category === category && event.location === location
);
console.log(`\n📊 Historical Data Analysis:`);
console.log(`- Found ${relevantEvents.length} similar events`);
// Seasonal analysis
const seasonalPatterns = this.analyzeSeasonalPatterns(relevantEvents);
console.log(`- Best performing month: ${this.getMonthName(seasonalPatterns.bestMonth)}`);
console.log(`- Seasonal score: ${(seasonalPatterns.score * 100).toFixed(1)}%`);
// Competition analysis
const competitionAnalysis = this.analyzeCompetition(category, location);
console.log(`- Competition level: ${competitionAnalysis.level}`);
console.log(`- Competition score: ${(competitionAnalysis.score * 100).toFixed(1)}%`);
// Demographic analysis
const demographicInsights = this.analyzeDemographicFactors(targetAudience);
console.log(`- Demographic optimization score: ${(demographicInsights.score * 100).toFixed(1)}%`);
// Calculate optimal timing
const optimalDate = this.calculateOptimalDate(seasonalPatterns, demographicInsights, duration);
const confidence = this.calculateConfidence(relevantEvents.length, seasonalPatterns.consistency);
console.log(`\n🎯 Recommended Optimal Timing:`);
console.log(`- Start Date: ${optimalDate.start.toLocaleDateString('en-US', {
weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'
})}`);
console.log(`- End Date: ${optimalDate.end.toLocaleDateString('en-US', {
weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'
})}`);
console.log(`- Confidence Level: ${(confidence * 100).toFixed(1)}%`);
// Generate reasoning
const reasoning = this.generateReasoningExplanation(seasonalPatterns, competitionAnalysis, demographicInsights);
console.log(`\n💡 AI Reasoning:`);
reasoning.forEach((reason, index) => {
console.log(` ${index + 1}. ${reason}`);
});
return {
recommendedStartDate: optimalDate.start,
recommendedEndDate: optimalDate.end,
confidence,
factors: {
seasonalScore: seasonalPatterns.score,
competitionScore: competitionAnalysis.score,
demographicScore: demographicInsights.score,
historicalPerformance: this.calculateHistoricalScore(relevantEvents)
},
reasoning
};
}
analyzeSeasonalPatterns(historicalData) {
const monthlyPerformance = new Map();
historicalData.forEach(event => {
const month = event.startDate.getMonth();
const existing = monthlyPerformance.get(month) || { attendance: 0, revenue: 0, count: 0 };
existing.attendance += event.ticketsSold;
existing.revenue += event.revenue;
existing.count += 1;
monthlyPerformance.set(month, existing);
});
const monthlyAverages = Array.from(monthlyPerformance.entries()).map(([month, data]) => ({
month,
avgAttendance: data.count > 0 ? data.attendance / data.count : 0,
avgRevenue: data.count > 0 ? data.revenue / data.count : 0,
}));
if (monthlyAverages.length === 0) {
return { bestMonth: 5, score: 0.5, consistency: 0.5 }; // Default to June
}
const bestMonth = monthlyAverages.reduce((best, current) =>
current.avgAttendance > best.avgAttendance ? current : best
);
const maxAttendance = Math.max(...monthlyAverages.map(m => m.avgAttendance));
const consistency = this.calculateSeasonalConsistency(monthlyAverages);
return {
bestMonth: bestMonth.month,
score: maxAttendance > 0 ? bestMonth.avgAttendance / maxAttendance : 0.5,
consistency
};
}
analyzeCompetition(category, location) {
// Simulate competition analysis
const competingEvents = Math.floor(Math.random() * 8); // 0-7 competing events
const level = competingEvents < 2 ? 'low' : competingEvents < 5 ? 'medium' : 'high';
const score = competingEvents < 2 ? 1.0 : competingEvents < 5 ? 0.7 : 0.4;
return { competingEvents, level, score, dataQuality: 0.8 };
}
analyzeDemographicFactors(targetAudience) {
const demographicScores = {
'young-adults': { weekends: 1.2, evenings: 1.3, score: 0.9 },
'families': { weekends: 1.4, afternoons: 1.2, score: 0.8 },
'professionals': { weekdays: 1.1, evenings: 1.2, score: 0.85 },
'seniors': { weekdays: 1.2, mornings: 1.3, score: 0.7 },
};
const profile = demographicScores[targetAudience] || { weekends: 1.0, evenings: 1.0, score: 0.75 };
return { targetAudience, preferences: profile, score: profile.score };
}
calculateOptimalDate(seasonalPatterns, demographicInsights, duration) {
const now = new Date();
const optimalMonth = seasonalPatterns.bestMonth;
// Find next occurrence of optimal month
let targetDate = new Date(now.getFullYear(), optimalMonth, 15, 18, 0); // Default to 6 PM
if (targetDate < now) {
targetDate.setFullYear(targetDate.getFullYear() + 1);
}
// Adjust for demographic preferences
if (demographicInsights.preferences && demographicInsights.preferences.weekends > 1.1) {
// Prefer weekends
while (targetDate.getDay() !== 6) { // Saturday
targetDate.setDate(targetDate.getDate() + 1);
}
}
const endDate = new Date(targetDate.getTime() + duration * 60 * 60 * 1000);
return { start: targetDate, end: endDate };
}
calculateConfidence(dataPoints, seasonalConsistency) {
const dataConfidence = Math.min(dataPoints / 20, 1.0);
return (dataConfidence + seasonalConsistency + 0.8) / 3; // 0.8 for competition data quality
}
calculateSeasonalConsistency(monthlyAverages) {
if (monthlyAverages.length < 2) return 0.5;
const attendances = monthlyAverages.map(m => m.avgAttendance);
const mean = attendances.reduce((sum, val) => sum + val, 0) / attendances.length;
const variance = attendances.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / attendances.length;
const stdDev = Math.sqrt(variance);
return Math.max(0, 1 - (stdDev / (mean || 1)));
}
calculateHistoricalScore(historicalData) {
if (historicalData.length === 0) return 0.5;
const avgAttendance = historicalData.reduce((sum, event) => sum + event.ticketsSold, 0) / historicalData.length;
const avgRevenue = historicalData.reduce((sum, event) => sum + event.revenue, 0) / historicalData.length;
return Math.min((avgAttendance / 100 + avgRevenue / 1000) / 2, 1.0);
}
generateReasoningExplanation(seasonalPatterns, competitionAnalysis, demographicInsights) {
const reasons = [];
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
reasons.push(`${monthNames[seasonalPatterns.bestMonth]} shows highest historical attendance for this category`);
if (competitionAnalysis.level === 'low') {
reasons.push('Low competition period identified - optimal market window');
} else if (competitionAnalysis.level === 'high') {
reasons.push('High competition detected - consider alternative dates for better performance');
} else {
reasons.push('Moderate competition level - good timing with proper marketing');
}
if (demographicInsights.targetAudience) {
reasons.push(`Timing optimized for ${demographicInsights.targetAudience} preferences and availability`);
}
if (seasonalPatterns.score > 0.8) {
reasons.push('Strong seasonal performance indicators support this timing');
}
return reasons;
}
getMonthName(monthIndex) {
const months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
return months[monthIndex];
}
suggestEventSchedule(category, location, duration, dateRange) {
console.log('\n📅 Event Schedule Suggestions');
console.log('=' .repeat(50));
const suggestions = [];
const current = new Date(dateRange.start);
const endRange = new Date(dateRange.end);
// Generate 5 suggestions within the date range
for (let i = 0; i < 5 && current <= endRange; i++) {
const timeSlot = {
startDate: new Date(current),
endDate: new Date(current.getTime() + duration * 60 * 60 * 1000)
};
const analysis = this.analyzeTimeSlot(timeSlot, category, location);
suggestions.push({
timeSlot,
expectedAttendance: analysis.expectedAttendance,
revenueProjection: analysis.revenueProjection,
competitionLevel: analysis.competitionLevel,
seasonalFactor: analysis.seasonalFactor,
confidence: analysis.confidence
});
// Move to next week
current.setDate(current.getDate() + 7);
}
// Sort by confidence
suggestions.sort((a, b) => b.confidence - a.confidence);
console.log('\nTop Schedule Recommendations:');
suggestions.forEach((suggestion, index) => {
console.log(`\n${index + 1}. ${suggestion.timeSlot.startDate.toLocaleDateString('en-US', {
weekday: 'long', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'
})}`);
console.log(` Expected Attendance: ${suggestion.expectedAttendance}`);
console.log(` Revenue Projection: $${suggestion.revenueProjection.toLocaleString()}`);
console.log(` Competition: ${suggestion.competitionLevel}`);
console.log(` Seasonal Factor: ${suggestion.seasonalFactor.toFixed(2)}x`);
console.log(` Confidence: ${(suggestion.confidence * 100).toFixed(1)}%`);
});
return suggestions;
}
analyzeTimeSlot(timeSlot, category, location) {
const seasonalFactor = this.getSeasonalFactor(timeSlot.startDate);
const competitionLevel = this.getCompetitionLevel();
const expectedAttendance = this.estimateAttendance(seasonalFactor, competitionLevel, category);
return {
expectedAttendance,
revenueProjection: expectedAttendance * (30 + Math.random() * 40), // $30-70 per ticket
competitionLevel,
seasonalFactor,
confidence: Math.random() * 0.3 + 0.7 // 70-100% confidence
};
}
getSeasonalFactor(date) {
const month = date.getMonth();
// Seasonal factors based on general event performance
const factors = [0.7, 0.6, 0.8, 0.9, 1.0, 1.1, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7];
return factors[month];
}
getCompetitionLevel() {
const levels = ['low', 'medium', 'high'];
return levels[Math.floor(Math.random() * levels.length)];
}
estimateAttendance(seasonalFactor, competitionLevel, category) {
const baseAttendance = 100;
const competitionMultiplier = competitionLevel === 'low' ? 1.2 : competitionLevel === 'medium' ? 1.0 : 0.8;
const categoryMultiplier = category === 'CONFERENCE' ? 1.3 : category === 'CONCERT' ? 1.5 : 1.0;
return Math.round(baseAttendance * seasonalFactor * competitionMultiplier * categoryMultiplier);
}
predictAttendanceImpact(currentDate, newDate, category, location) {
console.log('\n🔮 Attendance Impact Prediction');
console.log('=' .repeat(50));
console.log(`Current Date: ${currentDate.toLocaleDateString()}`);
console.log(`Proposed Date: ${newDate.toLocaleDateString()}`);
const baselineAttendance = 120; // Simulated baseline
const impactFactors = {
timeOfYear: this.getSeasonalFactor(newDate),
dayOfWeek: this.getDayOfWeekFactor(newDate),
timeOfDay: this.getTimeOfDayFactor(newDate),
competition: 0.9, // Simulated competition factor
demographics: 1.0
};
const projectedAttendance = Math.round(
baselineAttendance *
impactFactors.timeOfYear *
impactFactors.dayOfWeek *
impactFactors.timeOfDay *
impactFactors.competition *
impactFactors.demographics
);
const riskFactors = this.identifyRiskFactors(impactFactors, newDate);
const opportunities = this.identifyOpportunities(impactFactors, newDate);
console.log(`\nBaseline Attendance: ${baselineAttendance}`);
console.log(`Projected Attendance: ${projectedAttendance}`);
console.log(`Impact: ${projectedAttendance > baselineAttendance ? '+' : ''}${projectedAttendance - baselineAttendance} (${((projectedAttendance / baselineAttendance - 1) * 100).toFixed(1)}%)`);
console.log('\nImpact Factors:');
Object.entries(impactFactors).forEach(([factor, value]) => {
console.log(` ${factor}: ${value.toFixed(2)}x`);
});
if (riskFactors.length > 0) {
console.log('\n⚠️ Risk Factors:');
riskFactors.forEach(risk => console.log(` • ${risk}`));
}
if (opportunities.length > 0) {
console.log('\n🚀 Opportunities:');
opportunities.forEach(opportunity => console.log(` • ${opportunity}`));
}
return {
baselineAttendance,
projectedAttendance,
impactFactors,
riskFactors,
opportunities
};
}
getDayOfWeekFactor(date) {
const day = date.getDay();
return day === 0 || day === 6 ? 1.2 : 1.0; // Weekend boost
}
getTimeOfDayFactor(date) {
const hour = date.getHours();
if (hour >= 18 && hour <= 21) return 1.3; // Evening events
if (hour >= 14 && hour <= 17) return 1.1; // Afternoon events
return 1.0;
}
identifyRiskFactors(impactFactors, date) {
const risks = [];
if (impactFactors.competition < 0.9) {
risks.push('High competition from similar events');
}
if (impactFactors.timeOfYear < 0.8) {
risks.push('Low seasonal demand period');
}
if (date.getDay() >= 1 && date.getDay() <= 4) {
risks.push('Weekday scheduling may reduce attendance');
}
return risks;
}
identifyOpportunities(impactFactors, date) {
const opportunities = [];
if (impactFactors.competition > 1.1) {
opportunities.push('Low competition window identified');
}
if (impactFactors.timeOfYear > 1.1) {
opportunities.push('Peak seasonal demand period');
}
if (date.getDay() === 0 || date.getDay() === 6) {
opportunities.push('Weekend scheduling advantage');
}
return opportunities;
}
}
// Demo execution
function runDemo() {
console.log('🎯 Lumentix AI-Powered Event Scheduling Optimization Demo');
console.log('=' .repeat(60));
const scheduler = new SchedulingOptimizationDemo();
// Demo 1: Analyze optimal timing
const analysis = scheduler.analyzeOptimalTiming(
EventCategory.CONFERENCE,
'San Francisco',
2,
'professionals'
);
// Demo 2: Generate schedule suggestions
const suggestions = scheduler.suggestEventSchedule(
EventCategory.WORKSHOP,
'Austin',
3,
{
start: new Date('2024-06-01'),
end: new Date('2024-06-30')
}
);
// Demo 3: Predict attendance impact
scheduler.predictAttendanceImpact(
new Date('2024-05-15T19:00:00'),
new Date('2024-06-15T18:00:00'),
EventCategory.NETWORKING,
'Seattle'
);
console.log('\n✅ Demo completed! This demonstrates the core AI scheduling optimization features.');
console.log('\n📝 Key Features Demonstrated:');
console.log(' • Historical data analysis and pattern recognition');
console.log(' • Seasonal trend analysis and optimization');
console.log(' • Competition analysis and market timing');
console.log(' • Demographic-based scheduling preferences');
console.log(' • Multi-factor confidence scoring');
console.log(' • Risk and opportunity identification');
console.log(' • Attendance impact prediction');
}
// Run the demo
if (require.main === module) {
runDemo();
}
module.exports = { SchedulingOptimizationDemo, EventCategory };