How to use _get_parameter_string method in Slash

Best Python code snippet using slash

recommendations.py

Source:recommendations.py Github

copy

Full Screen

...43 # Removes the distance from the dictionaries and returns the best n tracks.44 for d in ordered_songs:45 del d['distance']46 return ordered_songs[:n]47def _get_parameter_string(min_key=-1, min_mode=0,48 min_acousticness=0.0, min_danceablility=0.0,49 min_energy=0.0, min_instrumentalness=0.0,50 min_liveness=0.0, min_loudness=-60,51 min_speechiness=0.0, min_valence=0.0, min_tempo=0,52 max_key=11, max_mode=1,53 max_acousticness=1.0, max_danceablility=1.0,54 max_energy=1.0, max_instrumentalness=1.0,55 max_liveness=1.0, max_loudness=0,56 max_speechiness=1.0, max_valence=1.0, max_tempo=99999):57 """ Fills in emtpy parameters with their default value. """58 return (f"&min_key={min_key}&max_key={max_key}" +59 f"&min_mode={min_mode}&max_mode={max_mode}" +60 f"&min_acousticness={min_acousticness}&max_acousticness={max_acousticness}" +61 f"&min_danceablility={min_danceablility}&max_danceablility={max_danceablility}" +62 f"&min_energy={min_energy}&max_energy={max_energy}" +63 f"&min_instrumentalness={min_instrumentalness}&max_instrumentalness={max_instrumentalness}" +64 f"&min_liveness={min_liveness}&max_liveness={max_liveness}" +65 f"&min_loudness={min_loudness}&max_loudness={max_loudness}" +66 f"&min_speechiness={min_speechiness}&max_speechiness={max_speechiness}" +67 f"&min_valence={min_valence}&max_valence={max_valence}" +68 f"&min_tempo={min_tempo}&max_tempo={max_tempo}")69def calculate_target_mood(target, current):70 """71 Updates the target mood, the new mood is the weighted mean between the target and current.72 :param target: the target mood formatted as: (excitedness, happiness).73 :param current: the current mood formatted as: (excitedness, happiness).74 :return: new target formatted as: (excitedness, happiness).75 """76 return 0.6 *target[0] + 0.4 * current[0], 0.6 * target[1] + 0.4 * current[1]77def recommend_input(tracks, userid, target=(0.0, 0.0), n=5):78 """79 Find recommendations given max 5 song ID's.80 The recommendations are based on the given songs and the given target mood.81 :param tracks: list of given songs.82 :param userid: Spotify user id of the user.83 :param target: the target mood formatted as: (excitedness, happiness).84 :param n: the amount of recommendations that are returned, standard is 5.85 :return: ascending list of n dictionaries formatted as:86 [{'songid': actual song id, excitedness: actual excitedness, happiness: actual happiness}].87 """88 access_token = spotify.get_access_token(User.get_refresh_token(userid))89 return find_song_recommendations(access_token, tracks, target, n, _get_parameter_string())90def recommend_metric(tracks, userid, metric, excitedness, happiness, n=5):91 """92 Find recommendations based on the last 5 songs, the given metric and the current mood.93 :param tracks: list of given songs.94 :param userid: Spotify user id of the user.95 :param metric: keywords for moods and events, the possible keywords are: sad, mellow, angry, excited, dance, study,96 karaoke, neutral.97 :param excitedness: the excitedness of a user.98 :param happiness: the happiness of a user.99 :param n: the amount of recommendations that are returned, standard is 5.100 :return: ascending list of n dictionaries formatted as: [{'songid': actual song id, excitedness: actual excitedness,101 happiness: actual happiness}].102 """103 moods = {'sad': (-10, -10), 'mellow': (-10, 10), 'angry': (10, -10), 'excited': (10, 10), }104 events = {'dance': _get_parameter_string(min_danceablility=0.4,105 min_energy=0.5, min_loudness=-10, min_speechiness=0.0,106 min_tempo=60, max_acousticness=0.2,107 max_instrumentalness=0.15, max_loudness=-2, max_speechiness=0.3,108 max_tempo=130),109 'study': _get_parameter_string(min_acousticness=0.6,110 min_instrumentalness=0.5, min_loudness=-30,111 max_danceablility=0.1, max_energy=0.35, max_instrumentalness=1.0,112 max_loudness=-10, max_speechiness=0.1),113 'karaoke': _get_parameter_string(min_energy=0.1,114 min_loudness=-15, max_instrumentalness=0.15,115 max_loudness=-4, max_speechiness=0.2),116 'neutral': _get_parameter_string()}117 access_token = spotify.get_access_token(User.get_refresh_token(userid))118 # Calculates the target mood and recommends songs based on this target.119 if metric in moods:120 target = calculate_target_mood(moods[metric], (excitedness, happiness))121 return find_song_recommendations(access_token, tracks, target, n, _get_parameter_string())122 # Recommends songs based on parameters corresponding to events, the target mood is the current mood.123 if metric in events:124 return find_song_recommendations(access_token, tracks, (excitedness, happiness), n, events[metric])125def find_song_recommendations(access_token, tracks, target, n, params):126 """127 Find recommendations based on the last 5 songs, the given metric and the current mood.128 :param access_token: A valid access token from the Spotify Accounts service.129 :param tracks: list of given songs.130 :param target: the target mood formatted as: (excitedness, happiness).131 :param n: the amount of recommendations that are returned, standard is 5.132 :param params: Audio feature parameters.133 :return: ascending list of n dictionaries formatted as:134 [{'songid': actual song id, excitedness: actual excitedness, happiness: actual happiness}].135 """...

