<commit_before>"""forecast_utils.py: collection of tools for forecasting future performance"""
import sys
from os import path
from datetime import datetime

import ujson as json
import pandas as pd
from pandas.io.json import json_normalize
from fbprophet import Prophet
import requests

requests.models.json = json

import publicAPI.crest_utils as crest_utils
import publicAPI.config as config
import prosper.common.prosper_logging as p_logging

HERE = path.abspath(path.dirname(__file__))
LOGGER = p_logging.DEFAULT_LOGGER

DEFAULT_RANGE = 700
CREST_RANGE = 365
def fetch_extended_history(
        region_id,
        type_id,
        raise_on_short=False,
        data_range=DEFAULT_RANGE,
        logger=LOGGER
):
    """fetch data from database

    Args:
        region_id (int): EVE Online regionID: https://crest-tq.eveonline.com/regions/
        type_id (int): EVE Online typeID: https://crest-tq.eveonline.com/types/
        raise_on_short (bool, optional): raise exception if <365 entries found
        data_range (int, optional): how far back to fetch data
        logger (:obj:`logging.logger`): logging handle

    Returns:
        (:obj:`pandas.data_frame`): collection of data from database
            ['date', 'avgPrice', 'highPrice', 'lowPrice', 'volume', 'orders']
    """
    pass

EMD_MARKET_HISTORY = 'http://eve-marketdata.com/api/item_history2.json'
def fetch_market_history_emd(
        region_id,
        type_id,
        data_range,
        endpoint_addr=EMD_MARKET_HISTORY,
        config=config.CONFIG
    ):
    """use EMD endpoint to fetch data instead of MySQL

    Args:
        region_id (int): EVE Online regionID: https://crest-tq.eveonline.com/regions/
        type_id (int): EVE Online typeID: https://crest-tq.eveonline.com/types/
        data_range (int): number of days to fetch
        endpoint_addr (str, optional): EMD endpoint to query against
        config (:obj:`configparser.ConfigParser`, optional): overrides for config

    Returns:
        (:obj:`dict` json): collection of data from endpoint
            ['typeID', 'regionID', 'date', 'lowPrice', 'highPrice', 'avgPrice', 'volume', 'orders']

    """
    payload = {
        'region_ids': region_id,
        'type_ids': type_id,
        'days': data_range,
        'char_name': config.get('GLOBAL', 'useragent_short')
    }
    headers = {
        'User-Agent': config.get('GLOBAL', 'useragent')
    }

    req = requests.get(
        endpoint_addr,
        headers=headers,
        params=payload
    )
    req.raise_for_status()
    data = req.json()['emd']

    if not data['result']:
        raise NoDataReturned()


    return data
<commit_msg>fixing `config` namespace collision<commit_after>"""forecast_utils.py: collection of tools for forecasting future performance"""
import sys
from os import path
from datetime import datetime

import ujson as json
import pandas as pd
from pandas.io.json import json_normalize
from fbprophet import Prophet
import requests

requests.models.json = json

import publicAPI.crest_utils as crest_utils
import publicAPI.config as api_config
import prosper.common.prosper_logging as p_logging

HERE = path.abspath(path.dirname(__file__))
LOGGER = p_logging.DEFAULT_LOGGER

DEFAULT_RANGE = 700
CREST_RANGE = 365
def fetch_extended_history(
        region_id,
        type_id,
        raise_on_short=False,
        data_range=DEFAULT_RANGE,
        logger=LOGGER
):
    """fetch data from database

    Args:
        region_id (int): EVE Online regionID: https://crest-tq.eveonline.com/regions/
        type_id (int): EVE Online typeID: https://crest-tq.eveonline.com/types/
        raise_on_short (bool, optional): raise exception if <365 entries found
        data_range (int, optional): how far back to fetch data
        logger (:obj:`logging.logger`): logging handle

    Returns:
        (:obj:`pandas.data_frame`): collection of data from database
            ['date', 'avgPrice', 'highPrice', 'lowPrice', 'volume', 'orders']
    """
    pass

EMD_MARKET_HISTORY = 'http://eve-marketdata.com/api/item_history2.json'
def fetch_market_history_emd(
        region_id,
        type_id,
        data_range,
        endpoint_addr=EMD_MARKET_HISTORY,
        config=api_config.CONFIG
    ):
    """use EMD endpoint to fetch data instead of MySQL

    Args:
        region_id (int): EVE Online regionID: https://crest-tq.eveonline.com/regions/
        type_id (int): EVE Online typeID: https://crest-tq.eveonline.com/types/
        data_range (int): number of days to fetch
        endpoint_addr (str, optional): EMD endpoint to query against
        config (:obj:`configparser.ConfigParser`, optional): overrides for config

    Returns:
        (:obj:`dict` json): collection of data from endpoint
            ['typeID', 'regionID', 'date', 'lowPrice', 'highPrice', 'avgPrice', 'volume', 'orders']

    """
    payload = {
        'region_ids': region_id,
        'type_ids': type_id,
        'days': data_range,
        'char_name': config.get('GLOBAL', 'useragent_short')
    }
    headers = {
        'User-Agent': config.get('GLOBAL', 'useragent')
    }

    req = requests.get(
        endpoint_addr,
        headers=headers,
        params=payload
    )
    req.raise_for_status()
    data = req.json()['emd']

    if not data['result']:
        raise NoDataReturned()

    return data

{'fraction_non_alphanumeric': 0.1072567035439715, 'fraction_numerical': 0.003750234389649353, 'mean_word_length': 3.043972706595906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 8, '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': '93086', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1616, 'n_words': 433}