<commit_before>import tempfile

import pandas as pd
import pytest
import pytz
import json

from eemeter.ee.meter import EnergyEfficiencyMeter
from eemeter.testing.mocks import MockWeatherClient
from eemeter.weather import TMY3WeatherSource
from eemeter.weather import ISDWeatherSource
from eemeter.modeling.formatters import ModelDataBillingFormatter
from eemeter.modeling.models import CaltrackMonthlyModel


@pytest.fixture
def project_meter_input():
    return {
        "type": "PROJECT_WITH_SINGLE_MODELING_PERIOD_GROUP",
        "zipcode": "91104",
        "project_id": "PROJECT_1",
        "modeling_period_group": {
            "baseline_period": {
                "start": None,
                "end": "2014-01-01T00:00:00+00:00"
            },
            "reporting_period": {
                "start": "2014-02-01T00:00:00+00:00",
                "end": None
            }
        }
    }


@pytest.fixture
def project_meter_input_bad_zipcode():
    return {
        "type": "PROJECT_WITH_SINGLE_MODELING_PERIOD_GROUP",
        "zipcode": "11111",  # not valid
        "modeling_period_group": {
            "baseline_period": {
                "start": None,
                "end": "2014-01-01T00:00:00+00:00"
            },
            "reporting_period": {
                "start": "2014-02-01T00:00:00+00:00",
                "end": None
            }
        }
    }


def _electricity_input(records):
    return {
        "type": "ARBITRARY_START",
        "interpretation": "ELECTRICITY_CONSUMPTION_SUPPLIED",
        "unit": "KWH",
        "records": records
    }


def _natural_gas_input(records):
    return {
        "type": "ARBITRARY_START",
        "interpretation": "NATURAL_GAS_CONSUMPTION_SUPPLIED",
        "unit": "THERM",
        "trace_id": "TRACE_1",
        "records": records
    }


@pytest.fixture
def meter_input_daily(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=365 * 4, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    trace = _natural_gas_input(records)
    trace.update({'interval': 'daily'})

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": trace,
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_empty(project_meter_input):

    records = []

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_daily_baseline_only(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=365 * 1, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_daily_reporting_only(project_meter_input):

    record_starts = pd.date_range(
        '2014-02-01', periods=365 * 1, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_monthly(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=50, freq='MS', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts<commit_msg>Trigger the heating coefficient for monthly fixture<commit_after>import tempfile

import pandas as pd
import pytest
import pytz
import json

from eemeter.ee.meter import EnergyEfficiencyMeter
from eemeter.testing.mocks import MockWeatherClient
from eemeter.weather import TMY3WeatherSource
from eemeter.weather import ISDWeatherSource
from eemeter.modeling.formatters import ModelDataBillingFormatter
from eemeter.modeling.models import CaltrackMonthlyModel


@pytest.fixture
def project_meter_input():
    return {
        "type": "PROJECT_WITH_SINGLE_MODELING_PERIOD_GROUP",
        "zipcode": "91104",
        "project_id": "PROJECT_1",
        "modeling_period_group": {
            "baseline_period": {
                "start": None,
                "end": "2014-01-01T00:00:00+00:00"
            },
            "reporting_period": {
                "start": "2014-02-01T00:00:00+00:00",
                "end": None
            }
        }
    }


@pytest.fixture
def project_meter_input_bad_zipcode():
    return {
        "type": "PROJECT_WITH_SINGLE_MODELING_PERIOD_GROUP",
        "zipcode": "11111",  # not valid
        "modeling_period_group": {
            "baseline_period": {
                "start": None,
                "end": "2014-01-01T00:00:00+00:00"
            },
            "reporting_period": {
                "start": "2014-02-01T00:00:00+00:00",
                "end": None
            }
        }
    }


def _electricity_input(records):
    return {
        "type": "ARBITRARY_START",
        "interpretation": "ELECTRICITY_CONSUMPTION_SUPPLIED",
        "unit": "KWH",
        "records": records
    }


def _natural_gas_input(records):
    return {
        "type": "ARBITRARY_START",
        "interpretation": "NATURAL_GAS_CONSUMPTION_SUPPLIED",
        "unit": "THERM",
        "trace_id": "TRACE_1",
        "records": records
    }


@pytest.fixture
def meter_input_daily(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=365 * 4, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    trace = _natural_gas_input(records)
    trace.update({'interval': 'daily'})

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": trace,
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_empty(project_meter_input):

    records = []

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_daily_baseline_only(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=365 * 1, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_daily_reporting_only(project_meter_input):

    record_starts = pd.date_range(
        '2014-02-01', periods=365 * 1, freq='D', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0,
            "estimated": False
        } for dt in record_starts
    ]

    meter_input = {
        "type": "SINGLE_TRACE_SIMPLE_PROJECT",
        "trace": _natural_gas_input(records),
        "project": project_meter_input,
    }
    return meter_input


@pytest.fixture
def meter_input_monthly(project_meter_input):

    record_starts = pd.date_range(
        '2012-01-01', periods=50, freq='MS', tz=pytz.UTC)

    records = [
        {
            "start": dt.isoformat(),
            "value": 1.0 if dt.month > 4 or dt.month < 10 else 2.0,
            "estimated": False
        } for dt in record_starts
{'fraction_non_alphanumeric': 0.11752347998022739, 'fraction_numerical': 0.03497281265447355, 'mean_word_length': 2.303265306122449, 'pattern_counts': {'":': 104, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446152', 'n_tokens_mistral': 2933, 'n_tokens_neox': 2656, 'n_words': 471}