def general_query(source='hive', timestart=0, timeend=0, tp=0, pt1=(0,0), pt2=(0,0), mmsi=[0], output='csv'): '''general query function Args: source: data source, include 'hive', 'mysql', 'oracle' timestart: start time of query range timeend: end time of query range type: space query type, 0: pt1 is upper left (lo,la) coordinate, pt2 is (vertical, horizontal) length 1: pt1 is upper left (lo,la) coordinate, pt2 is lower right (lo,la) coordinate 2: pt1 is the centor of the circle and pt2 is (R,0) where R is the redius pt1: (lo,la) point pt2: see 'type' mmsi: -1: all mmsi list: a single or list of mmsi output output file format, include 'csv', 'xls', 'txt', etc. Returns: ''' if source == 'hive': print 'source is hive' sq = sparkQuery(timestart, timeend, tp, pt1, pt2, mmsi, output) sq.start() #sq.querytest(mmsi) elif source == 'mysql': print 'source is mysql' mq = mysqlQuery(timestart, timeend, tp, pt1, pt2, mmsi, output) mq.start() elif source == 'oracle': pass
def general_query(formdict={}): '''general query function Args: source: data source, include 'hive', 'mysql', 'oracle' timestart: start time of query range timeend: end time of query range type: space query type, 0: pt1 is upper left (lo,la) coordinate, pt2 is (vertical, horizontal) length 1: pt1 is upper left (lo,la) coordinate, pt2 is lower right (lo,la) coordinate 2: pt1 is the centor of the circle and pt2 is (R,0) where R is the redius pt1: (lo,la) point pt2: see 'type' mmsi: -1: all mmsi list: a single or list of mmsi output output file format, include 'csv', 'xls', 'txt', etc. Returns: ''' # taskid = TaskLog.insertlog(formdict['source'],'0', '1', 'type','pt1', 'pt2', str(formdict['mmsi']), formdict['output']) taskid = TaskLog.getnewtaskid() timelist = [] for t in formdict['date']: timelist.append(tuple(t.split(','))) print "timelist:" print timelist positionlist = [] for p in formdict['position']: if p['postype'] == "geo": itemdict = {'tp':p['tp'],'pt1':tuple([float(x) for x in p['pt1'].split(',')]),'pt2':tuple(tuple([float(x) for x in p['pt2'].split(',')]))} positionlist.append(itemdict) elif p['postype'] == "port": print 'name:'+p['name'] print "positionlist:" print positionlist if formdict['source'] == 'hive': print 'source is hive' # sq = sparkQuery(timestart, timeend, tp, pt1, pt2, mmsi, output, taskid) # sq.start() #sq.querytest(mmsi) elif formdict['source'] == 'mysql': print 'source is mysql' mq = mysqlQuery(timelist,positionlist,mmsilist=formdict['mmsi'],countrylist = formdict['country'],output=formdict['output'],taskid =taskid) mq.start() elif source == 'oracle': pass