def __init__(self, fake=False): random.seed(time.time()) self.fake = fake self.channel = channel.Channel() self.fake_channel = channel.Channel(fake=True) if self.fake: self.channel = self.fake_channel self.rn = random_name.RandomName() self.user = user.User(fake=fake) self.client = slack.WebClient(token=slack_token.token) self.enricher = enricher.Enricher(fake=fake)
def __init__(self, fake=False): self.sf = slack_formatter.SlackFormatter() random.seed(time.time()) self.fake = fake self.fake_channel = channel.Channel(fake=True) self.channel = channel.Channel(fake=fake) self.rn = random_name.RandomName() self.user = user.User(fake=fake) self.client = slack.WebClient(token=slack_token.token) self.enricher = enricher.Enricher(fake=fake) self.cml = channel_members_log.ChannelMembersLog()
def __init__(self, fake=False): self.sf = slack_formatter.SlackFormatter(fake=fake) random.seed(time.time()) self.fake = fake self.fake_channel = channel.Channel(fake=True) self.fp = firstpost.FirstPost() self.channel = channel.Channel() self.rn = random_name.RandomName() self.user = user.User(fake=fake) self.client = slack.WebClient(token=slack_token.token) self.enricher = enricher.Enricher(fake=fake) self.uc = user_created.UserCreated()
def join_channel(): values = request.get_json() required = ['remote_node', 'local_node', 'chan'] if not all(k in values for k in required): return "Missing required fields", 400 remote_node = values['remote_node'] local_node = values['local_node'] chan = values['chan'] data = {'nodes': [local_node]} response = requests.post(f'{remote_node}/{chan}/nodes/register', data=json.dumps(data), headers={'Content-Type': 'application/json'}) body = response.json() chan_info = body['channel'] # manually cloning the channel? gross chan = channel.Channel(chan_info['name']) chan.created_at = chan_info['created_at'] chan.ref = chan_info['ref'] # TODO: clone all registered nodes on remote machine chan.chain.register_node(remote_node) black.CHANNELS[chan.ref] = chan # TODO: return a better response than just "OK" return jsonify({'message': "OK"})
def calculate(self): try: flow = float(self.flow.text()) kinvisc = float(self.kinvisc.text()) length = float(self.lengthEdit.text()) usIL = float(self.usInvert.text()) dsIL = float(self.dsInvert.text()) Ks = float(self.Ks.text()) / 1000.0 usK = float(self.usK.text()) dsK = float(self.dsK.text()) conduit = channel.Channel() conduit.setValues(flow, 0.8, 2, 100.0, 1.0, 0.9, 0.003, kinvisc) conduit.calculate() resultText = "critical depth:\t %0.3f" % conduit.crit_depth resultText += "\nnormal depth:\t %0.3f" % conduit.norm_depth resultText += "\nds water depth:\t %0.3f" % conduit.water[0] resultText += "\nus water depth:\t %0.3f" % conduit.water[-1] resultText += "\nds water level:\t %0.3f" % conduit.head[0] resultText += "\nus water level:\t %0.3f" % conduit.head[-1] resultText += "\nds energy level:\t %0.3f" % conduit.energy[0] resultText += "\nus energy level:\t %0.3f" % conduit.energy[-1] self.result.setText(str(resultText)) except ValueError: pass except: print("error") pass
def __init__(self, dir, atmFile=None): #***** Private Variables ***** self.__cameraFile = dir+'/camera.txt' self.__opticalChainFile = dir+'/opticalChain.txt' self.__channelFile = dir+'/channels.txt' #***** Public Variables ***** self.dir = dir self.name = dir.rstrip('/').split('/')[-1] self.camera = cm.Camera(self.__cameraFile) #Unpack channel file output = np.loadtxt(self.__channelFile, dtype=np.str) keyArr = output[0] elemArr = output[1:] #Create optic objects and store them into an array self.chanArr = [] for elem in elemArr: dict = {} for i in range(len(keyArr)): dict[keyArr[i]] = elem[i] self.chanArr.append(ch.Channel(dict, self.camera, self.__opticalChainFile, atmFile)) self.numChans = len(self.chanArr) #Gather channels into pixels self.pixels = {} for channel in self.chanArr: if channel.pixelID in self.pixels.keys(): self.pixels[channel.pixelID].append(channel) else: self.pixels[channel.pixelID] = [channel]
def make_ion_channels(self): channel_list = [] prev_start_x, prev_diam = 0, 0 active_list = [True, False] for i in range(CHANNEL_NUM): start_x, diam = prev_start_x+prev_diam+randint(25, 50), randint(25, 50) is_voltage_gated = choice(active_list) ion_choice = choice(ION_CHOICES) channel_list.append({'ion_perm':ion_choice, 'start_x':start_x, 'is_voltage_gated':is_voltage_gated, 'diam':diam}) prev_start_x, prev_diam = start_x, diam for channel in channel_list: start_x, diam = WIDTH*channel['start_x']/(prev_start_x+prev_diam), WIDTH*channel['diam']/(prev_start_x+prev_diam) is_voltage_gated = channel['is_voltage_gated'] ion_perm = channel['ion_perm'] try: self.channels.append(channel_class.Channel(ion_perm=ion_perm, start_x=start_x, is_voltage_gated=is_voltage_gated, diam=diam)) except Exception as e: print(e) for channel in self.channels: if channel.ion_perm in list(self.ion_channel_nums.keys()): self.ion_channel_nums[channel.ion_perm] += 1 else: self.ion_channel_nums[channel.ion_perm] = 1
def add_channel(self, chname, creator=None, ts=None): chans = [n.lower() for n in self.channels.keys()] if chname.lower not in chans: chan = channel.Channel(chname, creator, ts) self.channels[chname] = chan return chan else: return self.channels[chname]
def get_channel(self, channelname): if channelname in self.channels: channel1 = self.channels[channelname.lower()] else: channel1 = channel.Channel(self, channelname) print(channelname + " channel created") self.channels[channelname.lower()] = channel1 return channel1
def on_connect(self): for channel_to_join in self.joined_channels: self.log.info("JOINing " + channel_to_join) chan = channel.Channel(channel_to_join) self.channels[channel_to_join] = chan self.channels[channel_to_join].init_markov() self.join('#' + channel_to_join)
def createLogicalChannel(self, channelname): cleanname = channelname.replace("'", "").replace("\"", "") for pindex, p in enumerate(self.channels): if p["name"] == cleanname: return "" self.channels.append(channel.Channel(cleanname)) data.DAO(self).save() return cleanname + "\n"
def testChannel(stubhw): '''Test update of the channel status''' ch = channel.Channel("Ch1", 0, stubhw) ch.isenable = True ch.running = True assert (ch.running is True) ch.running = False assert (ch.running is False)
def testManual(stubhw): """Forced ON, OFF or return to AUTO""" ch = channel.Channel("Citronnier", 0, stubhw) assert (ch.manual == "AUTO") ch.manual = "OFF" assert (ch.manual == "OFF") ch.manual = "ON" assert (ch.manual == "ON") ch.manual = "DUMMY" assert (ch.manual == "AUTO")
def send_request(self, request): host = request.get_host() port = request.get_port() connectiontype = request.get_type() if not self._channels.has_key((host, port, connectiontype)): channel = channel.Channel(self.monitor) channel.setup_connection(host, port, connectiontype) self._channels[(host, port, connectiontype)] = channel channel = self._channels[(host, port, connectiontype)] return channel.send_request(request)
def __init__(self): if not data.DAO().exists(): self.channels = [] self.channels.append( channel.Channel("default", ['http://hcli.io'], ['http://hcli.io'])) data.DAO(self).save() data.DAO().load(self) else: data.DAO().load(self)
def __init__(self, beam_num, **options): """Initialize the beam object""" self.beam_num = beam_num self.options = options self.channels = [channel.Channel(i, beam_num, **options) for i in xrange(options["num_channels"])] # put error in channel zero. This is the Calgary average self.channels[0].error = True # put error in ignored channels if options["exclude_channels"] != None: for c in options["exclude_channels"]: self.channels[c].error = True
def new_channel(): values = request.get_json() required = ['name'] if not all(k in values for k in required): return 'Missing values', 400 chan = channel.Channel(values['name']) black.CHANNELS[chan.ref] = chan response = {'channel': chan.ref} return jsonify(response), 200
def channel(self, func=None, *params): ch = channel.Channel() if func == "add": if len(params) == 1: if self.user is not None: if ch.exists(self.firebase, params[0]): ret = '{"status": false, "message":"Channel already exists"}' return json.dumps(json.loads(ret)) else: ch.add(self.firebase, self.user, params[0]) ch.get(self.firebase, params[0]) ret = '{"status": true, "message": "Channel created"}' return json.dumps(json.loads(ret)) else: ret = '{"status": false, "message":"Not logged in"}' return json.dumps(json.loads(ret)) else: ret = '{"status": false, "message":"Wrong number of parameters"}' return json.dumps(json.loads(ret)) elif func == "get": if len(params) > 0: if ch.exists(self.firebase, params[0]): data = ch.get(self.firebase, params[0]).val() return json.dumps(data) else: ret = '{"status": false, "message": "Channel not found"}' return json.dumps(json.loads(ret)) else: try: data = ch.get(self.firebase).val() return json.dumps(data) except: ret = '{"status": false, "message": "Unable to fetch channels"}' return json.dumps(json.loads(ret)) elif func == "exist": if len(params) == 1: exist = ch.exists(self.firebase, params[0]) ret = '{"status": ' if exist: ret += 'true' else: ret += 'false' ret += '}' return json.dumps(json.loads(ret)) else: ret = '{"status": false, "message":"Wrong number of parameters"}' return json.dumps(json.loads(ret)) else: ret = '{"status": false, "message": "No such function for channel"}' return json.dumps(json.loads(ret))
def get_coordinates(beam_num, **options): """Return the AST, RA, and DEC for the specified beam after performing the necessary corrections""" # just use some random channel number, but make it different # for each beam in case we multithread this - we probably don't # want to open the same file in two places at once num = options["num_channels"] - beam_num - 1 # first, get the RA and AST from beam 0 then apply corrections temp_chan = channel.Channel(num, 0, **options) RA, skipDEC, AST = temp_chan.get_coordinates() # correct RA and AST for AST offset for i in xrange(len(AST)-1): AST[i] = AST[i] + (AST[i+1] - AST[i])*options["ast_offset"] RA[i] = RA[i] + (RA[i+1] - RA[i])*options["ast_offset"] # now get the DEC for this beam temp_chan = channel.Channel(num, beam_num, **options) skipRA, DEC, skipAST = temp_chan.get_coordinates() # correct DEC for AST offset for i in xrange(len(DEC)-1): DEC[i] = DEC[i] + (DEC[i+1] - DEC[i])*options["ast_offset"] # correct RA for RA correction RA = RA + options["ra_corr"][beam_num]/(60. * np.cos(np.deg2rad(DEC))) return RA, DEC, AST
def on_join(self, args, n, u, h): """JOIN command""" Target = args[1] target = Target.lower() if target[0] not in "#+": return if target not in channels: channels[target] = channel.Channel(Target) if channels[target].get_channeluser( users[n.lower()]) not in channels[target].members: channels[target].join_user(users[n.lower()])
def __init__(self): config = { "apiKey": "", "authDomain": "dis-test-146a0.firebaseapp.com", "databaseURL": "https://dis-test-146a0.firebaseio.com", "projectId": "dis-test-146a0", "storageBucket": "dis-test-146a0.appspot.com", "messagingSenderId": "502618154240" } self.firebase = pyrebase.initialize_app(config) self.user = user.User(self.firebase) self.event = event.Event(self.firebase, self.user) self.channel = channel.Channel(self.firebase, self.user)
def __init__(self, channels=None): self._data = {} self.user = user.User() self.reactions_accumulator = Accumulator( self.top_limit, lambda x: x[0]) self.reply_accumulator = Accumulator(self.top_limit, lambda x: x[0]) self.user_reply_accumulators = {} self.user_reaction_accumulators = {} self.reactions = {} self.reactions_from = {} # People who react to the people we're tracking self.configuration = configuration.Configuration() self.accum_methods = [x for x in dir(self) if x.find("accum_") == 0] self.track = {} self.channel = channel.Channel() self.channels = channels self.hydrated_channels = {}
def main(args): conf = config.Config(util.load_json(args.config)) conf.id = args.id mf = Filter() ch = channel.Channel(conf, mf) random.seed() v = random.randrange(2) r = 0 d = False while not (d): v, d = do_round(conf, ch, v, r) r += 1 print(v, d) return
def generate(self): #Store optical chain object self.log.log("Generating optical chain for camera %s" % (self.name), 1) self.optBandDict = self.__bandDict(self.bandDir+'/Optics') self.optChain = oc.OpticalChain(self.log, self.configDir+'/optics.txt', nrealize=self.nrealize, optBands=self.optBandDict) #Store channel objects self.log.log("Generating channels for camera %s" % (self.name), 1) self.detBandDict = self.__bandDict(self.bandDir+'/Detectors') chans = np.loadtxt(self.configDir+'/channels.txt', dtype=np.str, delimiter='|'); keyArr = chans[0]; elemArr = chans[1:] self.chanDicts = [{keyArr[i].strip(): elem[i].strip() for i in range(len(keyArr))} for elem in elemArr] self.channels = {chDict['Band ID']: ch.Channel(self.log, chDict, self, self.optChain, self.sky, self.scn, detBandDict=self.detBandDict, nrealize=self.nrealize, nobs=self.nobs, clcDet=self.clcDet, specRes=self.specRes) for chDict in self.chanDicts} #Store pixel dictionary self.log.log("Generating pixels for camera %s" % (self.name), 2) self.pixels = {} for c in self.channels: if self.channels[c].pixelID in self.pixels.keys(): self.pixels[self.channels[c].pixelID].append(self.channels[c]) else: self.pixels[self.channels[c].pixelID] = [self.channels[c]]
def onBtnClick(n_clicks, url, limit): if (url != ""): channel = c.Channel(url) app.title = channel.channelName global isLoading isLoading = True data = channel.getArticlesStats(int(limit)) if (limit != "" and limit.isdigit()) else channel.getArticlesStats() isLoading = False #titles = list(map(limitStr, data["names"])) global articleCounter articleCounter = 0 fig = go.Figure(data=[go.Scatter(y=data["views"], x=data["names"], mode="lines+markers", name = "Views")]) fig.add_trace(go.Scatter(y=data["readings"], x=data["names"], mode="lines+markers", name = "Readings")) fig.update_layout(transition_duration=500) return fig return go.Figure(data=[go.Scatter()])
def on_join(self, args): """JOIN command""" targets = args[1].split(",") for Target in targets: newchan = False if not Target: continue target = Target.lower() if target == "0": for i in self.user.channels[:]: channels[i].part_user(user=self.user, message="Left all channels") if (not channels[i].members and not channels[i].immutable): del channels[i] continue if target[0] not in "+&#": self.send_numeric(403, "%s :No such channel" % Target) continue if not target in channels: channels[target] = channel.Channel(Target) newchan = True if channels[target].get_channeluser( self.user) in channels[target].members: continue if (target in ("&errors", "&eval", "&rawlog") and self.olines and not self.user.isoper) or channels[target].is_really_banned( self.user) or ( "i" in channels[target].modeflags and not channels[target].is_invex(self.user)): self.send_numeric(471, "%s :Permission denied" % Target) continue if newchan and target[0] != "+": channels[target].join_user(self.user, self, -1) else: channels[target].join_user(self.user, self) if target[0] != "&": self.broadcast_remote(":%s JOIN %s" % (self.user.full_hostmask(), target))