-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_data.py
More file actions
486 lines (427 loc) · 19.4 KB
/
demo_data.py
File metadata and controls
486 lines (427 loc) · 19.4 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
"""
Demo data generator for the IT Project Health Dashboard.
Produces realistic project portfolio data so the dashboard can run
without a ServiceNow instance. Deterministic (seeded random) so that
repeated runs yield the same dataset.
Usage:
from demo_data import build_demo_data
sections_active, sections_closed, grand_all, grand_key, mail_all = build_demo_data()
"""
from __future__ import annotations
import hashlib
import random
import urllib.parse as ul
from datetime import date, datetime, timedelta
from typing import Any, Dict, List, Tuple
# ────────────────────────────────────────────────────────────────────
# Constants
# ────────────────────────────────────────────────────────────────────
PORTFOLIOS = [
"Cloud & Infrastructure",
"Cybersecurity",
"Data & Analytics",
"Digital Workplace",
"ERP & Finance Systems",
"Manufacturing & OT",
"Customer Experience",
"Integration & API Platform",
]
PROJECT_PREFIXES = {
"Cloud & Infrastructure": [
"Azure Landing Zone Expansion",
"AWS Cost Optimization",
"Hybrid Cloud Migration",
"Network Modernization",
"DC Consolidation Phase",
"Container Platform Rollout",
"SD-WAN Global Deployment",
"Cloud DR Site Setup",
"Infrastructure Monitoring Upgrade",
"Serverless Compute Pilot",
],
"Cybersecurity": [
"Zero Trust Architecture",
"SOC Modernization",
"PAM Implementation",
"Endpoint Detection & Response",
"Cloud Security Posture Mgmt",
"Identity Governance Refresh",
"Vulnerability Management Overhaul",
"Security Awareness Training Platform",
"DLP Rollout",
"Threat Intelligence Platform",
],
"Data & Analytics": [
"Enterprise Data Lake",
"BI Dashboards Modernization",
"Data Quality Framework",
"ML Ops Platform",
"Customer 360 Analytics",
"Real-Time Streaming Pipeline",
"Master Data Management",
"Self-Service Analytics Portal",
"Data Catalog Implementation",
"Predictive Maintenance Analytics",
],
"Digital Workplace": [
"M365 Copilot Rollout",
"Intranet Redesign",
"Digital Signage Platform",
"Unified Communications Upgrade",
"Employee Experience App",
"Meeting Room Modernization",
"Remote Work Toolkit",
"Knowledge Management System",
"ITSM Self-Service Portal",
"Print Management Consolidation",
],
"ERP & Finance Systems": [
"S/4HANA Migration Wave",
"Finance Close Automation",
"Procurement Digitalization",
"Travel & Expense Modernization",
"Treasury Management System",
"Consolidation Tool Upgrade",
"Intercompany Reconciliation",
"Fixed Assets Module Revamp",
"E-Invoicing Compliance",
"Budget Planning Platform",
],
"Manufacturing & OT": [
"MES Rollout Plant",
"SCADA Modernization",
"Digital Twin Pilot",
"OT Network Segmentation",
"Quality Management System",
"Warehouse Management System",
"Production Planning Optimization",
"IoT Sensor Integration",
"Maintenance Management Upgrade",
"Shop Floor Visualization",
],
"Customer Experience": [
"CRM Platform Migration",
"Customer Portal Redesign",
"Marketing Automation Suite",
"E-Commerce Platform",
"Customer Feedback Analytics",
"Service Desk Transformation",
"Chatbot Implementation",
"Loyalty Program System",
"Omnichannel Integration",
"Sales Force Effectiveness",
],
"Integration & API Platform": [
"API Gateway Modernization",
"iPaaS Implementation",
"Legacy System Integration",
"EDI Modernization",
"Event-Driven Architecture",
"Service Mesh Deployment",
"B2B Integration Hub",
"Middleware Upgrade",
"Real-Time Integration Layer",
"API Lifecycle Management",
],
}
PM_NAMES = [
("Anna Mueller", "anna.mueller@example.com"),
("Thomas Weber", "thomas.weber@example.com"),
("Sarah Fischer", "sarah.fischer@example.com"),
("Michael Brunner", "michael.brunner@example.com"),
("Laura Schneider", "laura.schneider@example.com"),
("Daniel Keller", "daniel.keller@example.com"),
("Julia Hofmann", "julia.hofmann@example.com"),
("Markus Steiner", "markus.steiner@example.com"),
("Nina Berger", "nina.berger@example.com"),
("Patrick Zimmermann", "patrick.zimmermann@example.com"),
("Elena Schwarz", "elena.schwarz@example.com"),
("Stefan Baumann", "stefan.baumann@example.com"),
("Claudia Gerber", "claudia.gerber@example.com"),
("Reto Wyss", "reto.wyss@example.com"),
("Sandra Moser", "sandra.moser@example.com"),
("Felix Huber", "felix.huber@example.com"),
("Monika Graf", "monika.graf@example.com"),
("Andreas Leuthard", "andreas.leuthard@example.com"),
]
BPM_NAMES = [
"Marc Dupont",
"Christina Meier",
"Oliver Frey",
"Isabelle Roth",
"Luca Bianchi",
"Simone Kessler",
"David Hartmann",
"Katrin Vogt",
"Philippe Martin",
"Barbara Fuchs",
"Roger Ammann",
"Petra Schmid",
"Jan de Vries",
"Monique Favre",
"Tobias Wenger",
]
EXECUTIVE_SUMMARIES = [
"Project on track. Sprint velocity has stabilized and the team delivered all planned features this month. Key risk around third-party API stability has been mitigated with a fallback mechanism.",
"Slight delay due to vendor resource constraints. We have escalated to procurement and expect resolution within two weeks. Budget utilization remains within approved limits.",
"Successfully completed UAT for module 2. Go-live planned for next quarter. One critical defect found during testing is being addressed by the development team with a hotfix scheduled for next week.",
"Project is progressing well. Infrastructure provisioning completed ahead of schedule. Data migration scripts are currently being validated in the staging environment.",
"Scope change request approved by steering committee. Timeline extended by 4 weeks to accommodate additional regulatory requirements. No budget impact expected.",
"Major milestone achieved: core platform deployment completed across all regions. Remaining work focuses on user training and documentation. Stakeholder satisfaction is high.",
"Risk materialized: key technical resource resigned. Knowledge transfer is underway with the replacement. Timeline impact being assessed but likely 2-3 week delay on Phase 3.",
"On track for year-end delivery. Integration testing with upstream systems completed successfully. Performance benchmarks exceeded targets by 15%.",
"Budget overrun identified in professional services category. Root cause is additional customization requirements discovered during implementation. Change request submitted for CHF 50k additional funding.",
"Pilot phase completed with positive user feedback (4.2/5 satisfaction score). Full rollout plan being finalized. Change management activities progressing well.",
"Project temporarily paused pending procurement decision on platform selection. RFP evaluation in progress with shortlist of two vendors. Expected to resume in 3 weeks.",
"All workstreams progressing according to plan. Security review completed with no critical findings. Two medium-severity items being addressed in current sprint.",
"Successful go-live of Phase 1 in the EMEA region. Minor post-go-live issues resolved within SLA. Phase 2 planning for APAC region has commenced.",
"Dependencies on the ERP upgrade project are creating scheduling challenges. Weekly sync meetings established to coordinate timelines. Contingency plan developed.",
"Positive progress on data migration workstream. 85% of legacy data has been cleansed and mapped. Remaining 15% requires manual review due to data quality issues.",
"Project completed code freeze milestone. Regression testing in progress with 92% pass rate. Remaining failures are cosmetic UI issues being fixed in the current cycle.",
]
STATUS_OPTIONS = ["green", "green", "green", "green", "yellow", "yellow", "red"]
# ────────────────────────────────────────────────────────────────────
# Helpers
# ────────────────────────────────────────────────────────────────────
def _deterministic_seed(name: str) -> int:
return int(hashlib.md5(name.encode()).hexdigest()[:8], 16)
def _fake_sysid(idx: int) -> str:
return hashlib.md5(f"project-{idx}".encode()).hexdigest()
def _rand_date(rng: random.Random, start: date, end: date) -> date:
delta = (end - start).days
if delta <= 0:
return start
return start + timedelta(days=rng.randint(0, delta))
# ────────────────────────────────────────────────────────────────────
# Timeline helpers (must match app_oauth.py section 4)
# ────────────────────────────────────────────────────────────────────
_today = date.today()
_rng_start = date(_today.year - 1, 4, 1)
_rng_end = date(_today.year + 1, 6, 30)
_rng_days = (_rng_end - _rng_start).days or 1
_min_w = (30 / _rng_days) * 100
def _pos(d: date) -> float:
return (d - _rng_start).days / _rng_days * 100
def _q(d: date) -> str:
return f"Q{((d.month - 1) // 3) + 1}'{str(d.year)[2:]}"
pct = lambda a, p: round(100 * a / p, 1) if p else None
# ────────────────────────────────────────────────────────────────────
# Main generator
# ────────────────────────────────────────────────────────────────────
def _generate_projects() -> Tuple[List[Dict], List[Dict]]:
"""Return (active_projects, closed_projects) as flat lists."""
rng = random.Random(42)
active: List[Dict] = []
closed: List[Dict] = []
proj_counter = 0
for portfolio in PORTFOLIOS:
names = PROJECT_PREFIXES[portfolio]
# 5-8 active projects per portfolio
n_active = rng.randint(5, 8)
# 1-3 closed projects per portfolio
n_closed = rng.randint(1, 3)
for i in range(n_active + n_closed):
proj_counter += 1
is_closed = i >= n_active
name_base = names[i % len(names)]
# Some projects are key projects (~20%)
is_key = rng.random() < 0.20
suffix = ""
if i >= len(names):
suffix = f" Phase {i - len(names) + 2}"
proj_name = name_base + suffix
if is_key:
proj_name += " [Key Project]"
# Cross-portfolio tagging for some projects (~15%)
if rng.random() < 0.15 and not is_key:
other = rng.choice([p for p in PORTFOLIOS if p != portfolio])
tag = other.split()[0][:2].upper()
proj_name += f" [{tag}]"
pm_name, pm_email = rng.choice(PM_NAMES)
bpm = rng.choice(BPM_NAMES)
# Financial data (CHF)
plan_cap = rng.choice([0, 0] + list(range(50_000, 2_500_001, 50_000)))
plan_ope = rng.choice([0] + list(range(20_000, 800_001, 10_000)))
# Actual spending: typically 30-110% of plan
if plan_cap > 0:
cap_ratio = rng.uniform(0.15, 1.15)
act_cap = round(plan_cap * cap_ratio, 2)
else:
act_cap = 0.0
if plan_ope > 0:
ope_ratio = rng.uniform(0.10, 1.20)
act_ope = round(plan_ope * ope_ratio, 2)
else:
act_ope = 0.0
# For closed projects, spending is 85-105% of plan
if is_closed:
if plan_cap > 0:
act_cap = round(plan_cap * rng.uniform(0.85, 1.05), 2)
if plan_ope > 0:
act_ope = round(plan_ope * rng.uniform(0.85, 1.05), 2)
# Dates
if is_closed:
end_d = _rand_date(rng, _today - timedelta(days=330),
_today - timedelta(days=30))
start_d = end_d - timedelta(days=rng.randint(90, 540))
work_end = end_d
else:
start_d = _rand_date(rng, _today - timedelta(days=540),
_today - timedelta(days=30))
end_d = start_d + timedelta(days=rng.randint(120, 720))
work_end = None
# Timeline positioning
s = _pos(start_d)
e = _pos(end_d)
if e < s:
s, e = e, s
left = max(min(s, 100), 0)
right = max(min(e, 100), 0)
width = max(0, right - left)
if width < _min_w:
width = _min_w
if left + width > 100:
left = max(0, 100 - width)
# Status indicators
schedule = rng.choice(STATUS_OPTIONS)
cost_st = rng.choice(STATUS_OPTIONS)
scope_st = rng.choice(STATUS_OPTIONS)
# Report date (current month = green, older = stale)
if rng.random() < 0.65:
rep_date = _today.replace(day=rng.randint(1, min(28, _today.day or 1)))
rep_date_str = rep_date.strftime("%Y-%m-%d")
elif rng.random() < 0.5:
last_month = _today.replace(day=1) - timedelta(days=1)
rep_date = last_month.replace(day=rng.randint(1, 28))
rep_date_str = rep_date.strftime("%Y-%m-%d")
else:
rep_date_str = None
summary = rng.choice(EXECUTIVE_SUMMARIES) if rep_date_str else ""
pid = _fake_sysid(proj_counter)
number = f"PRJ{proj_counter:07d}"
rep_id = _fake_sysid(proj_counter + 10000) if rep_date_str else None
rec: Dict[str, Any] = {
"id": pid,
"number": number,
"name": proj_name,
"pm": pm_name,
"pm_mail": pm_email,
"bpm": bpm,
"plan_cap": float(plan_cap),
"act_cap": act_cap,
"pct_cap": pct(act_cap, plan_cap),
"plan_ope": float(plan_ope),
"act_ope": act_ope,
"pct_ope": pct(act_ope, plan_ope),
"st_pct": round(left, 2),
"width_pct": round(width, 2),
"start_q": _q(start_d),
"end_q": _q(end_d),
"is_key": is_key,
"_portfolio": portfolio,
}
if is_closed:
rec["status"] = {"schedule": None, "cost": None, "scope": None}
rec["completion"] = work_end.strftime("%Y-%m-%d")
closed.append(rec)
else:
rec["status"] = {
"schedule": schedule,
"cost": cost_st,
"scope": scope_st,
}
rec["rep_date"] = rep_date_str
rec["rep_id"] = rep_id
rec["summary"] = summary
active.append(rec)
return active, closed
def _build_sections(
projects: List[Dict],
) -> List[Tuple[str, Dict[str, Any]]]:
"""Group flat project list into portfolio sections."""
sections: Dict[str, Any] = {}
for rec in projects:
port = rec.pop("_portfolio", "(No Portfolio)")
sec = sections.setdefault(
port,
{
"projs": [],
"tot": dict(pc=0, pa=0, oc=0, oa=0, cnt=0),
"ktot": dict(pc=0, pa=0, oc=0, oa=0, cnt=0),
},
)
sec["projs"].append(rec)
for k, v in (
("pc", "plan_cap"),
("pa", "act_cap"),
("oc", "plan_ope"),
("oa", "act_ope"),
):
sec["tot"][k] += rec[v]
if rec["is_key"]:
sec["ktot"][k] += rec[v]
sec["tot"]["cnt"] += 1
if rec["is_key"]:
sec["ktot"]["cnt"] += 1
outs = []
for name, sec in sections.items():
sec["projs"].sort(
key=lambda x: x["plan_cap"] + x["plan_ope"], reverse=True
)
outs.append((name, sec))
return sorted(outs, key=lambda x: x[0].lower())
def _grand_totals(
sections: List[Tuple[str, Dict]], key_only: bool = False
) -> Dict[str, float]:
g: Dict[str, float] = dict(pc=0.0, pa=0.0, oc=0.0, oa=0.0, cnt=0)
seen: set = set()
for _, sec in sections:
for p in sec["projs"]:
if key_only and not p["is_key"]:
continue
if p["id"] in seen:
continue
seen.add(p["id"])
g["pc"] += p["plan_cap"]
g["pa"] += p["act_cap"]
g["oc"] += p["plan_ope"]
g["oa"] += p["act_ope"]
g["cnt"] += 1
return g
def _make_mail_all(sections):
"""Mailto link for every PM with stale / missing report."""
today_dt = datetime.today()
yy, mm = today_dt.year, today_dt.month
emails: set = set()
for _, sec in sections:
for p in sec["projs"]:
d = p.get("rep_date")
ok = d and int(d[:4]) == yy and int(d[5:7]) == mm
if not ok and p.get("pm_mail"):
emails.add(p["pm_mail"])
if not emails:
return None
TO = ";".join(sorted(emails))
subj = ul.quote("Reminder: monthly project status report")
body = ul.quote(
"Dear Project Manager,\r\n"
"This is a kind reminder to submit your monthly status report(s) "
"in ServiceNow.\r\nThanks"
)
return f"mailto:{TO}?subject={subj}&body={body}"
# ────────────────────────────────────────────────────────────────────
# Public API
# ────────────────────────────────────────────────────────────────────
def build_demo_data():
"""
Build complete demo dataset.
Returns:
(sections_active, sections_closed, grand_all, grand_key, mail_all)
"""
active_projs, closed_projs = _generate_projects()
sections_active = _build_sections(active_projs)
sections_closed = _build_sections(closed_projs)
grand_all = _grand_totals(sections_active, False)
grand_key = _grand_totals(sections_active, True)
mail_all = _make_mail_all(sections_active)
return sections_active, sections_closed, grand_all, grand_key, mail_all