How to use check_item method in avocado

Best Python code snippet using avocado_python

admin.py

Source:admin.py Github

copy

Full Screen

1from django.contrib import admin , messages2from django.core import serializers3import json4from docxtpl import DocxTemplate5from basicdata.models import CheckItem6from datacenter.models import DataInformation7from examinationreport.models import Reports8from import_export.admin import ImportExportActionModelAdmin9import datetime10from docxtpl import DocxTemplate11from examinationsample.models import Sample , Checks12from examinationsample.models import Progress13from questionnairesurvey.models import Quenstion14from labinformation.models import ConventionalIndex , QpcrIndexes , BioChemicalIndexes , ScfasIndexes , \15 DegradationIndexes16admin.site.empty_value_display = '-empty-'17@admin.register( Reports )18class ReportsAdmin( ImportExportActionModelAdmin , admin.ModelAdmin ):19 list_display = ( 'id' , 'sample_number' , 'word_report' , 'pdf_report' , 'report_testing_date' , 'report_user' , 'is_status')20 list_display_links = ('sample_number' ,)21 # readonly_fields = ('report_testing_date','report_user')22 ordering = ('-id' ,)23 view_on_site = False24 list_max_show_all = 10025 list_per_page = 2026 list_filter = ['is_status' , ]27 search_fields = ('sample_number' ,)28 # resource_class =29 # form =30 # list_editable =31 actions = ['make_create' , 'make_published']32 def make_create(self , request , queryset):33 i = 0 # 提交成功的数据34 n = 0 # 提交过的数量35 t = 0 # 选中状态36 for obj in queryset:37 t += 138 if obj.is_status < 1:39 obj.is_status = 140 obj.save( )41 i += 142 else:43 n += 144 self.message_user( request , "选择%s条信息,完成操作%s条,不操作%s条" % (t , i , n) , level = messages.SUCCESS )45 make_create.short_description = "1同步数据"46 def make_published(self , request , queryset):47 i = 0 # 提交成功的数据48 n = 0 # 提交过的数量49 t = 0 # 选中状态50 for obj in queryset:51 t += 152 if obj.is_status == 1:53 obj.is_status = 254 obj.save( )55 i += 156 obj_progress , created = Progress.objects.get_or_create( sample_number = obj.sample_number )57 if obj.report_testing_date is not None:58 obj_progress.report_testing_date = obj.report_testing_date59 else:60 obj_progress.report_testing_date = datetime.date.today( )61 obj_progress.report_testing_staff = request.user.last_name + ' ' + request.user.first_name62 obj_progress.is_status = 363 obj_progress.save( )64 else:65 n += 166 self.message_user( request , "选择%s条信息,完成操作%s条,不操作%s条" % (t , i , n) , level = messages.SUCCESS )67 make_published.short_description = "2标记完成"68 def get_changeform_initial_data(self , request):69 initial = super( ).get_changeform_initial_data( request )70 initial ['report_user'] = request.user.last_name + ' ' + request.user.first_name71 initial ['report_testing_date'] = datetime.date.today( )72 return initial73 def save_model(self , request , obj , form , change):74 obj.report_user = "%s %s" % (request.user.last_name , request.user.first_name) # 系统自动添加创建人75 obj.report_user = request.user.last_name + ' ' + request.user.first_name76 obj.report_testing_date = datetime.date.today( )77 # 先同步数据78 # checkss = Checks.objects.filter(79 # sample_number__sample_number = obj.sample_number ) # TODO 假设不存在样本收样后,检查项为空的情况80 # for checks in checkss:81 # check_item = CheckItem.objects.get( number = checks.check_number )82 # data = {}83 # key_tmp = obj.sample_number + check_item.carbon_source + check_item.genus84 # if key_tmp in data.keys( ):85 # data [key_tmp] = {'sample_number': obj.sample_number , 'carbon_source': check_item.carbon_source ,86 # 'genus': check_item.genus}87 # if check_item.type.number == "JCMK0001": # 问卷调查88 # quenstion = Quenstion.objects.filter( sample_number = obj.sample_number ,89 # carbon_source = check_item.carbon_source ,90 # genus = check_item.genus )91 # tmp = serializers.serialize( 'json' , queryset = quenstion )92 # quenstion_data = json.loads( tmp ) [0] ['fields']93 # data [key_tmp] = data [key_tmp].update( quenstion_data )94 #95 # if check_item.type.number == "JCMK0002": # 常规指标项96 # conventional = ConventionalIndex.objects.filter( sample_number = obj.sample_number ,97 # carbon_source = check_item.carbon_source ,98 # genus = check_item.genus )99 # tmp = serializers.serialize( 'json' , queryset = conventional )100 # conventional_data = json.loads( tmp ) [0] ['fields']101 # data [key_tmp] = data [key_tmp].update( conventional_data )102 # if check_item.type.number == "JCMK0003": # 生化指标项103 # bio = BioChemicalIndexes.objects.filter( sample_number = obj.sample_number ,104 # carbon_source = check_item.carbon_source ,105 # genus = check_item.genus )106 # tmp = serializers.serialize( 'json' , queryset = bio )107 # bio_data = json.loads( tmp ) [0] ['fields']108 # data [key_tmp] = data [key_tmp].update( bio_data )109 # if check_item.type.number == "JCMK0004": # qPCR检测项110 # qpcr = QpcrIndexes.objects.filter( sample_number = obj.sample_number ,111 # carbon_source = check_item.carbon_source ,112 # genus = check_item.genus )113 # tmp = serializers.serialize( 'json' , queryset = qpcr )114 # qpcr_data = json.loads( tmp ) [0] ['fields']115 # data [key_tmp] = data [key_tmp].update( qpcr_data )116 # if check_item.type.number == "JCMK0005": # SCFAs检测项117 # scfas = ScfasIndexes.objects.filter( sample_number = obj.sample_number ,118 # carbon_source = check_item.carbon_source ,119 # genus = check_item.genus )120 # tmp = serializers.serialize( 'json' , queryset = scfas )121 # scfas_data = json.loads( tmp ) [0] ['fields']122 # data [key_tmp] = data [key_tmp].update( scfas_data )123 # if check_item.type.number == "JCMK0006": # 气压和降解率检测项124 # degradation = DegradationIndexes.objects.filter( sample_number = obj.sample_number ,125 # carbon_source = check_item.carbon_source ,126 # genus = check_item.genus )127 # tmp = serializers.serialize( 'json' , queryset = degradation )128 # degradation_data = json.loads( tmp ) [0] ['fields']129 # data [key_tmp] = data [key_tmp].update( degradation_data )130 # # for tmp in data.values( ):131 # # DataInformation( *tmp ).save( )132 #133 # # 生成word报告134 # doc = DocxTemplate(135 # 'media/' + str( Sample.objects.filter( sample_number = obj.sample_number ) [0].report_template_url ) )136 # checks = Checks.objects.filter( sample_number__sample_number = obj.sample_number )137 #138 #139 # context = {'company_name': str( checks.count( ) ) + "202年↑↑↑↑10月"}140 # doc.render( context )141 # doc.save( 'media/' + str( obj.word_report ) )...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...5from dnstest.libknot import libknot6from dnstest.module import ModStats7from dnstest.test import Test8from dnstest.utils import *9def check_item(server, section, item, value, idx=None, zone=None):10 try:11 ctl = libknot.control.KnotCtl()12 ctl.connect(os.path.join(server.dir, "knot.sock"))13 if zone:14 ctl.send_block(cmd="zone-stats", section=section, item=item, zone=zone.name)15 else:16 ctl.send_block(cmd="stats", section=section, item=item)17 stats = ctl.receive_stats()18 finally:19 ctl.send(libknot.control.KnotCtlType.END)20 ctl.close()21 if not stats and value == -1:22 return23 if zone:24 stats = stats.get("zone").get(zone.name.lower())25 if idx:26 if value == -1:27 isset(idx not in stats.get(section).get(item), idx)28 return29 else:30 data = int(stats.get(section).get(item).get(idx))31 else:32 data = int(stats.get(section).get(item))33 compare(data, value, "%s.%s" % (section, item))34ModStats.check()35proto = random.choice([4, 6])36t = Test(stress=False, tsig=False, address=proto)37knot = t.server("knot")38zones = t.zone_rnd(2)39t.link(zones, knot)40knot.add_module(None, ModStats())41knot.add_module(zones[0], ModStats())42knot.add_module(zones[1], ModStats())43t.start()44t.sleep(4)45check_item(knot, "server", "zone-count", 2)46resp = knot.dig(zones[0].name, "SOA", tries=1, udp=True)47query_size1 = resp.query_size()48reply_size1 = resp.response_size()49resp = knot.dig(zones[0].name, "NS", tries=1, udp=False)50query_size2 = resp.query_size()51reply_size2 = resp.response_size()52resp = knot.dig(zones[1].name, "TYPE11", tries=1, udp=True)53query_size3 = resp.query_size()54reply_size3 = resp.response_size()55# Successful transfer.56resp = knot.dig(zones[0].name, "AXFR", tries=1)57resp.check_xfr(rcode="NOERROR")58xfr_query_size = resp.query_size()59# Cannot get xfr_reply_size :-/60# Successful update.61up = knot.update(zones[1])62up.add(zones[1].name, "3600", "AAAA", "::1")63up.send("NOERROR")64ddns_query_size = up.query_size()65# Due to DDNS bulk processing, failed RCODE and response-bytes are not incremented!66# Check request protocol metrics.67check_item(knot, "mod-stats", "request-protocol", 2, "udp%s" % proto)68check_item(knot, "mod-stats", "request-protocol", 1, "udp%s" % proto, zone=zones[0])69check_item(knot, "mod-stats", "request-protocol", 1, "udp%s" % proto, zone=zones[1])70check_item(knot, "mod-stats", "request-protocol", 3, "tcp%s" % proto)71check_item(knot, "mod-stats", "request-protocol", 2, "tcp%s" % proto, zone=zones[0])72# Check request/response bytes metrics.73check_item(knot, "mod-stats", "request-bytes", query_size1 + query_size2 + query_size3,74 "query")75check_item(knot, "mod-stats", "request-bytes", ddns_query_size, "update")76check_item(knot, "mod-stats", "request-bytes", xfr_query_size, "other")77check_item(knot, "mod-stats", "response-bytes", reply_size1 + reply_size2 + reply_size3,78 "reply")79check_item(knot, "mod-stats", "request-bytes", query_size1 + query_size2, "query",80 zone=zones[0])81check_item(knot, "mod-stats", "response-bytes", reply_size1 + reply_size2, "reply",82 zone=zones[0])83check_item(knot, "mod-stats", "request-bytes", query_size3, "query", zone=zones[1])84check_item(knot, "mod-stats", "response-bytes", reply_size3, "reply", zone=zones[1])85# Check query size metrics (just for global module).86indices = dict()87for size in [query_size1, query_size2, query_size3]:88 idx = "%i-%i" % (int(size / 16) * 16, int(size / 16) * 16 + 15)89 if idx not in indices:90 indices[idx] = 191 else:92 indices[idx] += 1;93for size in indices:94 check_item(knot, "mod-stats", "query-size", indices[size], idx=size)95# Check reply size metrics (just for global module).96indices = dict()97for size in [reply_size1, reply_size2, reply_size3]:98 idx = "%i-%i" % (int(size / 16) * 16, int(size / 16) * 16 + 15)99 if idx not in indices:100 indices[idx] = 1101 else:102 indices[idx] += 1;103for size in indices:104 check_item(knot, "mod-stats", "reply-size", indices[size], idx=size)105# Check query type metrics.106check_item(knot, "mod-stats", "query-type", 1, idx="SOA")107check_item(knot, "mod-stats", "query-type", 1, idx="NS")108check_item(knot, "mod-stats", "query-type", 1, idx="TYPE11")109check_item(knot, "mod-stats", "query-type", 1, idx="SOA", zone=zones[0])110check_item(knot, "mod-stats", "query-type", 1, idx="NS", zone=zones[0])111check_item(knot, "mod-stats", "query-type", -1, idx="TYPE11", zone=zones[0])112check_item(knot, "mod-stats", "query-type", -1, idx="SOA", zone=zones[1])113check_item(knot, "mod-stats", "query-type", -1, idx="NS", zone=zones[1])114check_item(knot, "mod-stats", "query-type", 1, idx="TYPE11", zone=zones[1])115# Check server operation metrics.116check_item(knot, "mod-stats", "server-operation", 3, idx="query")117check_item(knot, "mod-stats", "server-operation", 1, idx="axfr")118check_item(knot, "mod-stats", "server-operation", 1, idx="update")119# Check response code metrics.120check_item(knot, "mod-stats", "response-code", 4, idx="NOERROR")121check_item(knot, "mod-stats", "response-code", 3, idx="NOERROR", zone=zones[0])122check_item(knot, "mod-stats", "response-code", 1, idx="NOERROR", zone=zones[1])123# Check nodata metrics.124check_item(knot, "mod-stats", "reply-nodata", 1, idx="other")125check_item(knot, "mod-stats", "reply-nodata", -1, idx="other", zone=zones[0])126check_item(knot, "mod-stats", "reply-nodata", 1, idx="other", zone=zones[1])...

