def page_list(): data.init() _highlight = None if request.method == "POST": _sort_by = "start_date" if request.form["sort_button"] == "Name": _sort_by = "project_name" _highlight = "name" elif request.form["sort_button"] == "ID": _sort_by = "project_no" _highlight = "id" elif request.form["sort_button"] == "Top projects": _sort_by = "lulz_had" _highlight = "top" _data = data.retrieve_projects(sort_by=_sort_by, search_fields=[_sort_by])[1] else: _data = data._data _highlight = None data_error = data._error_meaning[data._error_code] return render_template("list.html", _db_data=_data, _form_highlight = _highlight,data_error=data_error)
def page_search(): data.init() # keys is for the checkboxes keys = data._data[0].keys() techs = data.retrieve_techniques()[1] error = "" sstring = "" _search = {"sort_by": "", "sort_order": "", "techniques": [], "search": "", "search_fields": []} if request.method == "POST": _search["sort_by"] = request.form["sort_category"] _search["sort_order"] = str(request.form["sort_order"]) _search["techniques"] = request.form.getlist("search_techniques") _search["search"] = request.form["search_string"] _search["search_fields"] = request.form.getlist("search_categories") if len(_search["search_fields"]) == 0: _search["search_fields"] = keys sstring = data.retrieve_projects(sort_by=_search["sort_by"], sort_order=_search["sort_order"], techniques=_search["techniques"], search=_search["search"], search_fields=_search["search_fields"]) if sstring == None: sstring = "" data_error = data._error_meaning[data._error_code] return render_template("search.html", _search_result = sstring, keys=keys, techs=techs, error=error, data_error=data_error, _asd=_search)
def CalcAllPath(a, b): st = time.time() data.init() thrd = [] thrd.append(MultiGet(a,0)) thrd.append(MultiGet(a,1)) thrd.append(MultiGet(b,0)) thrd.append(MultiGet(b,1)) for i in thrd: i.start() for i in thrd: i.join() IsIda = IsId(a, thrd[0].d) IsIdb = IsId(b, thrd[2].d) print a,IsIda print b,IsIdb ed = time.time() print 'identify: ',ed-st st = time.time() if IsIda and IsIdb: AddId2Id(a, b, thrd[0].d,thrd[2].d) elif IsIda and not IsIdb: AddId2AuId(a, b, thrd[0].d,thrd[3].d) elif not IsIda and IsIdb: AddAuId2Id(a,b, thrd[1].d,thrd[2].d) else: AddAuId2AuId(a, b, thrd[1].d,thrd[3].d) ed = time.time() print 'http request & add edge: ',ed-st st = time.time() data.FindPath(a, b) ed = time.time() print 'find path: ',ed-st print 'total path: ',len(data.allpath) return json.dumps(data.allpath)
def page_project(id): data.init() _project = data.lookup_project(id)[1] if _project == None: _project = "" data_error = data._error_meaning[data._error_code] return render_template("project.html", _db_data=_project, data_error=data_error)
def project(id): data.init() id = id.encode('utf-8') log('Displaying project ' + str(id)) project = data.retrieve_projects(search = str(id), search_fields = ['project_no'])[1] if project == []: return render_template('no_result.html') return render_template('project.html', project = data.retrieve_projects(search = str(id), search_fields = ['project_no'])[1])
def index(id=None): data.init() #default template template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), projects=[], headline=get_text(os.path.basename(__file__)[:-3]), project_not_found=u'Databasen är inte tillgänglig', **common_language[DEFAULT_LANGUAGE]) if id == None: projects = data.retrieve_projects(sort_order='desc'); if projects[0] == 0: template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), projects=projects[1], headline=get_text(os.path.basename(__file__)[:-3]), project_not_found='', **common_language[DEFAULT_LANGUAGE]) # Find project by id else: project = data.lookup_project(id) # Project not found if project[0] == 2: projects = data.retrieve_projects(sort_order='desc'); if projects[0] == 0: template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + '-' + get_text('project_not_found'), projects=projects[1], headline=get_text(os.path.basename(__file__)[:-3]), project_not_found=get_text('project_not_found'), **common_language[DEFAULT_LANGUAGE]) # Show project by id else: project = data.retrieve_projects(search=id,search_fields=['project_no']); project[1][0]['techniques_used'] = ", ".join(project[1][0]['techniques_used']) template = kid.Template(name='projectsbyid', title=get_text('sitename') + '-' + get_text('projects') + ": " + project[1][0]['project_name'], headline=project[1][0]['project_name'], **dict(project[1][0],**common_language[DEFAULT_LANGUAGE])) template.cache = False return template.serialize(output='xhtml-strict')
def id_page(id): """ Portfolio id page """ db = data.init() #loads the given id project = data.get_project(db,id) #if project dont exist, display 404 error if project == None: return render_template("404.html") return render_template("portfolio.html",dataB = project)
def list(): data.init() log('Searching for a project') searchStr = request.args.get('search') sorting = request.args.get('sort') cats = request.args.getlist('categories') by_sorting = request.args.get('by_sort') technique = request.args.getlist('check_tech') if searchStr != None: searchStr = searchStr.encode('utf-8') if by_sorting == None: by_sorting = 'project_name' proj_hit = data.retrieve_projects(search = searchStr, search_fields = cats, techniques = technique, sort_order = sorting, sort_by = by_sorting)[1] if len(proj_hit) == 0: return render_template('list.html', fail = 'No project found') return render_template('list.html', proj_hit = data.retrieve_projects(search = searchStr, search_fields = cats, techniques = technique, sort_order = sorting, sort_by = by_sorting)[1])
def startup(NN=1, multi=False, **kwargs): n = 4 Nexp = 10000 // NN NMC = 500000 // NN if multi: llh = data.multi_init(n, Nexp, NMC, ncpu=4, **kwargs) mc = dict([(i, data.MC(NMC)) for i in range(n)]) else: llh = data.init(Nexp, NMC, ncpu=4, **kwargs) mc = data.MC(NMC) return llh, mc
def index(sort_by='start_date', sort_order='asc', techniques=None, search=None, search_fields=None): #default template template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), results=[], techs=[], search_fields=[], translate_field=[], headline=get_text(os.path.basename(__file__)[:-3]), project_not_found=get_text('database_not_available'), **common_language[DEFAULT_LANGUAGE]) if techniques == '': techniques = None if search_fields == '': search_fields = None if type(search_fields) != type([]) and search_fields != None: search_fields = [search_fields] data.init() # search projects results = data.retrieve_projects(sort_by, sort_order, techniques, search, search_fields) # Projects found if results[0] == 0: techniques = data.retrieve_techniques() template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + ' - ' + get_text('search'), headline=get_text(os.path.basename(__file__)[:-3]), results=results[1], techs=techniques[1], search_fields=data.data[0].keys(), translate_field=field_language[DEFAULT_LANGUAGE], project_not_found='', **common_language[DEFAULT_LANGUAGE]) template.cache = False return template.serialize(output='xhtml-strict')
def home_page(): """Home Page""" #Initiate DataFile db = data.init() #Code for Last Updated projects sorted_list = data.search(db, sort_by="end_date") x = 0 udb = [] for proj in sorted_list: udb.append(proj) x += 1 #Only add three last updated then break if x == 3: break return render_template("home.html", dataB = db, updatedPro = udb)
def index(): #default template template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), projects=[], techs= [], headline=get_text(os.path.basename(__file__)[:-3]), project_not_found=get_text('database_not_available'), **common_language[DEFAULT_LANGUAGE]) data.init() techniques = data.retrieve_technique_stats() if techniques[0] == 0: template = kid.Template(name=os.path.basename(__file__)[:-3], title=get_text('sitename') + ' - ' + get_text('techniques'), headline=get_text('techniques'), techs=techniques[1], project_not_found='', **common_language[DEFAULT_LANGUAGE]) template.cache = False return template.serialize(output='xhtml-strict')
def init(config): ## Initialise jarvis kernel jarvis = kernel.kernel(config) ## Connect to data source jarvis.register('data', data.init(jarvis)) ## Initialise functions jarvis.register('function', load_modules('functions')) ## Set up interfaces jarvis.register('interface', load_modules('interfaces')) ## Finish setup jarvis.setup() return jarvis
def list_page(): """List Page""" db = data.init() fields = data.get_fields(db) #If user is searhing (POST) if request.method == 'POST': search_list = [] for x in data.get_fields(db): #only add to list if x exists otherwise pass try: search_list.append(request.form[x]) except: pass if search_list == []: search_list = None #Selects how it should sort the list sort_order = request.form["sort_order"] db = data.search(db, search=request.form["search"],sort_order=sort_order, search_fields=search_list) return render_template("list.html",dataB = db, _fields = fields)
def list_tech(): """ Techniques page """ db = data.init() techs = data.get_techniques(db) all_techniques = techs #If user is searching (post) if request.method == 'POST': tech_list = [] for x in all_techniques: #only add to list if x exist otherwise pas try: if not request.form[x] in tech_list: tech_list.append(request.form[x]) except: pass if not tech_list == []: #To display all the techniques in a good way db = data.search(db, techniques = tech_list) techs = data.get_techniques(db) return render_template("list_techniques.html", dataB = db, techniques = techs, all_tech = all_techniques, selected_tech = tech_list) return render_template("list_techniques.html", dataB = db, techniques = techs, all_tech = all_techniques, selected_tech = techs)
def init_env(args): env = data.init(args.env_name, args) if args.sp: from self_play import SelfPlayWrapper env = SelfPlayWrapper(args, env) return env
# coding:utf-8 from flask import Flask import views import data import config app = Flask(__name__) app.config.from_object(config) data.init(app) views.init(app) if __name__ == '__main__': app.debug = True app.run()
# For TJ set comm action to 1 as specified in paper to showcase # importance of individual rewards even in cooperative games if args.env_name == "traffic_junction": args.comm_action_one = True # Enemy comm args.nfriendly = args.nagents if hasattr(args, 'enemy_comm') and args.enemy_comm: if hasattr(args, 'nenemies'): args.nagents += args.nenemies else: raise RuntimeError("Env. needs to pass argument 'nenemy'.") render = args.render args.render = False env = data.init(args.env_name, args, False) num_inputs = env.observation_dim args.num_actions = env.num_actions # Multi-action if not isinstance(args.num_actions, (list, tuple)): # single action case args.num_actions = [args.num_actions] args.dim_actions = env.dim_actions args.num_inputs = num_inputs # Hard attention if args.hard_attn and args.commnet: # add comm_action as last dim in actions args.num_actions = [*args.num_actions, 2] args.dim_actions = env.dim_actions + 1
# All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import torch, data import torch.nn as nn import torch.optim as optim import torch.nn.functional as F import sparseconvnet as scn import time import os, sys import math import numpy as np data.init(-1, 24, 24 * 8 + 15, 16) dimension = 3 reps = 2 #Conv block repetition factor m = 32 #Unet number of features nPlanes = [m, 2 * m, 3 * m, 4 * m, 5 * m] #UNet number of features per level class Model(nn.Module): def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, data.spatialSize, mode=3)).add( scn.SubmanifoldConvolution(dimension, 1, m, 3, False)).add( scn.FullyConvolutionalNet( dimension, reps,
from util import reader_util, writer_util, data_util, config from services import data_generator, solve import data import pprint, logging if __name__ == '__main__': data.init() # Import engine subtypes reader_util.import_engine_subtypes() # Import removal information data.removals_info, data.aos_cost = reader_util.import_removal_info( filepath='data_to_read/removal_info.csv', removals_data_storage=data.removals_info, aos_cost_data_storage=data.aos_cost) if config.first_run: logging.info( "FIRST_RUN is set to TRUE. All possible states and actions are going to be generated. This may take awhile." ) data_generator.generate_all_possible_states() data_generator.generate_all_possible_actions() for engine_subtype in data.engine_subtypes: data.need_to_update_removal_info[engine_subtype] = True logging.info( "All files needed for future runs have been created. Please set FIRST_RUN to FALSE for any future runs on this machine." ) else: # Import engine information
import secrets from secrets import token_hex from settings import Settings import data import evaluator import register import curator import traceback __author__ = "@pgarcgo" __version__ = "0.1" name = "Steem Community Curation BOT" steem_curation_account = "sccb" sa_session = data.init() settings = Settings() settings.load() message_evaluator = evaluator.MessageEvaluator(settings) user_registerer = register.UserRegisterer(sa_session) curator = curator.Curator() TOKEN = settings.discord_token print("Bot TOKEN: %s" % TOKEN) print("Discord.py version: %s" % discord.__version__) bot = commands.Bot(command_prefix='!')
def reload_init(): #reloads data.init() when called from other function data.init() logger('###data.init() reloaded') #sends message to logging function
def bootstrap(): data.init() cut_mugs()
# All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import torch, data import torch.nn as nn import torch.optim as optim import torch.nn.functional as F import sparseconvnet as scn import time import os, sys import math import numpy as np data.init(-1,24,24*8,16) dimension = 3 reps = 1 #Conv block repetition factor m = 32 #Unet number of features nPlanes = [m, 2*m, 3*m, 4*m, 5*m] #UNet number of features per level class Model(nn.Module): def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, data.spatialSize, mode=3)).add( scn.SubmanifoldConvolution(dimension, 1, m, 3, False)).add( scn.UNet(dimension, reps, nPlanes, residual_blocks=False, downsample=[3,2])).add( scn.BatchNormReLU(m)).add( scn.OutputLayer(dimension)) self.linear = nn.Linear(m, data.nClassesTotal)
async def on_ready(): print('Bot Client is ready!') data.init() update_data() reset()
p = {} p['n_epochs'] = 200 p['initial_lr'] = args.lr p['lr_decay'] = args.lr_decay p['weight_decay'] = args.weight_decay p['momentum'] = args.momentum p['check_point'] = False p['use_cuda'] = torch.cuda.is_available() wandb.init() wandb.config.update(args, allow_val_change=True) # data.init(-1,24,24*8,16) print(args) data.init(int(args.category), 24, 24 * 8, 16) dimension = 3 reps = 1 #Conv block repetition factor m = 32 #Unet number of features nPlanes = [m, 2 * m, 3 * m, 4 * m, 5 * m] #UNet number of features per level class Model(nn.Module): def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, data.spatialSize, mode=3)).add( scn.SubmanifoldConvolution(dimension, 1, m, 3, False)).add( scn.UNet(dimension, reps, nPlanes,
# This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import torch, data import torch.nn as nn import torch.optim as optim import sparseconvnet as scn import time import os, sys import math import numpy as np import logging logging.basicConfig(level=logging.INFO, filename='unet.log', filemode='w') data.init(24, 24 * 8, 16) dimension = 3 reps = 1 #Conv block repetition factor m = 32 #Unet number of features nPlanes = [m, 2 * m, 3 * m, 4 * m, 5 * m] #UNet number of features per level class Model(nn.Module): def __init__(self): nn.Module.__init__(self) self.sparseModel = scn.Sequential().add( scn.InputLayer(dimension, data.spatialSize, mode=3)).add( scn.SubmanifoldConvolution(dimension, 1, m, 3, False)).add( scn.UNet(dimension, reps, nPlanes,
import os import test import data comingDataDir = 'coming data/' proccesedDataDir = 'processed data/' outputImagesDir = 'output images/' files = os.listdir(comingDataDir) for file in files: fileInName = comingDataDir + file print fileInName data.init(fileInName) #timeStart='20111003_103000' #timeEnd='20111202_183000' timeStart='20111003_103000' timeEnd='20120224_183000' max_dif=-1000 fileToSave = proccesedDataDir + file[:-4] + '.csv' fo = open(fileToSave, 'w+') for i in range(1,201): for j in range(i+1,201): value = test.strat_reverse_calc(i, j, timeStart, timeEnd) fo.write(str(i)+','+str(j)+','+str(value)+'\n') max_dif=max(max_dif,value)
import eval # Imports import data import errors import os import importlib data.init() # Set up data def setup(env): @eval.proc(env, 'useg', eval.ARITY_1, data.str_t) # useg procedure - like from module import * def useg(env, *args): args = eval.parse_args(args, env) # Parse args for arg in args: try: # Try to open a local file first import_env = eval.Env(arg + '.wave') for name in env.getscope(): import_env.setval(name, env.getscope()[name]) import_env.run() env.pyvars.update(import_env.pyvars) for name in import_env.getscope(): env.setval(name, import_env.getscope()[name]) except FileNotFoundError: # If we can't do that then try to import a Python module try: try: importlib.import_module(arg).setup(env) except AttributeError: lib = importlib.import_module(arg) env.pyvars[arg] = lib except ImportError: # If we can't do that then try to open a standard library file try: import_env = eval.Env(os.path.abspath('lib/' + arg + '.wave'))
# -*-coding:utf8-*- from data import init from scipy.stats import chi2 import healpy as hp import numpy as np import matplotlib.pyplot as plt # convert test statistic to a p-value for a given point pVal_func = lambda TS, dec: -np.log10(0.5 * (chi2(1).sf(TS) + chi2(1).cdf(-TS))) if __name__=="__main__": # init the llh class llh = init(1000, 10000, ncpu=1, energy=True) print(llh) # iterator of all-sky scan with follow up scans of most interesting points for i, (scan, hotspot) in enumerate(llh.all_sky_scan(nside=16, pVal=pVal_func)): if i > 0: # break after first follow up break # plot results hp.mollview(scan["pVal"], min=0., cmap=plt.cm.afmhot) hp.projscatter(np.degrees(llh.exp["ra"]), np.degrees(np.arcsin(llh.exp["sinDec"])), lonlat=True, marker="x", color="red")
def main(): init() runUI()
from flask import Flask, render_template, request import data import logging app = Flask(__name__) logfile = 'index.log' #creates log file def logger(msg): #logging function, recieve message and print in log file logging.basicConfig(filename = logfile, level = logging.INFO) logging.info(msg) def reload_init(): #reloads data.init() when called from other function data.init() logger('###data.init() reloaded') #sends message to logging function data.init() #loads data.init() when server starts logger('###data.init() loaded') @app.route("/") def hello(): #loads main page reload_init() #calls reload function logger('###Main page visited') return render_template('main_content.html') #renders main content @app.route("/techniques") def techniques(): #opens techniques page reload_init() logger('###Techniques page visited')
from autocomplete import get_best_k_completions from data import init from tkinter import Tk, Menu, END, Entry, Button, Listbox init() root = Tk() root.title('Auto Complete') def search(): input = entry.get() list.delete(0, END) if input != "": if input[-1] == '#': entry.delete(0, END) else: best_completion = get_best_k_completions(input) i = 1 if best_completion: for sentence in best_completion: list.insert(END, f'{i}. {sentence.get_completed_sentence()}') list.insert(END, f'source: {sentence.get_source_text()} , offset: {sentence.get_offset()} , score: {sentence.get_score()}\n') list.insert(END, '\n\n') i += 1 else: list.insert(END, 'no results!') entry = Entry(width=70) entry.grid(row=0, column=0)
parser.add_option( '--llhweight', dest='llhweight', type=str, default='uniform', metavar='LLHWEIGHT', help='Sets the weighting used in the llh model for point source searches.') opts, args = parser.parse_args() batch = opts.batch batchsize = opts.batchsize llhweight = opts.llhweight ## We'll assign the proper weighting scheme for the search, then use it to calculate and cache the associated bckg trials: ## if llhweight == 'uniform': llhmodel = data.init(energy=True) else: llhmodel = data.init(energy=True, weighting=modelweights['{}'.format(llhweight)]) bckg_trials = PointSourceLLH.background_scrambles(llhmodel, src_ra, src_dec, alpha=0.5, maxiter=batchsize) #choose an output dir, and make sure it exists this_dir = os.path.dirname(os.path.abspath(__file__)) out_dir = misc.ensure_dir( '/data/user/brelethford/Output/stacking_sensitivity/SwiftBAT70m/{}/background_trials/' .format(llhweight))
src_ra, src_dec, redshift, flux = [params['ra'][0], params['ra'][6]], [ params['dec'][0], params['dec'][6] ], [params['redshift'][0], params['redshift'][6]], [params['flux'][0], params['flux'][6]] print('my sources are at declination(s):') print(str(src_dec)) ## Time to define my modelweights in a dictionary. ## modelweights = {'flux': flux, 'redshift': list(np.power(redshift, -2))} ## Now to import my llh model framework. ## import data ## Like in the background trials, we have to define which llhmodel to use. For this check I'll use flux because it's easiest. llhmodel = data.init(energy=True, weighting=modelweights['flux']) ##Remember, weighted sensitivity requires src dec in radians.# src_dec = np.radians(src_dec) src_ra = np.radians(src_ra) ##Now, I'll input my injection weighting scheme from the commandline. ## inj = PointSourceInjector(Gamma, sinDec_bandwidth=.05, src_dec=src_dec, theo_weight=modelweights['flux'], seed=0) #inj.e_range = [1.e4,1.e8] sensitivity = PointSourceLLH.weighted_sensitivity(llhmodel,
# -*- coding:utf-8 -*- from flask import Flask, render_template import data data.init() app = Flask(__name__) @app.route("/") def home(): return render_template('index.html') @app.route("/list") def list(): return render_template('list.html', projects = data.retrieve_projects()[1]) @app.route("/techniques") def techniques(): return render_template('techniques.html', techniques = data.retrieve_techniques()[1]) @app.route("/search/<id>") def search(id): return render_template('search.html', search_results = data.retrieve_projects(search=str(id), search_fields=[None])[1]) if __name__ == "__main__": app.run(debug = True)
args.mean_ratio = 0 if args.env_name == "traffic_junction": args.comm_action_one = True # Enemy comm args.nfriendly = args.nagents if hasattr(args, 'enemy_comm') and args.enemy_comm: if hasattr(args, 'nenemies'): args.nagents += args.nenemies else: raise RuntimeError("Env. needs to pass argument 'nenemy'.") if args.env_name == 'grf': render = args.render args.render = False env = data.init(args.env_name, args, False) num_inputs = env.observation_dim args.num_actions = env.num_actions # Multi-action if not isinstance(args.num_actions, (list, tuple)): # single action case args.num_actions = [args.num_actions] args.dim_actions = env.dim_actions args.num_inputs = num_inputs # Hard attention if args.hard_attn and args.commnet: # add comm_action as last dim in actions args.num_actions = [*args.num_actions, 2] args.dim_actions = env.dim_actions + 1