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})
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})
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})
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})
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})
def test_find_by_start(self): self.start = 150 self.end = None result = database.find_if(self.search_fn) self.assertEquals([self.player2], result)
def test_find_by_end(self): self.start = None self.end = 150 result = database.find_if(self.search_fn) self.assertEquals([self.player1], result)
def test_find_all(self): self.start = self.end = None result = database.find_if(self.search_fn) self.assertEquals(self.expected_data.values(), result)