コード例 #1
0
def test_socket_server_error_handeling():

    with raises(ValueError):
        n_closest_dict = s_client.get_n_nearest_ts_for_tsid(-999999, 5)

    with raises(ValueError):
        s_client.get_ts_with_id(-9999999)

    fake_ats = lambda x: x
    fake_ats.values = lambda a=None: [1, 2, 3]
    fake_ats.times = lambda b=None: [1, 2, 1]

    with raises(ValueError):
        s_client.save_ts_to_db(fake_ats)

    with raises(ValueError):
        s_client.get_n_nearest_ts_for_ts(fake_ats, 5)

    json_prep = {"type": "Non existent message type"}
    s = s_client.open_socket(json_prep)
    assert (s['error_type'] == 'ValueError')
コード例 #2
0
def test_save_ts_to_db_two():
    new_ts = ArrayTimeSeries(values=[0, 1, 2, 3, 10],
                             times=[0., .2, .3, .5, 1])
    #new_ts = ArrayTimeSeries(values=[ 1.90015224,4.11290636,2.45059022,2.45251473,-4.1988066], times=[ 0.,0.2,0.4,0.6,0.8])
    #new_ts = (tsmaker(0.5, 0.1, random.uniform(0,10),5))

    new_tsid = s_client.save_ts_to_db(new_ts)
    echo_ts = s_client.get_ts_with_id(new_tsid)
    interpolated_ats = new_ts.interpolate(
        np.arange(0.0, 1.0, (1.0 / TS_LENGTH)))
    assert (kernel_dist(standardize(echo_ts), standardize(interpolated_ats)) <
            .00001)
コード例 #3
0
ファイル: views.py プロジェクト: gitrdone4/cs207project
def get_ts_and_metadata(tsid=None):
    """
    Description
    -----------
    Handles GET requests for API endpoint /timeseries/id.

    Fetches both time series itself (through socket) 
    and metadata (from PostgreSQL) for the tsid.

    Parameters
    ----------
    tsid: int
        id of the desired time series

    Returns
    -------
    HTTP Response with requested time series (meta)data.

    Response is of the format:
    {
        'id': tsid,
        'metadata': {...}
        'time_series_data': [
            'time': [...],
            'value': [...]
        ]
    }
    """

    # get actual ts from socket
    try:
        actual_ts = cl.get_ts_with_id(tsid)
    except:
        return not_found('Time series with id {} not found in DB!'.format(tsid))

    # get metadata
    metadata = fetch_metadata('ts_metadata_id = {}'.format(tsid))

    # create response from query result, jsonify and return
    response = {
                'id': tsid,
                'metadata': [ts.to_dict() for ts in metadata],
                'time_series': actual_ts.to_dict()
            }

    return make_response(jsonify(response), 200)
コード例 #4
0
def test_get_by_id_over_socket():
    """Name says it all """
    ats100 = get_by_id(100)
    assert (ats100 == s_client.get_ts_with_id(100))
コード例 #5
0
def test_save_ts_to_db():
    # Save a ts, request it by id, compare to original
    new_ts = (tsmaker(0.5, 0.1, random.uniform(0, 10)))
    new_tsid = s_client.save_ts_to_db(new_ts)
    echo_ts = s_client.get_ts_with_id(new_tsid)
    assert (kernel_dist(standardize(echo_ts), standardize(new_ts)) < .00001)