text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _upload_media(self,directory,files=None,resize_request=None, \ movealbum_request=None,changetitle_request=None): """Uploads media file to FB, returns True if...
# Connect if we aren't already if not self._connectToFB(): logger.error("%s - Couldn't connect to fb") return False _megapixels=self._load_megapixels(directory) # Get an album ID (create album if not exists) _album_id,_album_name=self._get_album(directo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _title_uptodate(self,fullfile,pid,_title): """Check fb photo title against provided title, returns true if they match"""
i=self.fb.get_object(pid) if i.has_key('name'): if _title == i['name']: return True return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _already_in_album(self,fullfile,pid,album_id): """Check to see if photo with given pid is already in the album_id, returns true if this is the case """
logger.debug("fb: Checking if pid %s in album %s",pid,album_id) pid_in_album=[] # Get all photos in album photos = self.fb.get_connections(str(album_id),"photos")['data'] # Get all pids in fb album for photo in photos: pid_in_album.append(photo['id']) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def PrintSets(self): """Prints set name and number of photos in set"""
sets=self._getphotosets() for setname in sets: print("%s [%d]"%(setname,sets[setname]['number_photos']))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def chdir(__path: str) -> ContextManager: """Context handler to temporarily switch directories. Args: __path: Directory to change to Yields: Execution context in ...
old = os.getcwd() try: os.chdir(__path) yield finally: os.chdir(old)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def env(**kwargs: Union[Dict[str, str], None]) -> ContextManager: """Context handler to temporarily alter environment. If you supply a value of ``None``, then the...
old = os.environ.copy() try: os.environ.clear() # This apparent duplication is because ``putenv`` doesn’t update # ``os.environ``, and ``os.environ`` changes aren’t propagated to # subprocesses. for key, value in old.items(): os.environ[key] = value # NOQA: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def distance_to(self, address, measure="Miles", httpclient=None): """Distance to another address """
if isinstance(address, Address) and self.latlng and address.latlng: lat1, lon1 = map(float, self.latlng) lat2, lon2 = map(float, address.latlng) elif self.latlng and type(address) is tuple: lat1, lon1 = map(float, self.latlng) lat2, lon2 = address ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def json_dump_hook(cfg, text: bool=False): """ Dumps all the data into a JSON file. """
data = cfg.config.dump() if not text: json.dump(data, cfg.fd) else: return json.dumps(data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load(self, env=None): """ Load a section values of given environment. If nothing to specified, use environmental variable. If unknown environment was specifi...
self._load() e = env or \ os.environ.get(RUNNING_MODE_ENVKEY, DEFAULT_RUNNING_MODE) if e in self.config: return self.config[e] logging.warn("Environment '%s' was not found.", e)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def main(show_details:['-l']=False, cols:['-w', '--width']='', *files): ''' List information about a particular file or set of files :param show_details: Whether to show detailed info about files :param cols: specify screen width ''' print(files) print(show_details) print(cols)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def random_date(): '''Return a valid random date.''' d = datetime.datetime.now().date() d = d - datetime.timedelta(random.randint(20,2001)) return d
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def random_md_page(): '''Generate random markdown page content.. If the parameters are zero, instead of a fixed number of elements it uses a random number. ''' # headers #, ## # blockquote > # lists * # codeblock (indent 4 spaces) # hrule, 3 or more - in a line # emphasis: wor...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def all(self, **args): """ Return all Lists. """
limit = args['limit'] if 'limit' in args else 20 offset = args['offset'] if 'offset' in args else 0 r = requests.get( "https://kippt.com/api/lists?limit=%s&offset=%s" % (limit, offset), headers=self.kippt.header ) return (r.json())
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, title, **args): """ Create a new Kippt List. Parameters: - title (Required) - args Dictionary of other fields Accepted fields can be found here:...
# Merge our title as a parameter and JSONify it. data = json.dumps(dict({'title': title}, **args)) r = requests.post( "https://kippt.com/api/lists", headers=self.kippt.header, data=data ) return (r.json())
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cli(config_path, verbose): """Record-Recommender command line version."""
global config, store if not config_path: config_path = '/etc/record_recommender.yml' config = get_config(config_path) setup_logging(config) store = FileStore(config)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def fetch(weeks, force): """Fetch newest PageViews and Downloads."""
weeks = get_last_weeks(weeks) print(weeks) recommender = RecordRecommender(config) recommender.fetch_weeks(weeks, overwrite=force)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_recommender(ctx, weeks, processes): """ Download and build the recommendations. - Fetch new statistics from the current week. - Generate recommendatio...
weeks = get_last_weeks(weeks) recommender = RecordRecommender(config) # Redownload incomplete weeks first_weeks = weeks[:2] recommender.fetch_weeks(first_weeks, overwrite=True) # Download missing weeks recommender.fetch_weeks(weeks, overwrite=False) print("Build Profiles") ctx.invo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def profiles(weeks): """ Number of weeks to build. Starting with the current week. """
profiles = Profiles(store) weeks = get_last_weeks(weeks) if isinstance(weeks, int) else weeks print(weeks) profiles.create(weeks)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build(processes): """ Calculate all recommendations using the number of specified processes. The recommendations are calculated from the generated Profiles f...
recommender = RecordRecommender(config) recommender.create_all_recommendations(processes, ip_views=True)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _bind(self, _descriptor): """ Bind a ResponseObject to a given action descriptor. This updates the default HTTP response code and selects the appropriate con...
# If the method has a default code, use it self._defcode = getattr(_descriptor.method, '_wsgi_code', 200) # Set up content type and serializer self.content_type, self.serializer = _descriptor.serializer(self.req)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _serialize(self): """ Serialize the ResponseObject. Returns a webob `Response` object. """
# Do something appropriate if the response object is unbound if self._defcode is None: raise exceptions.UnboundResponse() # Build the response resp = self.response_class(request=self.req, status=self.code, headerlist=self._headers.items()...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def code(self): """ The HTTP response code associated with this ResponseObject. If instantiated directly without overriding the code, returns 200 even if the def...
if self._code is not None: return self._code elif self._defcode is not None: return self._defcode return 200
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def report_message(report): """Report message."""
body = 'Error: return code != 0\n\n' body += 'Archive: {}\n\n'.format(report['archive']) body += 'Docker image: {}\n\n'.format(report['image']) body += 'Docker container: {}\n\n'.format(report['container_id']) return body
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def task_failure_message(task_report): """Task failure message."""
trace_list = traceback.format_tb(task_report['traceback']) body = 'Error: task failure\n\n' body += 'Task ID: {}\n\n'.format(task_report['task_id']) body += 'Archive: {}\n\n'.format(task_report['archive']) body += 'Docker image: {}\n\n'.format(task_report['image']) body += 'Exception: {}\n\n'.f...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def send_email(self, message): """Initiate a SMTP session and send an email."""
msg = MIMEMultipart() msg['From'] = self.from_address msg['To'] = self.to_address msg['Subject'] = self.title msg.attach(MIMEText('<pre>' + cgi.escape(message) + '</pre>', 'html')) smtp = smtplib.SMTP(self.server, self.port, timeout=self.timeo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def jpath_parse(jpath): """ Parse given JPath into chunks. Returns list of dictionaries describing all of the JPath chunks. :param str jpath: JPath to be parsed ...
result = [] breadcrumbs = [] # Split JPath into chunks based on '.' character. chunks = jpath.split('.') for chnk in chunks: match = RE_JPATH_CHUNK.match(chnk) if match: res = {} # Record whole match. res['m'] = chnk # Record breadc...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def jpath_values(structure, jpath): """ Return all values at given JPath within given data structure. For performance reasons this method is intentionally not wr...
# Current working node set. nodes_a = [structure] # Next iteration working node set. nodes_b = [] # Process sequentially all JPath chunks. chunks = jpath_parse_c(jpath) for chnk in chunks: # Process all currently active nodes. for node in nodes_a: key = chnk['n...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def jpath_exists(structure, jpath): """ Check if node at given JPath within given data structure does exist. :param str structure: data structure to be searched ...
result = jpath_value(structure, jpath) if not result is None: return True return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def jpath_set(structure, jpath, value, overwrite = True, unique = False): """ Set given JPath to given value within given structure. For performance reasons this...
chunks = jpath_parse_c(jpath) size = len(chunks) - 1 current = structure # Process chunks in order, enumeration is used for detection of the last JPath chunk. for i, chnk in enumerate(chunks): key = chnk['n'] if not isinstance(current, dict) and not isinstance(current, collections...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def queue_ramp_dicts(ramp_dict_list, server_ip_and_port): """Simple utility function to queue up a list of dictionaries."""
client = server.ClientForServer(server.BECServer, server_ip_and_port) for dct in ramp_dict_list: client.queue_ramp(dct) client.start({})
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def flatten_dict(dct, separator='-->', allowed_types=[int, float, bool]): """Returns a list of string identifiers for each element in dct. Recursively scans thro...
flat_list = [] for key in sorted(dct): if key[:2] == '__': continue key_type = type(dct[key]) if key_type in allowed_types: flat_list.append(str(key)) elif key_type is dict: sub_list = flatten_dict(dct[key]) sub_list = [str(key) + ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_dict_item(dct, name_string, set_to): """Sets dictionary item identified by name_string to set_to. name_string is the indentifier generated using flatten_...
key_strings = str(name_string).split('-->') d = dct for ks in key_strings[:-1]: d = d[ks] item_type = type(d[key_strings[-1]]) d[key_strings[-1]] = item_type(set_to)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_name(obj, setting_name='LONG_NAME_FORMAT'): """ Returns the correct order of the name according to the current language. """
nickname = obj.get_nickname() romanized_first_name = obj.get_romanized_first_name() romanized_last_name = obj.get_romanized_last_name() non_romanized_first_name = obj.get_non_romanized_first_name() non_romanized_last_name = obj.get_non_romanized_last_name() non_translated_title = obj.get_title(...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def timethis(func): """A wrapper use for timeit."""
func_module, func_name = func.__module__, func.__name__ @functools.wraps(func) def wrapper(*args, **kwargs): start = _time_perf_counter() r = func(*args, **kwargs) end = _time_perf_counter() print('timethis : <{}.{}> : {}'.format(func_module, func_name, end - start)) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_info(name, info_type, url=None, parent=None, id=None, context=ctx_default, store=False): """Return a group object"""
id = str(uuid4()) if id is None else id pubsub = _pubsub_key(id) info = {'id': id, 'type': info_type, 'pubsub': pubsub, 'url': url, 'parent': parent, 'context': context, 'name': name, 'status': 'Queued' if info_type == 'jo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_id_from_user(user): """Get an ID from a user, creates if necessary"""
id = r_client.hget('user-id-map', user) if id is None: id = str(uuid4()) r_client.hset('user-id-map', user, id) r_client.hset('user-id-map', id, user) return id
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def traverse(self, id_=None): """Traverse groups and yield info dicts for jobs"""
if id_ is None: id_ = self.group nodes = r_client.smembers(_children_key(id_)) while nodes: current_id = nodes.pop() details = r_client.get(current_id) if details is None: # child has expired or been deleted, remove from :childre...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def close(self): """Unsubscribe the group and all jobs being listened too"""
for channel in self._listening_to: self.toredis.unsubscribe(channel) self.toredis.unsubscribe(self.group_pubsub)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def listen_for_updates(self): """Attach a callback on the group pubsub"""
self.toredis.subscribe(self.group_pubsub, callback=self.callback)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def listen_to_node(self, id_): """Attach a callback on the job pubsub if it exists"""
if r_client.get(id_) is None: return else: self.toredis.subscribe(_pubsub_key(id_), callback=self.callback) self._listening_to[_pubsub_key(id_)] = id_ return id_
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def unlisten_to_node(self, id_): """Stop listening to a job Parameters id_ : str An ID to remove Returns -------- str or None The ID removed or None if the ID wa...
id_pubsub = _pubsub_key(id_) if id_pubsub in self._listening_to: del self._listening_to[id_pubsub] self.toredis.unsubscribe(id_pubsub) parent = json_decode(r_client.get(id_)).get('parent', None) if parent is not None: r_client.srem(_chil...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def action(self, verb, args): """Process the described action Parameters verb : str, {'add', 'remove', 'get'} The specific action to perform args : {list, set, t...
if not isinstance(args, (list, set, tuple)): raise TypeError("args is unknown type: %s" % type(args)) if verb == 'add': response = ({'add': i} for i in self._action_add(args)) elif verb == 'remove': response = ({'remove': i} for i in self._action_remove(args...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _action_add(self, ids): """Add IDs to the group Parameters ids : {list, set, tuple, generator} of str The IDs to add Returns ------- list of dict The details...
return self._action_get((self.listen_to_node(id_) for id_ in ids))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _action_remove(self, ids): """Remove IDs from the group Parameters ids : {list, set, tuple, generator} of str The IDs to remove Returns ------- list of dict ...
return self._action_get((self.unlisten_to_node(id_) for id_ in ids))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _action_get(self, ids): """Get the details for ids Parameters ids : {list, set, tuple, generator} of str The IDs to get Notes ----- If ids is empty, then all...
if not ids: ids = self.jobs result = [] ids = set(ids) while ids: id_ = ids.pop() if id_ is None: continue try: payload = r_client.get(id_) except ResponseError: # wrong key ty...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def main(): """Main method that runs the build"""
data = Common.open_file(F_INFO) config = Common.open_file(F_CONFIG) file_full_path = "" env = load_jinja2_env(config['p_template']) for index, page in data.iteritems(): logging.info('Creating ' + index + ' page:') template = env.get_template(page['f_template'] + \ con...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure(self, *, hwm: int=None, rcvtimeo: int=None, sndtimeo: int=None, linger: int=None) -> 'Socket': """ Allows to configure some common socket options an...
if hwm is not None: self.set_hwm(hwm) if rcvtimeo is not None: self.setsockopt(zmq.RCVTIMEO, rcvtimeo) if sndtimeo is not None: self.setsockopt(zmq.SNDTIMEO, sndtimeo) if linger is not None: self.setsockopt(zmq.LINGER, linger) retu...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: """ Waits for the next multipart message and asserts that it contains the given data. """
expect_all(await self.recv_multipart(), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_payment(redirect_url, client_name, client_email, payment_owner, validate_address_cmd, *validate_item_cmds): """ Function used to generate a payment ...
return GeneratePayment(redirect_url, client_name, client_email, payment_owner, validate_address_cmd, *validate_item_cmds)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_address_cmd(street, number, quarter, postalcode, town, state, complement="Sem Complemento"): """ Build an address form to be used with payment funct...
return ValidateAddressCmd(street=street, number=number, quarter=quarter, postalcode=postalcode, town=town, state=state, complement=complement)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_item_cmd(description, price, quantity, reference=None): """ Create a commando to save items from the order. A list of items or commands must be crea...
return ValidateItemCmd(description=description, price=price, quantity=quantity, reference=reference)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search_all_payments(payment_status=None, page_size=20, start_cursor=None, offset=0, use_cache=True, cache_begin=True, relations=None): """ Returns a command ...
if payment_status: return PaymentsByStatusSearch(payment_status, page_size, start_cursor, offset, use_cache, cache_begin, relations) return AllPaymentsSearch(page_size, start_cursor, offset, use_cache, cache_begin, relations)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_config(name=__name__): """ Get a configuration parser for a given TAPP name. Reads config.ini files only, not in-database configuration records. :param n...
cfg = ConfigParser() path = os.environ.get('%s_CONFIG_FILE' % name.upper()) if path is None or path == "": fname = '/etc/tapp/%s.ini' % name if isfile(fname): path = fname elif isfile('cfg.ini'): path = 'cfg.ini' else: raise ValueError("Un...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_logging(name, prefix="trademanager", cfg=None): """ Create a logger, based on the given configuration. Accepts LOGFILE and LOGLEVEL settings. :param na...
logname = "/var/log/%s/%s_tapp.log" % (prefix, name) logfile = cfg.get('log', 'LOGFILE') if cfg is not None and \ cfg.get('log', 'LOGFILE') is not None and cfg.get('log', 'LOGFILE') != "" else logname loglevel = cfg.get('log', 'LOGLEVEL') if cfg is not None and \ cfg.get('log', 'LOGLEVEL') ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def destandardize_variables(self, tv, blin, bvar, errBeta, nonmissing): """Destandardize betas and other components."""
return self.test_variables.destandardize(tv, blin, bvar, errBeta, nonmissing)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def freeze_subjects(self): """Converts variable data into numpy arrays. This is required after all subjects have been added via the add_subject function, since w...
self.phenotype_data = numpy.array(self.phenotype_data) self.covariate_data = numpy.array(self.covariate_data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_subject(self, ind_id, sex=None, phenotype=None): """Add new subject to study, with optional sex and phenotype Throws MalformedInputFile if sex is can't b...
self.pedigree_data[ind_id] = len(self.phenotype_data[0]) if phenotype != None: if type(self.phenotype_data) is list: self.phenotype_data[0].append(phenotype) else: self.phenotype_data[-1, len(self.individual_mask)] = phenotype self.indivi...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format_time(date_obj, time_obj=None, datebox=False, dt_type=None, classes=None): """ Returns formatted HTML5 elements based on given datetime object. By defa...
if not time_obj: time_obj = getattr(date_obj, 'time', None) if dt_type: classes = '{0} {1}'.format(classes, dt_type) if datebox: classes = '{0} {1}'.format(classes, datebox) return { 'date_obj': date_obj, 'time_obj': time_obj, 'datebox': datebox, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def short_timesince(date): """ A shorter version of Django's built-in timesince filter. Selects only the first part of the returned string, splitting on the comm...
try: t = timesince(date).split(", ")[0] except IndexError: t = timesince(date) return t
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_values(func, dic): """ Validate each value in ``dic`` by passing it through ``func``. Raise a ``ValueError`` if ``func`` does not return ``True``. "...
for value_name, value in dic.items(): if not func(value): raise ValueError('{} can not be {}'.format(value_name, value))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def find_input_documents(self): """Find all tex documents input by this root document. Returns ------- paths : list List of filepaths for input documents. Paths ...
paths = [] itr = chain(texutils.input_pattern.finditer(self.text), texutils.input_ifexists_pattern.finditer(self.text)) for match in itr: fname = match.group(1) if not fname.endswith('.tex'): full_fname = ".".join((fname, 'tex')) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sections(self): """List with tuples of section names and positions. Positions of section names are measured by cumulative word count. """
sections = [] for match in texutils.section_pattern.finditer(self.text): textbefore = self.text[0:match.start()] wordsbefore = nlputils.wordify(textbefore) numwordsbefore = len(wordsbefore) sections.append((numwordsbefore, match.group(1))) self....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bib_path(self): """Absolute file path to the .bib bibliography document."""
bib_name = self.bib_name # FIXME need to bake in search paths for tex documents in all platforms osx_path = os.path.expanduser( "~/Library/texmf/bibtex/bib/{0}".format(bib_name)) if self._file_exists(bib_name): return bib_name # bib is in project directory ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write(self, path): """Write the document's text to a ``path`` on the filesystem."""
with codecs.open(path, 'w', encoding='utf-8') as f: f.write(self.text)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bibitems(self): """List of bibitem strings appearing in the document."""
bibitems = [] lines = self.text.split('\n') for i, line in enumerate(lines): if line.lstrip().startswith(u'\\bibitem'): # accept this line # check if next line is also part of bibitem # FIXME ugh, re-write j = 1 ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inline_inputs(self): """Inline all input latex files references by this document. The inlining is accomplished recursively. The document is modified in place...
self.text = texutils.inline(self.text, os.path.dirname(self._filepath)) # Remove children self._children = {}
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clearLayout(layout): """Removes all widgets in the layout. Useful when opening a new file, want to clear everything."""
while layout.count(): child = layout.takeAt(0) child.widget().deleteLater()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_dataset(request, dataset_id=None): """Handles creation of Dataset models from form POST information. Data Dictionary entry. If dataset_id is passed as an...
# Save form to create dataset model # Populate non-form fields if dataset_id: dataset_instance = Dataset.objects.get(pk=dataset_id) metadata_form = DatasetUploadForm( request.POST, request.FILES, instance=dataset_instance ) # metadata_fo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_csv_headers(dataset_id): """Return the first row of a CSV as a list of headers."""
data = Dataset.objects.get(pk=dataset_id) with open(data.dataset_file.path, 'r') as datasetFile: csvReader = reader(datasetFile, delimiter=',', quotechar='"') headers = next(csvReader) # print headers return headers
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def grab_names_from_emails(email_list): """Return a dictionary mapping names to email addresses. Only gives a response if the email is found in the staff API/JSO...
all_staff = STAFF_LIST emails_names = {} for email in email_list: for person in all_staff: if email == person['email'] and email not in emails_names: emails_names[email] = person['fullName'] # print emails_names[email] for email in email_list: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tag_lookup(request): """JSON endpoint that returns a list of potential tags. Used for upload template autocomplete. """
tag = request.GET['tag'] tagSlug = slugify(tag.strip()) tagCandidates = Tag.objects.values('word').filter(slug__startswith=tagSlug) tags = json.dumps([candidate['word'] for candidate in tagCandidates]) return HttpResponse(tags, content_type='application/json')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def source_lookup(request): """JSON endpoint that returns a list of potential sources. Used for upload template autocomplete. """
source = request.GET['source'] source_slug = slugify(source.strip()) source_candidates = Dataset.objects.values('source').filter( source_slug__startswith=source_slug ) sources = json.dumps([cand['source'] for cand in source_candidates]) return HttpResponse(sources, content_type='applic...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def download_data_dictionary(request, dataset_id): """Generates and returns compiled data dictionary from database. Returned as a CSV response. """
dataset = Dataset.objects.get(pk=dataset_id) dataDict = dataset.data_dictionary fields = DataDictionaryField.objects.filter( parent_dict=dataDict ).order_by('columnIndex') response = HttpResponse(content_type='text/csv') csvName = slugify(dataset.title + ' data dict') + '.csv' resp...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def home(request): """Renders Datafreezer homepage. Includes recent uploads."""
recent_uploads = Dataset.objects.order_by('-date_uploaded')[:11] email_list = [upload.uploaded_by.strip() for upload in recent_uploads] # print all_staff emails_names = grab_names_from_emails(email_list) # print emails_names for upload in recent_uploads: for item in emails_names: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def edit_dataset_metadata(request, dataset_id=None): """Renders a template to upload or edit a Dataset. """
if request.method == 'POST': return add_dataset(request, dataset_id) elif request.method == 'GET': # create a blank form # Edit if dataset_id: metadata_form = DatasetUploadForm( instance=get_object_or_404(Dataset, pk=dataset_id) ) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dataset_detail(request, dataset_id): """Renders individual dataset detail page."""
active_dataset = get_object_or_404(Dataset, pk=dataset_id) datadict_id = active_dataset.data_dictionary_id datadict = DataDictionaryField.objects.filter( parent_dict=datadict_id ).order_by('columnIndex') uploader_name = grab_names_from_emails([active_dataset.uploaded_by]) tags = Tag.obj...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self, request): """Handle HTTP GET request. Returns template and context from generate_page_title and generate_sections to populate template. """
sections_list = self.generate_sections() p = Paginator(sections_list, 25) page = request.GET.get('page') try: sections = p.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. sections = p.page(1) exc...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self, request): """View for HTTP GET method. Returns template and context from generate_page_title and generate_sections to populate template. """
sections = self.generate_sections() if self.paginated: p = Paginator(sections, 25) page = request.GET.get('page') try: sections = p.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_sections(self): """Return all hubs, slugs, and upload counts."""
datasets = Dataset.objects.values( 'hub_slug' ).annotate( upload_count=Count( 'hub_slug' ) ).order_by('-upload_count') return [ { 'count': dataset['upload_count'], 'name': get_hub_name_from_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_sections(self): """Return all authors to which datasets have been attributed."""
authors = Dataset.objects.values( 'uploaded_by' ).annotate( upload_count=Count( 'uploaded_by' ) ).order_by('-upload_count') email_name_map = grab_names_from_emails( [row['uploaded_by'] for row in authors] ) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_sections(self): """Return dictionary of source section slugs, name, and counts."""
sources = Dataset.objects.values( 'source', 'source_slug' ).annotate(source_count=Count('source_slug')) return sorted([ { 'slug': source['source_slug'], 'name': source['source'], 'count': source['source_count'] ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self, request, slug): """Basic functionality for GET request to view. """
matching_datasets = self.generate_matching_datasets(slug) if matching_datasets is None: raise Http404("Datasets meeting these criteria do not exist.") base_context = { 'datasets': matching_datasets, 'num_datasets': matching_datasets.count(), 'pa...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_additional_context(self, matching_datasets): """Return additional information about matching datasets. Includes upload counts, related hubs, related...
dataset_ids = [upload.id for upload in matching_datasets] tags = Tag.objects.filter( dataset__in=dataset_ids ).distinct().annotate( Count('word') ).order_by('-word__count')[:5] hubs = matching_datasets.values("hub_slug").annotate( Count('hub_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_additional_context(self, matching_datasets): """Return context about matching datasets."""
related_tags = Tag.objects.filter( dataset__in=matching_datasets ).distinct().annotate( Count('word') ).order_by('-word__count')[:5] return { 'related_tags': related_tags }
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_matching_datasets(self, data_slug): """Return datasets that belong to a vertical by querying hubs. """
matching_hubs = VERTICAL_HUB_MAP[data_slug]['hubs'] return Dataset.objects.filter(hub_slug__in=matching_hubs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_additional_context(self, matching_datasets): """Generate top tags and authors for a given Vertical."""
top_tags = Tag.objects.filter( dataset__in=matching_datasets ).annotate( tag_count=Count('word') ).order_by('-tag_count')[:3] top_authors = Dataset.objects.filter( id__in=matching_datasets ).values('uploaded_by').annotate( author_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate_additional_context(self, matching_datasets): """Return top tags for a source."""
top_tags = Tag.objects.filter( dataset__in=matching_datasets ).annotate( tag_count=Count('word') ).order_by('-tag_count')[:3] return { 'top_tags': top_tags }
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_fact_by_id(self, fact_id): """ Obtains fact data by it's id. As the fact is unique, it returns a tuple like: (activity_id, start_time, end_time, descript...
columns = 'activity_id, start_time, end_time, description' query = "SELECT %s FROM facts WHERE id = %s" result = self._query(query % (columns, fact_id)) if result: return result[0] # there only one fact with the id else: raise NoHamsterData('facts', f...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_activity_by_id(self, activity_id): """ Obtains activity data by it's id. As the activity is unique, it returns a tuple like: (name, category_id). If ther...
columns = 'name, category_id' query = "SELECT %s FROM activities WHERE id = %s" result = self._query(query % (columns, activity_id)) if result: return result[0] # there only one fact with the id else: raise NoHamsterData('activities', activity_id)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_tags_by_fact_id(self, fact_id): """ Obtains the tags associated by a fact_id. This function returns a list of the tags name associated to a fact, such as...
if not fact_id in self.all_facts_id: raise NoHamsterData('facts', fact_id) query = "SELECT tag_id FROM fact_tags WHERE fact_id = %s" return [self.tags[row[0]] for row in self._query(query % fact_id)]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def log_user_in(app_id, token, ticket, response, cookie_name='user', url_detail='https://pswdless.appspot.com/rest/detail'): ''' Log the user in setting the user data dictionary in cookie Returns a command that execute the logic ''' return LogUserIn(app_id, token, ticket, response, c...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def fetch_user(app_id, token, ticket, url_detail='https://pswdless.appspot.com/rest/detail'): ''' Fetch the user deatil from Passwordless ''' return FetchUserWithValidation(app_id, token, ticket, url_detail)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def send_login_email(app_id, token, hook, email=None, user_id=None, lang="en_US", url_login='https://pswdless.appspot.com/rest/login'): ''' Contact password-less server to send user a email containing the login link ''' return SendLoginEmail(app_id, token, hook, email, user_id, lang...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def history_file(self, location=None): """Return history file location. """
if location: # Hardcoded location passed from the config file. if os.path.exists(location): return location else: logger.warn("The specified history file %s doesn't exist", location) filenames = [] f...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tag_exists(self, version): """Check if a tag has already been created with the name of the version. """
for tag in self.available_tags(): if tag == version: return True return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _update_version(self, version): """Find out where to change the version and change it. There are three places where the version can be defined. The first one...
if self.get_python_file_version(): setup_cfg = pypi.SetupConfig() filename = setup_cfg.python_file_with_version() lines = open(filename).read().split('\n') for index, line in enumerate(lines): match = UNDERSCORED_VERSION_PATTERN.search(line) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def terminal_size(): """ Detect the current size of terminal window as a numer of rows and columns. """
try: (rows, columns) = os.popen('stty size', 'r').read().split() rows = int(rows) columns = int(columns) return (columns, rows) # Currently ignore any errors and return some reasonable default values. # Errors may occur, when the library is used in non-terminal applicati...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_setup(self, content = None, **kwargs): """ Get current setup by combining internal settings with the ones given. """
if content is None: content = self.content if content is None: raise Exception("No content given to be displayed") setup = {} for setting in self.list_settings(): if setting[0] in kwargs: setup[setting[0]] = kwargs.get(setting[0]) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _es_data(settings): """ Extract data formating related subset of widget settings. """
return {k: settings[k] for k in (ConsoleWidget.SETTING_DATA_FORMATING, ConsoleWidget.SETTING_DATA_TYPE)}
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _es_content(settings): """ Extract content formating related subset of widget settings. """
return {k: settings[k] for k in (ConsoleWidget.SETTING_WIDTH, ConsoleWidget.SETTING_ALIGN, ConsoleWidget.SETTING_PADDING, ConsoleWidget.SETTING_PADDING_LEFT, ...