How to use _default_weight method in Molotov

Best Python code snippet using molotov_python

wnconfig.py

Source: wnconfig.py Github

copy

Full Screen

1import logging, re, os, os.path, sys234class Config(object):56 def __init__(self):7 #self._names = names89 self.disable_fuzzy = False10 self.classify = False11 self.classify_bank = False12 self._hashtypes_missing = None # print only certain hashtypes1314 self.sort_always = False15 self._default_weight = 10016 self._sort_weights = []1718 def add_config(self, line):19 if line.startswith('#@nofuzzy'):20 self.disable_fuzzy = True2122 if line.startswith('#@classify'):23 self.classify = True24 if line.startswith('#@classify-bank'): #implicit: sets the above25 self.classify_bank = True2627 if line.startswith('#@hashtypes-missing'):28 line = line.replace('#@hashtypes-missing', '')29 self._hashtypes_missing = [item.lower().strip() for item in line.split()]3031 if line.startswith('#@sort-always'):32 self.sort_always = True33 if line.startswith('#@sort-weight') or line.startswith('#@sw'):34 self._add_sort_weight(line)3536 def add_lines(self, lines):37 if self.disable_fuzzy:38 lines.append('#@nofuzzy')39 if self.classify_bank:40 lines.append('#@classify-bank')41 elif self.classify:42 lines.append('#@classify')43 elif self._hashtypes_missing:44 lines.append('#@hashtypes-missing ' + ' '.join(self._hashtypes_missing))4546 def skip_hastype(self, hashtype):47 return self._hashtypes_missing and hashtype not in self._hashtypes_missing484950 # TODO maybe generate again when cleaning wwnames5152 # defined sorting weight, where higher = lower priority (0=top, 100=default, 999=lowest). examples:53 # group=value 10 # exact match54 # group*=value* 20 # partial match55 # group=- 999 # by default "any" has highest56 # value 20 # same as *=value57 #58 def _add_sort_weight(self, line):59 line = line.strip()60 elems = line.split(" ")61 if len(elems) != 3:62 logging.info("names: ignored weight %s", line )63 return64 match = elems[1]65 weight = elems[2]66 if not weight.isnumeric():67 logging.info("names: ignored weight %s", line )68 return6970 if '*' == match:71 self._default_weight = weight72 else:73 if '=' in match:74 gv = match.split("=")75 g_wr = self._get_weight_regex(gv[0])76 v_wr = self._get_weight_regex(gv[1])77 item = (g_wr, v_wr, weight)78 else:79 v_wr = self._get_weight_regex(match)80 item = (None, v_wr, weight)81 self._sort_weights.append(item)8283 def _get_weight_regex(self, text_in):84 if '*' in text_in:85 replaces = { '(':'\(', ')':'\)', '[':'\[', ']':'\]', '.':'\.', '*':'.*?' }86 regex_in = text_in87 for key, val in replaces.items():88 regex_in = regex_in.replace(key, val)89 regex = re.compile(regex_in, re.IGNORECASE)90 else:91 regex = re.compile(re.escape(text_in), re.IGNORECASE)92 return regex9394 def get_weight(self, groupname, valuename):95 for g_wr, v_wr, weight in self._sort_weights:96 if not g_wr:97 if v_wr.match(valuename):98 return weight99 else:100 if g_wr.match(groupname) and v_wr.match(valuename):101 return weight102103 if valuename == '-': #any usually goes first, unless overwritten104 return 0 ...

Full Screen

Full Screen

heatmap.py

Source: heatmap.py Github

copy

Full Screen

