Advertisement
Guest User

c

a guest
Jul 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. class DustTsiDataSourceFixed:
  2.  
  3.     def __init__(self, settings):
  4.         self.error_percentage = int(settings['Meta-Data']['err_percentage'])
  5.  
  6.         self.heads = settings['Dust-Tsi-Data']['heads']
  7.  
  8.         settings = settings['Meta-Data']
  9.  
  10.         self.fixed_list = ['send_fixed_dust_10', 'send_fixed_dust_25', 'send_fixed_dust_tsp', 'send_fixed_dust_4', 'send_fixed_dust_1']
  11.         self.fixed_hex_list = ['PM10', 'PM2.5', 'TSP', 'PM4', 'PM1']
  12.  
  13.         for f in self.fixed_list:
  14.             exec ('self.' + f + '=int(settings[\'' + f + '\'])')
  15.             f = 'value' + f[4:]
  16.             exec ('self.' + f + '=int(settings[\'' + f + '\'])')
  17.  
  18.     def get_sample(self, response):
  19.         for f in range(len(self.fixed_list)):
  20.             if self.heads == 'all' or self.fixed_hex_list[f] == self.heads:
  21.                 ok = False
  22.                 exec('if self.'+self.fixed_list[f]+' and register_type == \''+self.fixed_hex_list[f]+'\': ok = True')
  23.                 if ok:
  24.                     data = 'value' + self.fixed_list[f][4:]
  25.                     exec('response[f+1] = float(self.'+data+')')
  26.                     break
  27.  
  28.         if random.randint(0, 100) < self.error_percentage:
  29.             for i in range(1, len(response)):
  30.                 response[i] = response * 100
  31.  
  32.         return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement