Esempio n. 1
0
def test_interpolation():
    a = TS.TimeSeries([0, 5, 10], [1, 2, 3])
    b = TS.TimeSeries([2.5, 7.5], [100, -100])
    # Simple cases
    assert a.interpolate([1]) == TS.TimeSeries([1], [1.2])
    assert a.interpolate(b.times()) == TS.TimeSeries([2.5, 7.5], [1.5, 2.5])
    # Boundary conditions
    assert a.interpolate([-100, 100]) == TS.TimeSeries([-100, 100], [1, 3])
Esempio n. 2
0
def test_sub():
    a = TS.TimeSeries([0, 5, 10], [1, 2, 3])
    b = TS.TimeSeries([0, 5, 10], [10, 20, 30])
    c = 100
    d = TS.TimeSeries([0, 1, 2], [1, 2, 3])
    assert b - a == TS.TimeSeries([0, 5, 10], [9, 18, 27])
    assert a - c == TS.TimeSeries([0, 5, 10], [-99, -98, -97])
    with raises(ValueError):
        a - d
Esempio n. 3
0
def test_mul():
    a = TS.TimeSeries([0, 5, 10], [1, 2, 3])
    b = TS.TimeSeries([0, 5, 10], [10, 20, 30])
    c = 100
    d = TS.TimeSeries([0, 1, 2], [1, 2, 3])
    assert a * b == TS.TimeSeries([0, 5, 10], [10, 40, 90])
    assert a * c == TS.TimeSeries([0, 5, 10], [100, 200, 300])
    with raises(ValueError):
        a * d
    assert a * b == b * a
    assert c * a == a * c
    with raises(ValueError):
        d * a
Esempio n. 4
0
def test_add():
    a = TS.TimeSeries([0, 5, 10], [1, 2, 3])
    b = TS.TimeSeries([0, 5, 10], [10, 20, 30])
    c = 100
    d = TS.TimeSeries([0, 1, 2], [1, 2, 3])
    assert a + b == TS.TimeSeries([0, 5, 10], [11, 22, 33])
    assert a + c == TS.TimeSeries([0, 5, 10], [101, 102, 103])
    with raises(ValueError):
        a + d
    assert a + b == b + a
    assert c + a == a + c
    with raises(ValueError):
        d + a
Esempio n. 5
0
def getData(Config, fields):
    t = TimeSeries(Config)
    s = Stats(Config)

    r = s.sget("stats.hostlist")

    for i in r:
        print "Hostname: %s" % i
        line = "when\t\t\t\t"
        for f in fields:
            if f != 'when':
                line += f + "\t"
        print "%s" % line

        x = t.zget(i)
        for y in x:
            line = "%s" % asctime(localtime(y['when']))
            line += "\t"
            for f in fields:
                if f != 'when':
                    try:
                        if type(y[f]) == 'int':
                            line += y[f] + "\t"
                        elif type(y[f]) == 'float':
                            line += "%.2f" % y[f]
                            line += "\t"
                        else:
                            line += str(y[f]) + "\t"
                    except:
                        line += "-\t"
            print "%s" % line
        print '\n'
Esempio n. 6
0
 def testUpload(self):
     try:
         x = input("enter File Path ")
         self.ts = TimeSeries.TimeSeries(x)
         self.mainMenu()
     except:
         print("unable to load File")
         self.mainMenu()
Esempio n. 7
0
    def __init__(self, queue, Config, threadID):
        self.__queue = queue
        self.Config = Config
        self.threadName = "responder-" + str(threadID)
        threading.Thread.__init__(self, name=self.threadName)

#        myIP = socket.gethostbyname(socket.gethostname())

        self._db = TimeSeries()
Esempio n. 8
0
    def __init__(self, queue, Config, threadID):
        self.__queue = queue
        self._config = Config
        self.threadName = "responder-" + str(threadID)
        threading.Thread.__init__(self, name=self.threadName)

        logger.debug("responder started: %s" % self.threadName)

        # setup the time series connection
        self._db = TimeSeries(self._config)
Esempio n. 9
0
def _get_ts_df():
    tsg = TSG.TimeSeriesGenerator()
    list_ts = tsg.generate_month_data()

    ts = TS.TimeSeries()
    ts.set_ts_list(list_ts, ["TIME", "VALUE"])

    df = ts.get_ts_df()

    return df
Esempio n. 10
0
def main():
    ## reading test data
    data_file = '../data/o_10631'
    data_df = pd.read_csv(data_file, header=None)
    # re-define columns' name
    data_df.columns = ['timestamp', 'value', 'host_id']

    #print(ts_df.sample(10))
    data_ts = TimeSeries.TimeSeries(data_df.timestamp, data_df.value)
    data_test = data_ts.getDataframe()

    print(data_test.head(10))
Esempio n. 11
0
def _get_ts_array(time_type):
    tsg = TSG.TimeSeriesGenerator()
    ts = TS.TimeSeries()

    if time_type == "d":
        ts.set_ts_list(tsg.generate_day_data(), ["TIME", "VALUE"])
    elif time_type == "w":
        ts.set_ts_list(tsg.generate_week_data(), ["TIME", "VALUE"])
    elif time_type == "m" or time_type == "y":
        ts.set_ts_list(tsg.generate_month_data(), ["TIME", "VALUE"])

    ts_d = ts.get_ts_df()

    return ts_d["TIME"].array
Esempio n. 12
0
def _get_ts_df(time_type):
    tsg = TSG.TimeSeriesGenerator()
    ts = TS.TimeSeries()

    if time_type == "d":
        ts.set_ts_list(tsg.generate_day_data(), ["TIME", "VALUE"])
    elif time_type == "w":
        ts.set_ts_list(tsg.generate_week_data(), ["TIME", "VALUE"])
    elif time_type == "m" or time_type == "y":
        ts.set_ts_list(tsg.generate_month_data(), ["TIME", "VALUE"])

    ts_df = ts.get_ts_df()
    ts_df["VALUE"] = [1] * ts_df.shape[0]

    return ts_df
Esempio n. 13
0
def test_bool():
    a = TS.TimeSeries([0], [0])
    assert abs(a) == False
Esempio n. 14
0
 def __init__(self):
     self.ts = TS.TimeSeries()
     self.dwmy_df_t = DWMYDFT.DWMYDFTransformator()
     self.dwmy_group_t = DWMYGgroup.DWMYGroupTransformator()
     self.ts_to_index_t = TSToIndex.TSToIndexTransformator()
     self.tri_save_load = TripletSaverAndLoader.TripletSaverAndLoader(None)
Esempio n. 15
0
def main():
    pid = os.getpid()
    logFile = '/tmp/backend-%d.log' % pid
    debug = 1

    # define some defaults
    configFile = scriptPath + '/../etc/config.xml'

    # load up the configs
    Config = ParseConfig.parseConfig(configFile)

    # setup the logger
    if (debug):
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ch = logging.handlers.RotatingFileHandler(logFile,
                                              maxBytes=25000000,
                                              backupCount=5)

    if (debug):
        ch.setLevel(logging.DEBUG)
    else:
        ch.setLevel(logging.INFO)

    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # and fire up the logger
    logger.info('startup')

    first_time = True
    db = TimeSeries(Config)

    # here, we have to deal with how to talk to PowerDNS.
    while 1:  # loop forever reading from PowerDNS
        rawline = sys.stdin.readline()
        if rawline == '':
            logger.debug('EOF')
            return  # EOF detected
        line = rawline.rstrip()

        logger.debug('received from pdns:%s' % line)

        # If this is the first pass reading from PowerDNS, look for a HELO
        if first_time:
            if line == 'HELO\t1':
                fprint('OK\togslb backend firing up')
            else:
                fprint('FAIL')
                logger.debug('HELO input not received - execution aborted')
                rawline = sys.stdin.readline(
                )  # as per docs - read another line before aborting
                logger.debug('calling sys.exit()')
                sys.exit(1)
            first_time = False
        else:  # now we actually get busy
            query = line.split('\t')
            if len(query) != 6:
                #             fprint('LOG\tPowerDNS sent unparseable line')
                #             fprint('FAIL')
                fprint('END')
            else:
                logger.debug('Performing DNSLookup(%s)' % repr(query))
                lookup = ''
                # Here, we actually to the real work.  Lookup a hostname in redis and prioritize it
                lookup = DNSLookup(db, query)
                if lookup != '':
                    logger.debug(lookup)
                    fprint(lookup)
                fprint('END')
