Exemplo n.º 1
0
	def merge_dicts(self, l, name, transition_file):
		DEVELOP = False
		if DEVELOP:
			result = []
			for item in l:
				for i in range(len(item.between)):
					if i >= len(result):
						result.append({})
					val = item.between[i][0]
					if val not in result[i]:
						result[i][val] = 1
					else:
						result[i][val] += 1
		
			for item in result:
				sorted_result = sorted(item.iteritems(), key=operator.itemgetter(1), reverse=True)
				for k, v in sorted_result:
					print k + ":", v,
				print
		time_to_reach_first = self.__create_dict(True)
		duplicates_first = self.__create_dict(True)
		attributes_first = self.__create_dict(False, d=True)
		
		time_to_reach_last= self.__create_dict(True)
		duplicates_last = self.__create_dict(True)
		attributes_last = self.__create_dict(False, d=True)
		inter_time = []
	
		for item in l:
			for k, v in item.time_to_reach_first.iteritems():
				time_to_reach_first[k].append(v)
			for k, v in item.duplicates_first.iteritems():
				duplicates_first[k].append(v)
			for k, v in item.time_to_reach_last.iteritems():
				time_to_reach_last[k].append(v)
			for k, v in item.duplicates_last.iteritems():
				duplicates_last[k].append(v)
			for k, v in item.attributes_first.iteritems():
				self.__merge_attributes(v, attributes_first, k)
			for k, v in item.attributes_last.iteritems():
				self.__merge_attributes(v, attributes_last, k)
			if item.end_time != 0:
				inter_time.append(item.end_time - item.begin_time)
			
		print >>transition_file, name
		print >>transition_file, robustnetLib.listToStr(inter_time, DEL = "\n")
		print name
		print "average:", robustnetLib.meanValue(inter_time), "stdev:", robustnetLib.stdevValue(inter_time)
		print "min-ish:", robustnetLib.quartileResult(inter_time)[0]
		print "min:", min(inter_time)
		for k in time_to_reach_first.keys():
			if max(duplicates_first[k]) == 0 and max(duplicates_last[k]) == 0:
				continue
			print "\t", k, robustnetLib.meanValue(time_to_reach_first[k]), robustnetLib.meanValue(duplicates_first[k]), min(duplicates_first[k]), len(duplicates_first[k])
			self.__print_attributes(attributes_first, k)
			print "\t\t", robustnetLib.meanValue(time_to_reach_last[k]), robustnetLib.meanValue(duplicates_last[k]), min(duplicates_last[k])
			self.__print_attributes(attributes_last, k)
Exemplo n.º 2
0
    def __print_attributes(self, attribute_dict, event):
        for k, v in attribute_dict[event].iteritems():
            print "\t\t\t", k, "|",
            if len(v) > 0 and isinstance(v[0], int):
                try:
                    avg = float(sum(v)) / len(v)
                    stdev = robustnetLib.stdevValue(v, avg)
                    print "average:", avg, "stdev:", stdev
                    continue
                except:
                    pass

            counter = Counter(v).most_common(3)
            for items in counter:
                print items[0], ":", items[1], "|",
            print
Exemplo n.º 3
0
	def __print_attributes(self, attribute_dict, event):
		for k, v in attribute_dict[event].iteritems():
			print "\t\t\t", k, "|",
			if len(v) > 0 and isinstance(v[0], int):
				try:
					avg = float(sum(v))/len(v)
					stdev = robustnetLib.stdevValue(v, avg)
					print "average:", avg, "stdev:", stdev
					continue
				except:
					pass
			
			counter = Counter(v).most_common(3)
			for items in counter:
				print items[0], ":", items[1], "|",
			print
Exemplo n.º 4
0
    def merge_dicts(self, l, name, transition_file):
        DEVELOP = False
        if DEVELOP:
            result = []
            for item in l:
                for i in range(len(item.between)):
                    if i >= len(result):
                        result.append({})
                    val = item.between[i][0]
                    if val not in result[i]:
                        result[i][val] = 1
                    else:
                        result[i][val] += 1

            for item in result:
                sorted_result = sorted(item.iteritems(),
                                       key=operator.itemgetter(1),
                                       reverse=True)
                for k, v in sorted_result:
                    print k + ":", v,
                print
        time_to_reach_first = self.__create_dict(True)
        duplicates_first = self.__create_dict(True)
        attributes_first = self.__create_dict(False, d=True)

        time_to_reach_last = self.__create_dict(True)
        duplicates_last = self.__create_dict(True)
        attributes_last = self.__create_dict(False, d=True)
        inter_time = []

        for item in l:
            for k, v in item.time_to_reach_first.iteritems():
                time_to_reach_first[k].append(v)
            for k, v in item.duplicates_first.iteritems():
                duplicates_first[k].append(v)
            for k, v in item.time_to_reach_last.iteritems():
                time_to_reach_last[k].append(v)
            for k, v in item.duplicates_last.iteritems():
                duplicates_last[k].append(v)
            for k, v in item.attributes_first.iteritems():
                self.__merge_attributes(v, attributes_first, k)
            for k, v in item.attributes_last.iteritems():
                self.__merge_attributes(v, attributes_last, k)
            if item.end_time != 0:
                inter_time.append(item.end_time - item.begin_time)

        print >> transition_file, name
        print >> transition_file, robustnetLib.listToStr(inter_time, DEL="\n")
        print name
        print "average:", robustnetLib.meanValue(
            inter_time), "stdev:", robustnetLib.stdevValue(inter_time)
        print "min-ish:", robustnetLib.quartileResult(inter_time)[0]
        print "min:", min(inter_time)
        for k in time_to_reach_first.keys():
            if max(duplicates_first[k]) == 0 and max(duplicates_last[k]) == 0:
                continue
            print "\t", k, robustnetLib.meanValue(
                time_to_reach_first[k]), robustnetLib.meanValue(
                    duplicates_first[k]), min(duplicates_first[k]), len(
                        duplicates_first[k])
            self.__print_attributes(attributes_first, k)
            print "\t\t", robustnetLib.meanValue(
                time_to_reach_last[k]), robustnetLib.meanValue(
                    duplicates_last[k]), min(duplicates_last[k])
            self.__print_attributes(attributes_last, k)
