-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·109 lines (68 loc) · 2.42 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pymongo
from pymongo import MongoClient
import random
import time
from datetime import datetime
from datetime import timedelta
import bottle
from bottle import route, run, template
from bottle import static_file
@route('/<filename>')
def index(filename):
return static_file(filename, root='/home/bia/MakeIt')
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='/home/bia/MakeIt/static')
@route('/static/images/<filename>')
def server_static(filename):
return static_file(filename, root='/home/bia/MakeIt/static/images')
@route('/api/marker')
def marker():
return createMarker()
@route('/api/compteur')
def compteur():
return createCompteur()
@route('/api/vertical')
def compteur():
return createVertical()
def createMarker():
datenow = datetime.now()
dateplusone = datenow + timedelta(seconds=1)
formatString = "T%H:%M:%S"
dateString="2013-11-19"
dateDebut = dateString+datenow.strftime(formatString)
dateFin = dateString+dateplusone.strftime(formatString)
query = {'date_ts': { '$gt': dateDebut, '$lt': dateFin}}
res = col.find(query, {'_id':0})
listObject = []
for i in res:
listObject.append(i)
objet = {}
objet['requete']=listObject
return objet
def createCompteur():
datenow = datetime.now()
formatString = "T%H:%M:%S"
dateString="2013-11-19"
dateDebut = dateString+datenow.strftime(formatString)
query = {'date_ts': { '$gt' : dateString, '$lt': dateDebut}}
res = col.find(query).count()
retour = {}
retour['total']=res
retour['date']=dateDebut
return retour
def createVertical():
datenow = datetime.now()
dateplusone = datenow + timedelta(seconds=1)
formatString = "T%H:%M:%S"
dateString="2013-11-19"
dateDebut = dateString+datenow.strftime(formatString)
dateFin = dateString+dateplusone.strftime(formatString)
query = [{'$match' :{'date_ts': {'$gt': dateDebut, '$lt': dateFin }}} ,{'$group':{'_id':'$verticales', 'count':{'$sum':1}}}]
# db.recherches.aggregate([{$match :{'date_ts': {'$gt': '2013-11-16T15:32:25', '$lt': '2013-11-16T15:32:26'}}} ,{$group:{"_id":"$verticales", "count":{"$sum":1}}}])
res = col.aggregate(query)
return res
client = MongoClient('mongodb://aladin:[email protected]:27028/perfAladinDB')
db = client.perfAladinDB
col = db.recherches
run(host='bigdata04t.bbo1t.local', port=8080)