def update(self): if self.islocal: temp = self.reader.get() redisclient.set(self.id, temp) return temp return None
def update_efforts(year=None, week_number=None): transaction_start_time = datetime.now() log.info('Method=update_efforts Year=%s WeekNumber=%s' % (year, week_number)) try: if year != None and week_number != None: leagues = core.compile_efforts(year=year, week_number=week_number) else: leagues = core.compile_efforts() log.info('Leagues compiled Count=%s' % len(leagues)) except Exception as ex: log.exception('Failed to compile leagues') leagues = None error = ex data = json.dumps(leagues) result_key = get_results_key(year=year, week_number=week_number) log.info('Method=update_efforts Message="Storing results" ResultKey=%s' % result_key) redisclient.set(result_key, data) log.info('Method=update_efforts Message="Process complete"') time_taken = datetime.now() - transaction_start_time log.info('PERF Method=updateefforts ms=%s' % (time_taken.microseconds)) return "OK"
def add_sotw(self, segment_id, neutral_zones=None): log.info('Method=%s, SegmentId=%s, NeutralZones=%s' % ('add_sotw', segment_id, neutral_zones)) key_name = self.get_sotw_key_name() redisclient.set('%s_segment' % key_name, segment_id) if neutral_zones != None: for neutral_zone in neutral_zones: redisclient.sadd('%s_neutral_zones' % key_name, neutral_zone)
def setupTestData(self, file): config = self.loadconfig(file)['redis'] sotw_key = 'sotw_%s_%s' % (date.today().year, date.today().isocalendar()[1]) redisclient.set('api_token', config['api_token']) redisclient.set('%s_segment' % sotw_key, config['sotw_current']['segment']) for neutral_zone in config['sotw_current']['neutral_zones']: redisclient.sadd('%s_neutral_zones' % sotw_key, neutral_zone) if 'members' in config: for member in config['members']: member_data = config['members'][member] for key, value in member_data.items(): redisclient.hset(member, key, value) # if 'segments' in config: # for segment in config['segments']: # segment_data = config['segments'][segment] try: redisclient.delete('divisions') except Exception as e: print(e) for division in config['divisions']: division_data = config['divisions'][division] redisclient.sadd('divisions', division) redisclient.hset(division, 'name', division_data['name']) redisclient.hset(division, 'sex', division_data['sex']) try: redisclient.delete(division + '_members') except Exception as e: print(e) if 'members' in division_data: for value in division_data['members']: redisclient.sadd(division + '_members', value) if config['efforts']['segment']: config['loaded_efforts'] = json.loads(config['efforts']['segment']) if config['efforts']['neutral_zones']: config['loaded_neutral_zones'] = [] for neutral_zone in config['efforts']['neutral_zones']: loaded_neutral_zone_efforts = {} for neutral_zone_effort in neutral_zone: loaded_neutral_zone_efforts[neutral_zone_effort['id']] = neutral_zone_effort config['loaded_neutral_zones'].append(loaded_neutral_zone_efforts) return config
def set(self, state): redisclient.set(self.id, state) if self.islocal: self.update() else: url = 'http://' + self.host + ':5000/control/' + self.id + '/' + state print('Passing control request to ' + url) request.getfromurl(url)
def test(param): key_name = 'test_value' redisclient.set(key_name, param) persisted_value = redisclient.get(key_name) return "OK %s" % persisted_value
def setupTestData(self, file): config = self.loadconfig(file)['redis'] sotw_key = 'sotw_%s_%s' % (date.today().year, date.today().isocalendar()[1]) redisclient.set('api_token', config['api_token']) redisclient.set('%s_segment' % sotw_key, config['sotw_current']['segment']) for neutral_zone in config['sotw_current']['neutral_zones']: redisclient.sadd('%s_neutral_zones' % sotw_key, neutral_zone) if 'members' in config: for member in config['members']: member_data = config['members'][member] for key, value in member_data.items(): redisclient.hset(member, key, value) # if 'segments' in config: # for segment in config['segments']: # segment_data = config['segments'][segment] try: redisclient.delete('divisions') except Exception as e: print(e) for division in config['divisions']: division_data = config['divisions'][division] redisclient.sadd('divisions', division) redisclient.hset(division, 'name', division_data['name']) redisclient.hset(division, 'sex', division_data['sex']) try: redisclient.delete(division + '_members') except Exception as e: print(e) if 'members' in division_data: for value in division_data['members']: redisclient.sadd(division + '_members', value) if config['efforts']['segment']: config['loaded_efforts'] = json.loads(config['efforts']['segment']) if config['efforts']['neutral_zones']: config['loaded_neutral_zones'] = [] for neutral_zone in config['efforts']['neutral_zones']: loaded_neutral_zone_efforts = {} for neutral_zone_effort in neutral_zone: loaded_neutral_zone_efforts[ neutral_zone_effort['id']] = neutral_zone_effort config['loaded_neutral_zones'].append( loaded_neutral_zone_efforts) return config