Esempio n. 16
0
def test_median_empty():
    with raises(ValueError):
        TS.TimeSeries([], []).median()
Esempio n. 17
0
 def setUp(self):
     self.series = TimeSeries(1, 0.01, [1, -1, 3, -2, 5])
Esempio n. 18
0
#SAVE FUTURES PRICES TO FUTURES PRICE TIME SERIES DB
_FUT = dict()
# LOAD DATABASE FROM FILE IF IT EXISTS
if os.path.isfile(futDbFileName):
    dbfile = open(futDbFileName)
    _FUT = pickle.load(dbfile)
    dbfile.close()
#SAVE PRICES TO HASH TABLE
for code in FUTURES.keys():
    if not _FUT.has_key(code): _FUT[code] = dict()
    for year in FUTURES[code].keys():
        if not _FUT[code].has_key(year): _FUT[code][year] = dict()
        for month in FUTURES[code][year].keys():
            if not _FUT[code][year].has_key(month):
                _FUT[code][year][month] = TimeSeries()
            _FUT[code][year][month].Update(refDate, FUTURES[code][year][month])
#SAVE HASH DB TO FILE
dbfile = open(futDbFileName, 'w')
pickle.dump(_FUT, dbfile)
dbfile.close()

#PRINT VOL SURFACE DATA TO FILE FOR TEST
output = 'Code,Year,Month,Future'
for j in range(len(skews)):
    output += ',' + str(skews[j])
#COPY OUTPUT HEADER TO NORMAL VOLS OUTPUT
n_output = output
for code in sorted(SMILES.keys()):
    for year in sorted(SMILES[code].keys()):
        for month in sorted(SMILES[code][year].keys()):
Esempio n. 19
0
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))

# account for where we live
sys.path.append(scriptPath + '/..')
sys.path.append(scriptPath + '/../lib')
sys.path.append(scriptPath + '/../proto')

from time import time
from TimeSeries import *
import pprint
import random

pp = pprint.PrettyPrinter(indent=4)

t = TimeSeries()
value = {}
value['address'] = '1.2.3.4'
value['speed'] = 1234
value['when'] = time()

#t.zput('www.yahoo.com', value, value['when']);

r = t.zget('www.google.com')
pp.pprint(r)
#t.zexpire('www.yahoo.com')

addressData = {}
priorities = {}
for a in r:
    try:
Esempio n. 20
0
 def __init__(self, paramIndex, seriesType):
     self.data = TimeSeries.TimeSeries(paramIndex, seriesType)
     self.numberOfBlocks = 10
Esempio n. 21
0
def test_pos():
    a = TS.TimeSeries([0, 5, 10], [-1, -2, 3])
    assert +a == a
Esempio n. 22
0
def test_check_length():
    thunk = check_length(
        TS.TimeSeries(range(0, 4), range(1, 5)).lazy,
        TS.TimeSeries(range(1, 5), range(2, 6)))
Esempio n. 23
0
def test_setitem():
    tmpTestSeries = TS.TimeSeries(range(0, 4), range(1, 5))
    tmpTestSeries[0] = 5
    assert tmpTestSeries[0] == 5
Esempio n. 24
0
def test_std_empty():
    with raises(ValueError):
        TS.TimeSeries([], []).std()
Esempio n. 25
0
def test_abs():
    a = TS.TimeSeries([0, 5], [3, 4])
    assert abs(a) == 5.
Esempio n. 26
0
def test_neg():
    a = TS.TimeSeries([0, 5, 10], [1, 2, 3])
    b = TS.TimeSeries([0, 5, 10], [10, 20, 30])
    assert -a == TS.TimeSeries([0, 5, 10], [-1, -2, -3])
Esempio n. 27
0
from pytest import raises
import numpy as np
import TimeSeries as TS
from lazy import *
import collections

testSeries = TS.TimeSeries(range(0, 4), range(1, 5))
testSeries2 = TS.TimeSeries(range(0, 4), [10, 20, 30, 40, 50])


def test_len():
    assert len(testSeries) == 4


