diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/test-generator.py | 55 | ||||
-rwxr-xr-x | tools/test-integration.py | 26 | ||||
-rwxr-xr-x | tools/test-performance.py | 44 | ||||
-rwxr-xr-x | tools/translate.py | 54 |
4 files changed, 146 insertions, 33 deletions
diff --git a/tools/test-generator.py b/tools/test-generator.py new file mode 100755 index 000000000..681d1755d --- /dev/null +++ b/tools/test-generator.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +import sys +import math +import urllib +import urllib2 +import time + +id = '123456789012345' +server = 'http://localhost:5055' +period = 1 +step = 0.001 + +waypoints = [ + (40.722412, -74.006288), + (40.728592, -74.005258), + (40.728348, -74.002822), + (40.725437, -73.996750), + (40.721778, -73.999818), + (40.723323, -74.002994) +] + +points = [] + +for i in range(0, len(waypoints)): + (lat1, lon1) = waypoints[i] + (lat2, lon2) = waypoints[(i + 1) % len(waypoints)] + length = math.sqrt((lat2 - lat1) ** 2 + (lon2 - lon1) ** 2) + count = int(math.ceil(length / step)) + for j in range(0, count): + lat = lat1 + (lat2 - lat1) * j / count + lon = lon1 + (lon2 - lon1) * j / count + points.append((lat, lon)) + +def send(lat, lon, course): + params = (('id', id), ('timestamp', int(time.time())), ('lat', lat), ('lon', lon), ('bearing', course)) + urllib2.urlopen(server + '?' + urllib.urlencode(params)).read() + +def course(lat1, lon1, lat2, lon2): + lat1 = lat1 * math.pi / 180 + lon1 = lon1 * math.pi / 180 + lat2 = lat2 * math.pi / 180 + lon2 = lon2 * math.pi / 180 + y = math.sin(lon2 - lon1) * math.cos(lat2) + x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(lon2 - lon1) + return (math.atan2(y, x) % (2 * math.pi)) * 180 / math.pi + +index = 0 + +while True: + (lat1, lon1) = points[index % len(points)] + (lat2, lon2) = points[(index + 1) % len(points)] + send(lat1, lon1, course(lat1, lon1, lat2, lon2)) + time.sleep(period) + index += 1 diff --git a/tools/test-integration.py b/tools/test-integration.py index 64abc9ffe..2a332ba7d 100755 --- a/tools/test-integration.py +++ b/tools/test-integration.py @@ -21,7 +21,6 @@ messages = { 'suntech' : 'SA200STT;123456;042;20120101;12:11:00;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205\r', 'h02' : '*HQ,123456789012345,V1,121300,A,6000.0000,N,13000.0000,E,0.00,0.00,010112,ffffffff,000000,000000,000000,000000#', 'jt600' : '$\x00\x00\x12\x34\x56\x11\x00\x1B\x01\x01\x12\x12\x14\x00\x60\x00\x00\x00\x13\x00\x00\x00\x0F\x00\x00\x07\x50\x00\x00\x00\x2B\x91\x04\x4D\x1F\xA1', - 'ev603' : '!1,123456789012345;!A,01/01/12,12:15:00,60.000000,130.000000,0.0,25101,0;', 'v680' : '#123456789012345#1000#0#1000#AUT#1#66830FFB#13000.0000,E,6000.0000,N,001.41,259#010112#121600##', 'pt502' : '$POS,123456,121700.000,A,6000.0000,N,13000.0000,E,0.0,0.0,010112,,,A/00000,00000/0/23895000//\r\n', 'tr20' : '%%123456789012345,A,120101121800,N6000.0000E13000.0000,0,000,0,01034802,150,[Message]\r\n', @@ -41,7 +40,28 @@ messages = { 'pt3000' : '%123456789012345,$GPRMC,124500.000,A,6000.0000,N,13000.0000,E,0.00,,010112,,,A,+100000000000,N098d', 'topflytech' : '(123456789012345BP00XG00b600000000L00074b54S00000000R0C0F0014000100f0120101124700A6000.0000N13000.0000E000.0000.00)', 'laipac' : '$AVRMC,123456789012345,124800,a,6000.0000,N,13000.0000,E,0.00,0.00,010112,0,3.727,17,1,0,0*17\r\n', - 'gotop' : '#123456789012345,CMD-T,A,DATE:120101,TIME:125000,LAT:60.0000000N,LOT:130.0000000E,Speed:000.0,84-20,000#' + 'gotop' : '#123456789012345,CMD-T,A,DATE:120101,TIME:125000,LAT:60.0000000N,LOT:130.0000000E,Speed:000.0,84-20,000#', + 'sanav' : 'imei:123456789012345rmc:$GPRMC,093604.354,A,4735.0862,N,01905.2146,E,0.00,0.00,171013,,*09,AUTO-4103mv', + 'easytrack' : '*ET,123456789012345,DW,A,0A090D,101C0D,00CF27C6,0413FA4E,0000,0000,00000000,20,4,0000,00F123#', + 'gpsmarker' : '$GM200123456789012345T100511123300N55516789E03756123400000035230298#\r', + 'stl060' : '$1,123456789012345,D001,AP29AW0963,23/02/14,14:06:54,17248488N,078342226E,0.08,193.12,1,1,1,1,1,A#', + 'cartrack' : '$$123456????????&A9955&B102904.000,A,2233.0655,N,11404.9440,E,0.00,,030109,,*17|6.3|&C0100000100&D000024?>&E10000000##', + 'minifinder' : '!1,123456789012345;!A,01/01/12,12:15:00,60.000000,130.000000,0.0,25101,0;', + 'haicom' : '$GPRS123456789012345,T100001,150618,230031,5402267400332464,0004,2014,000001,,,1,00#V040*', + 'box' : 'H,BT,123456789012345,081028142432,F5813D19,6D6E6DC2\rL,081028142429,G,52.51084,-1.70849,0,170,0,1,0\r', + 'freedom' : 'IMEI,123456789012345,2014/05/22, 20:49:32, N, Lat:4725.9624, E, Lon:01912.5483, Spd:5.05\r\n', + 'telik' : '182012345699,010100001301,0,270613041652,166653,475341,3,0,355,6,2,1,231,8112432,23201,01,00,217,0,0,0,0,7\0', + 'trackbox' : 'a=connect&v=11&i=123456789012345\r\n183457.999,5126.0247N,00002.8686E,5.2,70.4,3,57.63,32.11,17.32,150507,05\r\n', + 'visiontek' : '$1,AP09BU9397,123456789012345,20,06,14,15,03,28,17267339N,078279407E,060.0,073,0550,11,0,1,0,0,1,1,26,A,0000000000#', + 'tr900' : '>123456,4,1,150626,131252,W05830.2978,S3137.2783,,00,348,18,00,003-000,0,3,11111011*3b!\r\n', + 'ardi01' : '123456789012345,20141010052719,24.4736042,56.8445807,110,289,40,7,5,78,-1\r\n', + 'xt013' : 'TK,123456789012345,150131090859,+53.267863,+5.767363,0,38,12,0,F,204,08,C94,336C,24,,4.09,1,,,,,,,,\r\n', + 'gosafe' : '*GS16,123456789012345,100356130215,,SYS:G79W;V1.06;V1.0.2,GPS:A;6;N24.802700;E46.616828;0;0;684;1.35,COT:60,ADC:4.31;0.10,DTT:20000;;0;0;0;1#', + 'xirgo' : '$$123456789012345,6001,2013/01/22,15:36:18,25.80907,-80.32531,7.1,19,165.2,11,0.8,11.1,17,1,1,3.9,2##', + 'mtx' : '#MTX,123456789012345,20101226,195550,41.6296399,002.3611174,000,035,000000.00,X,X,1111,000,0,0\r\n', + 'aquila' : '$$SRINI_1MS,123456,1,12.963515,77.533844,150925161628,A,27,0,8,0,68,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,*43\r\n', + 'flextrack' : '-1,LOGON,123456,8945000000\r-2,UNITSTAT,20060101,123442,1080424008,N0.00.0000,E0.00.0000,0,0,0,4129,-61,2,23866,0,999,A214,63,2EE2,3471676\r', + 'watch' : '[SG*123456*0087*UD,220414,134652,A,22.571707,N,113.8613968,E,0.1,0.0,100,7,60,90,1000,50,0000,4,1,460,0,9360,4082,131,9360,4092,148,9360,4091,143,9360,4153,141]' } baseUrl = 'http://localhost:8082' @@ -132,7 +152,7 @@ print 'Covered: %d' % len(protocols) for protocol in messages: send_message(ports[protocol], messages[protocol]) -time.sleep(5) +time.sleep(10) for device in devices: protocols -= set(get_protocols(cookie, devices[device])) diff --git a/tools/test-performance.py b/tools/test-performance.py new file mode 100755 index 000000000..ec31e9b86 --- /dev/null +++ b/tools/test-performance.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +import asyncio +import random + +host = 'localhost' +port = 5027 + +messageLogin = bytearray.fromhex('000F313233343536373839303132333435') +messageLocation = bytearray.fromhex('000000000000002b080100000140d4e3ec6e000cc661d01674a5e0fffc00000900000004020100f0000242322318000000000100007a04') + +devices = 100 +period = 1 + + +class AsyncClient(asyncio.Protocol): + + def __init__(self, loop): + self.loop = loop + self.buffer = memoryview(messageLogin) + + def connection_made(self, transport): + self.send_message(transport) + + def send_message(self, transport): + transport.write(self.buffer) + self.buffer = memoryview(messageLocation) + delay = period * (0.9 + 0.2 * random.random()) + self.loop.call_later(delay, self.send_message, transport) + + def data_received(self, data): + pass + + def connection_lost(self, exc): + self.loop.stop() + + +loop = asyncio.get_event_loop() + +for i in range(0, devices): + loop.create_task(loop.create_connection(lambda: AsyncClient(loop), host, port)) + +loop.run_forever() +loop.close() diff --git a/tools/translate.py b/tools/translate.py index fd7d139df..e8324a61a 100755 --- a/tools/translate.py +++ b/tools/translate.py @@ -1,41 +1,35 @@ #!/usr/bin/python -import re import os +import optparse +import urllib2 +import json +import base64 -abspath = os.path.abspath(__file__) -dname = os.path.dirname(abspath) -os.chdir(dname) +parser = optparse.OptionParser() +parser.add_option("-u", "--user", dest="username", help="transifex user login") +parser.add_option("-p", "--password", dest="password", help="transifex user password") -path = '../web/l10n/' +(options, args) = parser.parse_args() -files = [f for f in os.listdir(path) if os.path.isfile(path + f) and f.endswith('.js') and not f.endswith('en.js')] -for f in files: - f = path + f +if not options.username or not options.password: + parser.error('User name and password are required') - print 'en -> ' + f[-5:-3] +os.chdir(os.path.dirname(os.path.abspath(__file__))) - dict = {} +path = "../web/l10n/" - for line in open(f).read().splitlines(): - match = re.search(" (\\w+): '(.+)'(,)?", line) - if match: - dict[match.group(1)] = match.group(2) +def request(url): + req = urllib2.Request(url) + auth = base64.encodestring("%s:%s" % (options.username, options.password)).replace("\n", "") + req.add_header("Authorization", "Basic %s" % auth) + return urllib2.urlopen(req) - out = open(f, 'w') +resource = json.load(request("https://www.transifex.com/api/2/project/traccar/resource/web/?details")) - for line in open(path + 'en.js').read().splitlines(): - match = re.search(" (\\w+): '(.+)'(,)?", line) - if match: - if dict.has_key(match.group(1)): - value = dict[match.group(1)] - else: - print '"' + match.group(2) + '"' - value = match.group(2) + ' (*)' - - out.write(' ' + match.group(1) + ": '" + value + "'") - if match.group(3) is not None: - out.write(',') - out.write('\n') - else: - out.write(line + '\n') +for language in resource["available_languages"]: + code = language["code"] + data = request("https://www.transifex.com/api/2/project/traccar/resource/web/translation/" + code + "?file") + file = open(path + code + ".json", "wb") + file.write(data.read()) + file.close() |