Пример #1
0
    def test_sing(self):
        ENTITY_ID2 = 678
        store_events(ENTITY_ID2, [ORIGIN])
        past_events = find_events(ENTITY_ID2)

        res = apply_events(events=past_events)
        print res
        self.assertEquals(len(res), 1)
Пример #2
0
    def test_inter(self):
        ENTITY_ID = 666
        store_events(ENTITY_ID, self.l1)
        paste_events = find_events(ENTITY_ID)
        print paste_events
        self.assertEquals(len(paste_events), len(self.l1))

        res = apply_events(events=paste_events)
        self.assertEquals(len(res), len(self.l1))
Пример #3
0
def get_data_by_author(author=ORIGIN.author):
    past_events = find_events(ENTITY_ID)
    entity = apply_events([e for e in past_events if e.author == author])

    vector_x, vector_y = split_data(entity)
    return jsonify({
        "data": {
            'x': vector_x,
            'y': vector_y
            }
    })
Пример #4
0
def get_entity(ts):
    if ts == 0:
        ts = generate_timestamp()

    snapshotted = False
    entity, offset = select_snapshot(entity_id=ENTITY_ID, ts=ts)

    if entity:
        print('Got snapshot')
        snapshotted = True

    past_events = get_offsets(offset, ts)

    evs = len(past_events)
    entity = apply_events([e.value for e in past_events], entity=entity)

    # time_strategy(events=past_events, entity=entity)
    distance_strategy(past_events, entity)

    return entity, {'snapshotted': snapshotted, 'evs': evs}
Пример #5
0
def get_data(ts=0):
    entity, _ = get_entity(ts)

    # just for fun, by each retrieval we add a new Event
    if ts == 0 and GENERATOR_OPTION:
        new_events = make_new_measurement(entity)
        entity = apply_events(new_events, entity)
        store_events(ENTITY_ID, new_events)

    # transformation for plotting
    x_vector, y_vector = split_data(entity)
    return jsonify(
        {
            'data': {
                'x': x_vector,
                'y': y_vector
            },
            'times': get_times(),
            'authors': get_authors()
        })
Пример #6
0
 def test_map_red(self):
     res = apply_events(self.l1)
     sum = reduce(lambda x, y: x + y, res)
     avg1 = sum / len(res)
     res1 = avg(res)
     self.assertEquals(res1, avg1)
Пример #7
0
 def test_apply_correction(self):
     res1 = apply_events(self.l1 + [Event('jj', 0, 1, 19)])
     self.assertEquals(len(res1), len(self.l1))
     self.assertEquals(res1[1], 19)
Пример #8
0
 def test_apply_same_events(self):
     res1 = apply_events(self.l1)
     res2 = apply_events(self.l1 + self.l1)
     self.assertEquals(res1, res2, 'There should be no difference')
Пример #9
0
 def test_apply_simple_events(self):
     res = apply_events(self.l1)
     self.assertEquals(len(res), 3)
Пример #10
0
 def test_apply_noevents(self):
     res = apply_events([])
     self.assertEquals(len(res), 0, 'There should be no events')