def test_contains():
    assert (2 in testSeries) == True


def test_getitem():
    assert testSeries[0] == 1


def test_setitem():
    tmpTestSeries = TS.TimeSeries(range(0, 4), range(1, 5))
    tmpTestSeries[0] = 5
    assert tmpTestSeries[0] == 5


def test_equal():
    tmpTestSeries = TS.TimeSeries(range(0, 4), range(1, 5))
    assert tmpTestSeries == testSeries
Esempio n. 28
0
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))

# account for where we live
sys.path.append(scriptPath + '/..')
sys.path.append(scriptPath + '/../lib')

from TimeSeries import *
import time
import logging
import logging.handlers
import random
import pprint
pp = pprint.PrettyPrinter(indent=4)

logger = logging.getLogger("ogslb")
redis = TimeSeries()


def DNSLookup(query):
    """parse DNS query and produce lookup result.

   query: a sequence containing the DNS query as per PowerDNS manual appendix A:
   http://downloads.powerdns.com/documentation/html/backends-detail.html#PIPEBACKEND-PROTOCOL
   """
    (_type, qname, qclass, qtype, _id, ip) = query

    logger.debug("doing a lookup")

    results = ''
    # we only deal with a few of the query types
    if (qtype == 'A' or qtype == 'ANY' or qtype == 'CNAME'):
