Пример #1
0
def get_data():
    start = request.args.get('start', None)
    end = request.args.get('end', None)
    result = database.find_if(
        lambda item: (not start or (start and item['ts'] >= int(start))) and
        (not end or (end and item['ts'] <= int(end))))
    return jsonify({'data': result})
Пример #2
0
def get_data_count():
    data = database.find_if(lambda item: True)
    result = defaultdict(int)
    for item in data:
        ts_datetime = datetime.datetime.utcfromtimestamp(item['ts'])
        result[str(ts_datetime.date())] += 1
    return jsonify({'data': result})
Пример #3
0
def get_data_count():
    data = database.find_if(lambda item: True)
    result = defaultdict(int)
    for item in data:
        ts_datetime = datetime.datetime.utcfromtimestamp(item['ts'])
        result[str(ts_datetime.date())] += 1
    return jsonify({'data': result})
Пример #4
0
def get_data():
    start = request.args.get('start', None)
    end = request.args.get('end', None)
    result = database.find_if(
        lambda item:
            (not start or (start and item['ts'] >= int(start))) and
            (not end or (end and item['ts'] <= int(end)))
    )
    return jsonify({'data': result})
Пример #5
0
def get_data_heatmap():
    #
    # {
    #   floor1: [ {'x':10, 'y':20, 'count':5}, ... ]
    #   ...
    # }
    data = database.find_if(lambda item: True)
    result = defaultdict(dict)
    for item in data:
        heat_hash = str(item['position']['x']) + '|' + str(item['position']['y'])
        if heat_hash in result[item['floor']]:
            result[item['floor']][heat_hash]['count'] += 1
        else:
            result[item['floor']][heat_hash] = {
                'x': item['position']['x'],
                'y': item['position']['y'],
                'count': 1
            }
    final_result = {}
    for floor in result:
        final_result[floor] = list(result[floor].values())
    return jsonify({'data': final_result})
Пример #6
0
def get_data_heatmap():
    #
    # {
    #   floor1: [ {'x':10, 'y':20, 'count':5}, ... ]
    #   ...
    # }
    data = database.find_if(lambda item: True)
    result = defaultdict(dict)
    for item in data:
        heat_hash = str(item['position']['x']) + '|' + str(item['position']['y'])
        if heat_hash in result[item['floor']]:
            result[item['floor']][heat_hash]['count'] += 1
        else:
            result[item['floor']][heat_hash] = {
                'x': item['position']['x'],
                'y': item['position']['y'],
                'count': 1
            }
    final_result = {}
    for floor in result:
        final_result[floor] = result[floor].values()
    return jsonify({'data': final_result})
Пример #7
0
 def test_find_by_start(self):
     self.start = 150
     self.end = None
     result = database.find_if(self.search_fn)
     self.assertEquals([self.player2], result)
Пример #8
0
 def test_find_by_end(self):
     self.start = None
     self.end = 150
     result = database.find_if(self.search_fn)
     self.assertEquals([self.player1], result)
Пример #9
0
 def test_find_all(self):
     self.start = self.end = None
     result = database.find_if(self.search_fn)
     self.assertEquals(self.expected_data.values(), result)
Пример #10
0
 def test_find_by_start(self):
     self.start = 150
     self.end = None
     result = database.find_if(self.search_fn)
     self.assertEquals([self.player2], result)
Пример #11
0
 def test_find_by_end(self):
     self.start = None
     self.end = 150
     result = database.find_if(self.search_fn)
     self.assertEquals([self.player1], result)
Пример #12
0
 def test_find_all(self):
     self.start = self.end = None
     result = database.find_if(self.search_fn)
     self.assertEquals(self.expected_data.values(), result)