How to use old method in Testify

Best Python code snippet using Testify_python

armv8.py

Source:armv8.py Github

copy

Full Screen

1# Add all ARMv8 state2def upgrader(cpt):3 if cpt.get('root','isa') != 'arm':4 return5 import re6 print "Warning: The size of the FP register file has changed. "\7 "To get similar results you need to adjust the number of "\8 "physical registers in the CPU you're restoring into by "\9 "NNNN."10 # Find the CPU context's and upgrade their registers11 for sec in cpt.sections():12 re_xc_match = re.match('^.*?sys.*?\.cpu(\d+)*\.xc\.*', sec)13 if not re_xc_match:14 continue15 # Update floating point regs16 fpr = cpt.get(sec, 'floatRegs.i').split()17 # v8 has 128 normal fp and 32 special fp regs compared18 # to v7's 64 normal fp and 8 special fp regs.19 # Insert the extra normal fp registers at end of v7 normal fp regs20 for x in xrange(64):21 fpr.insert(64, "0")22 # Append the extra special registers23 for x in xrange(24):24 fpr.append("0")25 cpt.set(sec, 'floatRegs.i', ' '.join(str(x) for x in fpr))26 ir = cpt.get(sec, 'intRegs').split()27 # Add in v8 int reg state28 # Splice in R13_HYP29 ir.insert(20, "0")30 # Splice in INTREG_DUMMY and SP0 - SP331 ir.extend(["0", "0", "0", "0", "0"])32 cpt.set(sec, 'intRegs', ' '.join(str(x) for x in ir))33 # Update the cpu interrupt field34 for sec in cpt.sections():35 re_int_match = re.match("^.*?sys.*?\.cpu(\d+)*$", sec)36 if not re_int_match:37 continue38 irqs = cpt.get(sec, "interrupts").split()39 irqs.append("false")40 irqs.append("false")41 cpt.set(sec, "interrupts", ' '.join(str(x) for x in irqs))42 # Update the per cpu interrupt structure43 for sec in cpt.sections():44 re_int_match = re.match("^.*?sys.*?\.cpu(\d+)*\.interrupts$", sec)45 if not re_int_match:46 continue47 irqs = cpt.get(sec, "interrupts").split()48 irqs.append("false")49 irqs.append("false")50 cpt.set(sec, "interrupts", ' '.join(str(x) for x in irqs))51 # Update the misc regs and add in new isa specific fields52 for sec in cpt.sections():53 re_isa_match = re.match("^.*?sys.*?\.cpu(\d+)*\.isa$", sec)54 if not re_isa_match:55 continue56 cpt.set(sec, 'haveSecurity', 'false')57 cpt.set(sec, 'haveLPAE', 'false')58 cpt.set(sec, 'haveVirtualization', 'false')59 cpt.set(sec, 'haveLargeAsid64', 'false')60 cpt.set(sec, 'physAddrRange64', '40')61 # splice in the new misc registers, ~200 -> 605 registers,62 # ordering does not remain consistent63 mr_old = cpt.get(sec, 'miscRegs').split()64 mr_new = [ '0' for x in xrange(605) ]65 # map old v7 miscRegs to new v8 miscRegs66 mr_new[0] = mr_old[0] # CPSR67 mr_new[16] = mr_old[1] # CPSR_Q68 mr_new[1] = mr_old[2] # SPSR69 mr_new[2] = mr_old[3] # SPSR_FIQ70 mr_new[3] = mr_old[4] # SPSR_IRQ71 mr_new[4] = mr_old[5] # SPSR_SVC72 mr_new[5] = mr_old[6] # SPSR_MON73 mr_new[8] = mr_old[7] # SPSR_UND74 mr_new[6] = mr_old[8] # SPSR_ABT75 mr_new[432] = mr_old[9] # FPSR76 mr_new[10] = mr_old[10] # FPSID77 mr_new[11] = mr_old[11] # FPSCR78 mr_new[18] = mr_old[12] # FPSCR_QC79 mr_new[17] = mr_old[13] # FPSCR_EXC80 mr_new[14] = mr_old[14] # FPEXC81 mr_new[13] = mr_old[15] # MVFR082 mr_new[12] = mr_old[16] # MVFR183 mr_new[28] = mr_old[17] # SCTLR_RST,84 mr_new[29] = mr_old[18] # SEV_MAILBOX,85 mr_new[30] = mr_old[19] # DBGDIDR86 mr_new[31] = mr_old[20] # DBGDSCR_INT,87 mr_new[33] = mr_old[21] # DBGDTRRX_INT,88 mr_new[34] = mr_old[22] # DBGTRTX_INT,89 mr_new[35] = mr_old[23] # DBGWFAR,90 mr_new[36] = mr_old[24] # DBGVCR,91 #mr_new[] = mr_old[25] # DBGECR -> UNUSED,92 #mr_new[] = mr_old[26] # DBGDSCCR -> UNUSED,93 #mr_new[] = mr_old[27] # DBGSMCR -> UNUSED,94 mr_new[37] = mr_old[28] # DBGDTRRX_EXT,95 mr_new[38] = mr_old[29] # DBGDSCR_EXT,96 mr_new[39] = mr_old[30] # DBGDTRTX_EXT,97 #mr_new[] = mr_old[31] # DBGDRCR -> UNUSED,98 mr_new[41] = mr_old[32] # DBGBVR,99 mr_new[47] = mr_old[33] # DBGBCR,100 #mr_new[] = mr_old[34] # DBGBVR_M -> UNUSED,101 #mr_new[] = mr_old[35] # DBGBCR_M -> UNUSED,102 mr_new[61] = mr_old[36] # DBGDRAR,103 #mr_new[] = mr_old[37] # DBGBXVR_M -> UNUSED,104 mr_new[64] = mr_old[38] # DBGOSLAR,105 #mr_new[] = mr_old[39] # DBGOSSRR -> UNUSED,106 mr_new[66] = mr_old[40] # DBGOSDLR,107 mr_new[67] = mr_old[41] # DBGPRCR,108 #mr_new[] = mr_old[42] # DBGPRSR -> UNUSED,109 mr_new[68] = mr_old[43] # DBGDSAR,110 #mr_new[] = mr_old[44] # DBGITCTRL -> UNUSED,111 mr_new[69] = mr_old[45] # DBGCLAIMSET,112 mr_new[70] = mr_old[46] # DBGCLAIMCLR,113 mr_new[71] = mr_old[47] # DBGAUTHSTATUS,114 mr_new[72] = mr_old[48] # DBGDEVID2,115 mr_new[73] = mr_old[49] # DBGDEVID1,116 mr_new[74] = mr_old[50] # DBGDEVID,117 mr_new[77] = mr_old[51] # TEEHBR,118 mr_new[109] = mr_old[52] # v7 SCTLR -> aarc32 SCTLR_NS119 mr_new[189] = mr_old[53] # DCCISW,120 mr_new[188] = mr_old[54] # DCCIMVAC,121 mr_new[183] = mr_old[55] # DCCMVAC,122 mr_new[271] = mr_old[56] # v7 CONTEXTIDR -> aarch32 CONTEXTIDR_NS,123 mr_new[274] = mr_old[57] # v7 TPIDRURW -> aarch32 TPIDRURW_NS,124 mr_new[277] = mr_old[58] # v7 TPIDRURO -> aarch32 TPIDRURO_NS,125 mr_new[280] = mr_old[59] # v7 TPIDRPRW -> aarch32 TPIDRPRW_NS,126 mr_new[170] = mr_old[60] # CP15ISB,127 mr_new[185] = mr_old[61] # CP15DSB,128 mr_new[186] = mr_old[62] # CP15DMB,129 mr_new[114] = mr_old[63] # CPACR,130 mr_new[101] = mr_old[64] # CLIDR,131 mr_new[100] = mr_old[65] # CCSIDR,132 mr_new[104] = mr_old[66] # v7 CSSELR -> aarch32 CSSELR_NS,133 mr_new[163] = mr_old[67] # ICIALLUIS,134 mr_new[168] = mr_old[68] # ICIALLU,135 mr_new[169] = mr_old[69] # ICIMVAU,136 mr_new[172] = mr_old[70] # BPIMVA,137 mr_new[164] = mr_old[71] # BPIALLIS,138 mr_new[171] = mr_old[72] # BPIALL,139 mr_new[80] = mr_old[73] # MIDR,140 mr_new[126] = mr_old[74] # v7 TTBR0 -> aarch32 TTBR0_NS,141 mr_new[129] = mr_old[75] # v7 TTBR1 -> aarch32 TTBR1_NS,142 mr_new[83] = mr_old[76] # TLBTR,143 mr_new[137] = mr_old[77] # v7 DACR -> aarch32 DACR_NS,144 mr_new[192] = mr_old[78] # TLBIALLIS,145 mr_new[193] = mr_old[79] # TLBIMVAIS,146 mr_new[194] = mr_old[80] # TLBIASIDIS,147 mr_new[195] = mr_old[81] # TLBIMVAAIS,148 mr_new[198] = mr_old[82] # ITLBIALL,149 mr_new[199] = mr_old[83] # ITLBIMVA,150 mr_new[200] = mr_old[84] # ITLBIASID,151 mr_new[201] = mr_old[85] # DTLBIALL,152 mr_new[202] = mr_old[86] # DTLBIMVA,153 mr_new[203] = mr_old[87] # DTLBIASID,154 mr_new[204] = mr_old[88] # TLBIALL,155 mr_new[205] = mr_old[89] # TLBIMVA,156 mr_new[206] = mr_old[90] # TLBIASID,157 mr_new[207] = mr_old[91] # TLBIMVAA,158 mr_new[140] = mr_old[92] # v7 DFSR -> aarch32 DFSR_NS,159 mr_new[143] = mr_old[93] # v7 IFSR -> aarch32 IFSR_NS,160 mr_new[155] = mr_old[94] # v7 DFAR -> aarch32 DFAR_NS,161 mr_new[158] = mr_old[95] # v7 IFAR -> aarch32 IFAR_NS,162 mr_new[84] = mr_old[96] # MPIDR,163 mr_new[241] = mr_old[97] # v7 PRRR -> aarch32 PRRR_NS,164 mr_new[247] = mr_old[98] # v7 NMRR -> aarch32 NMRR_NS,165 mr_new[131] = mr_old[99] # TTBCR,166 mr_new[86] = mr_old[100] # ID_PFR0,167 mr_new[81] = mr_old[101] # CTR,168 mr_new[115] = mr_old[102] # SCR,169 # Set the non-secure bit170 scr = int(mr_new[115])171 scr = scr | 0x1172 mr_new[115] = str(scr)173 ###174 mr_new[116] = mr_old[103] # SDER,175 mr_new[165] = mr_old[104] # PAR,176 mr_new[175] = mr_old[105] # V2PCWPR -> ATS1CPR,177 mr_new[176] = mr_old[106] # V2PCWPW -> ATS1CPW,178 mr_new[177] = mr_old[107] # V2PCWUR -> ATS1CUR,179 mr_new[178] = mr_old[108] # V2PCWUW -> ATS1CUW,180 mr_new[179] = mr_old[109] # V2POWPR -> ATS12NSOPR,181 mr_new[180] = mr_old[110] # V2POWPW -> ATS12NSOPW,182 mr_new[181] = mr_old[111] # V2POWUR -> ATS12NSOUR,183 mr_new[182] = mr_old[112] # V2POWUW -> ATS12NWOUW,184 mr_new[90] = mr_old[113] # ID_MMFR0,185 mr_new[92] = mr_old[114] # ID_MMFR2,186 mr_new[93] = mr_old[115] # ID_MMFR3,187 mr_new[112] = mr_old[116] # v7 ACTLR -> aarch32 ACTLR_NS188 mr_new[222] = mr_old[117] # PMCR,189 mr_new[230] = mr_old[118] # PMCCNTR,190 mr_new[223] = mr_old[119] # PMCNTENSET,191 mr_new[224] = mr_old[120] # PMCNTENCLR,192 mr_new[225] = mr_old[121] # PMOVSR,193 mr_new[226] = mr_old[122] # PMSWINC,194 mr_new[227] = mr_old[123] # PMSELR,195 mr_new[228] = mr_old[124] # PMCEID0,196 mr_new[229] = mr_old[125] # PMCEID1,197 mr_new[231] = mr_old[126] # PMXEVTYPER,198 mr_new[233] = mr_old[127] # PMXEVCNTR,199 mr_new[234] = mr_old[128] # PMUSERENR,200 mr_new[235] = mr_old[129] # PMINTENSET,201 mr_new[236] = mr_old[130] # PMINTENCLR,202 mr_new[94] = mr_old[131] # ID_ISAR0,203 mr_new[95] = mr_old[132] # ID_ISAR1,204 mr_new[96] = mr_old[133] # ID_ISAR2,205 mr_new[97] = mr_old[134] # ID_ISAR3,206 mr_new[98] = mr_old[135] # ID_ISAR4,207 mr_new[99] = mr_old[136] # ID_ISAR5,208 mr_new[20] = mr_old[137] # LOCKFLAG,209 mr_new[19] = mr_old[138] # LOCKADDR,210 mr_new[87] = mr_old[139] # ID_PFR1,211 # Set up the processor features register212 pfr = int(mr_new[87])213 pfr = pfr | 0x1011214 mr_new[87] = str(pfr)215 ###216 mr_new[238] = mr_old[140] # L2CTLR,217 mr_new[82] = mr_old[141] # TCMTR218 mr_new[88] = mr_old[142] # ID_DFR0,219 mr_new[89] = mr_old[143] # ID_AFR0,220 mr_new[91] = mr_old[144] # ID_MMFR1,221 mr_new[102] = mr_old[145] # AIDR,222 mr_new[146] = mr_old[146] # v7 ADFSR -> aarch32 ADFSR_NS,223 mr_new[148] = mr_old[147] # AIFSR,224 mr_new[173] = mr_old[148] # DCIMVAC,225 mr_new[174] = mr_old[149] # DCISW,226 mr_new[184] = mr_old[150] # MCCSW -> DCCSW,227 mr_new[187] = mr_old[151] # DCCMVAU,228 mr_new[117] = mr_old[152] # NSACR,229 mr_new[262] = mr_old[153] # VBAR,230 mr_new[265] = mr_old[154] # MVBAR,231 mr_new[267] = mr_old[155] # ISR,232 mr_new[269] = mr_old[156] # FCEIDR -> FCSEIDR,233 #mr_new[] = mr_old[157] # L2LATENCY -> UNUSED,234 #mr_new[] = mr_old[158] # CRN15 -> UNUSED,235 mr_new[599] = mr_old[159] # NOP236 mr_new[600] = mr_old[160] # RAZ,237 # Set the new miscRegs structure238 cpt.set(sec, 'miscRegs', ' '.join(str(x) for x in mr_new))239 cpu_prefix = {}240 # Add in state for ITB/DTB241 for sec in cpt.sections():242 re_tlb_match = re.match('(^.*?sys.*?\.cpu(\d+)*)\.(dtb|itb)$', sec)243 if not re_tlb_match:244 continue245 cpu_prefix[re_tlb_match.group(1)] = True # Save off prefix to add246 # Set the non-secure bit (bit 9) to 1 for attributes247 attr = int(cpt.get(sec, '_attr'))248 attr = attr | 0x200249 cpt.set(sec, '_attr', str(attr))250 cpt.set(sec, 'haveLPAE', 'false')251 cpt.set(sec, 'directToStage2', 'false')252 cpt.set(sec, 'stage2Req', 'false')253 cpt.set(sec, 'bootUncacheability', 'true')254 # Add in extra state for the new TLB Entries255 for sec in cpt.sections():256 re_tlbentry_match = re.match('(^.*?sys.*?\.cpu(\d+)*)\.(dtb|itb).TlbEntry\d+$', sec)257 if not re_tlbentry_match:258 continue259 # Add in the new entries260 cpt.set(sec, 'longDescFormat', 'false')261 cpt.set(sec, 'vmid', '0')262 cpt.set(sec, 'isHyp', 'false')263 valid = cpt.get(sec, 'valid')264 if valid == 'true':265 cpt.set(sec, 'ns', 'true')266 cpt.set(sec, 'nstid', 'true')267 cpt.set(sec, 'pxn', 'true')268 cpt.set(sec, 'hap', '3')269 # All v7 code used 2 level page tables270 cpt.set(sec, 'lookupLevel', '2')271 attr = int(cpt.get(sec, 'attributes'))272 # set the non-secure bit (bit 9) to 1273 # as no previous v7 code used secure code274 attr = attr | 0x200275 cpt.set(sec, 'attributes', str(attr))276 else:277 cpt.set(sec, 'ns', 'false')278 cpt.set(sec, 'nstid', 'false')279 cpt.set(sec, 'pxn', 'false')280 cpt.set(sec, 'hap', '0')281 cpt.set(sec, 'lookupLevel', '0')282 cpt.set(sec, 'outerShareable', 'false')283 # Add d/istage2_mmu and d/istage2_mmu.stage2_tlb284 for key in cpu_prefix:285 for suffix in ['.istage2_mmu', '.dstage2_mmu']:286 new_sec = key + suffix287 cpt.add_section(new_sec)288 new_sec = key + suffix + ".stage2_tlb"289 cpt.add_section(new_sec)290 # Fill in tlb info with some defaults291 cpt.set(new_sec, '_attr', '0')292 cpt.set(new_sec, 'haveLPAE', 'false')293 cpt.set(new_sec, 'directToStage2', 'false')294 cpt.set(new_sec, 'stage2Req', 'false')295 cpt.set(new_sec, 'bootUncacheability', 'false')296 cpt.set(new_sec, 'num_entries', '0')...

