How to use threshold method in wpt

Best JavaScript code snippet using wpt

test_threshold_optimization_plugin.py

Source:test_threshold_optimization_plugin.py Github

copy

Full Screen

1import plugins.threshold_optimization_plugin as threshold_optimization_plugin2import protobuf.pb_util as pb_util3import unittest4import bson5MAKAI_CONFIG = {6 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),7 "triggering": {8 "default_ref_f": 60,9 "default_ref_v": 120,10 "default_threshold_percent_f_low": 0.5,11 "default_threshold_percent_f_high": 0.5,12 "default_threshold_percent_v_low": 2.5,13 "default_threshold_percent_v_high": 2.5,14 "default_threshold_percent_thd_high": 3,15 "triggering_overrides": [16 {17 "box_id": "0",18 "ref_f": 60,19 "ref_v": 120,20 "threshold_percent_f_low": 1,21 "threshold_percent_f_high": 1,22 "threshold_percent_v_low": 5,23 "threshold_percent_v_high": 5,24 "threshold_percent_thd_high": 525 },26 {27 "box_id": "1003",28 "ref_f": 60,29 "ref_v": 120,30 "threshold_percent_f_low": 0.5,31 "threshold_percent_f_high": 0.5,32 "threshold_percent_v_low": 2.5,33 "threshold_percent_v_high": 2.5,34 "threshold_percent_thd_high": 335 },36 {37 "box_id": "2001",38 "ref_f": 60,39 "ref_v": 120,40 "threshold_percent_f_low": 0.5,41 "threshold_percent_f_high": 0.5,42 "threshold_percent_v_low": 2.5,43 "threshold_percent_v_high": 2.5,44 "threshold_percent_thd_high": 345 }46 ]47 }48}49class ThresholdOptimizationPluginTests(unittest.TestCase):50 def setUp(self) -> None:51 self.makai_config_doc = MAKAI_CONFIG52 self.makai_config = threshold_optimization_plugin.MakaiConfig(self.makai_config_doc)53 def test_default_override(self):54 override = threshold_optimization_plugin._default_override(self.makai_config, "5000")55 self.assertEqual(override.as_dict(), {56 "box_id": "5000",57 "ref_f": 60,58 "ref_v": 120,59 "threshold_percent_f_low": 0.5,60 "threshold_percent_f_high": 0.5,61 "threshold_percent_v_low": 2.5,62 "threshold_percent_v_high": 2.5,63 "threshold_percent_thd_high": 364 })65 def test_trigger_override_single(self):66 override = threshold_optimization_plugin._default_override(self.makai_config, "5000")67 threshold_req = pb_util.build_threshold_optimization_request("test", ref_f=61).threshold_optimization_request68 override.modify_thresholds(threshold_req)69 self.assertEqual(override.as_dict(),70 {71 "box_id": "5000",72 "ref_f": 61,73 "ref_v": 120,74 "threshold_percent_f_low": 0.5,75 "threshold_percent_f_high": 0.5,76 "threshold_percent_v_low": 2.5,77 "threshold_percent_v_high": 2.5,78 "threshold_percent_thd_high": 379 })80 def test_trigger_override_none(self):81 override = threshold_optimization_plugin._default_override(self.makai_config, "5000")82 threshold_req = pb_util.build_threshold_optimization_request("test").threshold_optimization_request83 override.modify_thresholds(threshold_req)84 self.assertEqual(override.as_dict(),85 {86 "box_id": "5000",87 "ref_f": 60,88 "ref_v": 120,89 "threshold_percent_f_low": 0.5,90 "threshold_percent_f_high": 0.5,91 "threshold_percent_v_low": 2.5,92 "threshold_percent_v_high": 2.5,93 "threshold_percent_thd_high": 394 })95 def test_trigger_override_multi(self):96 override = threshold_optimization_plugin._default_override(self.makai_config, "5000")97 threshold_req = pb_util.build_threshold_optimization_request("test",98 ref_v=121,99 threshold_percent_f_low=20.5).threshold_optimization_request100 override.modify_thresholds(threshold_req)101 self.assertEqual(override.as_dict(),102 {103 "box_id": "5000",104 "ref_f": 60,105 "ref_v": 121,106 "threshold_percent_f_low": 20.5,107 "threshold_percent_f_high": 0.5,108 "threshold_percent_v_low": 2.5,109 "threshold_percent_v_high": 2.5,110 "threshold_percent_thd_high": 3111 })112 def test_makai_config_none(self):113 threshold_req = pb_util.build_threshold_optimization_request("test").threshold_optimization_request114 self.makai_config.modify_thresholds(threshold_req)115 self.assertEqual(self.makai_config.as_dict(), MAKAI_CONFIG)116 def test_makai_config_default_single(self):117 threshold_req = pb_util.build_threshold_optimization_request("test",118 default_ref_f=61).threshold_optimization_request119 self.makai_config.modify_thresholds(threshold_req)120 self.assertEqual(self.makai_config.as_dict(), {121 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),122 "triggering": {123 "default_ref_f": 61,124 "default_ref_v": 120,125 "default_threshold_percent_f_low": 0.5,126 "default_threshold_percent_f_high": 0.5,127 "default_threshold_percent_v_low": 2.5,128 "default_threshold_percent_v_high": 2.5,129 "default_threshold_percent_thd_high": 3,130 "triggering_overrides": [131 {132 "box_id": "0",133 "ref_f": 60,134 "ref_v": 120,135 "threshold_percent_f_low": 1,136 "threshold_percent_f_high": 1,137 "threshold_percent_v_low": 5,138 "threshold_percent_v_high": 5,139 "threshold_percent_thd_high": 5140 },141 {142 "box_id": "1003",143 "ref_f": 60,144 "ref_v": 120,145 "threshold_percent_f_low": 0.5,146 "threshold_percent_f_high": 0.5,147 "threshold_percent_v_low": 2.5,148 "threshold_percent_v_high": 2.5,149 "threshold_percent_thd_high": 3150 },151 {152 "box_id": "2001",153 "ref_f": 60,154 "ref_v": 120,155 "threshold_percent_f_low": 0.5,156 "threshold_percent_f_high": 0.5,157 "threshold_percent_v_low": 2.5,158 "threshold_percent_v_high": 2.5,159 "threshold_percent_thd_high": 3160 }161 ]162 }163 }164 )165 def test_makai_config_default_multi(self):166 threshold_req = pb_util.build_threshold_optimization_request("test",167 default_ref_f=61,168 default_threshold_percent_f_low=20).threshold_optimization_request169 self.makai_config.modify_thresholds(threshold_req)170 self.assertEqual(self.makai_config.as_dict(), {171 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),172 "triggering": {173 "default_ref_f": 61,174 "default_ref_v": 120,175 "default_threshold_percent_f_low": 20,176 "default_threshold_percent_f_high": 0.5,177 "default_threshold_percent_v_low": 2.5,178 "default_threshold_percent_v_high": 2.5,179 "default_threshold_percent_thd_high": 3,180 "triggering_overrides": [181 {182 "box_id": "0",183 "ref_f": 60,184 "ref_v": 120,185 "threshold_percent_f_low": 1,186 "threshold_percent_f_high": 1,187 "threshold_percent_v_low": 5,188 "threshold_percent_v_high": 5,189 "threshold_percent_thd_high": 5190 },191 {192 "box_id": "1003",193 "ref_f": 60,194 "ref_v": 120,195 "threshold_percent_f_low": 0.5,196 "threshold_percent_f_high": 0.5,197 "threshold_percent_v_low": 2.5,198 "threshold_percent_v_high": 2.5,199 "threshold_percent_thd_high": 3200 },201 {202 "box_id": "2001",203 "ref_f": 60,204 "ref_v": 120,205 "threshold_percent_f_low": 0.5,206 "threshold_percent_f_high": 0.5,207 "threshold_percent_v_low": 2.5,208 "threshold_percent_v_high": 2.5,209 "threshold_percent_thd_high": 3210 }211 ]212 }213 }214 )215 def test_makai_config_default_new_override(self):216 threshold_req = pb_util.build_threshold_optimization_request("test",217 box_id="6000",218 ref_f=61).threshold_optimization_request219 self.makai_config.modify_thresholds(threshold_req)220 self.assertEqual(self.makai_config.as_dict(), {221 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),222 "triggering": {223 "default_ref_f": 60,224 "default_ref_v": 120,225 "default_threshold_percent_f_low": 0.5,226 "default_threshold_percent_f_high": 0.5,227 "default_threshold_percent_v_low": 2.5,228 "default_threshold_percent_v_high": 2.5,229 "default_threshold_percent_thd_high": 3,230 "triggering_overrides": [231 {232 "box_id": "0",233 "ref_f": 60,234 "ref_v": 120,235 "threshold_percent_f_low": 1,236 "threshold_percent_f_high": 1,237 "threshold_percent_v_low": 5,238 "threshold_percent_v_high": 5,239 "threshold_percent_thd_high": 5240 },241 {242 "box_id": "1003",243 "ref_f": 60,244 "ref_v": 120,245 "threshold_percent_f_low": 0.5,246 "threshold_percent_f_high": 0.5,247 "threshold_percent_v_low": 2.5,248 "threshold_percent_v_high": 2.5,249 "threshold_percent_thd_high": 3250 },251 {252 "box_id": "2001",253 "ref_f": 60,254 "ref_v": 120,255 "threshold_percent_f_low": 0.5,256 "threshold_percent_f_high": 0.5,257 "threshold_percent_v_low": 2.5,258 "threshold_percent_v_high": 2.5,259 "threshold_percent_thd_high": 3260 },261 {262 "box_id": "6000",263 "ref_f": 61.0,264 "ref_v": 120,265 "threshold_percent_f_low": 0.5,266 "threshold_percent_f_high": 0.5,267 "threshold_percent_v_low": 2.5,268 "threshold_percent_v_high": 2.5,269 "threshold_percent_thd_high": 3270 }271 ]272 }273 }274 )275 def test_makai_config_default_override(self):276 threshold_req = pb_util.build_threshold_optimization_request("test",277 box_id="0",278 ref_f=61).threshold_optimization_request279 self.makai_config.modify_thresholds(threshold_req)280 self.assertEqual(self.makai_config.as_dict(), {281 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),282 "triggering": {283 "default_ref_f": 60,284 "default_ref_v": 120,285 "default_threshold_percent_f_low": 0.5,286 "default_threshold_percent_f_high": 0.5,287 "default_threshold_percent_v_low": 2.5,288 "default_threshold_percent_v_high": 2.5,289 "default_threshold_percent_thd_high": 3,290 "triggering_overrides": [291 {292 "box_id": "0",293 "ref_f": 61.0,294 "ref_v": 120,295 "threshold_percent_f_low": 1,296 "threshold_percent_f_high": 1,297 "threshold_percent_v_low": 5,298 "threshold_percent_v_high": 5,299 "threshold_percent_thd_high": 5300 },301 {302 "box_id": "1003",303 "ref_f": 60,304 "ref_v": 120,305 "threshold_percent_f_low": 0.5,306 "threshold_percent_f_high": 0.5,307 "threshold_percent_v_low": 2.5,308 "threshold_percent_v_high": 2.5,309 "threshold_percent_thd_high": 3310 },311 {312 "box_id": "2001",313 "ref_f": 60,314 "ref_v": 120,315 "threshold_percent_f_low": 0.5,316 "threshold_percent_f_high": 0.5,317 "threshold_percent_v_low": 2.5,318 "threshold_percent_v_high": 2.5,319 "threshold_percent_thd_high": 3320 }321 ]322 }323 }324 )325 def test_makai_config_all(self):326 threshold_req = pb_util.build_threshold_optimization_request("test",327 default_ref_f=1,328 default_ref_v=1,329 default_threshold_percent_f_low=1,330 default_threshold_percent_f_high=1,331 default_threshold_percent_v_low=1,332 default_threshold_percent_v_high=1,333 default_threshold_percent_thd_high=1,334 ref_f=2,335 ref_v=2,336 threshold_percent_f_low=2,337 threshold_percent_f_high=2,338 threshold_percent_v_low=2,339 threshold_percent_v_high=2,340 threshold_percent_thd_high=2,341 box_id="0",342 ).threshold_optimization_request343 self.makai_config.modify_thresholds(threshold_req)344 self.assertEqual(self.makai_config.as_dict(), {345 "_id": bson.ObjectId("5cd2152d49de19d1ea2b7a25"),346 "triggering": {347 "default_ref_f": 1.0,348 "default_ref_v": 1.0,349 "default_threshold_percent_f_low": 1.0,350 "default_threshold_percent_f_high": 1.0,351 "default_threshold_percent_v_low": 1.0,352 "default_threshold_percent_v_high": 1.0,353 "default_threshold_percent_thd_high": 1.0,354 "triggering_overrides": [355 {356 "box_id": "0",357 "ref_f": 2.0,358 "ref_v": 2.0,359 "threshold_percent_f_low": 2.0,360 "threshold_percent_f_high": 2.0,361 "threshold_percent_v_low": 2.0,362 "threshold_percent_v_high": 2.0,363 "threshold_percent_thd_high": 2.0364 },365 {366 "box_id": "1003",367 "ref_f": 60,368 "ref_v": 120,369 "threshold_percent_f_low": 0.5,370 "threshold_percent_f_high": 0.5,371 "threshold_percent_v_low": 2.5,372 "threshold_percent_v_high": 2.5,373 "threshold_percent_thd_high": 3374 },375 {376 "box_id": "2001",377 "ref_f": 60,378 "ref_v": 120,379 "threshold_percent_f_low": 0.5,380 "threshold_percent_f_high": 0.5,381 "threshold_percent_v_low": 2.5,382 "threshold_percent_v_high": 2.5,383 "threshold_percent_thd_high": 3384 }385 ]386 }387 }...

Full Screen

Full Screen

adaptive_threshold.py

Source:adaptive_threshold.py Github

copy

Full Screen

...18from massrc.com.citrix.mas.nitro.resource.Base.base_response import base_response19'''20Configuration for Af report sys log for adaptive threshold resource21'''22class adaptive_threshold(base_resource):23 _threshold_value= ""24 _monitor_duration= ""25 _id= ""26 __count=""27 '''28 get the resource id29 '''30 def get_resource_id(self) :31 try:32 if hasattr(self, 'id'):33 return self.id 34 else:35 return None 36 except Exception as e :37 raise e38 '''39 get the resource type40 '''41 def get_object_type(self) :42 try:43 return "adaptive_threshold"44 except Exception as e :45 raise e46 '''47 Returns the value of object identifier argument.48 '''49 def get_object_id(self) :50 try:51 return self._id52 except Exception as e :53 raise e54 '''55 Returns the value of object file path argument.56 '''57 @property58 def file_path_value(self) :59 try:60 return None61 except Exception as e :62 raise e63 '''64 Returns the value of object file component name.65 '''66 @property67 def file_component_value(self) :68 try :69 return "adaptive_thresholds"70 except Exception as e :71 raise e72 '''73 get threshold value in percentage74 '''75 @property76 def threshold_value(self) :77 try:78 return self._threshold_value79 except Exception as e :80 raise e81 '''82 set threshold value in percentage83 '''84 @threshold_value.setter85 def threshold_value(self,threshold_value):86 try :87 if not isinstance(threshold_value,int):88 raise TypeError("threshold_value must be set to int value")89 self._threshold_value = threshold_value90 except Exception as e :91 raise e92 '''93 get threshold monitoring duration.94 '''95 @property96 def monitor_duration(self) :97 try:98 return self._monitor_duration99 except Exception as e :100 raise e101 '''102 set threshold monitoring duration.103 '''104 @monitor_duration.setter105 def monitor_duration(self,monitor_duration):106 try :107 if not isinstance(monitor_duration,str):108 raise TypeError("monitor_duration must be set to str value")109 self._monitor_duration = monitor_duration110 except Exception as e :111 raise e112 '''113 get Id is Adaptive threshold ID114 '''115 @property116 def id(self) :117 try:118 return self._id119 except Exception as e :120 raise e121 '''122 set Id is Adaptive threshold ID123 '''124 @id.setter125 def id(self,id):126 try :127 if not isinstance(id,str):128 raise TypeError("id must be set to str value")129 self._id = id130 except Exception as e :131 raise e132 '''133 Use this operation to add threshold.134 '''135 @classmethod136 def add(cls,service=None,resource=None):137 try:138 if resource is None :139 raise Exception("Resource Object Not Found")140 if type(resource) is not list :141 return resource.perform_operation(service,"add")142 else : 143 adaptive_threshold_obj= adaptive_threshold()144 return cls.perform_operation_bulk_request(service,"add", resource,adaptive_threshold_obj)145 except Exception as e :146 raise e147 '''148 Use this operation to delete threshold.149 '''150 @classmethod151 def delete(cls,client=None,resource=None): 152 try :153 if resource is None :154 raise Exception("Resource Object Not Found")155 if type(resource) is not list :156 return resource.delete_resource(client)157 else :158 adaptive_threshold_obj=adaptive_threshold()159 return cls.delete_bulk_request(client,resource,adaptive_threshold_obj)160 except Exception as e :161 raise e162 '''163 Af Report for Adaptive Threshold Monitoring..164 '''165 @classmethod166 def get(cls,client = None,resource="",option_=""): 167 try:168 response=""169 if not resource :170 adaptive_threshold_obj=adaptive_threshold()171 response = adaptive_threshold_obj.get_resources(client,option_)172 else:173 response = resource.get_resource(client, option_)174 return response175 except Exception as e :176 raise e177 '''178 Use this operation to modify threshold.179 '''180 @classmethod181 def update(cls,client=None,resource=None):182 try:183 if resource is None :184 raise Exception("Resource Object Not Found")185 if type(resource) is not list :186 return resource.update_resource(client)187 else :188 adaptive_threshold_obj=adaptive_threshold()189 return cls.update_bulk_request(client,resource,adaptive_threshold_obj)190 except Exception as e :191 raise e192 '''193 Use this API to fetch filtered set of adaptive_threshold resources.194 filter string should be in JSON format.eg: "vm_state:DOWN,name:[a-z]+"195 '''196 @classmethod197 def get_filtered(cls,service,filter_) :198 try:199 adaptive_threshold_obj = adaptive_threshold()200 option_ = options()201 option_._filter=filter_202 return adaptive_threshold_obj.getfiltered(service, option_)203 except Exception as e :204 raise e205 '''206 * Use this API to count the adaptive_threshold resources.207 '''208 @classmethod209 def count(cls,service) :210 try:211 adaptive_threshold_obj = adaptive_threshold()212 option_ = options()213 option_._count=True214 response = adaptive_threshold_obj.get_resources(service, option_)215 if response :216 return response[0].__dict__['___count']217 return 0218 except Exception as e :219 raise e220 '''221 Use this API to count the filtered set of adaptive_threshold resources.222 filter string should be in JSON format.eg: "vm_state:DOWN,name:[a-z]+"223 '''224 @classmethod225 def count_filtered(cls,service,filter_):226 try:227 adaptive_threshold_obj = adaptive_threshold()228 option_ = options()229 option_._count=True230 option_._filter=filter_231 response = adaptive_threshold_obj.getfiltered(service, option_)232 if response :233 return response[0].__dict__['_count']234 return 0;235 except Exception as e :236 raise e237 '''238 Converts API response into object and returns the object array in case of get request.239 '''240 def get_nitro_response(self,service ,response):241 try :242 result=service.payload_formatter.string_to_resource(adaptive_threshold_response, response, self.__class__.__name__)243 if(result.errorcode != 0) :244 if (result.errorcode == 444) :245 service.clear_session(self)246 if result.severity :247 if (result.severity == "ERROR") :248 raise nitro_exception(result.errorcode, str(result.message), str(result.severity))249 else :250 raise nitro_exception(result.errorcode, str(result.message), str(result.severity))251 return result.adaptive_threshold252 except Exception as e :253 raise e254 '''255 Converts API response into object and returns the object array .256 '''257 def get_nitro_bulk_response(self,service ,response):258 try :259 result=service.payload_formatter.string_to_resource(adaptive_threshold_responses, response, "adaptive_threshold_response_array")260 if(result.errorcode != 0) :261 if (result.errorcode == 444) :262 service.clear_session(self)263 response = result.adaptive_threshold_response_array264 i=0265 error = [adaptive_threshold() for _ in range(len(response))]266 for obj in response :267 error[i]= obj._message268 i=i+1269 raise nitro_exception(result.errorcode, str(result.message), error)270 response = result.adaptive_threshold_response_array271 i=0272 adaptive_threshold_objs = [adaptive_threshold() for _ in range(len(response))]273 for obj in response :274 if hasattr(obj,'_adaptive_threshold'):275 for props in obj._adaptive_threshold:276 result = service.payload_formatter.string_to_bulk_resource(adaptive_threshold_response,self.__class__.__name__,props)277 adaptive_threshold_objs[i] = result.adaptive_threshold278 i=i+1279 return adaptive_threshold_objs280 except Exception as e :281 raise e282 '''283 Performs generic data validation for the operation to be performed284 '''285 def validate(self,operationType):286 try:287 super(adaptive_threshold,self).validate()288 except Exception as e :289 raise e290'''291Forms the proper response.292'''293class adaptive_threshold_response(base_response):294 def __init__(self,length=1) :295 self.adaptive_threshold= []296 self.errorcode = 0 297 self.message = "" 298 self.severity = "" 299 self.adaptive_threshold= [ adaptive_threshold() for _ in range(length)]300'''301Forms the proper response for bulk operation.302'''303class adaptive_threshold_responses(base_response):304 def __init__(self,length=1) :305 self.adaptive_threshold_response_array = []306 self.errorcode = 0 307 self.message = "" ...

Full Screen

Full Screen

geometry.py

Source:geometry.py Github

copy

Full Screen

1from shapely.geometry import Point2from shapely.geometry.polygon import Polygon3import cv24class Geometry:5 def __init__(self, debug = False, width=4096, height=2160):6 self.debug = debug7 self.width = width8 self.height = height9 # Divisions10 self.division_left_min_x = (2048/555)11 self.division_left_min_y = (1080/193)12 self.division_left_max_x = (2048/555)13 self.division_left_max_y = (1080/978)14 15 self.division_right_min_x = (2048/1473)16 self.division_right_min_y = (1080/177)17 self.division_right_max_x = (2048/1473)18 self.division_right_max_y = (1080/958)19 # Prediction Line20 self.lower_y = 96021 self.prediction_y = (1080/self.lower_y)22 # Tresholds - left23 24 self.threshold_left_min_x1 = (2048/22)25 self.threshold_left_min_y1 = (1080/37) 26 self.threshold_left_min_x2 = (2048/535)27 self.threshold_left_min_y2 = (1080/212)28 29 self.threshold_left_max_x1 = (2048/22)30 self.threshold_left_max_y1 = (1080/self.lower_y) 31 self.threshold_left_max_x2 = (2048/535)32 self.threshold_left_max_y2 = (1080/self.lower_y)33 # Tresholds - center34 self.threshold_center_min_x1 = (2048/570)35 self.threshold_center_min_y1 = (1080/193) 36 self.threshold_center_min_x2 = (2048/1466)37 self.threshold_center_min_y2 = self.threshold_center_min_y138 39 self.threshold_center_max_x1 = (2048/570)40 self.threshold_center_max_y1 = (1080/self.lower_y) 41 self.threshold_center_max_x2 = self.threshold_center_min_x242 self.threshold_center_max_y2 = (1080/self.lower_y)43 44 # Tresholds - right45 self.threshold_right_min_x1 = (2048/2018)46 self.threshold_right_min_y1 = (1080/8) 47 self.threshold_right_min_x2 = (2048/1486)48 self.threshold_right_min_y2 = (1080/203)49 50 self.threshold_right_max_x1 = (2048/2025)51 self.threshold_right_max_y1 = (1080/self.lower_y) 52 self.threshold_right_max_x2 = self.threshold_right_min_x253 self.threshold_right_max_y2 = (1080/self.lower_y)54 def drawTreshholds(self, frame):55 #devision lines56 cv2.line(frame,(int(self.width/self.division_left_min_x), int(self.height/self.division_left_min_y)),(int(self.width/self.division_left_max_x), int(self.height/self.division_left_max_y)),(255,0,0),2)57 cv2.line(frame,(int(self.width/self.division_right_min_x), int(self.height/self.division_right_min_y)),(int(self.width/self.division_right_max_x), int(self.height/self.division_right_max_y)),(255,0,0),2)58 59 #Tresholds right60 cv2.line(frame,(int(self.width/self.threshold_left_min_x1), int(self.height/self.threshold_left_min_y1)),(int(self.width/self.threshold_left_min_x2), int(self.height/self.threshold_left_min_y2)),(255,0,0),1)61 cv2.line(frame,(int(self.width/self.threshold_left_max_x1), int(self.height/self.threshold_left_max_y1)),(int(self.width/self.threshold_left_max_x2), int(self.height/self.threshold_left_max_y2)),(255,0,0),1)62 cv2.line(frame,(int(self.width/self.threshold_left_min_x1), int(self.height/self.threshold_left_min_y1)),(int(self.width/self.threshold_left_max_x1), int(self.height/self.threshold_left_max_y1)),(255,0,0),1)63 cv2.line(frame,(int(self.width/self.threshold_left_min_x2), int(self.height/self.threshold_left_min_y2)),(int(self.width/self.threshold_left_max_x2), int(self.height/self.threshold_left_max_y2)),(255,0,0),1)64 65 #Tresholds center66 cv2.line(frame,(int(self.width/self.threshold_center_min_x1), int(self.height/self.threshold_center_min_y1)),(int(self.width/self.threshold_center_min_x2), int(self.height/self.threshold_center_min_y2)),(255,0,0),1)67 cv2.line(frame,(int(self.width/self.threshold_center_max_x1), int(self.height/self.threshold_center_max_y1)),(int(self.width/self.threshold_center_max_x2), int(self.height/self.threshold_center_max_y2)),(255,0,0),1)68 cv2.line(frame,(int(self.width/self.threshold_center_min_x1), int(self.height/self.threshold_center_min_y1)),(int(self.width/self.threshold_center_max_x1), int(self.height/self.threshold_center_max_y1)),(255,0,0),1)69 cv2.line(frame,(int(self.width/self.threshold_center_min_x2), int(self.height/self.threshold_center_min_y2)),(int(self.width/self.threshold_center_max_x2), int(self.height/self.threshold_center_max_y2)),(255,0,0),1)70 71 #Tresholds right72 cv2.line(frame,(int(self.width/self.threshold_right_min_x1), int(self.height/self.threshold_right_min_y1)),(int(self.width/self.threshold_right_min_x2), int(self.height/self.threshold_right_min_y2)),(255,0,0),1)73 cv2.line(frame,(int(self.width/self.threshold_right_max_x1), int(self.height/self.threshold_right_max_y1)),(int(self.width/self.threshold_right_max_x2), int(self.height/self.threshold_right_max_y2)),(255,0,0),1)74 cv2.line(frame,(int(self.width/self.threshold_right_min_x1), int(self.height/self.threshold_right_min_y1)),(int(self.width/self.threshold_right_max_x1), int(self.height/self.threshold_right_max_y1)),(255,0,0),1)75 cv2.line(frame,(int(self.width/self.threshold_right_min_x2), int(self.height/self.threshold_right_min_y2)),(int(self.width/self.threshold_right_max_x2), int(self.height/self.threshold_right_max_y2)),(255,0,0),1)76 77 return frame78 79 def getCameraNameBoundaries(self):80 return int(self.width/self.division_left_min_x), int(self.width/self.division_right_min_x)81 def checkboundaries(self, image, frame):82 if self.checkPoint(image.x, image.y) and self.checkPoint(image.x + image.w, image.y + image.h):83 frame = self.drawColoredBox(frame, image, (0, 255, 0))84 return frame, 185 elif (image.y + image.h > int(self.height/self.prediction_y)):86 frame = self.drawColoredBox(frame, image, (255, 255, 0))87 return frame, 288 else :89 frame = self.drawColoredBox(frame, image, (0, 0, 255))90 return frame, 091 def checkPoint(self,x,y):92 if (y > int(self.height/self.threshold_center_min_y1) and y < int(self.height/self.threshold_center_max_y1) ):93 #center94 if (x > int(self.width/self.threshold_center_min_x1) and x < int(self.width/self.threshold_center_max_x2)) :95 return True96 #left97 elif (x > int(self.width/self.threshold_left_min_x1) and x < int(self.width/self.threshold_left_max_x2)) : 98 return True 99 #right100 elif (x > int(self.width/self.threshold_right_min_x2) and x < int(self.width/self.threshold_right_min_x1)) : 101 return True 102 else :103 return False104 def drawColoredBox(self, frame, image, color):105 if self.debug:106 cv2.rectangle(frame,[image.x, image.y, image.w, image.h], color, 5)...

Full Screen

Full Screen

relative_time.js

Source:relative_time.js Github

copy

Full Screen

1import { module, test } from '../qunit';2import moment from '../../moment';3module('relative time');4test('default thresholds fromNow', function (assert) {5 var a = moment();6 // Seconds to minutes threshold7 a.subtract(44, 'seconds');8 assert.equal(a.fromNow(), 'a few seconds ago', 'Below default seconds to minutes threshold');9 a.subtract(1, 'seconds');10 assert.equal(a.fromNow(), 'a minute ago', 'Above default seconds to minutes threshold');11 // Minutes to hours threshold12 a = moment();13 a.subtract(44, 'minutes');14 assert.equal(a.fromNow(), '44 minutes ago', 'Below default minute to hour threshold');15 a.subtract(1, 'minutes');16 assert.equal(a.fromNow(), 'an hour ago', 'Above default minute to hour threshold');17 // Hours to days threshold18 a = moment();19 a.subtract(21, 'hours');20 assert.equal(a.fromNow(), '21 hours ago', 'Below default hours to day threshold');21 a.subtract(1, 'hours');22 assert.equal(a.fromNow(), 'a day ago', 'Above default hours to day threshold');23 // Days to month threshold24 a = moment();25 a.subtract(25, 'days');26 assert.equal(a.fromNow(), '25 days ago', 'Below default days to month (singular) threshold');27 a.subtract(1, 'days');28 assert.equal(a.fromNow(), 'a month ago', 'Above default days to month (singular) threshold');29 // months to year threshold30 a = moment();31 a.subtract(10, 'months');32 assert.equal(a.fromNow(), '10 months ago', 'Below default days to years threshold');33 a.subtract(1, 'month');34 assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold');35});36test('default thresholds toNow', function (assert) {37 var a = moment();38 // Seconds to minutes threshold39 a.subtract(44, 'seconds');40 assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold');41 a.subtract(1, 'seconds');42 assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold');43 // Minutes to hours threshold44 a = moment();45 a.subtract(44, 'minutes');46 assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold');47 a.subtract(1, 'minutes');48 assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold');49 // Hours to days threshold50 a = moment();51 a.subtract(21, 'hours');52 assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold');53 a.subtract(1, 'hours');54 assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold');55 // Days to month threshold56 a = moment();57 a.subtract(25, 'days');58 assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold');59 a.subtract(1, 'days');60 assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold');61 // months to year threshold62 a = moment();63 a.subtract(10, 'months');64 assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold');65 a.subtract(1, 'month');66 assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold');67});68test('custom thresholds', function (assert) {69 // Seconds to minutes threshold70 moment.relativeTimeThreshold('s', 55);71 var a = moment();72 a.subtract(54, 'seconds');73 assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold');74 a.subtract(1, 'seconds');75 assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minutes threshold');76 moment.relativeTimeThreshold('s', 45);77 // Minutes to hours threshold78 moment.relativeTimeThreshold('m', 55);79 a = moment();80 a.subtract(54, 'minutes');81 assert.equal(a.fromNow(), '54 minutes ago', 'Below custom minutes to hours threshold');82 a.subtract(1, 'minutes');83 assert.equal(a.fromNow(), 'an hour ago', 'Above custom minutes to hours threshold');84 moment.relativeTimeThreshold('m', 45);85 // Hours to days threshold86 moment.relativeTimeThreshold('h', 24);87 a = moment();88 a.subtract(23, 'hours');89 assert.equal(a.fromNow(), '23 hours ago', 'Below custom hours to days threshold');90 a.subtract(1, 'hours');91 assert.equal(a.fromNow(), 'a day ago', 'Above custom hours to days threshold');92 moment.relativeTimeThreshold('h', 22);93 // Days to month threshold94 moment.relativeTimeThreshold('d', 28);95 a = moment();96 a.subtract(27, 'days');97 assert.equal(a.fromNow(), '27 days ago', 'Below custom days to month (singular) threshold');98 a.subtract(1, 'days');99 assert.equal(a.fromNow(), 'a month ago', 'Above custom days to month (singular) threshold');100 moment.relativeTimeThreshold('d', 26);101 // months to years threshold102 moment.relativeTimeThreshold('M', 9);103 a = moment();104 a.subtract(8, 'months');105 assert.equal(a.fromNow(), '8 months ago', 'Below custom days to years threshold');106 a.subtract(1, 'months');107 assert.equal(a.fromNow(), 'a year ago', 'Above custom days to years threshold');108 moment.relativeTimeThreshold('M', 11);109});110test('retrive threshold settings', function (assert) {111 moment.relativeTimeThreshold('m', 45);112 var minuteThreshold = moment.relativeTimeThreshold('m');113 assert.equal(minuteThreshold, 45, 'Can retrieve minute setting');...

Full Screen

Full Screen

server_info_threshold.py

Source:server_info_threshold.py Github

copy

Full Screen

...6# 从数据库中获取磁盘使用率阈值7disk_threshold = FullServerInfoThreshold.objects.get(id=1).disk_threshold8# 从数据库中获取带宽的阈值9bandwidth_threshold = FullServerInfoThreshold.objects.get(id=1).bandwidth_threshold10def get_server_info_threshold(info=None):11 server_info_threshold = {12 'cpu_threshold': float(cpu_threshold),13 'memory_threshold': float(memory_threshold),14 'disk_threshold': float(disk_threshold),15 'bandwidth_threshold': float(bandwidth_threshold)16 }17 if info:18 return server_info_threshold[info]19 else:20 return server_info_threshold21# 更新数据库中各项服务器报警阈值22def set_cpu_threshold(threshold):23 FullServerInfoThreshold.objects.filter(id=1).update(cpu_threshold=threshold)24def set_memory_threshold(threshold):25 FullServerInfoThreshold.objects.filter(id=1).update(memory_threshold=threshold)26def set_disk_threshold(threshold):27 FullServerInfoThreshold.objects.filter(id=1).update(disk_threshold=threshold)28def set_bandwidth_threshold(threshold):29 FullServerInfoThreshold.objects.filter(id=1).update(bandwidth_threshold=threshold)30# 每次更新数据库中的数据后会调用该函数来用数据库中的值来刷新全局变量中的数值31def refresh_data():32 global cpu_threshold33 global memory_threshold34 global disk_threshold35 global bandwidth_threshold36 cpu_threshold = FullServerInfoThreshold.objects.get(id=1).cpu_threshold37 memory_threshold = FullServerInfoThreshold.objects.get(id=1).memory_threshold38 disk_threshold = FullServerInfoThreshold.objects.get(id=1).disk_threshold...

Full Screen

Full Screen

Player.ts

Source:Player.ts Github

copy

Full Screen

1import type { IStatMax } from "game/entity/IStats";2import { Stat } from "game/entity/IStats";3import type Context from "../core/context/Context";4export class PlayerUtilities {5 public getWeight(context: Context) {6 return context.human.stat.get<IStatMax>(Stat.Weight).value;7 }8 public getMaxWeight(context: Context) {9 return context.human.stat.get<IStatMax>(Stat.Weight).max;10 }11 public isUsingVehicle(context: Context) {12 return !!context.human.vehicleItemReference;13 }14 public isHealthy(context: Context) {15 return context.human.stat.get<IStatMax>(Stat.Health).value > 8 && context.human.stat.get<IStatMax>(Stat.Hunger).value > 8;16 }17 public getRecoverThreshold(context: Context, stat: Stat) {18 let recoverThreshold: number | number[];19 switch (stat) {20 case Stat.Health:21 recoverThreshold = context.options.recoverThresholdHealth;22 break;23 case Stat.Stamina:24 recoverThreshold = context.options.recoverThresholdStamina;25 break;26 case Stat.Hunger:27 recoverThreshold = context.options.recoverThresholdHunger;28 break;29 case Stat.Thirst:30 recoverThreshold = [context.options.recoverThresholdThirst, context.options.recoverThresholdThirstFromMax];31 break;32 default:33 throw new Error(`Invalid recover threshold stat ${stat}`);34 }35 if (Array.isArray(recoverThreshold)) {36 recoverThreshold = Math.min(...recoverThreshold.map((threshold) => this.parseThreshold(context, stat, threshold)));37 } else {38 recoverThreshold = this.parseThreshold(context, stat, recoverThreshold);39 }40 return recoverThreshold;41 }42 private parseThreshold(context: Context, stat: Stat, threshold: number) {43 return threshold > 0 ? threshold : context.human.stat.get<IStatMax>(stat).max + threshold;44 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3 if (err) return console.error(err);4 api.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 api.getLocations(function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10 });11});12var wpt = require('webpagetest');13var api = new wpt('www.webpagetest.org');14 if (err) return console.error(err);15 api.getTestResults(data.data.testId, function(err, data) {16 if (err) return console.error(err);17 api.getLocations(function(err, data) {18 if (err) return console.error(err);19 console.log(data);20 });21 });22});23var wpt = require('webpagetest');24var api = new wpt('www.webpagetest.org');25 if (err) return console.error(err);26 api.getTestResults(data.data.testId, function(err, data) {27 if (err) return console.error(err);28 api.getLocations(function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 });32 });33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4 videoParams: {5 },6 timelineParams: {7 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var async = require('async');5var _ = require('lodash');6var csv = require('csv');7var csvWriter = require('csv-write-stream');8var writer = csvWriter({headers: ['PageTitle', 'PageId', 'PageLength', 'PageViews', 'PageViewsPerEdit', 'PageEdits', 'PageEditsPerDay', 'PageEditsPerMonth', 'PageEditsPerYear', 'PageEditsPerUser', 'PageUsers', 'PageUsersPerDay', 'PageUsersPerMonth', 'PageUsersPerYear', 'PageUsersPerEdit', 'PageUsersPerView', 'PageViewsPerUser', 'PageEditsPerUserPerDay', 'PageEditsPerUserPerMonth', 'PageEditsPerUserPerYear', 'PageViewsPerUserPerDay', 'PageViewsPerUserPerMonth', 'PageViewsPerUserPerYear']});9var pageData = require('./pageData.json');10var pageDataFiltered = _.filter(pageData, function(page) {11 return page.pageviews > 100000;12});13var pageDataFiltered = _.map(pageDataFiltered, function(page) {14 return page.title;15});16var pageDataFiltered = _.uniq(pageDataFiltered);17var pageDataFiltered = _.filter(pageDataFiltered, function(page) {18 return page.indexOf('Template:') == -1;19});20var pageDataFiltered = _.filter(pageDataFiltered, function(page) {21 return page.indexOf('Category:') == -1;22});23var pageDataFiltered = _.filter(pageDataFiltered, function(page) {24 return page.indexOf('Wikipedia:') == -1;25});26var pageDataFiltered = _.filter(pageDataFiltered, function(page) {27 return page.indexOf('Portal:') == -1;28});29var pageDataFiltered = _.filter(pageDataFiltered, function(page) {30 return page.indexOf('File:') == -1;31});32var pageDataFiltered = _.filter(pageDataFiltered, function(page) {33 return page.indexOf('Help:') == -1;34});35var pageDataFiltered = _.filter(pageDataFiltered, function(page) {36 return page.indexOf('Book:') == -1;37});38var pageDataFiltered = _.filter(pageDataFiltered, function(page) {39 return page.indexOf('User:') == -1;40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest-api');2var api = wpt('www.webpagetest.org');3var options = {4};5api.runTest(options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8 var speedindex = data.data.median.firstView.SpeedIndex;9 if (speedindex < 1000) {10 console.log("Speed index is less than 1000");11 } else {12 console.log("Speed index is greater than 1000");13 }14});15var wpt = require('webpagetest-api');16var api = wpt('www.webpagetest.org');17var options = {18};19api.runTest(options, function(err, data) {20 if (err) return console.error(err);21 console.log(data);22 var speedindex = data.data.median.firstView.SpeedIndex;23 if (speedindex < 1000) {24 console.log("Speed index is less than 1000");25 } else {26 console.log("Speed index is greater than 1000");27 }28});29var wpt = require('webpagetest-api');30var api = wpt('www.webpagetest.org');31var options = {32};33api.runTest(options, function(err, data) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = new wptools('Wikipedia');3wiki.get(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 }7 else {8 console.log(data);9 }10});11var wptools = require('wptools');12var wiki = new wptools('Wikipedia');13wiki.threshold(0.5);14wiki.get(function(err, data) {15 if (err) {16 console.log('Error: ' + err);17 }18 else {19 console.log(data);20 }21});22var wptools = require('wptools');23var wiki = new wptools('Wikipedia');24wiki.threshold(0.5);25wiki.get(function(err, data) {26 if (err) {27 console.log('Error: ' + err);28 }29 else {30 console.log(data);31 }32});33var wptools = require('wptools');34var wiki = new wptools('Wikipedia');35wiki.threshold(0.5);36wiki.get(function(err, data) {37 if (err) {38 console.log('Error: ' + err);39 }40 else {41 console.log(data);42 }43});44var wptools = require('wptools');45var wiki = new wptools('Wikipedia');46wiki.threshold(0.5);47wiki.get(function(err, data) {48 if (err) {49 console.log('Error: ' + err);50 }51 else {52 console.log(data);53 }54});55var wptools = require('wptools');56var wiki = new wptools('Wikipedia');57wiki.threshold(0.5);58wiki.get(function(err, data) {59 if (err) {60 console.log('Error: ' + err);61 }62 else {63 console.log(data);64 }65});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var fs = require('fs');3var image = fs.readFileSync('test.png');4wptoolkit.threshold(image, 0.5, function(err, image) {5 if (err) {6 console.log(err);7 return;8 }9 fs.writeFileSync('test-threshold.png', image);10});11var wptoolkit = require('wptoolkit');12var fs = require('fs');13var image = fs.readFileSync('test.png');14wptoolkit.threshold(image, 0.5, function(err, image) {15 if (err) {16 console.log(err);17 return;18 }19 fs.writeFileSync('test-threshold.png', image);20});21var wptoolkit = require('wptoolkit');22var fs = require('fs');23var image = fs.readFileSync('test.png');24wptoolkit.threshold(image, 0.5, function(err, image) {25 if (err) {26 console.log(err);27 return;28 }29 fs.writeFileSync('test-threshold.png', image);30});31var wptoolkit = require('wptoolkit');32var fs = require('fs');33var image = fs.readFileSync('test.png');34wptoolkit.threshold(image, 0.5, function(err, image) {35 if (err) {36 console.log(err);37 return;38 }39 fs.writeFileSync('test-threshold.png', image);40});41var wptoolkit = require('wptoolkit');42var fs = require('fs');43var image = fs.readFileSync('test.png');44wptoolkit.threshold(image, 0.5, function(err, image) {45 if (err) {46 console.log(err);47 return;48 }49 fs.writeFileSync('test-threshold.png', image);50});51var wptoolkit = require('wptoolkit');52var fs = require('fs');53var image = fs.readFileSync('test.png');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('API_KEY');3webPageTest.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var webPageTest = new wpt('API_KEY');12webPageTest.getTesters(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var webPageTest = new wpt('API_KEY');21webPageTest.getTestStatus('testID', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('webpagetest');29var webPageTest = new wpt('API_KEY');30webPageTest.getTestResults('testID', function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('webpagetest');38var webPageTest = new wpt('API_KEY');39webPageTest.getTestResults('testID', function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('webpagetest');47var webPageTest = new wpt('API_KEY');48webPageTest.getTestResults('testID', function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('webpagetest');56var webPageTest = new wpt('API_KEY');

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