Full Screen

Full Screen

aoc_17_14.py

Source:aoc_17_14.py Github

copy

Full Screen

1from adventofcode_10 import *2import copy3import sys45real = "hwlqcszp"6test = "flqrgnkx"78def knots(text):9 return [text + "-" + str(x) for x in range(128)]1011real_knots = knots(real)12test_knots = knots(test)1314def char_to_binary(char):15 return bin(int(char, base=16))[2:].zfill(4)1617def hash_to_binary(hash_):18 binary = ""19 for char in hash_:20 binary += char_to_binary(char)21 return binary2223m_grid = lambda y: "".join([hash_to_binary(full_hash(x, 64)) for x in y])2425def part1(grid):26 return grid.count("1")2728# print(part1(m_grid(real_knots)))2930def part2(grid, size, print_=False, regions=0):31 print(grid.count("1"))32 if grid.count("1") == 0:33 return regions34 else:35 if print_:36 print("xxxxx")37 first = grid.find("1")38 regions += 139 checklist = [first]40 while True:41 if len(checklist) == 0:42 break43 check_item = checklist.pop(0)44 if print_:45 print("Checking:", check_item, checklist)46 if grid[check_item] == "1":47 grid = grid[:check_item] + "0" + grid[check_item+1:]48 if check_item < size:49 if check_item == 0:50 checklist.append(check_item+1)51 checklist.append(check_item+size)52 elif check_item == size-1:53 checklist.append(check_item-1)54 checklist.append(check_item+size)55 elif 0 < check_item < size-1:56 checklist.append(check_item-1)57 checklist.append(check_item+size)58 checklist.append(check_item+1)59 elif check_item+size > len(grid)-1:60 if check_item%size == 0:61 checklist.append(check_item+1)62 checklist.append(check_item-size)63 elif check_item%size == size-1:64 checklist.append(check_item-1)65 checklist.append(check_item-size)66 elif 0 < check_item%size < size-1:67 checklist.append(check_item-1)68 checklist.append(check_item-size)69 checklist.append(check_item+1)70 else:71 if check_item%size == 0:72 checklist.append(check_item+1)73 checklist.append(check_item+size)74 checklist.append(check_item-size)75 elif check_item%size == size-1:76 checklist.append(check_item-1)77 checklist.append(check_item+size)78 checklist.append(check_item-size)79 elif 0 < check_item%size < size-1:80 checklist.append(check_item-1)81 checklist.append(check_item+size)82 checklist.append(check_item-size)83 checklist.append(check_item+1)84 if print_:85 print(checklist)86 return part2(grid, size, print_, regions)8788def part2(grid, size, print_=False):89 regions = 090 while grid.count("1") > 0:91 regions += 192 if print_:93 print("xxxxx")94 first = grid.find("1")95 checklist = [first]96 while True:97 if len(checklist) == 0:98 break99 check_item = checklist.pop(0)100 if print_:101 print("Checking:", check_item, checklist)102 if grid[check_item] == "1":103 grid = grid[:check_item] + "0" + grid[check_item+1:]104 if check_item < size:105 if check_item == 0:106 checklist.append(check_item+1)107 checklist.append(check_item+size)108 elif check_item == size-1:109 checklist.append(check_item-1)110 checklist.append(check_item+size)111 elif 0 < check_item < size-1:112 checklist.append(check_item-1)113 checklist.append(check_item+size)114 checklist.append(check_item+1)115 elif check_item+size > len(grid)-1:116 if check_item%size == 0:117 checklist.append(check_item+1)118 checklist.append(check_item-size)119 elif check_item%size == size-1:120 checklist.append(check_item-1)121 checklist.append(check_item-size)122 elif 0 < check_item%size < size-1:123 checklist.append(check_item-1)124 checklist.append(check_item-size)125 checklist.append(check_item+1)126 else:127 if check_item%size == 0:128 checklist.append(check_item+1)129 checklist.append(check_item+size)130 checklist.append(check_item-size)131 elif check_item%size == size-1:132 checklist.append(check_item-1)133 checklist.append(check_item+size)134 checklist.append(check_item-size)135 elif 0 < check_item%size < size-1:136 checklist.append(check_item-1)137 checklist.append(check_item+size)138 checklist.append(check_item-size)139 checklist.append(check_item+1)140 return regions141 ...