Full Screen

Full Screen

trapezoidal_map.py

Source:trapezoidal_map.py Github

copy

Full Screen

1import random2from typing import (List,3 Sequence)4from .bounding_box import BoundingBox5from .edge import Edge6from .leaf import Leaf7from .node import Node8from .point import Point9from .trapezoid import Trapezoid10from .x_node import XNode11from .y_node import YNode12def build_graph(points: Sequence[Point], shuffle: bool) -> Node:13 bounding_box = BoundingBox(True, Point(0, 0), Point(0, 0))14 points = list(points)15 points_count = len(points)16 for point in points:17 if not point.x:18 point.x = 019 if not point.y:20 point.y = 021 bounding_box.add(point)22 # Last 4 points are corner points of enclosing rectangle. Enclosing23 # rectangle made slightly larger in case corner points are already in the24 # triangulation.25 if bounding_box.empty:26 bounding_box.add(Point(0., 0.))27 bounding_box.add(Point(1., 1.))28 else:29 small = 0.1 # Any value > 0.30 bounding_box.expand((bounding_box.upper - bounding_box.lower) * small)31 edges = []32 for index in range(points_count):33 start, end = points[index], points[(index + 1) % points_count]34 edges.append(Edge(start, end)35 if end.is_right_of(start)36 else Edge(end, start))37 if shuffle:38 random.shuffle(edges)39 result = Leaf(bounding_box_to_trapezoid(bounding_box))40 for edge in edges:41 result = add_edge_to_graph(result, edge)42 return result43def bounding_box_to_trapezoid(box: BoundingBox) -> Trapezoid:44 return Trapezoid(box.lower, Point(box.upper.x, box.lower.y),45 Edge(box.lower, Point(box.upper.x, box.lower.y)),46 Edge(Point(box.lower.x, box.upper.y), box.upper))47def add_edge_to_graph(graph: Node, edge: Edge) -> Node:48 trapezoids = find_trapezoids_intersecting_edge(graph, edge)49 p = edge.left50 q = edge.right51 left_old = None # old trapezoid to the left.52 left_below = None # below trapezoid to the left.53 left_above = None # above trapezoid to the left.54 for index, old in enumerate(trapezoids):55 start_trap = index == 056 end_trap = index == len(trapezoids) - 157 have_left = start_trap and edge.left != old.left58 have_right = end_trap and edge.right != old.right59 left = right = None60 if start_trap and end_trap:61 if have_left:62 left = Trapezoid(old.left, p, old.below, old.above)63 below = Trapezoid(p, q, old.below, edge)64 above = Trapezoid(p, q, edge, old.above)65 if have_right:66 right = Trapezoid(q, old.right, old.below, old.above)67 if have_left:68 left.lower_left = old.lower_left69 left.upper_left = old.upper_left70 left.lower_right = below71 left.upper_right = above72 else:73 below.lower_left = old.lower_left74 above.upper_left = old.upper_left75 if have_right:76 right.lower_right = old.lower_right77 right.upper_right = old.upper_right78 below.lower_right = right79 above.upper_right = right80 else:81 below.lower_right = old.lower_right82 above.upper_right = old.upper_right83 elif start_trap:84 # Old trapezoid is the first of 2+ trapezoids85 # that the edge intersects.86 if have_left:87 left = Trapezoid(old.left, p, old.below, old.above)88 below = Trapezoid(p, old.right, old.below, edge)89 above = Trapezoid(p, old.right, edge, old.above)90 # Set pairs of trapezoid neighbours.91 if have_left:92 left.lower_left = old.lower_left93 left.upper_left = old.upper_left94 left.lower_right = below95 left.upper_right = above96 else:97 below.lower_left = old.lower_left98 above.upper_left = old.upper_left99 below.lower_right = old.lower_right100 above.upper_right = old.upper_right101 elif end_trap:102 # Old trapezoid is the last of 2+ trapezoids that the edge103 # intersects.104 if left_below.below == old.below:105 below = left_below106 below.right = q107 else:108 below = Trapezoid(old.left, q, old.below, edge)109 if left_above.above == old.above:110 above = left_above111 above.right = q112 else:113 above = Trapezoid(old.left, q, edge, old.above)114 if have_right:115 right = Trapezoid(q, old.right, old.below, old.above)116 # Set pairs of trapezoid neighbours.117 if have_right:118 right.lower_right = old.lower_right119 right.upper_right = old.upper_right120 below.lower_right = right121 above.upper_right = right122 else:123 below.lower_right = old.lower_right124 above.upper_right = old.upper_right125 # Connect to new trapezoids replacing old.126 if below != left_below:127 below.upper_left = left_below128 below.lower_left = (left_below129 if old.lower_left is left_old130 else old.lower_left)131 if above != left_above:132 above.lower_left = left_above133 above.upper_left = (left_above134 if old.upper_left is left_old135 else old.upper_left)136 else:137 # Middle trapezoid.138 # Old trapezoid is neither the first nor last of the 3+ trapezoids139 # that the edge intersects.140 if left_below.below == old.below:141 below = left_below142 below.right = old.right143 else:144 below = Trapezoid(old.left, old.right, old.below, edge)145 if left_above.above == old.above:146 above = left_above147 above.right = old.right148 else:149 above = Trapezoid(old.left, old.right, edge, old.above)150 # Connect to new trapezoids replacing prevOld.151 if below != left_below: # below is new.152 below.upper_left = left_below153 below.lower_left = (left_below154 if old.lower_left is left_old155 else old.lower_left)156 if above != left_above: # above is new.157 above.lower_left = left_above158 above.upper_left = (left_above159 if old.upper_left is left_old160 else old.upper_left)161 below.lower_right = old.lower_right162 above.upper_right = old.upper_right163 new_top_node = YNode(edge,164 below.trapezoid_node165 if below == left_below166 else Leaf(below),167 above.trapezoid_node168 if above == left_above169 else Leaf(above))170 if have_right:171 new_top_node = XNode(q, new_top_node, Leaf(right))172 if have_left:173 new_top_node = XNode(p, Leaf(left), new_top_node)174 old_node = old.trapezoid_node175 if old_node is graph:176 graph = new_top_node177 else:178 old_node.replace_with(new_top_node)179 if not end_trap:180 # Prepare for next loop.181 left_old = old182 left_above = above183 left_below = below184 return graph185def find_trapezoids_intersecting_edge(graph: Node,186 edge: Edge) -> List[Trapezoid]:187 trapezoid = graph.search_edge(edge)188 result = [trapezoid]189 while edge.right.is_right_of(trapezoid.right):190 orient = edge.orientation_with(trapezoid.right)191 assert orient, 'Unable to deal with point on edge.'192 if orient == -1:193 trapezoid = trapezoid.lower_right194 elif orient == 1:195 trapezoid = trapezoid.upper_right196 assert trapezoid is not None, ('Expected neighbour trapezoid, '197 'but none found.')198 result.append(trapezoid)...

