<commit_before># -*- coding: utf-8 -*-

# FOGLAMP_BEGIN
# See: http://foglamp.readthedocs.io/
# FOGLAMP_END

import asyncio
import time
import json
from foglamp.common import logger
from aiohttp import web
from foglamp.services.core import server
from foglamp.services.core.api.statistics import get_statistics

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
__license__ = "Apache 2.0"
__version__ = "${VERSION}"

__start_time = time.time()

_logger = logger.setup(__name__, level=20)

_help = """
    -------------------------------------------------------------------------------
    | GET             | /foglamp/ping                                             |
    | PUT             | /foglamp/shutdown                                         |
    -------------------------------------------------------------------------------
"""


async def ping(request):
    """
    Args:
       request:

    Returns:
           basic health information json payload
           {'uptime': 32892} Time in seconds since FogLAMP started

    :Example:
           curl -X GET http://localhost:8081/foglamp/ping
    """
    since_started = time.time() - __start_time

    new_request = request.clone(rel_url='foglamp/statistics')
    interim_stat = await get_statistics(new_request)
    stat = json.loads(interim_stat.body.decode())

    data_read = [a['value'] for a in stat if a['key'] == 'READINGS']
    data_sent_1 = [a['value'] for a in stat if a['key'] == 'SENT_1']
    data_sent_2 = [a['value'] for a in stat if a['key'] == 'SENT_2']
    data_sent_3 = [a['value'] for a in stat if a['key'] == 'SENT_3']
    data_sent_4 = [a['value'] for a in stat if a['key'] == 'SENT_4']
    data_purged = [a['value'] for a in stat if a['key'] == 'PURGED']

    return web.json_response({'uptime': since_started,
                              'data.read': data_read[0],
                              'data.sent': int(data_sent_1[0])+int(data_sent_2[0])+int(data_sent_3[0])+int(data_sent_4[0]),
                              'data.purged': int(data_purged[0]),
                              'auth': request.is_auth_optional
                              })

async def shutdown(request):
    """
    Args:
        request:

    Returns:
<commit_msg>FOGL-790 - feedback changes<commit_after># -*- coding: utf-8 -*-

# FOGLAMP_BEGIN
# See: http://foglamp.readthedocs.io/
# FOGLAMP_END

import asyncio
import time
import json
from foglamp.common import logger
from aiohttp import web
from foglamp.services.core import server
from foglamp.services.core.api.statistics import get_statistics

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
__license__ = "Apache 2.0"
__version__ = "${VERSION}"

__start_time = time.time()

_logger = logger.setup(__name__, level=20)

_help = """
    -------------------------------------------------------------------------------
    | GET             | /foglamp/ping                                             |
    | PUT             | /foglamp/shutdown                                         |
    -------------------------------------------------------------------------------
"""


async def ping(request):
    """
    Args:
       request:

    Returns:
           basic health information json payload
           {'uptime': 32892} Time in seconds since FogLAMP started

    :Example:
           curl -X GET http://localhost:8081/foglamp/ping
    """
    since_started = time.time() - __start_time

    new_request = request.clone(rel_url='foglamp/statistics')
    interim_stat = await get_statistics(new_request)
    stat = json.loads(interim_stat.body.decode())

    data_read = [a['value'] for a in stat if a['key'] == 'READINGS']
    data_sent_1 = [a['value'] for a in stat if a['key'] == 'SENT_1']
    data_sent_2 = [a['value'] for a in stat if a['key'] == 'SENT_2']
    data_sent_3 = [a['value'] for a in stat if a['key'] == 'SENT_3']
    data_sent_4 = [a['value'] for a in stat if a['key'] == 'SENT_4']
    data_purged = [a['value'] for a in stat if a['key'] == 'PURGED']

    return web.json_response({'uptime': since_started,
                              'dataRead': data_read[0],
                              'dataSent': int(data_sent_1[0])+int(data_sent_2[0])+int(data_sent_3[0])+int(data_sent_4[0]),
                              'dataPurged': int(data_purged[0]),
                              'auth': request.is_auth_optional
                              })

async def shutdown(request):
    """
    Args:
        request:

    Returns:

{'fraction_non_alphanumeric': 0.19391131700860356, 'fraction_numerical': 0.01654533421575116, 'mean_word_length': 1.7833026396562308, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3301868', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1357, 'n_words': 318}