Full Screen

Full Screen

mode.py

Source:mode.py Github

copy

Full Screen

2# mode.py3# Originally, mode selection should be done by NLP, analyzing the given sentence by syntax. 4# However in this case, since the system is simple enough, we just use classification function like following...5from constant_variables import*6def check_item(my_list, word):7 flag = False8 for token in my_list:9 if word in token:10 flag = True11 break12 return flag13def split_string(string):14 """split and lower the string"""15 return string.lower().split(' ')16def mode_selection_eng(string): 17 my_list = split_string(string)18 if check_item(my_list, 'hello') or check_item(my_list, 'hi') or (check_item(my_list, 'meet') and check_item(my_list, 'nice') and check_item(my_list, 'you')):19 return GREETING20 elif check_item(my_list, 'corona') or check_item(my_list, 'covid'):21 return COVID22 elif check_item(my_list, 'brightness') or (check_item(my_list, 'light') and (check_item(my_list, 'down') or check_item(my_list, 'up'))):23 return BRIGHTNESS24 elif check_item(my_list, 'volume'):25 return VOLUME26 elif (check_item(my_list, 'time') and check_item(my_list, 'what')) or check_item(my_list, 'clock'):27 return CLOCK28 elif check_item(my_list, 'timer'):29 return TIMER30 elif check_item(my_list, 'joke') or check_item(my_list, 'jokes') or (check_item(my_list, 'funny') and (check_item(my_list, 'story') or check_item(my_list, 'stories'))):31 return JOKE32 elif check_item(my_list, 'protocol') and (check_item(my_list, 'house') or check_item(my_list, 'party'), check_item(my_list, 'final')):33 return HOUSE_PARTY_PROTOCOL34 else:35 return UNKNOWN_ERROR36def mode_selection_kor(string):37 my_list = split_string(string)38 if check_item(my_list, '안녕'):39 return GREETING40 elif check_item(my_list, '코로나') or check_item(my_list, '확진자'):41 return COVID42 elif check_item(my_list, '밝기') or (check_item(my_list, '화면이') and (check_item(my_list, '밝아') or check_item(my_list, '어두워'))):43 return BRIGHTNESS44 elif check_item(my_list, '볼륨') or check_item(my_list, '소리'):45 return VOLUME46 elif check_item(my_list, '시간') or (check_item(my_list, '몇') and check_item(my_list, '시')) or check_item(my_list, '시계'):47 return CLOCK48 elif check_item(my_list, '타이머') or (check_item(my_list, '후에') and check_item(my_list, '알려줘')):49 return TIMER50 elif check_item(my_list, '농담') or ((check_item(my_list, '재미있는') or check_item(my_list, '재밌는')) and (check_item(my_list, '이야기') or check_item(my_list, '얘기'))):51 return JOKE52 elif (check_item(my_list, '전부') or check_item(my_list, '다') or (check_item(my_list, '할') and check_item(my_list, '수') and check_item(my_list, '있는지'))) and (check_item(my_list, '보여') and check_item(my_list, '줘')):53 return HOUSE_PARTY_PROTOCOL54 else:55 return UNKNOWN_ERROR56def mode_selection_esp(string):57 """Determine mode with EXTREMELY primitive NLP"""58 my_list = split_string(string)59 if check_item(my_list, 'hola'):60 return GREETING61 elif check_item(my_list, 'corona') or check_item(my_list, 'virus') or check_item(my_list, 'covid'):62 return COVID63 else:64 return UNKNOWN_ERROR65def universal_mode_selection(string, language):66 """First order mode selection: by Language67 Language Key Dictionary68 0 : English69 1 : Korean70 2 : Spanish71 """72 if language == ENGLISH:73 return mode_selection_eng(string)74 elif language == KOREAN:75 return mode_selection_kor(string)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful