signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def project(dataIn, projectionScript): | <EOL>dataOut = {}<EOL>try:<EOL><INDENT>projectionScript = str(projectionScript)<EOL>program = makeProgramFromString(projectionScript)<EOL>if PY3:<EOL><INDENT>loc = {<EOL>'<STR_LIT>': dataIn,<EOL>'<STR_LIT>': dataOut<EOL>}<EOL>exec(program, {}, loc)<EOL>dataOut = loc['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>exec(progr... | Programs may make use of data in the `dataIn` variable and should
produce data on the `dataOut` variable. | f3383:m0 |
def guess_endpoint_uri(rq, gh_repo): | auth = (static.DEFAULT_ENDPOINT_USER, static.DEFAULT_ENDPOINT_PASSWORD)<EOL>if auth == ('<STR_LIT:none>', '<STR_LIT:none>'):<EOL><INDENT>auth = None<EOL><DEDENT>if has_request_context() and "<STR_LIT>" in request.args:<EOL><INDENT>endpoint = request.args['<STR_LIT>']<EOL>glogger.info("<STR_LIT>" + endpoint)<EOL>return ... | Guesses the endpoint URI from (in this order):
- An endpoint parameter in URL
- An #+endpoint decorator
- A endpoint.txt file in the repo
Otherwise assigns a default one | f3384:m0 |
def count_query_results(query, endpoint): | <EOL>return <NUM_LIT:1000><EOL> | Returns the total number of results that query 'query' will generate
WARNING: This is too expensive just for providing a number of result pages
Providing a dummy count for now | f3384:m1 |
def _getDictWithKey(key, dict_list): | for d in dict_list:<EOL><INDENT>if key in d:<EOL><INDENT>return d<EOL><DEDENT><DEDENT>return None<EOL> | Returns the first dictionary in dict_list which contains the given key | f3384:m2 |
def get_parameters(rq, variables, endpoint, query_metadata, auth=None): | <EOL>internal_matcher = re.compile("<STR_LIT>")<EOL>variable_matcher = re.compile(<EOL>"<STR_LIT>")<EOL>parameters = {}<EOL>for v in variables:<EOL><INDENT>if internal_matcher.match(v):<EOL><INDENT>continue<EOL><DEDENT>match = variable_matcher.match(v)<EOL>if match:<EOL><INDENT>vname = match.group('<STR_LIT:name>')<EOL... | ?_name The variable specifies the API mandatory parameter name. The value is incorporated in the query as plain literal.
?__name The parameter name is optional.
?_name_iri The variable is substituted with the parameter value as a IRI (also: number or literal).
?_name_en The parameter value is considered as literal with... | f3384:m3 |
def get_defaults(rq, v, metadata): | glogger.debug("<STR_LIT>".format(metadata))<EOL>if '<STR_LIT>' not in metadata:<EOL><INDENT>return None<EOL><DEDENT>defaultsDict = _getDictWithKey(v, metadata['<STR_LIT>'])<EOL>if defaultsDict:<EOL><INDENT>return defaultsDict[v]<EOL><DEDENT>return None<EOL> | Returns the default value for a parameter or None | f3384:m4 |
def get_enumeration(rq, v, endpoint, metadata={}, auth=None): | <EOL>if '<STR_LIT>' not in metadata:<EOL><INDENT>return None<EOL><DEDENT>enumDict = _getDictWithKey(v, metadata['<STR_LIT>'])<EOL>if enumDict:<EOL><INDENT>return enumDict[v]<EOL><DEDENT>if v in metadata['<STR_LIT>']:<EOL><INDENT>return get_enumeration_sparql(rq, v, endpoint, auth)<EOL><DEDENT>return None<EOL> | Returns a list of enumerated values for variable 'v' in query 'rq' | f3384:m5 |
def get_enumeration_sparql(rq, v, endpoint, auth=None): | glogger.info('<STR_LIT>'.format(v))<EOL>vcodes = []<EOL>tpattern_matcher = re.compile("<STR_LIT>",<EOL>flags=re.DOTALL)<EOL>glogger.debug(rq)<EOL>tp_match = tpattern_matcher.match(rq)<EOL>if tp_match:<EOL><INDENT>vtpattern = tp_match.group('<STR_LIT>')<EOL>gnames = tp_match.group('<STR_LIT>')<EOL>glogger.debug("<STR_LI... | Returns a list of enumerated values for variable 'v' in query 'rq' | f3384:m6 |
def get_yaml_decorators(rq): | <EOL>if not rq:<EOL><INDENT>return None<EOL><DEDENT>if isinstance(rq, dict) and '<STR_LIT>' in rq: <EOL><INDENT>yaml_string = rq['<STR_LIT>']<EOL>query_string = rq<EOL><DEDENT>else: <EOL><INDENT>yaml_string = "<STR_LIT:\n>".join([row.lstrip('<STR_LIT>') for row in rq.split('<STR_LIT:\n>') if row.startswith('<STR_LIT>... | Returns the yaml decorator metadata only (this is needed by triple pattern fragments) | f3384:m7 |
def get_metadata(rq, endpoint): | query_metadata = get_yaml_decorators(rq)<EOL>query_metadata['<STR_LIT:type>'] = '<STR_LIT>'<EOL>query_metadata['<STR_LIT>'] = rq<EOL>if isinstance(rq, dict): <EOL><INDENT>rq, proto, opt = SPARQLTransformer.pre_process(rq)<EOL>rq = rq.strip()<EOL>query_metadata['<STR_LIT>'] = proto<EOL>query_metadata['<STR_LIT>'] = opt... | Returns the metadata 'exp' parsed from the raw query file 'rq'
'exp' is one of: 'endpoint', 'tags', 'summary', 'request', 'pagination', 'enumerate' | f3384:m9 |
def turtleize(swag): | swag_graph = Graph()<EOL>return swag_graph.serialize(format='<STR_LIT>')<EOL> | Transforms a JSON swag object into a text/turtle LDA equivalent representation | f3386:m0 |
def getLoader(user, repo, sha=None, prov=None): | if user is None and repo is None:<EOL><INDENT>loader = LocalLoader()<EOL><DEDENT>else:<EOL><INDENT>loader = GithubLoader(user, repo, sha, prov)<EOL><DEDENT>return loader<EOL> | Build a fileLoader (LocalLoader or GithubLoader) for the given repository. | f3386:m1 |
def build_swagger_spec(user, repo, sha, serverName): | if user and repo:<EOL><INDENT>prov_g = grlcPROV(user, repo)<EOL><DEDENT>else:<EOL><INDENT>prov_g = None<EOL><DEDENT>swag = swagger.get_blank_spec()<EOL>swag['<STR_LIT:host>'] = serverName<EOL>try:<EOL><INDENT>loader = getLoader(user, repo, sha, prov_g)<EOL><DEDENT>except Exception as e:<EOL><INDENT>swag['<STR_LIT:info>... | Build grlc specification for the given github user / repo in swagger format | f3386:m3 |
def __init__(self, user, repo): | self.user = user<EOL>self.repo = repo<EOL>self.prov_g = Graph()<EOL>prov_uri = URIRef("<STR_LIT>")<EOL>self.prov = Namespace(prov_uri)<EOL>self.prov_g.bind('<STR_LIT>', self.prov)<EOL>self.agent = URIRef("<STR_LIT>".format(static.SERVER_NAME))<EOL>self.entity_d = URIRef("<STR_LIT>".format(static.SERVER_NAME, self.user,... | Default constructor | f3387:c0:m0 |
def init_prov_graph(self): | try:<EOL><INDENT>repo_prov = check_output(<EOL>['<STR_LIT>', '<STR_LIT>'.format(self.user, self.repo),<EOL>'<STR_LIT>']).decode("<STR_LIT:utf-8>")<EOL>repo_prov = repo_prov[repo_prov.find('<STR_LIT:@>'):]<EOL>glogger.debug('<STR_LIT>')<EOL>with open('<STR_LIT>', '<STR_LIT:w>') as temp_prov:<EOL><INDENT>temp_prov.write(... | Initialize PROV graph with all we know at the start of the recording | f3387:c0:m1 |
def add_used_entity(self, entity_uri): | entity_o = URIRef(entity_uri)<EOL>self.prov_g.add((entity_o, RDF.type, self.prov.Entity))<EOL>self.prov_g.add((self.activity, self.prov.used, entity_o))<EOL> | Add the provided URI as a used entity by the logged activity | f3387:c0:m2 |
def end_prov_graph(self): | endTime = Literal(datetime.now())<EOL>self.prov_g.add((self.entity_d, self.prov.generatedAtTime, endTime))<EOL>self.prov_g.add((self.activity, self.prov.endedAtTime, endTime))<EOL> | Finalize prov recording with end time | f3387:c0:m3 |
def log_prov_graph(self): | glogger.debug("<STR_LIT>")<EOL>glogger.debug(self.prov_g.serialize(format='<STR_LIT>'))<EOL> | Log provenance graph so far | f3387:c0:m4 |
def serialize(self, format): | if PY3:<EOL><INDENT>return self.prov_g.serialize(format=format).decode('<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>return self.prov_g.serialize(format=format)<EOL><DEDENT> | Serialize provenance graph in the specified format | f3387:c0:m5 |
def data_from_nesta(): | data = pd.read_csv(nesta_uk_url)<EOL>return data<EOL> | Read data from the GitHub repo. | f3391:m0 |
def get_labs(format): | ukmakerspaces_data = data_from_nesta()<EOL>ukmakerspaces = {}<EOL>for index, row in ukmakerspaces_data.iterrows():<EOL><INDENT>current_lab = UKMakerspace()<EOL>current_lab.address_1 = row["<STR_LIT>"].replace("<STR_LIT:\r>", "<STR_LIT:U+0020>")<EOL>current_lab.address_2 = row["<STR_LIT>"].replace("<STR_LIT:\r>", "<STR_... | Gets current UK Makerspaces data as listed by NESTA. | f3391:m1 |
def labs_count(): | ukmakerspaces = get_labs("<STR_LIT:object>")<EOL>return len(ukmakerspaces)<EOL> | Gets the number of current UK Makerspaces listed by NESTA. | f3391:m2 |
def data_from_repaircafe_org(): | <EOL>browser = webdriver.Chrome()<EOL>browser.get("<STR_LIT>")<EOL>browser.maximize_window()<EOL>viewmore_button = True<EOL>while viewmore_button:<EOL><INDENT>try:<EOL><INDENT>viewmore = browser.find_element_by_id("<STR_LIT>")<EOL>browser.execute_script("<STR_LIT>", viewmore)<EOL>viewmore.click()<EOL><DEDENT>except:<EO... | Gets data from repaircafe_org. | f3392:m0 |
def get_labs(format): | data = data_from_repaircafe_org()<EOL>repaircafes = {}<EOL>for i in data:<EOL><INDENT>current_lab = RepairCafe()<EOL>current_lab.name = i["<STR_LIT:name>"]<EOL>slug = i["<STR_LIT:url>"].replace("<STR_LIT>", "<STR_LIT>")<EOL>if slug.endswith("<STR_LIT:/>"):<EOL><INDENT>slug.replace("<STR_LIT:/>", "<STR_LIT>")<EOL><DEDEN... | Gets Repair Cafe data from repairecafe.org. | f3392:m1 |
def labs_count(): | repaircafes = data_from_repaircafe_org()<EOL>return len(repaircafes["<STR_LIT>"])<EOL> | Gets the number of current Repair Cafes registered on repaircafe.org. | f3392:m2 |
def get_lab_text(lab_slug, language): | if language == "<STR_LIT>" or language == "<STR_LIT>" or language == "<STR_LIT>" or language == "<STR_LIT>":<EOL><INDENT>language = "<STR_LIT>"<EOL><DEDENT>elif language == "<STR_LIT>" or language == "<STR_LIT>" or language == "<STR_LIT>" or language == "<STR_LIT>" or language == "<STR_LIT>":<EOL><INDENT>language = "<S... | Gets text description in English or Italian from a single lab from makeinitaly.foundation. | f3393:m0 |
def get_single_lab(lab_slug): | wiki = MediaWiki(makeinitaly__foundation_api_url)<EOL>wiki_response = wiki.call(<EOL>{'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT>': lab_slug,<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:content>'})<EOL>for i in wiki_response["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>content = wiki_response["<STR_LIT>"]["<... | Gets data from a single lab from makeinitaly.foundation. | f3393:m1 |
def get_labs(format): | labs = []<EOL>wiki = MediaWiki(makeinitaly__foundation_api_url)<EOL>wiki_response = wiki.call(<EOL>{'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT:list>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'})<EOL>if "<STR_LIT>" in wiki_response:<EOL><INDENT>nextpage = wiki_response[<EOL>"<STR_LIT>"]... | Gets data from all labs from makeinitaly.foundation. | f3393:m2 |
def labs_count(): | labs = get_labs(data_format="<STR_LIT>")<EOL>return len(labs)<EOL> | Gets the number of current Labs registered on makeinitaly.foundation. | f3393:m3 |
def data_from_fablabs_io(endpoint): | data = requests.get(endpoint).json()<EOL>return data<EOL> | Gets data from fablabs.io. | f3394:m0 |
def get_labs(format): | fablabs_json = data_from_fablabs_io(fablabs_io_labs_api_url_v0)<EOL>fablabs = {}<EOL>for i in fablabs_json["<STR_LIT>"]:<EOL><INDENT>current_lab = FabLab()<EOL>current_lab.name = i["<STR_LIT:name>"]<EOL>current_lab.address_1 = i["<STR_LIT>"]<EOL>current_lab.address_2 = i["<STR_LIT>"]<EOL>current_lab.address_notes = i["... | Gets Fab Lab data from fablabs.io. | f3394:m1 |
def labs_count(): | fablabs = data_from_fablabs_io(fablabs_io_labs_api_url_v0)<EOL>return len(fablabs["<STR_LIT>"])<EOL> | Gets the number of current Fab Labs registered on fablabs.io. | f3394:m2 |
def get_projects(format): | projects_json = data_from_fablabs_io(fablabs_io_projects_api_url_v0)<EOL>projects = {}<EOL>project_url = "<STR_LIT>"<EOL>fablabs = get_labs(format="<STR_LIT:object>")<EOL>for i in projects_json["<STR_LIT>"]:<EOL><INDENT>i = i["<STR_LIT>"]<EOL>current_project = Project()<EOL>current_project.id = i["<STR_LIT:id>"]<EOL>cu... | Gets projects data from fablabs.io. | f3394:m3 |
def projects_count(): | projects = data_from_fablabs_io(fablabs_io_projects_api_url_v0)<EOL>return len(projects["<STR_LIT>"])<EOL> | Gets the number of current projects submitted on fablabs.io. | f3394:m4 |
def get_multiple_data(): | <EOL>all_labs = {}<EOL>all_labs["<STR_LIT>"] = diybio_org.get_labs(format="<STR_LIT>")<EOL>all_labs["<STR_LIT>"] = fablabs_io.get_labs(format="<STR_LIT>")<EOL>all_labs["<STR_LIT>"] = makeinitaly_foundation.get_labs(<EOL>format="<STR_LIT>")<EOL>all_labs["<STR_LIT>"] = hackaday_io.get_labs(format="<STR_LIT>")<EOL>all_lab... | Get data from all the platforms listed in makerlabs. | f3395:m0 |
def get_timeline(source): | <EOL>timeline_format = ["<STR_LIT:name>", "<STR_LIT:type>", "<STR_LIT:source>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"]<EOL>timeline... | Rebuild a timeline of the history of makerlabs. | f3395:m1 |
def get_single_lab(lab_slug, open_cage_api_key): | wiki = MediaWiki(hackerspaces_org_api_url)<EOL>wiki_response = wiki.call(<EOL>{'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT>': lab_slug,<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:content>'})<EOL>for i in wiki_response["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>content = wiki_response["<STR_LIT>"]["<STR_LIT... | Gets data from a single lab from hackerspaces.org. | f3397:m0 |
def get_labs(format, open_cage_api_key): | labs = []<EOL>wiki = MediaWiki(hackerspaces_org_api_url)<EOL>wiki_response = wiki.call(<EOL>{'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT:list>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'})<EOL>nextpage = wiki_response["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>urls = []<EOL>for i in wik... | Gets data from all labs from hackerspaces.org. | f3397:m1 |
def labs_count(): | labs = get_labs()<EOL>return len(labs)<EOL> | Gets the number of current Hackerspaces registered on hackerspaces.org. | f3397:m2 |
def data_from_techshop_ws(tws_url): | r = requests.get(tws_url)<EOL>if r.status_code == <NUM_LIT:200>:<EOL><INDENT>data = BeautifulSoup(r.text, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>data = "<STR_LIT>"<EOL><DEDENT>return data<EOL> | Scrapes data from techshop.ws. | f3398:m0 |
def get_labs(format): | techshops_soup = data_from_techshop_ws(techshop_us_url)<EOL>techshops = {}<EOL>data = techshops_soup.findAll('<STR_LIT>', attrs={'<STR_LIT:id>': '<STR_LIT>'})<EOL>for element in data:<EOL><INDENT>links = element.findAll('<STR_LIT:a>')<EOL>hrefs = {}<EOL>for k, a in enumerate(links):<EOL><INDENT>if "<STR_LIT>" not in a[... | Gets Techshop data from techshop.ws. | f3398:m1 |
def labs_count(): | techshops = get_labs("<STR_LIT:object>")<EOL>return len(techshops)<EOL> | Gets the number of current Techshops listed on techshops.ws. | f3398:m2 |
def data_from_hackaday_io(endpoint): | data = requests.get(endpoint).json()<EOL>return data<EOL> | Gets data from hackaday.io. | f3399:m0 |
def get_labs(format): | hackerspaces_json = data_from_hackaday_io(hackaday_io_labs_map_url)<EOL>hackerspaces = {}<EOL>for i in hackerspaces_json:<EOL><INDENT>current_lab = Hackerspace()<EOL>current_lab.id = i["<STR_LIT:id>"]<EOL>current_lab.url = "<STR_LIT>" + current_lab.id<EOL>current_lab.name = i["<STR_LIT:name>"]<EOL>if len(i["<STR_LIT:de... | Gets Hackerspaces data from hackaday.io. | f3399:m1 |
def labs_count(): | hackerspaces = data_from_hackaday_io(hackaday_io_labs_api_url)<EOL>return len(hackerspaces["<STR_LIT>"])<EOL> | Gets the number of current Hackerspaces listed on hackaday.io. | f3399:m2 |
def data_from_makery_info(endpoint): | data = requests.get(endpoint).json()<EOL>return data<EOL> | Gets data from makery.info. | f3400:m0 |
def get_labs(format): | labs_json = data_from_makery_info(makery_info_labs_api_url)<EOL>labs = {}<EOL>for i in labs_json["<STR_LIT>"]:<EOL><INDENT>current_lab = MakeryLab()<EOL>current_lab.address_1 = i["<STR_LIT>"]<EOL>current_lab.address_2 = i["<STR_LIT>"]<EOL>current_lab.address_notes = i["<STR_LIT>"]<EOL>current_lab.avatar = i["<STR_LIT>"... | Gets Lab data from makery.info. | f3400:m1 |
def labs_count(): | labs = data_from_makery_info(makery_info_labs_api_url)<EOL>return len(labs["<STR_LIT>"])<EOL> | Gets the number of current Labs listed on makery.info. | f3400:m2 |
def get_location(query, format, api_key): | <EOL>sleep(<NUM_LIT:1>)<EOL>geolocator = OpenCage(api_key=api_key, timeout=<NUM_LIT:10>)<EOL>data = {"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:state>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_... | Get geographic data of a lab in a coherent way for all labs. | f3401:m0 |
def data_from_diybio_org(): | r = requests.get(diy_bio_labs_url)<EOL>if r.status_code == <NUM_LIT:200>:<EOL><INDENT>data = BeautifulSoup(r.text.replace(u'<STR_LIT>', u'<STR_LIT>'), "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>data = "<STR_LIT>"<EOL><DEDENT>return data<EOL> | Scrapes data from diybio.org. | f3402:m0 |
def get_labs(format, open_cage_api_key): | diybiolabs_soup = data_from_diybio_org()<EOL>diybiolabs = {}<EOL>rows_list = []<EOL>continents_dict = {}<EOL>continents_order = <NUM_LIT:0><EOL>ranges_starting_points = []<EOL>for row in diybiolabs_soup.select("<STR_LIT>"):<EOL><INDENT>cells = row.find_all('<STR_LIT>')<EOL>rows_list.append(cells)<EOL><DEDENT>for k, row... | Gets DIYBio Lab data from diybio.org. | f3402:m1 |
def labs_count(): | diybiolabs = get_labs("<STR_LIT:object>")<EOL>return len(diybiolabs)<EOL> | Gets the number of current DIYBio Labs listed on diybio.org. | f3402:m2 |
def __send_notification(self, message, title, title_link='<STR_LIT>', color='<STR_LIT>',<EOL>fields='<STR_LIT>', log_level=LogLv.INFO): | if log_level < self.log_level:<EOL><INDENT>return None<EOL><DEDENT>payload = self.__build_payload(message, title, title_link, color, fields)<EOL>try:<EOL><INDENT>response = self.__post(payload)<EOL><DEDENT>except Exception:<EOL><INDENT>raise Exception(traceback.format_exc())<EOL><DEDENT>return response<EOL> | Send a message to a channel.
Args:
title: Message title.
title_link: Link of the message title.
message: Message body.
color: Message line color on Slack. This parameter should be one of the following values: 'good', 'warning',
'danger' or any hex col... | f3408:c1:m4 |
def load_data(flist, drop_duplicates=False): | if (len(flist['<STR_LIT:train>'])==<NUM_LIT:0>) or (len(flist['<STR_LIT:target>'])==<NUM_LIT:0>) or (len(flist['<STR_LIT:test>'])==<NUM_LIT:0>):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>X_train = pd.DataFrame()<EOL>test = pd.DataFrame()<EOL>print('<STR_LIT>')<EOL>for i in flist['<STR_LIT:train>']:<EOL><INDE... | Usage: set train, target, and test key and feature files.
FEATURE_LIST_stage2 = {
'train':(
TEMP_PATH + 'v1_stage1_all_fold.csv',
TEMP_PATH + 'v2_stage1_all_fold.csv',
TEMP_PATH + 'v3_stage1_all_fold.csv',
),#target is not i... | f3410:m1 |
def __init__(self, name="<STR_LIT>", flist={}, params={}, kind='<STR_LIT:s>', fold_name=cv_id_name): | if BaseModel.problem_type == '<STR_LIT>':<EOL><INDENT>if not ((BaseModel.classification_type in classification_type_list)<EOL>and (BaseModel.eval_type in eval_type_list)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif BaseModel.problem_type == '<STR_LIT>':<EOL><INDENT>if not BaseModel.eval_type in ... | name: Model name
flist: Feature list
params: Parameters
kind: Kind of run()
{'s': Stacking only. Svaing a oof prediction({}_all_fold.csv)
and average of test prediction based on fold-train models({}_test.csv).
't': Training all data and predict test({}_TestInAllTrainingData.csv).
'st': Stacking and then traini... | f3410:c0:m0 |
@classmethod<EOL><INDENT>def set_prob_type(cls, problem_type, classification_type, eval_type):<DEDENT> | assert problem_type in problem_type_list, '<STR_LIT>'<EOL>if problem_type == '<STR_LIT>':<EOL><INDENT>assert classification_type in classification_type_list,'<STR_LIT>'<EOL><DEDENT>assert eval_type in eval_type_list, '<STR_LIT>'<EOL>cls.problem_type = problem_type<EOL>cls.classification_type = classification_type<EOL>c... | Set problem type | f3410:c0:m1 |
def make_multi_cols(self, num_class, name): | cols = ['<STR_LIT:c>' + str(i) + '<STR_LIT:_>' for i in range(num_class)]<EOL>cols = [x + name for x in cols]<EOL>return cols<EOL> | make cols for multi-class predictions | f3410:c0:m3 |
def load_data(self): | return load_data(self.flist, drop_duplicates=False )<EOL> | flistにシリアライゼーションを渡すことでより効率的に
data構造をここで考慮 | f3410:c0:m5 |
def datagram_received(self, data, addr): | channel = self.peer_to_channel.get(addr)<EOL>if channel:<EOL><INDENT>self.client_protocol._send(struct.pack('<STR_LIT>', channel, len(data)) + data,<EOL>self.client_address)<EOL><DEDENT> | Relay data from peer to client. | f3435:c0:m2 |
def error_response(self, request, code, message): | response = stun.Message(<EOL>message_method=request.message_method,<EOL>message_class=stun.Class.ERROR,<EOL>transaction_id=request.transaction_id)<EOL>response.attributes['<STR_LIT>'] = (code, message)<EOL>return response<EOL> | Build an error response for the given request. | f3435:c1:m7 |
def candidate_foundation(candidate_type, candidate_transport, base_address): | key = '<STR_LIT>' % (candidate_type, candidate_transport, base_address)<EOL>return hashlib.md5(key.encode('<STR_LIT:ascii>')).hexdigest()<EOL> | See RFC 5245 - 4.1.1.3. Computing Foundations | f3439:m0 |
def candidate_priority(candidate_component, candidate_type, local_pref=<NUM_LIT>): | if candidate_type == '<STR_LIT:host>':<EOL><INDENT>type_pref = <NUM_LIT><EOL><DEDENT>elif candidate_type == '<STR_LIT>':<EOL><INDENT>type_pref = <NUM_LIT><EOL><DEDENT>elif candidate_type == '<STR_LIT>':<EOL><INDENT>type_pref = <NUM_LIT:100><EOL><DEDENT>else:<EOL><INDENT>type_pref = <NUM_LIT:0><EOL><DEDENT>return (<NUM_... | See RFC 5245 - 4.1.2.1. Recommended Formula | f3439:m1 |
@classmethod<EOL><INDENT>def from_sdp(cls, sdp):<DEDENT> | bits = sdp.split()<EOL>if len(bits) < <NUM_LIT:8>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>kwargs = {<EOL>'<STR_LIT>': bits[<NUM_LIT:0>],<EOL>'<STR_LIT>': int(bits[<NUM_LIT:1>]),<EOL>'<STR_LIT>': bits[<NUM_LIT:2>],<EOL>'<STR_LIT>': int(bits[<NUM_LIT:3>]),<EOL>'<STR_LIT:host>': bits[<NUM_LIT:4>],<EOL>'<STR... | Parse a :class:`Candidate` from SDP.
.. code-block:: python
Candidate.from_sdp(
'6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0') | f3439:c0:m1 |
def to_sdp(self): | sdp = '<STR_LIT>' % (<EOL>self.foundation,<EOL>self.component,<EOL>self.transport,<EOL>self.priority,<EOL>self.host,<EOL>self.port,<EOL>self.type)<EOL>if self.related_address is not None:<EOL><INDENT>sdp += '<STR_LIT>' % self.related_address<EOL><DEDENT>if self.related_port is not None:<EOL><INDENT>sdp += '<STR_LIT>' %... | Return a string representation suitable for SDP. | f3439:c0:m2 |
def can_pair_with(self, other): | a = ipaddress.ip_address(self.host)<EOL>b = ipaddress.ip_address(other.host)<EOL>return (<EOL>self.component == other.component and<EOL>self.transport.lower() == other.transport.lower() and<EOL>a.version == b.version<EOL>)<EOL> | A local candidate is paired with a remote candidate if and only if
the two candidates have the same component ID and have the same IP
address version. | f3439:c0:m3 |
async def create_turn_endpoint(protocol_factory, server_addr, username, password,<EOL>lifetime=<NUM_LIT>, ssl=False, transport='<STR_LIT>'): | loop = asyncio.get_event_loop()<EOL>if transport == '<STR_LIT>':<EOL><INDENT>_, inner_protocol = await loop.create_connection(<EOL>lambda: TurnClientTcpProtocol(server_addr,<EOL>username=username,<EOL>password=password,<EOL>lifetime=lifetime),<EOL>host=server_addr[<NUM_LIT:0>],<EOL>port=server_addr[<NUM_LIT:1>],<EOL>ss... | Create datagram connection relayed over TURN. | f3441:m2 |
async def connect(self): | request = stun.Message(message_method=stun.Method.ALLOCATE,<EOL>message_class=stun.Class.REQUEST)<EOL>request.attributes['<STR_LIT>'] = self.lifetime<EOL>request.attributes['<STR_LIT>'] = UDP_TRANSPORT<EOL>try:<EOL><INDENT>response, _ = await self.request(request)<EOL><DEDENT>except exceptions.TransactionFailed as e:<E... | Create a TURN allocation. | f3441:c1:m2 |
async def delete(self): | if self.refresh_handle:<EOL><INDENT>self.refresh_handle.cancel()<EOL>self.refresh_handle = None<EOL><DEDENT>request = stun.Message(message_method=stun.Method.REFRESH,<EOL>message_class=stun.Class.REQUEST)<EOL>request.attributes['<STR_LIT>'] = <NUM_LIT:0><EOL>await self.request(request)<EOL>logger.info('<STR_LIT>', self... | Delete the TURN allocation. | f3441:c1:m5 |
async def refresh(self): | while True:<EOL><INDENT>await asyncio.sleep(<NUM_LIT:5>/<NUM_LIT:6> * self.lifetime)<EOL>request = stun.Message(message_method=stun.Method.REFRESH,<EOL>message_class=stun.Class.REQUEST)<EOL>request.attributes['<STR_LIT>'] = self.lifetime<EOL>await self.request(request)<EOL>logger.info('<STR_LIT>', self.relayed_address)... | Periodically refresh the TURN allocation. | f3441:c1:m6 |
async def request(self, request): | assert request.transaction_id not in self.transactions<EOL>if self.integrity_key:<EOL><INDENT>self.__add_authentication(request)<EOL><DEDENT>transaction = stun.Transaction(request, self.server, self)<EOL>self.transactions[request.transaction_id] = transaction<EOL>try:<EOL><INDENT>return await transaction.run()<EOL><DED... | Execute a STUN transaction and return the response. | f3441:c1:m7 |
async def send_data(self, data, addr): | channel = self.peer_to_channel.get(addr)<EOL>if channel is None:<EOL><INDENT>channel = self.channel_number<EOL>self.channel_number += <NUM_LIT:1><EOL>self.channel_to_peer[channel] = addr<EOL>self.peer_to_channel[addr] = channel<EOL>await self.channel_bind(channel, addr)<EOL><DEDENT>header = struct.pack('<STR_LIT>', cha... | Send data to a remote host via the TURN server. | f3441:c1:m8 |
def send_stun(self, message, addr): | logger.debug('<STR_LIT>', self, addr, message)<EOL>self._send(bytes(message))<EOL> | Send a STUN message to the TURN server. | f3441:c1:m9 |
def close(self): | asyncio.ensure_future(self.__inner_protocol.delete())<EOL> | Close the transport.
After the TURN allocation has been deleted, the protocol's
`connection_lost()` method will be called with None as its argument. | f3441:c4:m1 |
def get_extra_info(self, name, default=None): | if name == '<STR_LIT>':<EOL><INDENT>return self.__inner_protocol.transport.get_extra_info('<STR_LIT>')<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>return self.__relayed_address<EOL><DEDENT>return default<EOL> | Return optional transport information.
- `'related_address'`: the related address
- `'sockname'`: the relayed address | f3441:c4:m2 |
def sendto(self, data, addr): | asyncio.ensure_future(self.__inner_protocol.send_data(data, addr))<EOL> | Sends the `data` bytes to the remote peer given `addr`.
This will bind a TURN channel as necessary. | f3441:c4:m3 |
def candidate_pair_priority(local, remote, ice_controlling): | G = ice_controlling and local.priority or remote.priority<EOL>D = ice_controlling and remote.priority or local.priority<EOL>return (<NUM_LIT:1> << <NUM_LIT:32>) * min(G, D) + <NUM_LIT:2> * max(G, D) + (G > D and <NUM_LIT:1> or <NUM_LIT:0>)<EOL> | See RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs | f3444:m0 |
def get_host_addresses(use_ipv4, use_ipv6): | addresses = []<EOL>for interface in netifaces.interfaces():<EOL><INDENT>ifaddresses = netifaces.ifaddresses(interface)<EOL>for address in ifaddresses.get(socket.AF_INET, []):<EOL><INDENT>if use_ipv4 and address['<STR_LIT>'] != '<STR_LIT:127.0.0.1>':<EOL><INDENT>addresses.append(address['<STR_LIT>'])<EOL><DEDENT><DEDENT... | Get local IP addresses. | f3444:m1 |
async def server_reflexive_candidate(protocol, stun_server): | <EOL>loop = asyncio.get_event_loop()<EOL>stun_server = (<EOL>await loop.run_in_executor(None, socket.gethostbyname, stun_server[<NUM_LIT:0>]),<EOL>stun_server[<NUM_LIT:1>])<EOL>request = stun.Message(message_method=stun.Method.BINDING,<EOL>message_class=stun.Class.REQUEST)<EOL>response, _ = await protocol.request(reque... | Query STUN server to obtain a server-reflexive candidate. | f3444:m2 |
def sort_candidate_pairs(pairs, ice_controlling): | def pair_priority(pair):<EOL><INDENT>return -candidate_pair_priority(pair.local_candidate,<EOL>pair.remote_candidate,<EOL>ice_controlling)<EOL><DEDENT>pairs.sort(key=pair_priority)<EOL> | Sort a list of candidate pairs. | f3444:m3 |
async def request(self, request, addr, integrity_key=None, retransmissions=None): | assert request.transaction_id not in self.transactions<EOL>if integrity_key is not None:<EOL><INDENT>request.add_message_integrity(integrity_key)<EOL>request.add_fingerprint()<EOL><DEDENT>transaction = stun.Transaction(request, addr, self, retransmissions=retransmissions)<EOL>transaction.integrity_key = integrity_key<E... | Execute a STUN transaction and return the response. | f3444:c1:m6 |
def send_stun(self, message, addr): | self.__log_debug('<STR_LIT>', addr, message)<EOL>self.transport.sendto(bytes(message), addr)<EOL> | Send a STUN message. | f3444:c1:m8 |
@property<EOL><INDENT>def local_candidates(self):<DEDENT> | return self._local_candidates[:]<EOL> | Local candidates, automatically set by :meth:`gather_candidates`. | f3444:c2:m1 |
@property<EOL><INDENT>def remote_candidates(self):<DEDENT> | return self._remote_candidates[:]<EOL> | Remote candidates, which you need to set.
Assigning this attribute will automatically signal end-of-candidates.
If you will be adding more remote candidates in the future, use the
:meth:`add_remote_candidate` method instead. | f3444:c2:m2 |
def add_remote_candidate(self, remote_candidate): | if self._remote_candidates_end:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if remote_candidate is None:<EOL><INDENT>self._prune_components()<EOL>self._remote_candidates_end = True<EOL>return<EOL><DEDENT>self._remote_candidates.append(remote_candidate)<EOL>for protocol in self._protocols:<EOL><INDENT>if (prot... | Add a remote candidate or signal end-of-candidates.
To signal end-of-candidates, pass `None`. | f3444:c2:m4 |
async def gather_candidates(self): | if not self._local_candidates_start:<EOL><INDENT>self._local_candidates_start = True<EOL>addresses = get_host_addresses(use_ipv4=self._use_ipv4, use_ipv6=self._use_ipv6)<EOL>for component in self._components:<EOL><INDENT>self._local_candidates += await self.get_component_candidates(<EOL>component=component,<EOL>address... | Gather local candidates.
You **must** call this coroutine before calling :meth:`connect`. | f3444:c2:m5 |
def get_default_candidate(self, component): | for candidate in sorted(self._local_candidates, key=lambda x: x.priority):<EOL><INDENT>if candidate.component == component:<EOL><INDENT>return candidate<EOL><DEDENT><DEDENT> | Gets the default local candidate for the specified component. | f3444:c2:m6 |
async def connect(self): | if not self._local_candidates_end:<EOL><INDENT>raise ConnectionError('<STR_LIT>')<EOL><DEDENT>if (self.remote_username is None or<EOL>self.remote_password is None):<EOL><INDENT>raise ConnectionError('<STR_LIT>')<EOL><DEDENT>for remote_candidate in self._remote_candidates:<EOL><INDENT>for protocol in self._protocols:<EO... | Perform ICE handshake.
This coroutine returns if a candidate pair was successfuly nominated
and raises an exception otherwise. | f3444:c2:m7 |
async def close(self): | <EOL>if self._query_consent_handle and not self._query_consent_handle.done():<EOL><INDENT>self._query_consent_handle.cancel()<EOL>try:<EOL><INDENT>await self._query_consent_handle<EOL><DEDENT>except asyncio.CancelledError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if self._check_list and not self._check_list_done:<EOL><INDE... | Close the connection. | f3444:c2:m8 |
async def recv(self): | data, component = await self.recvfrom()<EOL>return data<EOL> | Receive the next datagram.
The return value is a `bytes` object representing the data received.
If the connection is not established, a `ConnectionError` is raised. | f3444:c2:m9 |
async def recvfrom(self): | if not len(self._nominated):<EOL><INDENT>raise ConnectionError('<STR_LIT>')<EOL><DEDENT>result = await self._queue.get()<EOL>if result[<NUM_LIT:0>] is None:<EOL><INDENT>raise ConnectionError('<STR_LIT>')<EOL><DEDENT>return result<EOL> | Receive the next datagram.
The return value is a `(bytes, component)` tuple where `bytes` is a
bytes object representing the data received and `component` is the
component on which the data was received.
If the connection is not established, a `ConnectionError` is raised. | f3444:c2:m10 |
async def send(self, data): | await self.sendto(data, <NUM_LIT:1>)<EOL> | Send a datagram on the first component.
If the connection is not established, a `ConnectionError` is raised. | f3444:c2:m11 |
async def sendto(self, data, component): | active_pair = self._nominated.get(component)<EOL>if active_pair:<EOL><INDENT>await active_pair.protocol.send_data(data, active_pair.remote_addr)<EOL><DEDENT>else:<EOL><INDENT>raise ConnectionError('<STR_LIT>')<EOL><DEDENT> | Send a datagram on the specified component.
If the connection is not established, a `ConnectionError` is raised. | f3444:c2:m12 |
def set_selected_pair(self, component, local_foundation, remote_foundation): | <EOL>protocol = None<EOL>for p in self._protocols:<EOL><INDENT>if (p.local_candidate.component == component and<EOL>p.local_candidate.foundation == local_foundation):<EOL><INDENT>protocol = p<EOL>break<EOL><DEDENT><DEDENT>remote_candidate = None<EOL>for c in self._remote_candidates:<EOL><INDENT>if c.component == compon... | Force the selected candidate pair.
If the remote party does not support ICE, you should using this
instead of calling :meth:`connect`. | f3444:c2:m13 |
def check_incoming(self, message, addr, protocol): | component = protocol.local_candidate.component<EOL>remote_candidate = None<EOL>for c in self._remote_candidates:<EOL><INDENT>if c.host == addr[<NUM_LIT:0>] and c.port == addr[<NUM_LIT:1>]:<EOL><INDENT>remote_candidate = c<EOL>assert remote_candidate.component == component<EOL>break<EOL><DEDENT><DEDENT>if remote_candida... | Handle a succesful incoming check. | f3444:c2:m16 |
async def check_start(self, pair): | self.check_state(pair, CandidatePair.State.IN_PROGRESS)<EOL>request = self.build_request(pair)<EOL>try:<EOL><INDENT>response, addr = await pair.protocol.request(<EOL>request, pair.remote_addr,<EOL>integrity_key=self.remote_password.encode('<STR_LIT:utf8>'))<EOL><DEDENT>except exceptions.TransactionError as exc:<EOL><IN... | Starts a check. | f3444:c2:m18 |
def check_state(self, pair, state): | self.__log_info('<STR_LIT>', pair, pair.state, state)<EOL>pair.state = state<EOL> | Updates the state of a check. | f3444:c2:m19 |
def _find_pair(self, protocol, remote_candidate): | for pair in self._check_list:<EOL><INDENT>if (pair.protocol == protocol and pair.remote_candidate == remote_candidate):<EOL><INDENT>return pair<EOL><DEDENT><DEDENT>return None<EOL> | Find a candidate pair in the check list. | f3444:c2:m20 |
def _prune_components(self): | seen_components = set(map(lambda x: x.component, self._remote_candidates))<EOL>missing_components = self._components - seen_components<EOL>if missing_components:<EOL><INDENT>self.__log_info('<STR_LIT>' % missing_components)<EOL>self._components = seen_components<EOL><DEDENT> | Remove components for which the remote party did not provide any candidates.
This can only be determined after end-of-candidates. | f3444:c2:m22 |
async def query_consent(self): | failures = <NUM_LIT:0><EOL>while True:<EOL><INDENT>await asyncio.sleep(CONSENT_INTERVAL * (<NUM_LIT> + <NUM_LIT> * random.random()))<EOL>for pair in self._nominated.values():<EOL><INDENT>request = self.build_request(pair)<EOL>try:<EOL><INDENT>await pair.protocol.request(<EOL>request, pair.remote_addr,<EOL>integrity_key... | Periodically check consent (RFC 7675). | f3444:c2:m23 |
def parse_message(data, integrity_key=None): | if len(data) < HEADER_LENGTH:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>message_type, length, cookie, transaction_id = unpack('<STR_LIT>', data[<NUM_LIT:0>:HEADER_LENGTH])<EOL>if len(data) != HEADER_LENGTH + length:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>attributes = OrderedDict()<EOL>pos = H... | Parses a STUN message.
If the ``integrity_key`` parameter is given, the message's HMAC will be verified. | f3445:m22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.