Exemplo n.º 5
0
	def merge_dicts_and_print(self, l, name, transition_file):
		DEVELOP = False
		if DEVELOP:
			result = []
			for item in l:
				for i in range(len(item.between)):
					if i >= len(result):
						result.append({})
					val = item.between[i][0]
					if val not in result[i]:
						result[i][val] = 1
					else:
						result[i][val] += 1
		
			for item in result:
				sorted_result = sorted(item.iteritems(), key=operator.itemgetter(1), reverse=True)
#				for k, v in sorted_result:
#					print k + ":", v,
#				print
		time_to_reach_first = self.__create_dict(True, item=None)
		duplicates_first = self.__create_dict(True)
		attributes_first = self.__create_dict(False, d=True)
		
		time_to_reach_last= self.__create_dict(True, item=None)
		duplicates_last = self.__create_dict(True)
		attributes_last = self.__create_dict(False, d=True)

		duplicates_all = self.__create_dict(True)
		attributes_all = self.__create_dict(False, d=True)

		inter_time = []

		for item in l:
			for k, v in item.time_to_reach_first.iteritems():
				time_to_reach_first[k].append(v)
			for k, v in item.duplicates_first.iteritems():
				duplicates_first[k].append(v)
			for k, v in item.time_to_reach_last.iteritems():
				time_to_reach_last[k].append(v)
			for k, v in item.duplicates_last.iteritems():
				duplicates_last[k].append(v)
			for k, v in item.duplicates_all.iteritems():
				duplicates_all[k].append(v)
			for k, v in item.attributes_first.iteritems():
				robustnetLib.mergeDict(v, attributes_first, k)
			for k, v in item.attributes_last.iteritems():
				robustnetLib.mergeDict(v, attributes_last, k)
			for k, v in item.attributes_all.iteritems():
				robustnetLib.mergeDict(v, attributes_all, k, True)
			if item.end_time != 0:
				inter_time.append(item.end_time - item.begin_time)
		if transition_file:	
			print >>transition_file, name
			print >>transition_file, robustnetLib.listToStr(inter_time, DEL = "\n")
		print name
		print "average:", robustnetLib.meanValue(inter_time), "stdev:", robustnetLib.stdevValue(inter_time)
		print "min-ish:", robustnetLib.quartileResult(inter_time)[0]
		print "min:", min(inter_time)
		for k in time_to_reach_first.keys():
			if max(duplicates_first[k]) == 0 and max(duplicates_last[k]) == 0:
				continue
			print "\t", k 
			print "\t\tBEGIN: ",
                        print "time from start:", robustnetLib.meanValue(time_to_reach_first[k]),
			print "frequency appears: ", self.fraction_there(duplicates_first[k]),
			print "duplicates:", robustnetLib.meanValue(duplicates_first[k]),
			print "min appearances:", min(duplicates_first[k]),
			print "number of tests:", len(duplicates_first[k])
			self.__print_attributes(attributes_first, k)
			print "\t\tALL: ",
			print "frequency appears:", self.fraction_there(duplicates_all[k]),
			print "duplicates:", robustnetLib.meanValue(duplicates_all[k]),
			print "number of tests:", len(duplicates_all[k])
			self.__print_attributes(attributes_all, k)
			print "\t\tEND: ",
			print "time from end:", robustnetLib.meanValue(time_to_reach_last[k]),
			print "frequency appears:", self.fraction_there(duplicates_last[k]),
			print "duplicates:", robustnetLib.meanValue(duplicates_last[k]),
			print "min appearances:", min(duplicates_last[k])
			print "RSSI and power ratio:", item.RSSI, item.power_ratio
			
			self.__print_attributes(attributes_last, k)