437 lines
20 KiB
Python
Executable file
437 lines
20 KiB
Python
Executable file
#!/usr/bin/env python3
|
||
"""
|
||
Ekeepa 360 Agile Cockpit Data Aggregator (v2.6 Enhanced)
|
||
Fetches real-time sprint data, boards (EKD & EMO), member performance,
|
||
rollover analysis, time tracking transparency, historical sprints, and PRD references.
|
||
"""
|
||
|
||
import os
|
||
import json
|
||
import urllib.request
|
||
import urllib.parse
|
||
from datetime import datetime
|
||
|
||
BASE_DIR = "/workspace/prds"
|
||
ENV_PATH = os.path.join(BASE_DIR, ".jira.env")
|
||
OUTPUT_PATH = os.path.join(BASE_DIR, "data", "cockpit_data.json")
|
||
PRDS_JSON = os.path.join(BASE_DIR, "data", "prds.json")
|
||
|
||
def load_env():
|
||
env = {}
|
||
if os.path.exists(ENV_PATH):
|
||
with open(ENV_PATH, "r", encoding="utf-8") as f:
|
||
for line in f:
|
||
if "=" in line and not line.strip().startswith("#"):
|
||
k, v = line.strip().split("=", 1)
|
||
env[k.strip()] = v.strip().strip('"')
|
||
return env
|
||
|
||
ENV = load_env()
|
||
JIRA_URL = ENV.get("JIRA_URL", "https://jira.ekeepa-dev.ir")
|
||
JIRA_PAT = ENV.get("JIRA_PAT", "")
|
||
|
||
TEAM_MEMBERS = {
|
||
"arminzahedi": {
|
||
"id": "arminzahedi",
|
||
"name": "آرمین زاهدی",
|
||
"role": "بکاند (Node.js)",
|
||
"track": "develop",
|
||
"avatar": "👨💻",
|
||
"color": "#3b82f6"
|
||
},
|
||
"morteazasadeghi": {
|
||
"id": "morteazasadeghi",
|
||
"name": "مرتضی صادقی",
|
||
"role": "فرانتاند (React / Next.js)",
|
||
"track": "develop",
|
||
"avatar": "🎨",
|
||
"color": "#06b6d4"
|
||
},
|
||
"ehsanasadi": {
|
||
"id": "ehsanasadi",
|
||
"name": "احسان اسدی",
|
||
"role": "برنامهنویس با هوش مصنوعی",
|
||
"track": "develop",
|
||
"avatar": "🤖",
|
||
"color": "#8b5cf6"
|
||
},
|
||
"ImanPorsamad": {
|
||
"id": "ImanPorsamad",
|
||
"name": "ایمان پورصمد",
|
||
"role": "برنامهنویس با هوش مصنوعی",
|
||
"track": "develop",
|
||
"avatar": "🧠",
|
||
"color": "#6366f1"
|
||
},
|
||
"admin": {
|
||
"id": "admin",
|
||
"name": "سارا محمودزاده",
|
||
"role": "مدیر محصول (Product Manager)",
|
||
"track": "management",
|
||
"avatar": "👑",
|
||
"color": "#ec4899"
|
||
},
|
||
"ghazale.madadi": {
|
||
"id": "ghazale.madadi",
|
||
"name": "غزاله مددی",
|
||
"role": "کامرس و پروداکت تجربه (تفریحات ۱ روزه)",
|
||
"track": "marketing",
|
||
"avatar": "🎪",
|
||
"color": "#f59e0b"
|
||
},
|
||
"Elahe Fallahi": {
|
||
"id": "Elahe Fallahi",
|
||
"name": "الهه فلاحی",
|
||
"role": "لید مارکتینگ",
|
||
"track": "marketing",
|
||
"avatar": "📢",
|
||
"color": "#10b981"
|
||
},
|
||
"parastoosamaavt": {
|
||
"id": "parastoosamaavt",
|
||
"name": "پرستو سماوات",
|
||
"role": "لید سوشال مدیا",
|
||
"track": "marketing",
|
||
"avatar": "📱",
|
||
"color": "#14b8a6"
|
||
},
|
||
"mobunabayat": {
|
||
"id": "mobunabayat",
|
||
"name": "مبینا بیات",
|
||
"role": "ادیتور مدیا و ویدیو",
|
||
"track": "marketing",
|
||
"avatar": "🎬",
|
||
"color": "#f97316"
|
||
},
|
||
"HamedFallahi": {
|
||
"id": "HamedFallahi",
|
||
"name": "حامد فلاحی",
|
||
"role": "مدیر ارشد و همبنیانگذار",
|
||
"track": "management",
|
||
"avatar": "⚡",
|
||
"color": "#64748b"
|
||
},
|
||
"DaraAskari": {
|
||
"id": "DaraAskari",
|
||
"name": "دارا عسکری",
|
||
"role": "تحقیقات بازار و بیزینس",
|
||
"track": "develop",
|
||
"avatar": "📊",
|
||
"color": "#84cc16"
|
||
},
|
||
"AmirMohseninia": {
|
||
"id": "AmirMohseninia",
|
||
"name": "امیر محسننیا",
|
||
"role": "توسعهدهنده سابق (تسکهای قدیمی)",
|
||
"track": "develop",
|
||
"avatar": "👤",
|
||
"color": "#94a3b8"
|
||
}
|
||
}
|
||
|
||
# Root cause analysis & suggestions for chronic rollovers (>=3 sprints)
|
||
CHRONIC_RECOMMENDATIONS = {
|
||
"EKD-16": {
|
||
"rootCause": "تسک ایجاد دسترسی برای احسان در وضعیت Resolved قرار دارد و احسان ماههاست دسترسی دارد و فعالیت میکند، ولی تیکت در جیرا به وضعیت نهایی Closed برده نشده و هر اسپرینت به اسپرینت بعد سرریز میشود.",
|
||
"recommendation": "بستن فوری (Close) در جیرا. تسک عملاً ۱۰۰٪ انجام شده و نگه داشتن آن در اسپرینت فقط خطای آماری در محاسبات ظرفیت ایجاد میکند.",
|
||
"actionBadge": "بستن فوری (Close)",
|
||
"actionColor": "#10b981"
|
||
},
|
||
"EKD-76": {
|
||
"rootCause": "برنچ گیت قدیمی با تعارضات (Merge Conflicts) شدید به دلیل تغییر ساختار کامپوننتهای لغو رزرو رها شده است. به دلیل نبود مالک مشخص در تیم فعلی، تسک ۶ اسپرینت منتقل شده است.",
|
||
"recommendation": "یک تایمباکس ۲ ساعته به مرتضی و آرمین داده شود: اگر منطق کنسلی جدید از قبل در کدبیس هست، تیکت Cancel شود؛ در غیر این صورت تغییرات دستی اعمال و برنچ بسته شود.",
|
||
"actionBadge": "بررسی کانفلیکت یا بستن",
|
||
"actionColor": "#f59e0b"
|
||
},
|
||
"EKD-137": {
|
||
"rootCause": "تسک دیتابیسی و مغایرتگیری تیبل مالی V transaction با تسکهای روزمره تلاقی کرده و چون مالک آن حامد است و درگیر کارهای ارشد بیزینس است، ماهها در بورد دِولپ منتقل شده است.",
|
||
"recommendation": "انتقال مالکیت به آرمین (بکاند) برای نوشتن یک کوئری مغایرتگیری خودکار، یا خروج کامل از اسپرینتهای اسکرام به بکلاگ عمومی جهت جلوگیری از کاهش Velocity تیم فنی.",
|
||
"actionBadge": "تفویض به بکاند یا بکلاگ",
|
||
"actionColor": "#6366f1"
|
||
},
|
||
"EKD-140": {
|
||
"rootCause": "موضوع تسک اداری-بانکی (وام پستبانک و وزارت اقتصاد) است و ماهیت توسعه نرمافزاری ندارد. قرار گرفتن کارهای اداری/حقوقی در بورد اسکرام مهندسی باعث انحراف گزارشها شده است.",
|
||
"recommendation": "انتقال قطعی به بورد مدیریت/عملیات یا سامانه مدیریت وظایف تجاری. تسکهای غیرکدنویسی نباید در اسپرینتهای فنی وارد شوند.",
|
||
"actionBadge": "انتقال به بورد مدیریت",
|
||
"actionColor": "#ec4899"
|
||
},
|
||
"EKD-99": {
|
||
"rootCause": "یکسانسازی محاسبات بین جداول wallet_transactions و v_penalty_check به صورت نصفه انجام شده و کرانجاب هنوز نهایی نشده است. ایمان ۲ ساعت روی آن لاگ زده ولی کار رها شده.",
|
||
"recommendation": "برگزاری جلسه فنی ۱۵ دقیقهای هماهنگی بین ایمان و آرمین برای بازبینی فرمول مالی و استقرار کرانجاب نهایی در همین اسپرینت.",
|
||
"actionBadge": "جلسه همگامسازی فوری",
|
||
"actionColor": "#3b82f6"
|
||
},
|
||
"EKD-151": {
|
||
"rootCause": "آمادهسازی پروپوزال تجاری برای مدرسه مفید (ایونت و بازیوارسازی) یک تسک بیزینسی B2B است نه تسک برنامهنویسی تیم اسکرام فنی.",
|
||
"recommendation": "تفویض به غزاله (کامرس و رویدادها) یا انتقال به پروژه EMO (مارکتینگ و عملیات).",
|
||
"actionBadge": "انتقال به تیم کامرس",
|
||
"actionColor": "#f59e0b"
|
||
},
|
||
"EKD-353": {
|
||
"rootCause": "توسعه پنل مالی سلرها؛ ایمان ۲ روز و ۱ ساعت زمان ثبت کرده و بخش اعظم کدها زده شده اما مرحله تست و تحویل نهایی به کاربر انجام نشده است.",
|
||
"recommendation": "تست خروجی توسط پروداکت منیجر (سارا) در استیجینگ و تحویل به چند سلر پایلوت تا تیکت به وضعیت Done برود.",
|
||
"actionBadge": "تست و تایید پروداکت",
|
||
"actionColor": "#10b981"
|
||
},
|
||
"EKD-362": {
|
||
"rootCause": "اصلاح فرمولهای محاسباتی پنل مالی سلرها؛ وابسته به تست نهایی تسک EKD-353 بوده و به دلیل بلاتکلیفی تسک مادر معطل مانده است.",
|
||
"recommendation": "مرج کردن این تسک با EKD-353 به صورت سابتسک یا تست همزمان با آن.",
|
||
"actionBadge": "مرج با تسک مادر",
|
||
"actionColor": "#8b5cf6"
|
||
},
|
||
"EKD-271": {
|
||
"rootCause": "اپلیکیشن اتوماسیون اینستاگرام و فیسبوک (inzy)؛ تسک وابسته به تغییرات API متا و سیاستهای مارکتینگ اکیپا است و اولویت آن با تغییر استراتژی محتوا نامشخص مانده است.",
|
||
"recommendation": "استعلام فوری از الهه فلاحی (لید مارکتینگ): اگر برای فصل پاییز نیاز نیست، به Icebox منتقل شود تا اسپرینت سبک شود.",
|
||
"actionBadge": "استعلام مارکتینگ یا Icebox",
|
||
"actionColor": "#ef4444"
|
||
}
|
||
}
|
||
|
||
def jira_get(path):
|
||
url = f"{JIRA_URL}{path}"
|
||
req = urllib.request.Request(url, headers={
|
||
"Authorization": f"Bearer {JIRA_PAT}",
|
||
"Content-Type": "application/json"
|
||
})
|
||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||
return json.loads(resp.read().decode("utf-8"))
|
||
|
||
def jira_search(jql, max_results=100, fields=None):
|
||
if fields is None:
|
||
fields = "summary,status,assignee,priority,created,updated,timetracking,aggregateprogress,description,customfield_10006"
|
||
params = urllib.parse.urlencode({
|
||
"jql": jql,
|
||
"maxResults": max_results,
|
||
"fields": fields
|
||
})
|
||
path = f"/rest/api/2/search?{params}"
|
||
return jira_get(path)
|
||
|
||
def clean_issue(iss, prd_keys):
|
||
fields = iss.get("fields", {})
|
||
key = iss.get("key", "")
|
||
|
||
status_obj = fields.get("status", {})
|
||
status_name = status_obj.get("name", "Unknown")
|
||
status_category = status_obj.get("statusCategory", {}).get("key", "new")
|
||
|
||
assignee_obj = fields.get("assignee")
|
||
assignee_id = assignee_obj.get("name") if assignee_obj else None
|
||
assignee_name = assignee_obj.get("displayName") if assignee_obj else "بدون مسئول"
|
||
|
||
role_label = "سایر همکاران"
|
||
user_color = "#94a3b8"
|
||
user_avatar = "👤"
|
||
if assignee_id and assignee_id in TEAM_MEMBERS:
|
||
m = TEAM_MEMBERS[assignee_id]
|
||
role_label = m["role"]
|
||
user_color = m["color"]
|
||
user_avatar = m["avatar"]
|
||
|
||
timetracking = fields.get("timetracking", {})
|
||
time_spent = timetracking.get("timeSpent", "")
|
||
time_estimate = timetracking.get("originalEstimate", "")
|
||
time_remaining = timetracking.get("remainingEstimate", "")
|
||
has_time_log = bool(time_spent or time_estimate)
|
||
|
||
closed_sprints = fields.get("closedSprints", [])
|
||
if not closed_sprints and "customfield_10006" in fields:
|
||
raw_sprints = fields.get("customfield_10006")
|
||
if isinstance(raw_sprints, list):
|
||
closed_sprints = [s for s in raw_sprints if "state=CLOSED" in str(s) or "state=closed" in str(s)]
|
||
|
||
is_rollover = len(closed_sprints) > 0
|
||
rollover_count = len(closed_sprints)
|
||
|
||
prev_names = []
|
||
for cs in closed_sprints:
|
||
if isinstance(cs, dict):
|
||
prev_names.append(cs.get("name", ""))
|
||
elif isinstance(cs, str):
|
||
import re
|
||
m = re.search(r'name=([^,]+)', cs)
|
||
if m:
|
||
prev_names.append(m.group(1))
|
||
|
||
has_prd = key in prd_keys
|
||
prd_id = prd_keys.get(key)
|
||
|
||
chronic_rec = CHRONIC_RECOMMENDATIONS.get(key, None)
|
||
|
||
return {
|
||
"key": key,
|
||
"summary": fields.get("summary", ""),
|
||
"description": (fields.get("description") or "")[:400],
|
||
"status": status_name,
|
||
"statusCategory": status_category,
|
||
"assigneeId": assignee_id,
|
||
"assigneeName": assignee_name,
|
||
"roleLabel": role_label,
|
||
"userColor": user_color,
|
||
"userAvatar": user_avatar,
|
||
"priority": fields.get("priority", {}).get("name", "Medium"),
|
||
"created": (fields.get("created") or "")[:10],
|
||
"updated": (fields.get("updated") or "")[:10],
|
||
"timeSpent": time_spent,
|
||
"timeEstimate": time_estimate,
|
||
"timeRemaining": time_remaining,
|
||
"hasTimeLog": has_time_log,
|
||
"isRollover": is_rollover,
|
||
"rolloverCount": rollover_count,
|
||
"previousSprints": prev_names,
|
||
"hasPRD": has_prd,
|
||
"prdId": prd_id,
|
||
"chronicRecommendation": chronic_rec
|
||
}
|
||
|
||
def main():
|
||
print("🚀 Fetching comprehensive Jira sprint & board data (v2.6)...")
|
||
|
||
prd_keys = {}
|
||
if os.path.exists(PRDS_JSON):
|
||
with open(PRDS_JSON, "r", encoding="utf-8") as f:
|
||
for p in json.load(f):
|
||
if "jiraKey" in p:
|
||
prd_keys[p["jiraKey"]] = p.get("id")
|
||
|
||
# Fetch boards
|
||
boards = jira_get("/rest/agile/1.0/board").get("values", [])
|
||
|
||
# Fetch all sprints from EKD board (ID 1)
|
||
sprints_data = jira_get("/rest/agile/1.0/board/1/sprint").get("values", [])
|
||
sprints_list = []
|
||
active_sprint = None
|
||
for s in sprints_data:
|
||
s_info = {
|
||
"id": s.get("id"),
|
||
"name": s.get("name"),
|
||
"state": s.get("state"),
|
||
"startDate": (s.get("startDate") or "")[:10],
|
||
"endDate": (s.get("endDate") or "")[:10],
|
||
"goal": s.get("goal") or ""
|
||
}
|
||
sprints_list.append(s_info)
|
||
if s.get("state") == "active":
|
||
active_sprint = s_info
|
||
|
||
# Fetch Sprint 10 issues
|
||
s10_raw = jira_get("/rest/agile/1.0/sprint/10/issue?maxResults=100").get("issues", [])
|
||
s10_issues = [clean_issue(iss, prd_keys) for iss in s10_raw]
|
||
|
||
# Fetch Sprint 9 issues
|
||
s9_raw = jira_get("/rest/agile/1.0/sprint/9/issue?maxResults=100").get("issues", [])
|
||
s9_issues = [clean_issue(iss, prd_keys) for iss in s9_raw]
|
||
|
||
# Fetch EMO (Marketing) issues
|
||
emo_raw = jira_search("project = EMO ORDER BY updated DESC", max_results=100).get("issues", [])
|
||
emo_issues = [clean_issue(iss, prd_keys) for iss in emo_raw]
|
||
|
||
# Historical multi-sprint metrics for trend line & velocity comparison
|
||
historical_sprints = [
|
||
{"id": 5, "name": "هفته آخر تیر و ۱ مرداد", "total": 72, "done": 61, "rate": 84.7, "spillover": 15},
|
||
{"id": 6, "name": "هفته ۱ و ۲ مرداد", "total": 100, "done": 87, "rate": 87.0, "spillover": 18},
|
||
{"id": 7, "name": "هفته ۳ و ۴ مرداد", "total": 76, "done": 61, "rate": 80.3, "spillover": 22},
|
||
{"id": 9, "name": "هفته ۱ و ۲ شهریور", "total": 90, "done": 66, "rate": 73.3, "spillover": 28},
|
||
{"id": 10, "name": "هفته ۳ و ۴ شهریور", "total": len(s10_issues), "done": sum(1 for x in s10_issues if x["statusCategory"] == "done"), "rate": round(sum(1 for x in s10_issues if x["statusCategory"] == "done")/len(s10_issues)*100, 1) if s10_issues else 0, "spillover": sum(1 for x in s10_issues if x["isRollover"])}
|
||
]
|
||
|
||
# Time tracking stats
|
||
s10_with_time = sum(1 for x in s10_issues if x["hasTimeLog"])
|
||
s10_without_time = len(s10_issues) - s10_with_time
|
||
time_tracking_stats = {
|
||
"totalTasks": len(s10_issues),
|
||
"withTime": s10_with_time,
|
||
"withoutTime": s10_without_time,
|
||
"missingPercentage": round(s10_without_time / len(s10_issues) * 100, 1) if s10_issues else 0
|
||
}
|
||
|
||
# Member Workload & Growth Analytics across Sprint 9 vs Sprint 10
|
||
member_comparison = {}
|
||
for uid, udata in TEAM_MEMBERS.items():
|
||
if udata["track"] == "marketing":
|
||
continue
|
||
# S9 stats
|
||
u_s9 = [x for x in s9_issues if x["assigneeId"] == uid]
|
||
s9_done = sum(1 for x in u_s9 if x["statusCategory"] == "done")
|
||
# S10 stats
|
||
u_s10 = [x for x in s10_issues if x["assigneeId"] == uid]
|
||
s10_done = sum(1 for x in u_s10 if x["statusCategory"] == "done")
|
||
s10_in_progress = sum(1 for x in u_s10 if x["statusCategory"] == "indeterminate")
|
||
s10_todo = sum(1 for x in u_s10 if x["statusCategory"] == "new")
|
||
s10_rollover = sum(1 for x in u_s10 if x["isRollover"])
|
||
s10_time_count = sum(1 for x in u_s10 if x["hasTimeLog"])
|
||
|
||
growth_delta = s10_done - s9_done
|
||
growth_pct = round((growth_delta / s9_done * 100), 1) if s9_done > 0 else (100.0 if s10_done > 0 else 0.0)
|
||
|
||
member_comparison[uid] = {
|
||
"id": uid,
|
||
"name": udata["name"],
|
||
"role": udata["role"],
|
||
"avatar": udata["avatar"],
|
||
"color": udata["color"],
|
||
"s9Total": len(u_s9),
|
||
"s9Done": s9_done,
|
||
"s10Total": len(u_s10),
|
||
"s10Done": s10_done,
|
||
"s10InProgress": s10_in_progress,
|
||
"s10Todo": s10_todo,
|
||
"s10Rollover": s10_rollover,
|
||
"s10TimeLoggedCount": s10_time_count,
|
||
"s10MissingTimeCount": len(u_s10) - s10_time_count,
|
||
"growthDelta": growth_delta,
|
||
"growthPct": growth_pct
|
||
}
|
||
|
||
# Marketing breakdown
|
||
emo_stats = {
|
||
"total": len(emo_issues),
|
||
"done": sum(1 for x in emo_issues if x["statusCategory"] == "done"),
|
||
"inProgress": sum(1 for x in emo_issues if x["statusCategory"] == "indeterminate"),
|
||
"open": sum(1 for x in emo_issues if x["statusCategory"] == "new"),
|
||
}
|
||
|
||
# Output structure
|
||
payload = {
|
||
"generatedAt": datetime.now().strftime("%Y-%m-%d %H:%M"),
|
||
"teamMembers": TEAM_MEMBERS,
|
||
"sprints": sprints_list,
|
||
"activeSprint": active_sprint,
|
||
"historicalSprints": historical_sprints,
|
||
"timeTrackingStats": time_tracking_stats,
|
||
"memberComparison": list(member_comparison.values()),
|
||
"stats": {
|
||
"s10": {
|
||
"name": "هفته سوم و چهارم شهریور",
|
||
"total": len(s10_issues),
|
||
"done": sum(1 for x in s10_issues if x["statusCategory"] == "done"),
|
||
"inProgress": sum(1 for x in s10_issues if x["statusCategory"] == "indeterminate"),
|
||
"todo": sum(1 for x in s10_issues if x["statusCategory"] == "new"),
|
||
"rollovers": sum(1 for x in s10_issues if x["isRollover"]),
|
||
"completionRate": round(sum(1 for x in s10_issues if x["statusCategory"] == "done") / len(s10_issues) * 100, 1) if s10_issues else 0
|
||
},
|
||
"s9": {
|
||
"name": "هفته اول و دوم شهریور (اسپرینت گذشته)",
|
||
"total": len(s9_issues),
|
||
"done": sum(1 for x in s9_issues if x["statusCategory"] == "done"),
|
||
"completionRate": round(sum(1 for x in s9_issues if x["statusCategory"] == "done") / len(s9_issues) * 100, 1) if s9_issues else 0
|
||
},
|
||
"emo": emo_stats
|
||
},
|
||
"issues": {
|
||
"s10": s10_issues,
|
||
"s9": s9_issues,
|
||
"emo": emo_issues
|
||
}
|
||
}
|
||
|
||
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
|
||
json.dump(payload, f, ensure_ascii=False, indent=2)
|
||
|
||
print(f"✅ Cockpit data aggregated successfully to {OUTPUT_PATH}")
|
||
print(f" - Active Sprint Issues: {len(s10_issues)}")
|
||
print(f" - Historical Sprints: {len(historical_sprints)}")
|
||
print(f" - Missing Time Logs: {time_tracking_stats['withoutTime']} / {time_tracking_stats['totalTasks']} ({time_tracking_stats['missingPercentage']}%)")
|
||
|
||
if __name__ == "__main__":
|
||
main()
|