# Path: fooltrader/contract/data_contract.py
# TICK_COL = ['timestamp', 'price', 'volume', 'turnover', 'direction']
# 
# Path: fooltrader/contract/files_contract.py
# def get_tick_path(item, date):
#     return os.path.join(get_tick_dir(item), date + ".csv")
# 
# Path: fooltrader/settings.py
# TIME_FORMAT_DAY = '%Y-%m-%d'
# 
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"


import datetime
import logging
import os
import pandas as pd
from logging.handlers import RotatingFileHandler
from fooltrader.contract.data_contract import TICK_COL
from fooltrader.contract.files_contract import get_tick_path
from fooltrader.settings import TIME_FORMAT_DAY, TIME_FORMAT_MICRO
def get_year_quarter(time):
    if type(time) == str:
        time = get_datetime(time)
    return time.year, ((time.month - 1) // 3) + 1


def get_quarters(start, end=datetime.date.today()):
    start_year_quarter = get_year_quarter(start)
    current_year_quarter = get_year_quarter(end)
    if current_year_quarter[0] == start_year_quarter[0]:
        return [(current_year_quarter[0], x) for x in range(start_year_quarter[1], current_year_quarter[1] + 1)]
    elif current_year_quarter[0] - start_year_quarter[0] == 1:
        return [(start_year_quarter[0], x) for x in range(start_year_quarter[1], 5)] + \
               [(current_year_quarter[0], x) for x in range(1, current_year_quarter[1] + 1)]
    elif current_year_quarter[0] - start_year_quarter[0] > 1:
        return [(start_year_quarter[0], x) for x in range(start_year_quarter[1], 5)] + \
               [(x, y) for x in range(start_year_quarter[0] + 1, current_year_quarter[0]) for y in range(1, 5)] + \
               [(current_year_quarter[0], x) for x in range(1, current_year_quarter[1] + 1)]
    else:
        raise Exception("wrong start time:{}".format(start))


def fill_doc_type(doc_type, json_object):
    for key in json_object:
        doc_type[key] = json_object[key]


def to_float(str, default=None):
    try:
        return float(str.replace(',', ''))

# Path: fooltrader/contract/data_contract.py
# TICK_COL = ['timestamp', 'price', 'volume', 'turnover', 'direction']
# 
# Path: fooltrader/contract/files_contract.py
# def get_tick_path(item, date):
#     return os.path.join(get_tick_dir(item), date + ".csv")
# 
# Path: fooltrader/settings.py
# TIME_FORMAT_DAY = '%Y-%m-%d'
# 
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"


# Path: fooltrader/utils/utils.py
import datetime
import logging
import os
import pandas as pd
from logging.handlers import RotatingFileHandler
from fooltrader.contract.data_contract import TICK_COL
from fooltrader.contract.files_contract import get_tick_path
from fooltrader.settings import TIME_FORMAT_DAY, TIME_FORMAT_MICRO

def get_year_quarter(time):
    if type(time) == str:
        time = get_datetime(time)
    return time.year, ((time.month - 1) // 3) + 1


def get_quarters(start, end=datetime.date.today()):
    start_year_quarter = get_year_quarter(start)
    current_year_quarter = get_year_quarter(end)
    if current_year_quarter[0] == start_year_quarter[0]:
        return [(current_year_quarter[0], x) for x in range(start_year_quarter[1], current_year_quarter[1] + 1)]
    elif current_year_quarter[0] - start_year_quarter[0] == 1:
        return [(start_year_quarter[0], x) for x in range(start_year_quarter[1], 5)] + \
               [(current_year_quarter[0], x) for x in range(1, current_year_quarter[1] + 1)]
    elif current_year_quarter[0] - start_year_quarter[0] > 1:
        return [(start_year_quarter[0], x) for x in range(start_year_quarter[1], 5)] + \
               [(x, y) for x in range(start_year_quarter[0] + 1, current_year_quarter[0]) for y in range(1, 5)] + \
               [(current_year_quarter[0], x) for x in range(1, current_year_quarter[1] + 1)]
    else:
        raise Exception("wrong start time:{}".format(start))


def fill_doc_type(doc_type, json_object):
    for key in json_object:
        doc_type[key] = json_object[key]


def to_float(str, default=None):
    try:
        return float(str.replace(',', ''))

    except Exception as e: