-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmisc.py
135 lines (104 loc) · 3.26 KB
/
testmisc.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
__author__ = 'daokh'
import datetime
from datetime import datetime as dt
import json
from dateutil import parser
import pytz
from pytz import timezone
import requests
import geoutils
from mpmutils import jsondict
import dateutils
dt_str = dt(datetime.MINYEAR, 1, 1)
print dt_str
# dt = parser.parse(dt_str)
# print dt
parser.parse('2011-01-02', None)
S = []
print len(S)
now = dt.now(pytz.utc)
t1 = dt.now(timezone("UTC"))
t2 = t1 + datetime.timedelta(seconds=5)
# print dateutils.timestamp(t1)
# print dateutils.timestamp(t2)
testdict = jsondict({})
if testdict.radius: testdict.pop("radius")
list = [{'name': 'a'}, {'name': 'b'}]
jsondict = {'commplans': list}
jsonstring = json.dumps(jsondict)
d = dict([("age", 25), ("foo", 25)])
def make_incrementor(n):
return lambda x: x + n
f = make_incrementor(2)
print f(42)
foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
print reduce(lambda x, y: x + y, foo)
adder = lambda x, y: x + y
sum = adder(1, 3)
print sum
try:
foo = None
foo.something = 1
except AttributeError as e:
print "error"
def query(strquery, *fields):
strFields = "&fields="
strSearchQuery = ""
if fields:
for field in fields:
strFields += field + "&"
strSearchQuery = "pretty=true&sort=id&q=" + strquery + strFields + "_source=true"
else:
strSearchQuery = "pretty=true&sort=id&q=" + strquery + "&_source=true"
try:
res = requests.get("http://localhost:9200/mission_plan_manager/MissionPlans/_search?" + strSearchQuery)
jsonstr = json.dumps(res.json())
retJson = json.loads(jsonstr, object_hook=geoutils.jsondict)
return [hit._source for hit in retJson.hits.hits]
except:
return {}
normalQuery = "mission"
activeQuery = "False"
activeQuery = activeQuery.lower()
querystr = """
{
"query": {
"bool": {
"must": {
"query_string": {
"query": "<QUERY_STRING>"
}
},
"must": {
"query_string": {
"query": "<ACTIVE_QUERY_STRING>",
"fields": ["active"]
}
}
}
}
}
"""
querystr = querystr.replace("<QUERY_STRING>",normalQuery)
querystr = querystr.replace("<ACTIVE_QUERY_STRING>",activeQuery)
print querystr
foo = dict ([("name", "fi"),("foo",33)])
foo["flightNumber"] = 0
print foo
if "flightNumber" not in foo:
print
items1 = [ {"key": "abc","notification": "a"}, {"key": "abc2","notification": "b"} ]
items2 = [ {"key": "abc","notification": "aa"}, {"key": "abc2","notification": "bb"}, {"key": "abc3","notification": "bb"} ]
notificationDitc = {}
for item in items1:
notificationDitc[item["key"]] = item["notification"]
for item in items2:
notificationDitc[item["key"]] = item["notification"]
listitems = notificationDitc.items()
apiCall = "/jsonapi/nodes/{nodeId}/devices/{deviceId}".format(3,3)
data = [[1,33,3], [4,5,6], [7,8,9]]
sorted_by_second = sorted(data, key=lambda tup: tup[1])
print
if __name__ == '__main__':
list = query("9", "missionPlanElements.id")
print