# Path: dashboard/services/sheets.py
# class Row(OrderedDict):
#     def __init__(self, *args, **kwargs):
# def load_sheet(sheet_id, sheet_auth_file=""):
# def _load_via_api(sheet_id, sheet_auth_file):
# def _load_via_csv(sheet_id):
# def parse_csv(csv_text):
# 
# Path: dashboard/services/jira.py
# LOGGER = logging.getLogger("dashboard.services.jira")
# def query_url(filter_id, jira_url=None):
# def fetch_query_results(filter_id, requests=requests, logger=LOGGER):
# def summarize_results(results):
# def summarize_query(filter_id):
# 
# Path: dashboard/services/summaries.py
# SAVED = "saved"
# UPDATED = "updated"
# def fill_updated_at(summary):
# def create(filter_id, complete, incomplete, total, created_on=None):
# def store(summary_obj):
# def for_date(filter_id, date):
# def for_date_range(filter_id, start_date, end_date=None):
# def latest_update():
# 
# Path: dashboard/services/predictions.py
# def throughput_history(summaries):
# def forecast(throughputs, backlog_size, num_simulations=10000, seed=None):
# def for_project(filter_id, backlog_size, start_date):


import datetime
import logging
from dateutil.relativedelta import relativedelta
from dateutil.parser import parse
from django.conf import settings
from django.core.cache import cache
from django.utils.timezone import get_default_timezone
from django_rq import job
from .services import sheets, jira, summaries, predictions






def _add_current_jira_summary(xtras, jira_filter_id, logger):
    summary_data = jira.summarize_query(jira_filter_id)
    logger.debug("Filter {} summarized".format(jira_filter_id))
    if summary_data.get('errors', []):
        xtras['jira_summary_errors'] = summary_data['errors']
        logger.warn("Filter {} summary error".format(summary_data['errors']))
    elif summary_data:
        p = summaries.create(
            filter_id=int(xtras['_jira_filter']),
            incomplete=summary_data['incomplete'],
            complete=summary_data['complete'],
            total=summary_data['total'],
            created_on=datetime.date.today(),
        )

# Path: dashboard/services/sheets.py
# class Row(OrderedDict):
#     def __init__(self, *args, **kwargs):
# def load_sheet(sheet_id, sheet_auth_file=""):
# def _load_via_api(sheet_id, sheet_auth_file):
# def _load_via_csv(sheet_id):
# def parse_csv(csv_text):
# 
# Path: dashboard/services/jira.py
# LOGGER = logging.getLogger("dashboard.services.jira")
# def query_url(filter_id, jira_url=None):
# def fetch_query_results(filter_id, requests=requests, logger=LOGGER):
# def summarize_results(results):
# def summarize_query(filter_id):
# 
# Path: dashboard/services/summaries.py
# SAVED = "saved"
# UPDATED = "updated"
# def fill_updated_at(summary):
# def create(filter_id, complete, incomplete, total, created_on=None):
# def store(summary_obj):
# def for_date(filter_id, date):
# def for_date_range(filter_id, start_date, end_date=None):
# def latest_update():
# 
# Path: dashboard/services/predictions.py
# def throughput_history(summaries):
# def forecast(throughputs, backlog_size, num_simulations=10000, seed=None):
# def for_project(filter_id, backlog_size, start_date):


# Path: dashboard/jobs.py
import datetime
import logging
from dateutil.relativedelta import relativedelta
from dateutil.parser import parse
from django.conf import settings
from django.core.cache import cache
from django.utils.timezone import get_default_timezone
from django_rq import job
from .services import sheets, jira, summaries, predictions







def _add_current_jira_summary(xtras, jira_filter_id, logger):
    summary_data = jira.summarize_query(jira_filter_id)
    logger.debug("Filter {} summarized".format(jira_filter_id))
    if summary_data.get('errors', []):
        xtras['jira_summary_errors'] = summary_data['errors']
        logger.warn("Filter {} summary error".format(summary_data['errors']))
    elif summary_data:
        p = summaries.create(
            filter_id=int(xtras['_jira_filter']),
            incomplete=summary_data['incomplete'],
            complete=summary_data['complete'],
            total=summary_data['total'],
            created_on=datetime.date.today(),
        )

        summaries.store(p)