当前位置: 首页>>代码示例>>Python>>正文


Python Photo.compare方法代码示例

本文整理汇总了Python中photo.Photo.compare方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.compare方法的具体用法?Python Photo.compare怎么用?Python Photo.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在photo.Photo的用法示例。


在下文中一共展示了Photo.compare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mergeWith

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import compare [as 别名]
	def mergeWith(self, event):
		if type(event) is types.DictType:
			event = Event(event)
		event = event.toJSON()
		
		photo_list1 = self._event['photos'] 
		photo_list2 = event['photos']
		
		new_photo_list = []
		l1 = 0
		l2 = 0
		merged = 0
		while l1 < len(photo_list1) and l2 < len(photo_list2):
			p1 = Photo(photo_list1[l1])
			p2 = Photo(photo_list2[l2])
			compare = p1.compare(p2)
			if compare == 1:
				new_photo_list.append(photo_list1[l1])
				l1 += 1
				continue
			
			if compare == -1:
				new_photo_list.append(photo_list2[l2])
				l2 += 1
				merged += 1
				continue
			
			# compare == 0
			new_photo_list.append(photo_list1[l1])
			l1 += 1
			l2 += 1
		
		while l1 < len(photo_list1):
			new_photo_list.append(photo_list1[l1])
			l1 += 1
		
		while l2 < len(photo_list2):
			new_photo_list.append(photo_list2[l2])
			l2 += 1
			merged += 1
		
		self._event['photos'] = new_photo_list
		# update actual value
		self.setActualValue(self._getActualValueByCounting())
		
		# do not change the order of the following code
		actual_value_1 = self._event['actual_value']
		actual_value_2  = event['actual_value']
		zscore1 = float(self._event['zscore'])
		zscore2 = float(event['zscore'])
		std1 = float(self._event['predicted_std'])
		std2 = float(event['predicted_std'])
		new_std = (std1 * actual_value_1 + std2 * actual_value_2) / (actual_value_1 + actual_value_2)
		new_zscore = (zscore1 * actual_value_1 + zscore2 * actual_value_2) / (actual_value_1 + actual_value_2)
		self.setZscore(new_zscore)
		new_mu = actual_value_1 - new_zscore * new_std
		self.setPredictedValues(new_mu, new_std)
		
		return merged
开发者ID:daifanxiang,项目名称:CityBeat,代码行数:61,代码来源:event.py

示例2: _mergeWith

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import compare [as 别名]
    def _mergeWith(self, event):

        if type(event) is not types.DictType:
            event = event.toDict()

        element_list1 = self._event[self._element_type]
        element_list2 = event[BaseEvent(self._element_type, event)._element_type]

        new_element_list = []
        l1 = 0
        l2 = 0
        merged = 0
        while l1 < len(element_list1) and l2 < len(element_list2):
            if self._element_type == 'photos':
                d1 = Photo(element_list1[l1])
                d2 = Photo(element_list2[l2])
            else:
                d1 = Tweet(element_list1[l1])
                d2 = Tweet(element_list2[l2])
            compare = d1.compare(d2)
            if compare == 1:
                new_element_list.append(element_list1[l1])
                l1 += 1
                continue

            if compare == -1:
                new_element_list.append(element_list2[l2])
                l2 += 1
                merged += 1
                continue

            # compare == 0
            new_element_list.append(element_list1[l1])
            l1 += 1
            l2 += 1

        while l1 < len(element_list1):
            new_element_list.append(element_list1[l1])
            l1 += 1

        while l2 < len(element_list2):
            new_element_list.append(element_list2[l2])
            l2 += 1
            merged += 1

        self._event[self._element_type] = new_element_list
        # update actual value
        self.setActualValue(self._getActualValueByCounting())

        # do not change the order of the following code
        actual_value_1 = self._event['actual_value']
        actual_value_2 = event['actual_value']
        zscore1 = float(self._event['zscore'])
        zscore2 = float(event['zscore'])
        std1 = float(self._event['predicted_std'])
        std2 = float(event['predicted_std'])
        new_std = (std1 * actual_value_1 + std2 * actual_value_2) / (actual_value_1 + actual_value_2)
        new_zscore = (zscore1 * actual_value_1 + zscore2 * actual_value_2) / (actual_value_1 + actual_value_2)
        self.setZscore(new_zscore)
        new_mu = actual_value_1 - new_zscore * new_std
        self.setPredictedValues(new_mu, new_std)
        return merged
开发者ID:juicyJ,项目名称:citybeat_online,代码行数:64,代码来源:base_event.py


注:本文中的photo.Photo.compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。