<commit_before>#!/usr/bin/env python
'''
ooiservices.controller.stream

StreamObjectController
StreamListController
'''

from ooiservices.controller.base import ObjectController, ListController
from ooiservices.model.stream import StreamModel
from ooiservices.config import ERDDAPURL
from ooiservices import app
from flask import request
from flask.ext.restful import Resource

import re
import time
import requests

CACHE_UPDATE = None
META_OUTLINE = None

class StreamController(ObjectController):

    def get(self, id):
        result = self.model.read(id)
        return result

class StreamListController(ListController):

    def get(self):
        stream_list = get_stream_list()
        if request.args.get('reference_designator', None):
            ref_def = request.args.get('reference_designator')
            ref_def = re.sub(r'-', '_', ref_def)
            stream_list = [ s for s in stream_list if ref_def in s['Dataset ID'] ]

        return stream_list

def get_stream_list():
    index = get_index()
    streams = []
    columns = index['table']['columnNames']
    for row in index['table']['rows']:
        stream = {}
        for i, ele in enumerate(row):
            stream[columns[i]] = ele
        stream['id'] = stream['Dataset ID']
        streams.append(stream)
    return streams

def get_index():
    global META_OUTLINE
    global CACHE_UPDATE
    if META_OUTLINE is None:
        cahce_update = time.time()
        url = ERDDAPURL+"/info/index.json"
        META_OUTLINE = requests.get(url)
        META_OUTLINE = META_OUTLINE.json()
    if CACHE_UPDATE < (time.time() + 60):
        cahce_update = time.time()
        url = ERDDAPURL+"/info/index.json"
        META_OUTLINE = requests.get(url)
        META_OUTLINE = META_OUTLINE.json()
    return META_OUTLINE
<commit_msg>updated stream controller<commit_after>#!/usr/bin/env python
'''
ooiservices.controller.stream

StreamObjectController
StreamListController
'''

from ooiservices.controller.base import ObjectController, ListController
from ooiservices.model.stream import StreamModel
from ooiservices.config import ERDDAPURL
from ooiservices import app
from flask import request
from flask.ext.restful import Resource

import re
import time
import requests

CACHE_UPDATE = None
META_OUTLINE = None

class StreamController(ObjectController):

    model = StreamModel()

    def __init__(self):
        ObjectController.__init__(self)

    def get(self,id):
        result = self.model.read(id)
        if not result:
            return self.response_HTTP204()
        return result

class StreamListController(ListController):

    model = StreamModel()

    def get(self):
        args = request.args
        if args:
            result = self.process_args(self.model, args,'stream_id')
        else:
            result = self.model.read()
        if not result:
            return self.response_HTTP204()
        return result
{'fraction_non_alphanumeric': 0.09025394646533974, 'fraction_numerical': 0.002745367192862045, 'mean_word_length': 3.1288951841359776, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '4916669', 'n_tokens_mistral': 861, 'n_tokens_neox': 843, 'n_words': 216}