<commit_before># coding: utf-8

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pylab import *
## agg backend is used to create plot as a .png file
#mpl.use('agg')


#############################
# get data
##############################


##################################
#monthly streak data for huc
#need a dictionary with a single huc as a key and
#12 monthly values in a list as the value
def GetSAM_MonthlyHUCStreakOutput(jobid, hucid):
	#fake
    sam_dict = {0:[0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.]}

    #actual mongo query - function is in front end in /REST/rest_funcs.py
    #sam_dict = get_sam_huc_output(jid, huc12)

    #get values from dictionary- return the list
    sam_huc = sam_dict.values()

	return sam_huc

#annual streak data for huc
#need a dictionary with a single huc as a key and
#30 annual values in a list as the value
def GetSAM_AnnualHUCStreakOutput(jobid, hucid):
	#fake
    sam_dict = {0:[0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.,
                   0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.,
                   0.,0.,0.,3.3,2.4,1.1]}

    #actual mongo query - function is in front end in /REST/rest_funcs.py<commit_msg>mongo model object retrieval support on back end<commit_after># coding: utf-8

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pylab import *
## agg backend is used to create plot as a .png file
#mpl.use('agg')

#mongo call support
import json
import auth_s3
import requests
import logging

# Set HTTP header
http_headers = auth_s3.setHTTPHeaders()
#this probably not set for back end
url_part1 = os.environ['UBERTOOL_REST_SERVER']

##############################
## mongo calls
###########################function to retrieve model object from MongoDB################################
def get_model_object(jid, model_name):
    """Retrieves JSON from MongoDB representing model (Python) object and returns it as Python dictionary"""
    all_dic = {"jid": jid, "model_name": model_name}
    data = json.dumps(all_dic)
    url = url_part1 + '/get_model_object'
    try:
        response = requests.post(url, data=data, headers=http_headers, timeout=60)
        if response:
            model_object = json.loads(response.content)['model_object']
        else:
            model_object = ""

    except:
        return { "error": "error" }

    return model_object

###########################function to retrieve model object from MongoDB################################
def get_sam_huc_output(jid, huc12):
    """Retrieves JSON from MongoDB representing model (Python) object and returns it as Python dictionary"""
    all_dic = {"jid": jid, "model_name": "sam", "huc12": huc12}
    data = json.dumps(all_dic)
    url = url_part1 + '/get_sam_huc_output'
    try:
        response = requests.post(url, data=data, headers=http_headers, timeout=60)
        if response:
            model_object = json.loads(response.content)['huc12_output']
        else:
            model_object =""

    except:
        logging.exception(Exception)
        return "error"

    return model_object





#############################
# get data
##############################

##################################
#monthly streak data for huc
#need a dictionary with a single huc as a key and
#12 monthly values in a list as the value
def GetSAM_MonthlyHUCStreakOutput(jobid, hucid):
	#fake
    sam_dict = {0:[0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.]}

    #actual mongo query - function is in front end in /REST/rest_funcs.py
    #sam_dict = get_sam_huc_output(jid, huc12)

    #get values from dictionary- return the list
    sam_huc = sam_dict.values()

	return sam_huc

#annual streak data for huc
#need a dictionary with a single huc as a key and
#30 annual values in a list as the value
def GetSAM_AnnualHUCStreakOutput(jobid, hucid):
	#fake
    sam_dict = {0:[0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.,
                   0.,0.,0.,3.3,2.4,1.1,3.6,2.0,0.,0.,0.,0.,
                   0.,0.,0.,3.3,2.4,1.1]}

    #actual mongo query - function is in front end in /REST/rest_funcs.py
{'fraction_non_alphanumeric': 0.1908845871110022, 'fraction_numerical': 0.037980887037490814, 'mean_word_length': 3.466083150984683, 'pattern_counts': {'":': 6, '<': 3, '<?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': '6871462', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1373, 'n_words': 399}