def graph_update_view(request): import mimetypes mimetypes.init() mimetypes.add_type("pde","text/processing") db = current_spectra.current_spectra(mode = 'r') spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = spectrum[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] timeS = '%02i:%02i:%02i on %02i/%02i/%04i'%(spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) print mode print cnf.modes[mode]['low_chan'] print cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']] print cnf.modes[mode]['high_chan'] + 1 print cnf.getFreqs(mode)[cnf.modes[mode]['high_chan'] + 1] freqs = cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] / 10e5 db.close() miny = np.asscalar(spectrum.min()) maxy = np.asscalar(spectrum.max()) js = json.dumps(spectrum.tolist()) return {'spectrum':js,\ 'freqs':json.dumps(freqs.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): import mimetypes mimetypes.init() mimetypes.add_type("pde", "text/processing") db = current_spectra.current_spectra(mode='r') spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = spectrum[cnf. modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] timeS = '%02i:%02i:%02i on %02i/%02i/%04i' % (spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) print mode print cnf.modes[mode]['low_chan'] print cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']] print cnf.modes[mode]['high_chan'] + 1 print cnf.getFreqs(mode)[cnf.modes[mode]['high_chan'] + 1] freqs = cnf.getFreqs( mode)[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] / 10e5 db.close() miny = np.asscalar(spectrum.min()) maxy = np.asscalar(spectrum.max()) js = json.dumps(spectrum.tolist()) return {'spectrum':js,\ 'freqs':json.dumps(freqs.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): db = current_spectra.current_spectra() spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = cnf.Base64Decode(spectrum) timeS = '%02i:%02i:%02i on %02i/%02i/%04i'%(spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) miny = spectrum.min() maxy = spectrum.max() freqs = cnf.getFreqs(1)/ 10e6 data = np.empty((spectrum.size + freqs.size,), dtype=spectrum.dtype) data[0::2] = freqs data[1::2] = spectrum db.close() return {'data':json.dumps(data.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): db = current_spectra.current_spectra() spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = cnf.Base64Decode(spectrum) timeS = '%02i:%02i:%02i on %02i/%02i/%04i' % (spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) miny = spectrum.min() maxy = spectrum.max() freqs = cnf.getFreqs(1) / 10e6 data = np.empty((spectrum.size + freqs.size, ), dtype=spectrum.dtype) data[0::2] = freqs data[1::2] = spectrum db.close() return {'data':json.dumps(data.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_channel_view(request): import datetime db = dbControl.dbControl(cnf.monitor_db[0], cnf.monitor_db[1], cnf.monitor_db[2], cnf.monitor_db[3]) mini = db.rfi_monitor_get_oldest_timestamp() minDateTime = datetime.datetime.fromtimestamp(mini+60) schema = channel_date_range().bind(min_date=minDateTime) form = deform.Form(schema,buttons=('submit','download')) reqts = form.get_widget_resources() for i in range(len(reqts['css'])): reqts['css'][i] = "deform:static/%s"%reqts['css'][i] for i in range(len(reqts['js'])): reqts['js'][i] = "deform:static/%s"%reqts['js'][i] sTimestamp = 0 frequency = -1 overranges = [] times = [] data = [] if 'submit' in request.params: print "IN SUBMIT" controls = request.POST.items() print "controls" print controls try: appstruct = form.validate(controls) sTime = appstruct['date_time_start'].timetuple() eTime = appstruct['date_time_end'].timetuple() frequencyS = appstruct['Frequency'] try: frequency = float(frequencyS) except ValueError: try: floats = [float(s) for s in frequencyS.split(" ") if s.isDigit()] frequency = floats[0] except: print "Not valid input" channel = cnf.freq_to_chan_mode(frequency) # db.frequency_to_channel(frequency) # freqs = cnf.getFreqs(channel[0][0] - 1) # print "Incoming frequency = %f converted to mode_chan %s"%(frequency, str(channel)) # print "Incoming frequency = %f converted to mode_chan %s"%(frequency, str(channel[0][1])) # print "outgoing frequency 1 is %f"%freqs[channel[0][1]] # freqs = cnf.getFreqs(channel[1][0] - 1) # print "outgoing frequency 2 is %f"%freqs[channel[1][1]] # time.sleep(5) # print "frequency = %f channel = %i"%(frequency, channel) sTimestamp = int(time.mktime(sTime)) eTimestamp = int(time.mktime(eTime)) timeS = '%02i:%02i:%02i on %02i/%02i/%04i to %02i:%02i:%02i on %02i/%02i/%04i'%(sTime[3], sTime[4], sTime[5], sTime[2], sTime[1], sTime[0], eTime[3], eTime[4], eTime[5], eTime[2], eTime[1], eTime[0],) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, channel) #362 overranges = db.rfi_monitor_get_adc_overrange_pos(sTimestamp, eTimestamp) miny = spectrum.min() maxy = spectrum.max() times = np.arange(int(sTimestamp) - 1,int(sTimestamp -1 + spectrum.size),1) except deform.ValidationFailure as e: return {'overrange':json.dumps(adc_overrange),\ 'overrangeS':overrangeS,\ 'times':"whoops",\ 'form':e.render(),\ 'reqts':reqts, 'xaxis':"",\ 'yaxis':"",\ 'minx':0,\ 'maxx':1,\ 'miny':0,\ 'maxy':1} elif 'download' in request.params: print "IN DOWNLOAD" controls = request.POST.items() try: appstruct = form.validate(controls) sTime = appstruct['date_time_start'].timetuple() eTime = appstruct['date_time_end'].timetuple() sTimestamp = int(time.mktime(sTime)) eTimestamp = int(time.mktime(eTime)) frequencyS = appstruct['Frequency'] try: frequency = float(frequencyS) except ValueError: try: floats = [float(s) for s in frequencyS.split(" ") if s.isDigit()] frequency = floats[0] except: print "Not valid input" channel = cnf.freq_to_chan_mode(frequency) timeS = '%02i_%02i_%02i_on_%02i_%02i_%04i_to_%02i_%02i_%02i_on_%02i_%02i_%04i'%(sTime[3], sTime[4], sTime[5], sTime[2], sTime[1], sTime[0], eTime[3], eTime[4], eTime[5], eTime[2], eTime[1], eTime[0],) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, channel) indices = range(spectrum.shape[0]) datetimes = [time.localtime(sTimestamp + i)[1:7] for i in indices] data = [[datetimes[i][0], datetimes[i][1], datetimes[i][2], datetimes[i][3], datetimes[i][4], datetimes[i][5], spectrum[i]] for i in indices] fileName = "%s/srv/%s.csv"%(cnf.root_dir,timeS) import os if not os.path.exists("%s/srv/"%cnf.root_dir): os.makedirs("%s/srv/"%cnf.root_dir) dbControl.array_to_csv_file(data,("month","day","hour","minute","second","day of week", "power dbm"),fileName) fApp = FileApp(fileName) return fApp.make_response() except deform.ValidationFailure as e: return {'overrange':json.dumps(adc_overrange),\ 'overrangeS':overrangeS,\ 'times':"whoops",\ 'form':e.render(),\ 'reqts':reqts, 'xaxis':"",\ 'yaxis':"",\ 'minx':0,\ 'maxx':1,\ 'miny':0,\ 'maxy':1} else: print "NO SUBMIT" sTimestamp = time.time() - 3600 * 2 eTimestamp = time.time() #eTimestamp = eTimestamp - eTimestamp % 3600 sTime = time.localtime(sTimestamp) eTime = time.localtime(eTimestamp) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, [[1, 23667.0], [2, 2731.0]]) overranges = db.rfi_monitor_get_adc_overrange_pos(sTimestamp, eTimestamp) freqs = cnf.getFreqs(0) / 10e5 frequency = freqs[23667.0] timeS = '%02i:%02i:%02i to %02i:%02i:%02i'%(sTime[3], sTime[4], sTime[5], eTime[3], eTime[4], eTime[5]) miny = spectrum[:-2].min() maxy = spectrum[:-2].max() print np.where(spectrum==maxy) times = np.arange(int(sTimestamp),int(sTimestamp + spectrum.size),1) print len(overranges) db.close() return {'data':json.dumps(spectrum.tolist()),\ 'times':json.dumps(times.tolist()),\ 'overranges':json.dumps(overranges),\ 'maxx':int(sTimestamp - 1 + spectrum.size),\ 'minx':int(sTimestamp - 1),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"%.2fMHz taken from %s"%(frequency,timeS),\ 'xaxis':"Time",\ 'yaxis':"Power (dBm)",\ 'form':form.render(),\ 'reqts':reqts}
def graph_channel_view(request): import datetime db = dbControl.dbControl(cnf.monitor_db[0], cnf.monitor_db[1], cnf.monitor_db[2], cnf.monitor_db[3]) mini = db.rfi_monitor_get_oldest_timestamp() minDateTime = datetime.datetime.fromtimestamp(mini + 60) schema = channel_date_range().bind(min_date=minDateTime) form = deform.Form(schema, buttons=('submit', 'download')) reqts = form.get_widget_resources() for i in range(len(reqts['css'])): reqts['css'][i] = "deform:static/%s" % reqts['css'][i] for i in range(len(reqts['js'])): reqts['js'][i] = "deform:static/%s" % reqts['js'][i] sTimestamp = 0 frequency = -1 overranges = [] times = [] data = [] if 'submit' in request.params: print "IN SUBMIT" controls = request.POST.items() print "controls" print controls try: appstruct = form.validate(controls) sTime = appstruct['date_time_start'].timetuple() eTime = appstruct['date_time_end'].timetuple() frequencyS = appstruct['Frequency'] try: frequency = float(frequencyS) except ValueError: try: floats = [ float(s) for s in frequencyS.split(" ") if s.isDigit() ] frequency = floats[0] except: print "Not valid input" channel = cnf.freq_to_chan_mode(frequency) # db.frequency_to_channel(frequency) # freqs = cnf.getFreqs(channel[0][0] - 1) # print "Incoming frequency = %f converted to mode_chan %s"%(frequency, str(channel)) # print "Incoming frequency = %f converted to mode_chan %s"%(frequency, str(channel[0][1])) # print "outgoing frequency 1 is %f"%freqs[channel[0][1]] # freqs = cnf.getFreqs(channel[1][0] - 1) # print "outgoing frequency 2 is %f"%freqs[channel[1][1]] # time.sleep(5) # print "frequency = %f channel = %i"%(frequency, channel) sTimestamp = int(time.mktime(sTime)) eTimestamp = int(time.mktime(eTime)) timeS = '%02i:%02i:%02i on %02i/%02i/%04i to %02i:%02i:%02i on %02i/%02i/%04i' % ( sTime[3], sTime[4], sTime[5], sTime[2], sTime[1], sTime[0], eTime[3], eTime[4], eTime[5], eTime[2], eTime[1], eTime[0], ) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, channel) #362 overranges = db.rfi_monitor_get_adc_overrange_pos( sTimestamp, eTimestamp) miny = spectrum.min() maxy = spectrum.max() times = np.arange( int(sTimestamp) - 1, int(sTimestamp - 1 + spectrum.size), 1) except deform.ValidationFailure as e: return {'overrange':json.dumps(adc_overrange),\ 'overrangeS':overrangeS,\ 'times':"whoops",\ 'form':e.render(),\ 'reqts':reqts, 'xaxis':"",\ 'yaxis':"",\ 'minx':0,\ 'maxx':1,\ 'miny':0,\ 'maxy':1} elif 'download' in request.params: print "IN DOWNLOAD" controls = request.POST.items() try: appstruct = form.validate(controls) sTime = appstruct['date_time_start'].timetuple() eTime = appstruct['date_time_end'].timetuple() sTimestamp = int(time.mktime(sTime)) eTimestamp = int(time.mktime(eTime)) frequencyS = appstruct['Frequency'] try: frequency = float(frequencyS) except ValueError: try: floats = [ float(s) for s in frequencyS.split(" ") if s.isDigit() ] frequency = floats[0] except: print "Not valid input" channel = cnf.freq_to_chan_mode(frequency) timeS = '%02i_%02i_%02i_on_%02i_%02i_%04i_to_%02i_%02i_%02i_on_%02i_%02i_%04i' % ( sTime[3], sTime[4], sTime[5], sTime[2], sTime[1], sTime[0], eTime[3], eTime[4], eTime[5], eTime[2], eTime[1], eTime[0], ) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, channel) indices = range(spectrum.shape[0]) datetimes = [time.localtime(sTimestamp + i)[1:7] for i in indices] data = [[ datetimes[i][0], datetimes[i][1], datetimes[i][2], datetimes[i][3], datetimes[i][4], datetimes[i][5], spectrum[i] ] for i in indices] fileName = "%s/srv/%s.csv" % (cnf.root_dir, timeS) import os if not os.path.exists("%s/srv/" % cnf.root_dir): os.makedirs("%s/srv/" % cnf.root_dir) dbControl.array_to_csv_file(data, ("month", "day", "hour", "minute", "second", "day of week", "power dbm"), fileName) fApp = FileApp(fileName) return fApp.make_response() except deform.ValidationFailure as e: return {'overrange':json.dumps(adc_overrange),\ 'overrangeS':overrangeS,\ 'times':"whoops",\ 'form':e.render(),\ 'reqts':reqts, 'xaxis':"",\ 'yaxis':"",\ 'minx':0,\ 'maxx':1,\ 'miny':0,\ 'maxy':1} else: print "NO SUBMIT" sTimestamp = time.time() - 3600 * 2 eTimestamp = time.time() #eTimestamp = eTimestamp - eTimestamp % 3600 sTime = time.localtime(sTimestamp) eTime = time.localtime(eTimestamp) spectrum = db.rfi_monitor_get_range(sTimestamp, eTimestamp, [[1, 23667.0], [2, 2731.0]]) overranges = db.rfi_monitor_get_adc_overrange_pos( sTimestamp, eTimestamp) freqs = cnf.getFreqs(0) / 10e5 frequency = freqs[23667.0] timeS = '%02i:%02i:%02i to %02i:%02i:%02i' % ( sTime[3], sTime[4], sTime[5], eTime[3], eTime[4], eTime[5]) miny = spectrum[:-2].min() maxy = spectrum[:-2].max() print np.where(spectrum == maxy) times = np.arange(int(sTimestamp), int(sTimestamp + spectrum.size), 1) print len(overranges) db.close() return {'data':json.dumps(spectrum.tolist()),\ 'times':json.dumps(times.tolist()),\ 'overranges':json.dumps(overranges),\ 'maxx':int(sTimestamp - 1 + spectrum.size),\ 'minx':int(sTimestamp - 1),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"%.2fMHz taken from %s"%(frequency,timeS),\ 'xaxis':"Time",\ 'yaxis':"Power (dBm)",\ 'form':form.render(),\ 'reqts':reqts}