1from collections import namedtuple2from gmplot.utility import _get, _format_LatLng3class _Heatmap(object):4 _DEFAULT_WEIGHT = 15 _Point = namedtuple('Point', ['location', 'weight'])6 def __init__(self, lats, lngs, precision, **kwargs):7 '''8 Args:9 lats ([float]): Latitudes.10 lngs ([float]): Longitudes.11 precision (int): Number of digits after the decimal to round to for lat/​lng values.12 Optional:13 Args:14 radius (int): Radius of influence for each data point, in pixels.15 gradient ([(int, int, int, float)]): Color gradient of the heatmap, as a list of `RGBA`_ colors.16 The color order defines the gradient moving towards the center of a point.17 opacity (float): Opacity of the heatmap, ranging from 0 to 1.18 max_intensity (int): Maximum intensity of the heatmap.19 dissipating (bool): True to dissipate the heatmap on zooming, False to disable dissipation.20 weights ([float]): List of weights corresponding to each data point. Each point has a weight21 of 1 by default. Specifying a weight of N is equivalent to plotting the same point N times.22 23 .. _RGBA: https:/​/​www.w3.org/​TR/​css-color-3/​#rgba-color24 '''25 weights = _get(kwargs, ['weights'], [self._DEFAULT_WEIGHT] * len(lats))26 self._points = [self._Point(_format_LatLng(lat, lng, precision), weight) for lat, lng, weight in zip(lats, lngs, weights)]27 self._radius = kwargs.get('radius')28 self._gradient = kwargs.get('gradient')29 self._opacity = kwargs.get('opacity')30 self._max_intensity = kwargs.get('max_intensity')31 self._dissipating = kwargs.get('dissipating')32 def write(self, w):33 '''34 Write the heatmap.35 Args:36 w (_Writer): Writer used to write the heatmap.37 '''38 w.write('new google.maps.visualization.HeatmapLayer({')39 w.indent()40 if self._radius is not None: w.write('radius: %d,' % self._radius)41 if self._max_intensity is not None: w.write('maxIntensity: %d,' % self._max_intensity)42 if self._opacity is not None: w.write('opacity: %f,' % self._opacity)43 if self._dissipating is False: w.write('dissipating: false,')44 if self._gradient:45 w.write('gradient: [')46 w.indent()47 for r, g, b, a in self._gradient:48 w.write('"rgba(%d, %d, %d, %f)",' % (r, g, b, a))49 w.dedent()50 w.write('],')51 w.write('map: map,')52 w.write('data: [')53 w.indent()54 for point in self._points:55 if point.weight == self._DEFAULT_WEIGHT:56 w.write('%s,' % point.location)57 else:58 w.write('{location: %s, weight: %f},' % (point.location, point.weight))59 w.dedent()60 w.write(']')61 w.dedent()62 w.write('});')...

Full Screen

Full Screen

nodescraper.py

Source: nodescraper.py Github

copy

Full Screen

1_NAME_WEIGHT = 22_DEFAULT_WEIGHT = 13# generic parent class4class NodeScraper:5 def __init__(self, node):6 self.node = node7 def extract_content(self):8 # by default, just extract the name9 name = (self.node["name"], _NAME_WEIGHT)10 return [name]11class CourseNodeScraper(NodeScraper):12 def extract_content(self):13 # grab the default scraped info14 content = super().extract_content()15 # extract description and subjects16 description = (self.node["description"] or "", _DEFAULT_WEIGHT)17 subjects = map(lambda x: (x["name"], _DEFAULT_WEIGHT), self.node["subjects"])18 content.extend(subjects)19 content.append(description)20 return content21class SubjectNodeScraper(NodeScraper):22 def extract_content(self):23 # grab the default24 content = super().extract_content()25 # throw in abbreviation26 abbreviation = (self.node["abbreviation"], _DEFAULT_WEIGHT)27 content.append(abbreviation)28 return content29# supported scraper types30__node_scraper_map = {31 'CourseNode': CourseNodeScraper,32 'SubjectNode': SubjectNodeScraper,33 'InstructorNode': NodeScraper34}35def scrape_node_contents(node):36 node_type = node["nodeType"]37 # ignore if node type not supported38 if node_type not in __node_scraper_map.keys():39 return40 # instantiate a scraper41 scraper_type = __node_scraper_map[node_type]42 scraper = scraper_type(node)43 # grab content from scraper44 content = scraper.extract_content()...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

Fault-Based Testing and the Pesticide Paradox

In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.

A Reconsideration of Software Testing Metrics

There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?

An Interactive Guide To CSS Hover Effects

Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

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