Best Python code snippet using hypothesis
test_threshold_optimization_plugin.py
Source:test_threshold_optimization_plugin.py  
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        }...adaptive_threshold.py
Source:adaptive_threshold.py  
...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 = "" ...geometry.py
Source:geometry.py  
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)...relative_time.js
Source:relative_time.js  
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');...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