Esempio n. 29
0
def ReadData(assembly, filename):
    metadata = pd.read_excel(filename, sheet_name=None)
    node_data = metadata.get('Node')
    section_data = metadata.get('Section')
    material_data = metadata.get('Material')
    degrade_force_material_data = metadata.get('DegradeForceMaterial')
    beam_data = metadata.get('Beam')
    axial_sp_data = metadata.get('AxialSpring')
    shear_sp_data = metadata.get('ShearSpring')
    rot_sp_data = metadata.get('RotSpring')
    seismic_data = metadata.get('Seismic')

    # write node data
    node_id = list(node_data['id'])
    node_x = list(node_data['x'])
    node_y = list(node_data['y'])
    node_z = list(node_data['z'])
    restrain_x = list(node_data['restrain_x'])
    restrain_y = list(node_data['restrain_y'])
    restrain_z = list(node_data['restrain_z'])
    restrain_rx = list(node_data['restrain_rx'])
    restrain_ry = list(node_data['restrain_ry'])
    restrain_rz = list(node_data['restrain_rz'])

    for (i, x, y, z) in zip(node_id, node_x, node_y, node_z):
        n = Node(i, Point(x, y, z))
        assembly.add_node(n)

    nodes = assembly.nodes
    for j, (n, x, y, z, rx, ry, rz) in enumerate(
            zip(nodes, restrain_x, restrain_y, restrain_z, restrain_rx,
                restrain_ry, restrain_rz)):
        for i, dof in enumerate([x, y, z, rx, ry, rz]):
            if dof == 1:
                n.restrain_dof(i)

    assembly.assign_eq_number()

    # write section data
    sect_id = list(section_data['id'])
    density = list(section_data['density'])
    E = list(section_data['E'])
    G = list(section_data['G'])
    Area = list(section_data['Area'])
    Iy = list(section_data['Iy'])
    Iz = list(section_data['Iz'])
    J = list(section_data['J'])

    for (i, d, e, g, a, iy, iz, j) in zip(sect_id, density, E, G, Area, Iy, Iz,
                                          J):
        sect = Section(i, d, e, g, a, iy, iz, j)
        assembly.add_section(sect)

    # write material data
    mat_id = list(material_data['id'])
    mat_k1 = list(material_data['k1'])
    mat_k2 = list(material_data['k2'])
    mat_uy = list(material_data['uy'])

    for (i, k1, k2, uy) in zip(mat_id, mat_k1, mat_k2, mat_uy):
        mat = BilinearMaterial(i, k1, k2, uy)
        assembly.add_material(mat)

    # write degrading force material data
    defmat_id = list(degrade_force_material_data['id'])
    defmat_k1 = list(degrade_force_material_data['k1'])
    defmat_uy = list(degrade_force_material_data['uy'])
    defmat_ud = list(degrade_force_material_data['ud'])
    defmat_fd = list(degrade_force_material_data['fd'])

    for (i, k1, uy, ud, f) in zip(defmat_id, defmat_k1, defmat_uy, defmat_ud,
                                  defmat_fd):
        mat = DegradingStrengthMaterial(i, k1, uy, ud, f)
        assembly.add_material(mat)

    # write beam data
    beam_id = list(beam_data['id'])
    node1 = list(beam_data['node1'])
    node2 = list(beam_data['node2'])
    section = list(beam_data['section'])
    rayleigh = list(beam_data['rayleigh'])
    # ref_x = list(beam_data['ref_x'])
    # ref_y = list(beam_data['ref_y'])
    # ref_z = list(beam_data['ref_z'])

    node = assembly.node
    sect = assembly.section
    for (i, n1, n2, s, r) in zip(beam_id, node1, node2, section, rayleigh):
        e = Beam2D(i, node(n1), node(n2), sect(s), r)
        assembly.add_element(e)

    # write axial spring data
    asp_id = list(axial_sp_data['id'])
    asp_n1 = list(axial_sp_data['node1'])
    asp_n2 = list(axial_sp_data['node2'])
    asp_mat = list(axial_sp_data['material'])
    asp_mass = list(axial_sp_data['mass'])
    asp_inertia = list(axial_sp_data['inertia'])
    # ref_x = list(axial_sp_data['ref_x'])
    # ref_y = list(axial_sp_data['ref_y'])
    # ref_z = list(axial_sp_data['ref_z'])

    material = assembly.material
    for (i, n1, n2, mat, mass, inertia) in zip(asp_id, asp_n1, asp_n2, asp_mat,
                                               asp_mass, asp_inertia):
        asp = TwoNodeAxialSpring2D(i, node(n1), node(n2), material(mat), mass,
                                   inertia)
        assembly.add_element(asp)

    # write shear spring data
    ssp_id = list(shear_sp_data['id'])
    ssp_n1 = list(shear_sp_data['node1'])
    ssp_n2 = list(shear_sp_data['node2'])
    ssp_mat = list(shear_sp_data['material'])
    ssp_mass = list(shear_sp_data['mass'])
    ssp_inertia = list(shear_sp_data['inertia'])
    # ref_x = list(shear_sp_data['ref_x'])
    # ref_y = list(shear_sp_data['ref_y'])
    # ref_z = list(shear_sp_data['ref_z'])
    shear_loc_ration = list(shear_sp_data['shear_loc_ratio'])

    for (i, n1, n2, mat, mass, inertia,
         loc) in zip(ssp_id, ssp_n1, ssp_n2, ssp_mat, ssp_mass, ssp_inertia,
                     shear_loc_ration):
        ssp = TwoNodeShearSpring2D(i, node(n1), node(n2), material(mat), mass,
                                   inertia, loc)
        assembly.add_element(ssp)

    # write rotation spring data
    rsp_id = list(rot_sp_data['id'])
    rsp_n1 = list(rot_sp_data['node1'])
    rsp_n2 = list(rot_sp_data['node2'])
    rsp_mat = list(rot_sp_data['material'])
    rsp_mass = list(rot_sp_data['mass'])
    rsp_inertia = list(rot_sp_data['inertia'])
    # ref_x = list(rot_sp_data['ref_x'])
    # ref_y = list(rot_sp_data['ref_y'])
    # ref_z = list(rot_sp_data['ref_z'])

    for (i, n1, n2, mat, mass, inertia) in zip(rsp_id, rsp_n1, rsp_n2, rsp_mat,
                                               rsp_mass, rsp_inertia):
        rsp = TwoNodeModifiedCloughRotationSpring2D(i, node(n1), node(n2),
                                                    material(mat), mass,
                                                    inertia)
        assembly.add_element(rsp)

    # declare seismic time series
    time = list(seismic_data['time'])
    acceleration = list(seismic_data['acceleration'])
    t0 = time[0]
    dt = time[1] - t0
    seismic = TimeSeries(t0, dt, acceleration)
    assembly.seismics.append(seismic)
Esempio n. 30
0
def test_equal():
    tmpTestSeries = TS.TimeSeries(range(0, 4), range(1, 5))
    assert tmpTestSeries == testSeries