Exemplo n.º 1
0
def execute_job(job_dict):
    """
    Takes job_dict as input.
    Gets the data from get_db_data so data bounds are correct.
    Returns completed data get as results.
    """
    data_list = get_db_data(job_dict["start"], job_dict["end"],
                            job_dict["limit"], job_dict["offset"])
    return data_list
Exemplo n.º 2
0
def get_year(year):
    """
    Takes a year as route argument.
    Checks input with input_checker, returns 400 and errors if they exist.
    Returns data point dictionary corresponding to year.
    """
    start, end, limit, offset, errors = input_checker(year=year)
    if errors:
        return jsonify(errors), 400
    data_list = get_db_data(start, end, limit, offset)
    return jsonify(data_list[0])
Exemplo n.º 3
0
def get_db_data_with_args():
    """
    Takes a start, end, limit, and offset value from route arguments.
    Checks input with input_checker, returns 400 and errors if they exist.
    Otherwises returns json list of data requested.
    """
    start = request.args.get('start')
    end = request.args.get('end')
    limit = request.args.get('limit')
    offset = request.args.get('offset')

    start, end, limit, offset, errors = input_checker(start, end, limit,
                                                      offset)
    if errors:
        return jsonify(errors), 400
    data_list = get_db_data(start, end, limit, offset)
    return jsonify(data_list)
Exemplo n.º 4
0
def execute_job(job_dict):
    """
    Takes job_dict as input.
    Gets the data from get_db_data so data bounds are correct.
    Runs 'statistics' operations on the data_set and places in a 'result's dictionary.
    Returns dictionary as results
    """
    data_list = get_db_data(job_dict["start"], job_dict["end"],
                            job_dict["limit"], job_dict["offset"])

    sun_data = [dict_x["spots"] for dict_x in data_list]

    if sun_data:
        stats_list = [
            {
                "mean": statistics.mean(sun_data)
            },
            {
                "harmonic mean": statistics.harmonic_mean(sun_data)
            },
            {
                "median": statistics.median(sun_data)
            },
            {
                "low median": statistics.median_low(sun_data)
            },
            {
                "high median": statistics.median_high(sun_data)
            },
            {
                "mode": statistics.mode(sun_data)
            },
            {
                "variance": statistics.variance(sun_data)
            },
            {
                "standard deviation": statistics.stdev(sun_data)
            },
        ]
    return stats_list
def test_limit_no_offset_check():
    assert int(open(CSV_FILE).readlines()[0][0:4]) ==\
            get_db_data(CSV_FILE, limit=20)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[19][0:4]) ==\
            get_db_data(CSV_FILE, limit=20)[1][-1]["year"]
def test_start_greater_than_end_check():
    assert get_db_data(CSV_FILE, 1829, 1729)[0] is True
def test_start_and_end_check():
    assert int(open(CSV_FILE).readlines()[20][0:4]) ==\
            get_db_data(CSV_FILE, 1790, 1840)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[70][0:4]) ==\
            get_db_data(CSV_FILE, 1790, 1840)[1][-1]["year"]
def test_end_no_start_check():
    assert int(open(CSV_FILE).readlines()[0][0:4]) ==\
            get_db_data(CSV_FILE, end=1820)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[50][0:4]) ==\
            get_db_data(CSV_FILE, end=1820)[1][-1]["year"]
def test_start_no_end_check():
    assert int(open(CSV_FILE).readlines()[60][0:4]) ==\
            get_db_data(CSV_FILE, 1830)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[-1][0:4]) ==\
            get_db_data(CSV_FILE, 1830)[1][-1]["year"]
Exemplo n.º 10
0
def test_list_first_and_last_value_check():
    assert int(open(CSV_FILE).readlines()[0][0:4]) == get_db_data(
        CSV_FILE)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[-1][0:4]) == get_db_data(
        CSV_FILE)[1][-1]["year"]
Exemplo n.º 11
0
def test_keys_check():
    for line in get_db_data(CSV_FILE)[1]:
        assert isinstance(line["id"], int)
        assert isinstance(line["year"], int)
        assert isinstance(line["spots"], int)
Exemplo n.º 12
0
def test_dict_length_check():
    for line in get_db_data(CSV_FILE)[1]:
        assert len(line) == 3
Exemplo n.º 13
0
def test_dict_type_check():
    for line in get_db_data(CSV_FILE)[1]:
        assert isinstance(line, dict)
Exemplo n.º 14
0
def test_list_type_check():
    assert isinstance(get_db_data(CSV_FILE)[1], list)
Exemplo n.º 15
0
def test_limit_and_offset_check():
    assert int(open(CSV_FILE).readlines()[15][0:4]) ==\
            get_db_data(CSV_FILE, limit=20, offset=15)[1][0]["year"]
    assert int(open(CSV_FILE).readlines()[34][0:4]) ==\
            get_db_data(CSV_FILE, limit=20, offset=15)[1][-1]["year"]
Exemplo n.º 16
0
import sys
from os import path
sys.path.append(path.abspath(path.join(__file__, '../../database')))
#print(sys.path)
import get_db_data as gdd
from scipy.signal import savgol_filter
from scipy.stats import zscore
import numpy as np
import pandas as pd

data = gdd.get_db_data()
pars = data.get_participants(True)

pars_tuples = {}
for g, p, _ in pars:
    pars_tuples[g] = pars_tuples.get(g, []) + [p]

gm_orth = lambda v, u: v - u * (v @ u) / (u @ u)


def yield_group_signals(group_id, series_type, interp_type):
    return data.get_signal_by_series_type_and_interp_type(
        group_id, series_type, interp_type)


class savitzky_golay:
    def __init__(self, group_ids, f1_length, f2_length, series_type,
                 interp_type):
        self.group_ids = group_ids
        self.f1_length = f1_length
        self.f2_length = f2_length
Exemplo n.º 17
0
def test_list_length_check():
    assert len(open(CSV_FILE).readlines()) == len(get_db_data(CSV_FILE)[1])