Skip to content

Instantly share code, notes, and snippets.

@grafuls
Last active March 19, 2021 18:12
Show Gist options
  • Save grafuls/ab78c0b3772a86e04fcaeecf97377b2b to your computer and use it in GitHub Desktop.
Save grafuls/ab78c0b3772a86e04fcaeecf97377b2b to your computer and use it in GitHub Desktop.
shail data collect
#! /usr/bin/env python
import asyncio
from datetime import date, datetime
from quads.config import conf
from quads.model import Cloud, CloudHistory, Schedule
from quads.tools.jira import Jira
async def main():
jira = Jira(
conf["jira_url"],
conf["jira_username"],
conf["jira_password"],
)
clouds = Cloud.objects(name__ne="cloud01")
start = datetime.combine(date(2020, 1, 1), datetime.min.time())
print(f"cloud, description, owner, ticket, start, end, days, server_count, product")
for cloud in clouds:
pipeline = [
{"$match": {"name": cloud.name}},
{"$lookup": {
"from": "schedule",
"let": {"cloudId": "$_id"},
"pipeline": [
{"$match": {"$expr": {"$eq": ["$cloud", "$$cloudId"]}}},
{"$group": {"_id": "$start", "schedule": {"$push": "$_id"}}},
],
"as": "schedule",
}},
{"$unwind": "$schedule"},
{"$replaceRoot": {"newRoot": "$schedule"}}
]
cloud_schedules = Cloud.objects.aggregate(*pipeline)
for cs in cloud_schedules:
first_sched = cs["schedule"][0]
fsched_obj = Schedule.objects(id=first_sched).first()
if fsched_obj.end > start:
ticket = await jira.get_ticket(cloud.ticket)
fields = ticket.get("fields")
if fields:
description = fields.get("description")
if description:
import re
x = re.search("Primary product being tested: *.+\\n", description)
result = x.group()
strings = result.split()
product = strings[-1]
cloud_history = CloudHistory.objects(__raw__={"_id": {"$lt": fsched_obj.id}, "name": cloud.name}).order_by(
"-_id").first()
length = fsched_obj.end - fsched_obj.start
print(
f"{cloud.name}, {cloud_history.description}, {cloud_history.owner}, {cloud_history.ticket}, {fsched_obj.start}, {fsched_obj.end}, {length.days}, {len(cs['schedule'])}, {product}")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment