def api_label_insert(): new_label = request.get_json() label = Label(id=new_label['id'], name=new_label['name']) db.session.add(label) db.session.commit() label_json = {"id": label.id, "name": label.name} return jsonify(label_json)
def import_labels(filename): with open(filename) as f: all_labels = json.loads(f.read()) labels = all_labels["labels"] for name, value in labels.items(): label = Label(value["label"], name) db.session.add(label) db.session.commit()
def get_standard_labels(): """ Get the list of standard labels that apply to every repository. @return: the list of standard labels """ labels_dict = load_yaml_from_file("labels") standard_labels = [] for group_info in labels_dict["groups"]: label_names = group_info.pop("labels", []) group = Group(**group_info) for label_info in label_names: label = Label(**label_info, group=group) standard_labels.append(label) for label_info in labels_dict["standalone"]: label = Label(**label_info) standard_labels.append(label) return standard_labels
def init_labels(self): """ set up labels in the DB (if not already there) """ label_defs = { 'dodgy_pr': dict( prettyname="Dodgy PR", description= "Statistics, survey results and/or 'research' in this article was sponsored by a PR company.", icon="warn_pr.png"), 'churn': dict( prettyname='Churnalism', description= "This article is basically just a press release, copied and pasted.", icon="warn_churn.png"), 'bad_headline': dict(prettyname='Misleading headline', description="Massively misleading headline", icon="warn_badheadline.png"), 'bogus_data': dict(prettyname='Bogus research', description= "Claims in this article are based on bogus research", icon="warn_generic.png"), 'misrep': dict( prettyname='Misrepresented research', description= "This article misrepresents the research/statistics on which it claims to be based", icon="warn_twisteddata.png"), } session = self.Session() for id, inf in label_defs.iteritems(): label = session.query(Label).get(id) if label is None: label = Label(id=id, prettyname=inf['prettyname'], description=inf['description'], icon=inf['icon']) session.add(label) logging.warn("label '%s' missing from db - now installed", id) else: if label.description != inf[ 'description'] or label.prettyname != inf[ 'prettyname'] or label.icon != inf['icon']: label.prettyname = inf['prettyname'] label.description = inf['description'] label.icon = inf['icon'] logging.warn("Update definition for label '%s'" % (label.id, )) session.commit()
def parse_metadata(self, metadata, stack): # ignore if not aligned to 0 if metadata.indent != 0: return match = regex_label.match(metadata.line) if match: label = match["label"] self.current_label = Label(label, metadata) parser = ContextParser(self, metadata) stack.push(parser) return
def get_label_id(session, uid, label_text): """ Get the id of the label with the given label text from the database. Adds a new label for the given label text to the database if it's not already there. """ label = session.query(Label).filter_by(uid=uid, label=label_text).first() if not label: session.add(Label(uid=uid, label=label_text)) session.commit() label = session.query(Label).filter_by(uid=uid, label=label_text).first() return label.id
def loadLabelsFromFile(in_file, track_id=track_id): infile = os.path.abspath(os.path.join(os.path.dirname(__file__), in_file)) logReader = csv.reader(open(infile, 'rb'), delimiter="\t", quotechar='"') for row in logReader: y = row[0] x = row[1] name = row[2].title() desc = row[3].title() point = "POINT(%s %s)" % (x, y) label = Label(name=name, geom=point, track_id=track_id) label.save() print point, name, track_id
def get_groups(): """ Get the list of label groups. @return: the list of label groups. """ labels_dict = load_yaml_from_file("labels") groups = [] for group_info in labels_dict["groups"]: group = Group(**group_info) label_names = group_info.pop("labels", []) groups.append(group) for label_info in label_names: Label(**label_info, group=group) return groups
def create_label(): data = request.get_json() if not 'name' in data or data['name'].strip() == '': return 'Label name is empty', 400 # (Disabled because somehow I do like spaces in my label names..) # if re.match('^[\w]+[\w-]*$', data['name']) is None: # return 'Invalid label name "' + name + '"', 422 label = Label(data['name']) db.session.add(label) db.session.commit() return jsonify(label.to_dict()), 201
def get_skill_label_from_name(skill_group, skill_name): """ Generate the skill label purely from the name of the skill. The name of the skill is plugged into the description and the lower-cased version is used as the label name. @param skill_group: the logical parent group of all skill labels @param skill_name: the name of the skill to convert into a label @return: an instance of Label derived from the skill name """ return Label( name=skill_name.lower(), description=f"Requires proficiency in '{skill_name}'", emoji="💪", group=skill_group, )
def buildSingleLabel(self, po, line): self.resetValues() self.po = po self.line = line poDetail = session.query(PoDetail).filter_by(PO=po, Line=line).first() self.orderQty = poDetail.Order_Quantity self.orderUnit = poDetail.Purchase_Unit poHeader = session.query(PoHeader).filter_by( ObjectID=poDetail.PO_Header_OID).first() self.vendor = poHeader.Vendor self.orderDate = poHeader.Order_Date source = session.query(Source).filter_by( PO_Detail=poDetail.PO_Detail).first() if source.Misc_Material: self.misc = True #If the source lists a material requirement, it came from a job, so go grab that job and fill in the details if source.Material_Req: materialReq = session.query(MatReq).filter_by( Material_Req=source.Material_Req).first() self.job = materialReq.Job self.materialName = materialReq.Material self.materialDescription = materialReq.Description job = session.query(Job).get( self.job) #get job object for job details self.jobCustomer = job.Customer self.jobDescription = job.Description self.jobPart = job.Part_Number else: #else the source sould list the name and description self.materialName = source.Material self.materialDescription = source.Description label = Label(self.materialName, self.materialDescription, self.vendor, self.orderDate, self.orderQty, self.po, self.line, self.misc, self.purchaseUnit, self.stockUnit, self.job, self.jobCustomer, self.jobDescription, self.jobPart) print(label) return label
def addLabel(request): ''' 添加标签 ''' params = yield from request.json() kw = dict(**params) name = kw.get('name', None) if not name or not name.strip(): result = dict(code=0, msg="标签名字不能为空") else: labels = yield from Label.findAll('name=?', [name]) if len(labels) > 0: result = dict(code=0, msg="已经存在该标签名称") else: id = next_id() label = Label(id=id, name=name) yield from label.save() result = dict(code=1, msg="标签添加成功") return result
def addLabelToPatient(request, lbl_name, patient_id): patients_with_id = PatientInfo.objects.filter(pid=patient_id) labels_with_name = Label.objects.filter(label_name=lbl_name) patient = None label = None print "Adding label to Patient" if len(patients_with_id) > 0: patient = patients_with_id[0] if len(labels_with_name) > 0: label = labels_with_name[0] else: label = Label() label.label_name = lbl_name label.save() label.patients_with_label.add(patient) return HttpResponse()
def _new_model(self): return Label()
def parse_argument(arg: Element) -> InstructionArgument: """ Zpracovani parametru instrukce. Parameters ---------- arg: Element XML element parametru. Returns ------- InstructionArgument Zpracovany parametr. """ if len(list(arg)) > 0: exit_app(exitCodes.INVALID_XML_STRUCT, 'Argument contains unexpected elements.', True) arg_type = arg.attrib.get('type') arg_value = arg.text if arg.text is not None else '' if arg_type == ArgumentTypes.LABEL.value: InstructionsParser.validate_variable_name(arg_value, True) return Label(arg_value) elif arg_type == ArgumentTypes.VARIABLE.value: variable_parts = arg_value.split('@', 1) if len(variable_parts) == 2: InstructionsParser.validate_scope(variable_parts[0]) InstructionsParser.validate_variable_name(variable_parts[1]) if variable_parts[0] == 'GF': return Variable(Frames.GLOBAL, variable_parts[1]) elif variable_parts[0] == 'TF': return Variable(Frames.TEMPORARY, variable_parts[1]) elif variable_parts[0] == 'LF': return Variable(Frames.LOCAL, variable_parts[1]) else: exit_app(exitCodes.INVALID_XML_STRUCT, 'Invalid variable. ({})'.format(arg_value), True) elif arg_type == 'nil': if arg_value != 'nil': exit_app(exitCodes.INVALID_XML_STRUCT, 'Invalid value of nil. ({})'.format(arg_value), True) return Symbol(DataTypes.NIL, None) elif arg_type == 'int': try: return Symbol(DataTypes.INT, int(arg_value)) except ValueError: exit_app(exitCodes.INVALID_XML_STRUCT, 'Invalid int value. ({})'.format(arg_value), True) elif arg_type == 'bool': if arg_value == 'true': return Symbol(DataTypes.BOOL, True) elif arg_value == 'false': return Symbol(DataTypes.BOOL, False) else: exit_app(exitCodes.INVALID_XML_STRUCT, 'Invalid boolean value. ({})'.format(arg_value), True) elif arg_type == 'string': if re.compile('.*#.*').match(arg_value): exit_app(exitCodes.INVALID_XML_STRUCT, 'Text cannot contains #.', True) fixed_string = InstructionsParser.fix_string(arg_value) return Symbol(DataTypes.STRING, fixed_string) elif arg_type == 'type': if arg_value == 'int': return Type(int) elif arg_value == 'string': return Type(str) elif arg_value == 'bool': return Type(bool) elif arg_value == 'float': return Type(float) else: exit_app(exitCodes.INVALID_XML_STRUCT, 'Unknown type value. ({})'.format(arg_value), True) elif arg_type == 'float': try: return Symbol(DataTypes.FLOAT, float.fromhex(arg_value)) except Exception: exit_app(exitCodes.INVALID_XML_STRUCT, 'Invalid format of operand.') else: exit_app(exitCodes.INVALID_XML_STRUCT, 'Unknown argument type. ({})'.format(arg_type), True)
def parse_response(results) -> List[Label]: result_list = [] for element in results['responses'][0]['labelAnnotations']: result_list.append(Label(element['description'], element['score'])) return result_list
def populate(): python = Subject('Python') web = Subject('Web') oop = Subject('OOP') art = Subject('Art') db.session.add(python) db.session.add(web) db.session.add(oop) db.session.add(art) km61 = Group('KM-61') km62 = Group('KM-62') km63 = Group('LA-73') km62.subjects.append(web) km62.subjects.append(oop) km62.subjects.append(python) km63.subjects.append(art) db.session.add(km61) db.session.add(km62) db.session.add(km63) richmound = Student('*****@*****.**', '123456', 'Richmound Tizard', 'KM-62', 1) torrie = Student('*****@*****.**', '123456', 'Torrie Chinge', 'KM-62', 2) becca = Student('*****@*****.**', '123456', 'Becca Parell', 'LA-73', 3) db.session.add(richmound) db.session.add(torrie) db.session.add(becca) python_intro = Lection('Introduction to python', 'Den Mitchel', 'Introduction to python blah blah blah', 'Python') js_intro = Lection('Introduction to JS', 'Dan Abramov', 'Introduction to JS blah blah blah', 'Web') js_object = Lection('Objects in JS', 'Dan Abramov', 'Objects in JS blah blah blah', 'Web') db.session.add(python_intro) db.session.add(js_intro) db.session.add(js_object) python_beginner = Label('Python language for beginners', 0) js_beginner = Label('JS for beginners', 1) js_intermediate = Label('JS for intermediate', 2) db.session.add(python_beginner) db.session.add(js_beginner) db.session.add(js_intermediate) python_docs = Resource('Official doc for python', 'lalala', 'https://docs.python.org/3/', 0, 'Introduction to python', '*****@*****.**') js_docs = Resource('Official doc for JS', 'lalala JS', 'https://developer.mozilla.org/ru/docs/Web/JavaScript', 0, 'Introduction to JS', '*****@*****.**') abramov_blog = Resource('Dan`s Abramov blog', 'lalala blog', 'https://overreacted.io/', 0, 'Objects in JS', '*****@*****.**') db.session.add(python_docs) db.session.add(js_docs) db.session.add(abramov_blog) js_lab_1 = Laboratory('Arithmetical operations in JS', 1, 'Manual is here', 'Web') js_lab_2 = Laboratory('Conditions in JS', 2, 'Manual is here', 'Web') js_lab_3 = Laboratory('Loops in JS', 3, 'Manual is here', 'Web') db.session.add(js_lab_1) db.session.add(js_lab_2) db.session.add(js_lab_3) js_lab_1_v1 = Task(1, 'Arithmetical operations in JS', 'Please, add two numbers') js_lab_1_v2 = Task(2, 'Arithmetical operations in JS', 'Please, multiple two numbers') js_lab_1_v3 = Task(3, 'Arithmetical operations in JS', 'Please, divide two numbers') db.session.add(js_lab_1_v1) db.session.add(js_lab_1_v2) db.session.add(js_lab_1_v3) richmound_attempt_1 = Implementation(1, '*****@*****.**', 'Arithmetical operations in JS', 'Tests passed', 'code', 'Data validation failed!', 'IFFOIIFOFDFIO', 20) richmound_attempt_2 = Implementation(2, '*****@*****.**', 'Arithmetical operations in JS', 'Tests passed', 'code', 'Stack overflow!', 'IFFOIIFFFIO', 36) richmound_attempt_3 = Implementation(3, '*****@*****.**', 'Arithmetical operations in JS', 'Tests passed', 'code', 'Success!', 'IOIIIIIFOFDFIO', 15) db.session.add(richmound_attempt_1) db.session.add(richmound_attempt_2) db.session.add(richmound_attempt_3) first_lab_test_1 = Test('Check functionality', 1, 'Arithmetical operations in JS', '{a: 2, b: 2}', '{return: 4}', 'Arithmetical error!') first_lab_test_2 = Test('Check validation', 1, 'Arithmetical operations in JS', '{a: "c", b: 2}', '{return: "Not a number"}', 'Data validation failed!') first_lab_test_3 = Test('Check small numbers', 1, 'Arithmetical operations in JS', '{a: 0.333333333, b: 0.2222222222}', '{return: 0.555555555}', 'Data validation failed!') db.session.add(first_lab_test_1) db.session.add(first_lab_test_2) db.session.add(first_lab_test_3) db.session.commit()