Full Screen

Full Screen

sir.py

Source:sir.py Github

copy

Full Screen

1import matplotlib.pyplot as plt2import random as rn 3import numpy as np 4import statistics56n = 10_0007i0 = 58s0 = n-i09r = 01011a = 0.000212b = 0.51314r0 = (a*s0)/b1516def set_title():17 title = 'Comportamento delle 3 funzioni con r0:'+str(r0)18 plt.title(title)19 plt.xlabel('Giorni')20 plt.ylabel('Abitanti')2122def abline(slope,x1,y1):23 """Plot a line from slope and intercept"""24 axes = plt.gca()25 x_vals = np.array(axes.get_xlim())26 for i in range(len(x_vals)):27 x_vals[i] += 228 y_vals = slope*x_vals-slope*x1+y129 plt.plot(x_vals, y_vals, '--')3031def drange(start, stop, step):32 while start < stop:33 yield start34 start += step3536def nextSs(a,oldS,oldI,t):37 out = oldS - (a*oldS*oldI)*t38 return out 394041def nextIs(a,b,oldS,oldI,t):42 out = oldI + (a*oldS*oldI)*t - (b*oldI)*t43 return out4445def nextRs(b,r,oldI,t):46 out = r + (b*oldI)*t47 return out4849def connect(old, new,i,c,step):50 plt.plot([i-step,i],[old,new],c)51525354def simple_plot():55 set_title()5657 for i in range(25):58 if i == 0:59 S = s060 I = i061 R = r62 print('S0 is: ',S)63 else:64 print('-----------------')65 oldS = S66 print('old S: ',oldS)67 oldI = I68 print('old I: ',oldI)69 oldR = R70 print('old R: ',oldR)7172 73 S = nextSs(a,oldS,oldI,1)74 I = nextIs(a,b,oldS,oldI,1)75 R = nextRs(b,oldR,oldI,1)76 print('S nuovo giorno: ', S)77 print('I nuovo giorno: ', I)7879 connect(oldS,S,i,'r-',1)80 connect(oldI,I,i,'b-',1)81 connect(oldR,R,i,'g-',1)8283 plt.plot(i,S,'ro')84 plt.plot(i,I,'Hb')85 plt.plot(i,R,'sg')8687 plt.show()8889#simple_plot()9091step = 0.0192def disc_plot():93 set_title()94 step = 0.29596 for i in drange(0,25,step):97 if i == 0:98 S = s099 I = i0100 R = r101 print('S0 is: ',S)102 else:103 print('-----------------')104 oldS = S105 print('old S: ',oldS)106 oldI = I107 print('old I: ',oldI)108 oldR = R109 print('old R: ',oldR)110111 112 S = nextSs(a,oldS,oldI, step)113 I = nextIs(a,b,oldS,oldI, step)114 R = nextRs(b,oldR,oldI, step)115 print('S nuovo giorno: ', S)116 print('I nuovo giorno: ', I)117118 connect(oldS,S,i,'r-',step)119 connect(oldI,I,i,'b-',step)120 connect(oldR,R,i,'g-',step)121122 plt.plot(i,S,'ro')123 plt.plot(i,I,'Hb')124 plt.plot(i,R,'sg')125126 plt.show()127#disc_plot()128129def r0_variation():130 131 for i in range(10):132 print('Grafico n.',i+1)133 a = 0.0002134 print('initial a:', a)135 delta = rn.randrange(-19,19)136 delta = delta *10**-5137 print('random delta:', delta)138 a = a + delta139 print('final a:', a)140 print('---------------------------')141142 r0 = (a*s0)/b143 disc_plot()144145146def plot_total_new():147 #plt.title('Variazione di S nel tempo')148 #plt.xlabel('Giorni')149 #plt.ylabel('Abitanti')150151 step = 0.01152153 for i in drange(0,15,step):154 155 if i == 0:156 S = s0157 I = i0158 R = r159160 print('S0 is: ',S)161162163 tot_case = I+R164 #_r = r0165 else:166 print('-----------------')167 print('day: ',i)168 oldS = S169 print('old S: ',oldS)170 oldI = I171 print('old I: ',oldI)172 oldR = R173 print('old R: ',oldR)174175 #oldTot = tot_case176 #old_r = _r177178 S = nextSs(a,oldS,oldI, step)179 I = nextIs(a,b,oldS,oldI, step)180 R = nextRs(b,oldR,oldI, step)181 print('S nuovo giorno: ', S)182 print('I nuovo giorno: ', I)183184 tot_case = I + R185 #_r = (a*S)/b186187 #connect(oldTot,tot_case,i,'-r',step)188 #connect(oldI,I,i,'-b',step)189 #connect(oldS, S,i,'-g',step)190 #connect(old_r,_r,i,'-b',step)191192 #plt.plot(i,tot_case, 'ro')193 #plt.plot(i,S, 'go')194 #plt.plot(i,I,'bo')195 #plt.plot(i,_r,'bo')196197 198 if i == 6.009999999999916:199 #make pie200 labels = 'Infetti', 'Rimossi'201 colors = ['lightcoral', 'lightskyblue']202 sizes = [I,R]203204 plt.pie(sizes, labels=labels, colors=colors,205 autopct='%1.1f%%', shadow=True, startangle=140)206207208209 plt.axis('equal')210 plt.show()211 212 213 plt.show()214plot_total_new()215216def plot_total_and_der():217 step = 0.01218 casi_list = []219 derivate_list = []220221 plt.title('Casi totali, Derivata e nuovi casi')222 plt.xlabel('Giorni')223 plt.ylabel('Abitanti')224225 for i in drange(0,15,step):226 if i == 0:227 S = s0228 I = i0229 R = r230 print('S0 is: ',S)231 tot_case = I+R232 derivata = 0233 else:234 #print('-----------------')235 oldS = S236 #print('old S: ',oldS)237 oldI = I238 #print('old I: ',oldI)239 oldR = R240 #print('old R: ',oldR)241242 oldTot = tot_case243 oldD = derivata244245 S = nextSs(a,oldS,oldI, step)246 I = nextIs(a,b,oldS,oldI, step)247 R = nextRs(b,oldR,oldI, step)248 #print('S nuovo giorno: ', S)249 #print('I nuovo giorno: ', I)250251 tot_case = I + R252 derivataI = (I-oldI)/step253 derivata = (tot_case-oldTot)/step254255 #connect(oldTot,tot_case,i,'-r',step)256 connect(oldD,derivata,i,'-g',step)257 connect(oldI,I,i,'-b',step)258259 #plt.plot(i,tot_case, 'ro')260 plt.plot(i,derivata,'go')261 plt.plot(i,I,'bo')262263 '''264 #traccia rette con coef deriv265 if i==4.89999999999994:266 #print('here')267 abline(derivata,i,tot_case)268 if i==6.999999999999895:269 abline(derivata,i,tot_case)270 '''271272 casi_list.append(tot_case)273 derivate_list.append(derivata)274 275 print('\n\n\n------ Risultati: --------')276 maxi = 0277 #trovare 'derivata massima'278 for i in range(len(derivate_list)):279 if i == 0:280 maxi = derivate_list[i]281 else:282 if derivate_list[i] >= maxi:283 maxi = derivate_list[i]284 corrispondente_i = i285 print('Coefficente in punto massimo della crescita:', maxi)286 print('X nel giorno di massima crescita:', corrispondente_i*10**-2)287288 for i in range(len(casi_list)):289 if i!=0 and i!=1:290 grow = (casi_list[i]-casi_list[i-1])/(casi_list[i-1]-casi_list[i-2])291 #print(grow)292 if grow == 1.0000960554645488:293 print('X del punto di flesso : ',i*10**-2)294295 '''296 moltiplicatori = []297 for i in range(200,300):298 moltiplicatore = casi_list[i+100]/casi_list[i]299 moltiplicatori.append(moltiplicatore)300 print(moltiplicatori)301 maximum = max(moltiplicatori)302 print(maximum)303 for i in drange(0,5,step):304 y=maximum**i305 plt.plot(i,y,'bo')306 '''307308 plt.show()309plot_total_and_der()310311 ...

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 Testify 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