-
-
Save sadsfae/6e96ef157e905d425feb8ac5a2e2fbf1 to your computer and use it in GitHub Desktop.
Quads product breakdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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(loop): | |
jira = Jira( | |
conf["jira_url"], | |
conf["jira_username"], | |
conf["jira_password"], | |
loop=loop, | |
) | |
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) | |
try: | |
result = x.group() | |
except: | |
product = "N/A" | |
else: | |
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 | |
if cloud_history: | |
print( | |
f"{cloud.name}," | |
f"{cloud_history.description}," | |
f"{cloud_history.owner}," | |
f"{cloud_history.ticket}," | |
f"{fsched_obj.start}," | |
f"{fsched_obj.end}," | |
f"{length.days}," | |
f"{len(cs['schedule'])}," | |
f"{product}" | |
) | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main(loop)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment