Exemplo n.º 1
0
 def plotGains(coordinator_id ,tx_node_id, rx_node_id, year = None, month = None, day = None):
     #call the method when you want to plot the results from the file
     #open file with measurements and plot results from it
     #specify year, month, day if you only want to take into account gain measurements made until that date. If those are not specified, then all measurements will be taken into account.
     
     #first get data from the file
     gains = GainCalculations.getFileResults(coordinator_id, tx_node_id, rx_node_id, year=year, month=month, day=day)
     #gains will have the following form : [ [gain - linear , received_power[w] , noise_power[w], transmitted_power[w], date ], [gain - linear , received_power[w] , noise_power[w], transmitted_power[w], date ], .. ]
     
     if gains is None:
         aux = tx_node_id
         tx_node_id = rx_node_id
         rx_node_id = aux
         print "There are no values available for this combination. Trying with gain_between_tx_%d_and_rx_%d.dat? (yes or no)" %(tx_node_id, rx_node_id)
         choice = raw_input("")
         
         if choice.lower() == "no":
             print "You have chosen no"
             return None
         elif choice.lower() == "yes":
             gains = GainCalculations.getFileResults(coordinator_id, tx_node_id, rx_node_id, year=year, month=month, day=day)
             if gains is None:
                 print "Sorry, there are no measurements for this combination at all"
                 return None
         else:
             print "Invalid input, you were supposed to enter yes or no"
             return None
         
     print "Plot gains"    
         
     #define a gain_list : [[gain_dB], [date]]
     gain_list = [[],[]]
     
     for i in gains:
         date = DateTime.strptime((i[4])[0:16], "%Y-%m-%d %H:%M")
         gain_list[0].append(10.00 * math.log10(i[0]) )
         gain_list[1].append(date)
         
     #plot results
     Plot.plotGains(gain_list[1], gain_list[0], "Number of measurements", "Gain [dB]", "Gain between tx%d and rx%d" %(tx_node_id, rx_node_id), False)