# Path: performanceplatform/utils/datetimeutil.py
# def to_datetime(a_date):
#     if type(a_date) == datetime:
#         return a_date.replace(tzinfo=pytz.UTC)
#     return datetime.combine(a_date, time(0)).replace(tzinfo=pytz.UTC)
# 
# def to_utc(a_datetime):
#     return a_datetime.astimezone(pytz.UTC)


from performanceplatform.utils.datetimeutil \
    import to_datetime, to_utc
    from performanceplatform.collector.ga.plugins import load_plugins
import logging
import base64
import re
def build_document_set(results, data_type, mappings, special_fields,
                       idMapping=None,
                       additionalFields={}):
    if special_fields and len(results) != len(special_fields):
        raise ValueError(
            "There must be same number of special fields as results")
    parsed = []
    for i, item in enumerate(results):
        if not special_fields:
            special = {}
        else:
            special = special_fields[i]
        parsed.append(build_document(item,
                                     data_type,
                                     special,
                                     mappings,
                                     idMapping,
                                     additionalFields=additionalFields))
    return parsed


def build_document(item, data_type, special_fields={},
                   mappings=None, idMapping=None,
                   additionalFields={}):
    if data_type is None:
        raise ValueError("Must provide a data type")
    if mappings is None:
        mappings = {}

    base_properties = {

# Path: performanceplatform/utils/datetimeutil.py
# def to_datetime(a_date):
#     if type(a_date) == datetime:
#         return a_date.replace(tzinfo=pytz.UTC)
#     return datetime.combine(a_date, time(0)).replace(tzinfo=pytz.UTC)
# 
# def to_utc(a_datetime):
#     return a_datetime.astimezone(pytz.UTC)


# Path: performanceplatform/utils/data_parser.py
from performanceplatform.utils.datetimeutil \
    import to_datetime, to_utc
    from performanceplatform.collector.ga.plugins import load_plugins
import logging
import base64
import re

def build_document_set(results, data_type, mappings, special_fields,
                       idMapping=None,
                       additionalFields={}):
    if special_fields and len(results) != len(special_fields):
        raise ValueError(
            "There must be same number of special fields as results")
    parsed = []
    for i, item in enumerate(results):
        if not special_fields:
            special = {}
        else:
            special = special_fields[i]
        parsed.append(build_document(item,
                                     data_type,
                                     special,
                                     mappings,
                                     idMapping,
                                     additionalFields=additionalFields))
    return parsed


def build_document(item, data_type, special_fields={},
                   mappings=None, idMapping=None,
                   additionalFields={}):
    if data_type is None:
        raise ValueError("Must provide a data type")
    if mappings is None:
        mappings = {}

    base_properties = {

        "_timestamp": to_datetime(item["start_date"]),