Full Screen

Full Screen

function.py

Source:function.py Github

copy

Full Screen

...49 def _body_context(self, code_formatter):50 self._write_decorators(code_formatter)51 code_formatter.writeln('def {}({}):'.format(52 self._get_function_name(),53 self._get_parameter_string()))54 with code_formatter.indented():55 if not self.suite.debug_info:56 code_formatter.writeln('pass')57 self._write_parameter_values(code_formatter)58 self._write_immediate_events(code_formatter)59 self._write_deferred_events(code_formatter)60 self._write_prologue(code_formatter)61 yield62 self._write_epilogue(code_formatter)63 self._write_return(code_formatter)64 code_formatter.writeln()65 def _get_parameter_string(self):66 returned = ', '.join(self._get_argument_strings())67 if returned and self._additional_parameter_string:68 returned += ', '69 returned += self._additional_parameter_string70 return returned71 def _write_prologue(self, code_formatter):72 pass73 def _write_epilogue(self, code_formatter):74 pass75 def _write_immediate_events(self, code_formatter):76 for event in self._events:77 self._write_event(code_formatter, event)78 def _write_deferred_events(self, code_formatter):79 if not self.suite.debug_info:...

Full Screen

Full Screen

Vulnerabilities.py

Source:Vulnerabilities.py Github

copy

Full Screen

...6logger = logging.getLogger(__name__)7def _get_vulnerabilities_url(self):8 return self.config['baseurl'] + '/api/vulnerabilities'9def get_vulnerabilities(self, vulnerability, parameters={}):10 url = self._get_vulnerabilities_url() + "/{}".format(vulnerability) + self._get_parameter_string(parameters)11 headers = {'Accept': 'application/vnd.blackducksoftware.vulnerability-4+json'}12 response = self.execute_get(url, custom_headers=headers)13 return response.json()14def get_vulnerability_affected_projects(self, vulnerability):15 url = self._get_vulnerabilities_url() + "/{}/affected-projects".format(vulnerability) 16 custom_headers = {'Accept': 'application/vnd.blackducksoftware.vulnerability-4+json'}17 response = self.execute_get(url, custom_headers=custom_headers)18 return response.json()19# TODO: Refactor this, i.e. use get_link method?20def get_vulnerable_bom_components(self, version_obj, limit=9999):21 url = "{}/vulnerable-bom-components".format(version_obj['_meta']['href'])22 custom_headers = {'Accept': 'application/vnd.blackducksoftware.bill-of-materials-6+json'}23 param_string = self._get_parameter_string({'limit': limit})24 url = "{}{}".format(url, param_string)25 response = self.execute_get(url, custom_headers=custom_headers)26 return response.json()27# TODO: Remove or refactor this28def get_component_remediation(self, bom_component):29 url = "{}/remediating".format(bom_component['componentVersion'])30 logger.debug("Url for getting remediation info is : {}".format(url))31 response = self.execute_get(url)...

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