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
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 return merged
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
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