def return_upgma(seq_list, names_list, df, cfd_dict=None):
    '''input:  a list of names and a list of sequences, calibrated
	output: an upgma instance.
	'''
    if df == Metric.CRISTA:
        base = list(map(lambda sg: sg[3:-6], seq_list))  # seq_list
        seq_list = list(
            map(lambda t: Metric.pos_in_metric_general(t, df, base, cfd_dict),
                seq_list))
        df = Metric.find_dist_np

    if df == Metric.cfd_funct:  # to uncomment
        #base = random.sample(seq_list, int(math.log(len(seq_list))))
        #base = random.sample(seq_list, 80)
        #base = random.sample(seq_list, int(len(seq_list)**0.9))
        #base = seq_list
        #seq_list = list(map(lambda t: Metric.pos_in_metric_general(t,df,base, cfd_dict), seq_list))
        seq_list = list(
            map(lambda t: Metric.pos_in_metric_cfd_np(t, cfd_dict),
                seq_list))  #to uncomment

        #	df = Metric.find_dist_t  #if prev line is not  is use #to uncomment
        df = Metric.find_dist_np
    matrix = UPGMA.make_initiale_matrix(df, seq_list)
    m2 = UPGMA.make_distance_matrix(
        names_list,
        matrix)  #shuold be m2 = UPGMA.make_distance_matrix(names_list, matrix)
    upgma1 = UPGMA.make_UPGMA(m2)
    return upgma1
    def __init__(self, parent, gui, **options):
        """ Initializes TkMetricManager object
		
		@param parent
		@param gui
		@param options
		"""
        super(TkMetricManager, self).__init__(parent, gui, **options)
        self.m = Metric('placeholder', archive=False)
        self.index = self.m.getIndex()
        self.sessions = self.index['sessions']
        self.metrics = self.index['metrics']
        self.scales = {
            'hour': (23, 240),
            'minute': (59, 600),
            'second': (59, 600),
            'millisecond': (999, 1000)
        }
        self.shapes = {}
        self.resolutions = {
            'day': 86400.0,
            'hour': 3600.0,
            'minute': 60.0,
            'second': 1.0,
            'millisecond': 0.001
        }
 def factory_method(self,type):
     if(type=="View"):
         return Metric.ViewMetric(type)
     elif(type=="Engagement"):
         return Metric.EngagementMetric(type)
     elif(type=="Watch"):
         return Metric.WatchMetric(type)
Пример #4
0
    def dfs(self, gen, graph, x_cord, y_cord, components_cnt):
        graph[y_cord][x_cord] = components_cnt
        if Metric.is_inside_box(x_cord + 1, y_cord, self.block_cnt):
            # print('y = ' + str(y_cord) + '  x = ' + str(x_cord) + ' -> ' + str(y_cord) + ' ' + str(x_cord + 1))
            if graph[y_cord][x_cord + 1] == 0 and self.is_best_body(
                    gen[y_cord][x_cord], gen[y_cord][x_cord + 1], 'R'):
                graph = self.dfs(gen, graph, x_cord + 1, y_cord,
                                 components_cnt)

        if Metric.is_inside_box(x_cord, y_cord + 1, self.block_cnt):
            # print('y = ' + str(y_cord) + ' x = ' + str(x_cord) + ' -> ' + str(y_cord + 1) + ' ' + str(x_cord))
            if graph[y_cord + 1][x_cord] == 0 and self.is_best_body(
                    gen[y_cord][x_cord], gen[y_cord + 1][x_cord], 'D'):
                graph = self.dfs(gen, graph, x_cord, y_cord + 1,
                                 components_cnt)

        if Metric.is_inside_box(x_cord, y_cord - 1, self.block_cnt):
            # print('y = ' + str(y_cord) + ' x = ' + str(x_cord) + ' -> ' + str(y_cord - 1) + ' ' + str(x_cord))
            if graph[y_cord - 1][x_cord] == 0 and self.is_best_body(
                    gen[y_cord][x_cord], gen[y_cord - 1][x_cord], 'U'):
                graph = self.dfs(gen, graph, x_cord, y_cord - 1,
                                 components_cnt)

        if Metric.is_inside_box(x_cord - 1, y_cord, self.block_cnt):
            # print('y = ' + str(y_cord) + ' x = ' + str(x_cord) + ' -> ' + str(y_cord) + ' ' + str(x_cord - 1))
            if graph[y_cord][x_cord - 1] == 0 and self.is_best_body(
                    gen[y_cord][x_cord], gen[y_cord][x_cord - 1], 'L'):
                graph = self.dfs(gen, graph, x_cord - 1, y_cord,
                                 components_cnt)

        return graph
Пример #5
0
    def setPortfolio(self, portfolio):
        super().setPortfolio(portfolio)

        for asset in self.portfolio.assets:
            # skip USDT
            if asset.symbol != 'USDT':
                Metric.loadMetric('price', asset, self.from_date, self.to_date,
                                  self.timeframe)
Пример #6
0
def run():
    global metric
    global ranking
    print 'Loading RDG...',
    metric = Metric(rdgfolder, refcorpus)
    print 'done'
    print 'Ranking terms...',
    ranking = []
    ranking = metric.rankTerms(measure='Weighted')
    print 'done'
    def SearchWithReplace(self):
        # 第一步,在没有领域典型的条件得到的贪心最优值
        current_profiles = self.SearchWithoutConstraints()
        print self.AttributeRepresentative(set(current_profiles))
        # 持久化找到的代表性人物
        # with open("%dGBProfiles" % len(current_profiles),"wb") as f:
        #     for profile in current_profiles:
        #         f.write(profile)
        #         f.write("\n")
        # self.best_profiles = self.SearchWithK()
        # print metric.AttributeLoss(self.features,self.best_profiles)

        # 贪心排除多余的
        self.best_profiles = self.Delete(set(current_profiles))

        # 统计一下每个领域的人数
        # categories = self.DomainDistribution(self.best_profiles)

        # 第二步,排除不够典型的,统计贪心算法求得的解中有哪些不够典型的
        # 将best_profiles中不够典型的元素求出
        best_profiles = list(self.best_profiles)
        # 直接贪心搜索到的解的损耗是
        print "直接贪心搜索到的解的属性代表性是"
        print self.AttributeRepresentative(self.best_profiles)
        # vertexs = set()
        # # 顶点替换代价
        # vertexs_cost = {}
        # 不够典型的点的编号
        NoneTypical = []
        edges = []
        i = 0
        while i < len(best_profiles):
            j = i + 1
            while j < len(best_profiles):
                if metric.Similarity(self.features, best_profiles[i],
                                     best_profiles[j]) > self.epsilon:
                    edges.append((i, j))
                j += 1
            i += 1
        for profile in best_profiles:
            if not metric.checkOneTypical(self.features, profile,
                                          self.best_profiles, self.epsilon):
                NoneTypical.append(best_profiles.index(profile))
        print NoneTypical

        print "开始替换不够领域典型的人物"
        self.SearchRecursion(0, best_profiles, list(NoneTypical), edges)

        return self.best_profiles
    def train(self, start_training, end_training, timeframe):
        #Load list of values for all metrics
        for metric in self.metrics_list:
            Metric.loadMetric(metric, self.ass, start_training, end_training,
                              timeframe)

        #Initialize the array(inputs) and list(outputs) to be used to train the linear regression
        current_metrics_array = self.currentMetricsArrayGenerator(
            self.ass, start_training, end_training, timeframe)
        future_prices_list = self.futurePricesListGenerator(
            self.ass, start_training, end_training, timeframe)

        #Train the linear model and set it as a global variable - to be used for future predictions
        self.linear_model = self.regression(current_metrics_array,
                                            future_prices_list)
Пример #9
0
def start_all_jobs(rsv, condor):
    """ Start all metrics and consumers """

    num_errors = 0

    # Start all the metrics for each host
    for host in rsv.get_host_info():
        enabled_metrics = host.get_enabled_metrics()
        if len(enabled_metrics) > 0:
            rsv.echo("Starting %s metrics for host '%s'." % (len(enabled_metrics), host.host))
            for metric_name in enabled_metrics:
                metric = Metric.Metric(metric_name, rsv, host.host)
                if not condor.start_metric(metric, host):
                    num_errors += 1

    # Start the consumers
    enabled_consumers = rsv.get_enabled_consumers()
    if len(enabled_consumers) > 0:
        rsv.echo("Starting %s consumers." % len(enabled_consumers))
        for consumer in enabled_consumers:
            if not condor.start_consumer(rsv, consumer):
                num_errors += 1
    else:
        rsv.echo("No consumers are enabled.  Jobs will run but records will not be generated.")

    if num_errors > 0:
        return False

    return True
Пример #10
0
    def get_elite(self, population):
        gen_match = list()
        elite_list = list()
        print('len population : ' + str(len(population)))

        for gen in population:
            cur_viability = Metric.calc_gen_viability(gen, self.metric_info,
                                                      self.block_cnt)
            gen_match.append([cur_viability, gen])

        gen_match.sort()

        for i in range(self.elite_cnt):
            elite_list.append(gen_match[i][1])

        elite_list.append(gen_match[random.randint(0, len(population) - 1)][1])
        """
        for elite_gen in elite_list:
            population.append(elite_gen)
        """
        # print('best : ' + str(gen_match[0][0]) + ' ' + str(gen_match[0][1]))
        # len(gen_match) - 1
        # print(str(len(elite_list)) + ' <- elite')
        # return gen_match[0][1], gen_match[1][1]
        return elite_list
Пример #11
0
def printResult(indices, data):
    # convert ket qua tu dang chuan hoa sang du lieu doc duoc
    for idx in indices:
        for c in data[idx]:
            print(mt.rvlct(c) if (c != zero) else "", end="")
        print(" ", end="")
    print("")
Пример #12
0
def getInput(input):
    # lay du lieu input roi chuan hoa
    for idx, c in enumerate(input):
        input[idx] = mt.cvlct(c)
    while len(input) < maxNum:
        input.append(zero)
    return [input]
Пример #13
0
def stop_metric(rsv, condor, metric, host):
    """ Stop a single metric against the specified host """
    rsv.echo("Stopping metric '%s' for host '%s'" % (metric.name, host.host))
    metric = Metric.Metric(metric.name, rsv, host.host)
    if not condor.stop_jobs("OSGRSVUniqueName==\"%s\"" % metric.get_unique_name()):
        return 1

    return 0
Пример #14
0
def evaluate(gold_set_list, predict_set_list):
    metric = Metric()

    predict_num = 0
    correct_num = 0
    gold_num = 0

    for gold_set, predict_set in zip(gold_set_list, predict_set_list):
        predict_num += len(predict_set)
        gold_num += len(gold_set)
        correct_num += len(predict_set & gold_set)

    metric.correct_label_count = correct_num
    metric.predicated_label_count = predict_num
    metric.overall_label_count = gold_num

    return metric
Пример #15
0
    def get_metric_info(self):
        """ Return a dictionary with information about each installed metric """

        metrics = {}
        for metric in self.get_installed_metrics():
            metrics[metric] = Metric.Metric(metric, self)

        return metrics
Пример #16
0
def Run():
    features = datapre.Features()
    epsilons = [0.1560, 0.1556, 0.1555]
    number = [40, 60, 80, 100]
    for epsilon in epsilons:
        for n in number:
            start_time = time.time()
            profile1 = greedy.Greedy(n, features,
                                     datapre.CategoriesDistribution(),
                                     epsilon).SearchWithReplace()
            end_time = time.time()
            with open("GB%d_%.4f" % (n, epsilon), "wb") as f:
                f.write("cost %f s" % (end_time - start_time))
                f.write("Attribute Representativeness is:")
                f.write(str(metric.AttributeRepresentative(features,
                                                           profile1)))
                f.write("\n")
                for profile in profile1:
                    f.write(profile + "\t")
            start_time = time.time()
            profile2 = kmedoids.KMedoids(n, features,
                                         datapre.CategoriesDistribution(),
                                         epsilon).Search()
            end_time = time.time()
            with open("kmedoids%d_%.4f" % (n, epsilon), "wb") as f:
                f.write("cost %f s" % (end_time - start_time))
                f.write("Attribute Representativeness is:")
                f.write(str(metric.AttributeRepresentative(features,
                                                           profile2)))
                f.write("\n")
                for profile in profile2:
                    f.write(profile + "\t")
            start_time = time.time()
            profile3 = sa.SAalgo(n, features, datapre.CategoriesDistribution(),
                                 epsilon, 0.3, 10, 0.9).Search()
            end_time = time.time()
            with open("sa%d_%.4f" % (n, epsilon), "wb") as f:
                f.write("cost %f s" % (end_time - start_time))
                f.write("Attribute Representativeness is:")
                f.write(str(metric.AttributeRepresentative(features,
                                                           profile3)))
                f.write("\n")
                for profile in profile3:
                    f.write(profile + "\t")
def makeD(X):
    D = np.empty((0))
    rows, colums = X.shape
    for i in range(0, rows - 1):
        for j in range(i, rows - 1):
            if (i != j):
                D = np.append(D, metric.euclidian_dist(X[i], X[j]))

    D /= np.max(D, axis=0)
    return D
Пример #18
0
 def __init__(self, k, init_temper, dec, users, feature, R, id_list, g):
     # 初始温度init_temper,温度下降参数delta
     self.temper = init_temper
     self.dec = dec
     # 需要找寻的代表性子集的大小
     self.k = k
     # 加载用户数据
     self.users = users
     # 加载评价类
     self.metric = metric.Metrics(users, feature, R, id_list, g)
Пример #19
0
    def OnViewSessionClick(self, datestring):
        """ action - displays a session
		"""
        self.start = datetime.datetime.strptime(datestring, '%Y-%m-%d')
        self.end = self.start + datetime.timedelta(seconds=86399)
        self.session = self.sessions[datestring]
        self.metrics = {}
        for s in self.session:
            self.metrics[s[0]['name']] = Metric(s[0]['name'], -1, False)
        self.viewSession()
Пример #20
0
def test():
    category = "Sports"
    users, R, id_list, g = init.Init(category)
    metric = Metric.Metrics(users, R, id_list, g)
    num = len(users) * 0.05
    s3 = S3(users, len(users), R, num, 0.6)
    start_time = time.time()
    profiles = s3.SearchWithNoGroups()
    end_time = time.time()
    print "cost %f s" % (end_time - start_time)
    rc, rt, rscore = metric.RScore(profiles)
    print "特征代表性:%f,拓扑结构代表性:%f,rscore:%f" % (rc, rt, rscore)
    def futurePricesListGenerator(self, asset, start_time, end_time,
                                  timeframe):
        #Since the price list is supposed to be the outputs change initial time to be the one which can be predicted
        price_list = []
        time_at_future = start_time + timeframe

        #loop to find price at all separate points in time
        while time_at_future < end_time:
            price_list.append(Metric.getMetric("price", asset, time_at_future))
            time_at_future += timeframe

        return price_list
Пример #22
0
def test():
    category = "Actor"
    users, R, id_list, g = init.Init(category)
    metric = Metric.Metrics(users, R, id_list, g)
    num = len(users) * 0.15
    xsn = XSN(num, id_list, g)
    start_time = time.time()
    profiles = xsn.Search()
    end_time = time.time()
    rc, rt, r_score = metric.RScore(profiles)
    print "cost %f s" % (end_time - start_time)
    print "rc:%f,rt:%f,r_score:%f" % (rc, rt, r_score)
Пример #23
0
	def _compare_documents(document1, document2):
		""" Calculates the distance between the given documents """

		doc1_topic_description = []
		doc2_topic_description = []

		for (topic, weight) in document1:
			doc1_topic_description.append(weight)

		for (topic, weight) in document2:
			doc2_topic_description.append(weight)

		return Metric.js_distance(doc1_topic_description, doc2_topic_description)
def test():
    features = datapre.Features()
    to_run = [40, 60, 80, 100]
    for i in to_run:
        start_time = time.time()
        method = KMedoids(i, datapre.Features(),
                          datapre.CategoriesDistribution(), 0.1555)
        profiles = method.Search()
        end_time = time.time()
        print metric.AttributeRepresentative(features, profiles)
        print profiles
        print "cost %f s" % (end_time - start_time)
        with open("%dclustering_result" % i, "wb") as f:
            f.write("cost %f s" % (end_time - start_time))
            f.write("\n")
            f.write("Attribute Representativeness is:")
            f.write(str(metric.AttributeRepresentative(features, profiles)))
            f.write("\n")
            for profile in profiles:
                f.write(profile + "\t")


# test()
Пример #25
0
    def _compare_documents(document1, document2):
        """ Calculates the distance between the given documents """

        doc1_topic_description = []
        doc2_topic_description = []

        for (topic, weight) in document1:
            doc1_topic_description.append(weight)

        for (topic, weight) in document2:
            doc2_topic_description.append(weight)

        return Metric.js_distance(doc1_topic_description,
                                  doc2_topic_description)
Пример #26
0
 def __init__(self, users, R, k, id_list, g):
     # 返回top k个
     self.k = k
     # 用户数据
     self.users = users
     # 图结构
     self.g = g
     # 结点对应编号
     # 转换成字典,id_list中的id为string类型
     self.id_dic = dict(zip(id_list, range(len(id_list))))
     # 节点编号
     self.id_list = id_list
     # 评价标准
     self.metric = Metric.Metrics(users, R, id_list, g)
Пример #27
0
	def __init__(self, parent, gui, **options):
		super(TkMetricManager,self).__init__(parent, gui, **options)
		self.m = Metric('placeholder', archive = False)
		self.index = self.m.getIndex()
		self.sessions = self.index['sessions']
		self.metrics = self.index['metrics']
		self.scales = {
			'hour': (23, 240),
			'minute': (59, 600),
			'second': (59, 600),
			'millisecond': (999, 1000)
		}
		self.shapes = {}
		self.resolutions = { 'day': 86400.0, 'hour': 3600.0, 'minute': 60.0, 'second': 1.0, 'millisecond': 0.001}
Пример #28
0
    def get_metric_matching_info(self):
        """
        Getting R, G and B pixels data for any part of the puzzle
        """
        files = sorted(os.listdir(self.blocks_path),
                       key=lambda string: int(string[0:string.find('.')]))
        distances = list()
        cnt = 0
        for file in files:
            current_dist = list()

            for another_file in files:
                if file != another_file:
                    img_file = Image.open(self.blocks_path + file)
                    img_another_file = Image.open(self.blocks_path +
                                                  another_file)

                    up = Metric.get_metric_distance(img_file, img_another_file,
                                                    'U', self.block_size)
                    down = Metric.get_metric_distance(img_file,
                                                      img_another_file, 'D',
                                                      self.block_size)
                    left = Metric.get_metric_distance(img_file,
                                                      img_another_file, 'L',
                                                      self.block_size)
                    right = Metric.get_metric_distance(img_file,
                                                       img_another_file, 'R',
                                                       self.block_size)

                    current_dist.append([up, down, left, right])
                else:
                    current_dist.append([-1, -1, -1, -1])
            cnt += 1
            print(str(cnt) + ' ' + str(current_dist))
            distances.append(current_dist)

        return distances
    def action(self):
        super().action()
        #Set value for time and asset
        asset = self.portfolio.getAsset('ETH')
        now = self.curr_time

        #Load metrics values for the particular moment for predicition
        list_of_metric_values = []
        for metric in self.metrics_list:
            list_of_metric_values.append(
                Metric.getMetric(metric, self.ass, now))

        #The model expects a 2D Array of values to predict, hence put list in a list
        list_of_metric_values = [list_of_metric_values]
        #Get predicted price and current price
        curr_price = Metric.getMetric("price", self.ass, now)
        pred_price = self.prediction_at_time(list_of_metric_values)
        #Buy if predicted price is higher than current
        if pred_price > curr_price:
            self.market.buy(asset, 1)

        #Sell if predicted price is lower than current
        elif pred_price < curr_price:
            self.market.sell(asset, 1)
Пример #30
0
    def is_best_body(self, first_part, second_part, side):
        side_index = Metric.get_side_index(side)
        reverse_size_index = Metric.get_reversed_side_index(side)
        min_cost_first = 100000.0
        min_cost_second = 100000.0

        for i in range(self.block_cnt):
            if self.metric_info[first_part][i][side_index] != -1:
                if self.metric_info[first_part][i][side_index] < min_cost_first:
                    min_cost_first = self.metric_info[first_part][i][
                        side_index]

            if self.metric_info[second_part][i][reverse_size_index] != -1:
                if self.metric_info[second_part][i][
                        reverse_size_index] < min_cost_second:
                    min_cost_second = self.metric_info[second_part][i][
                        reverse_size_index]
        # print('first: ' + str(min_cost_first) + ' ' + str(side_index) + ' second: ' + str(min_cost_second) + ' ' + str(
        #   reverse_size_index))

        if min_cost_first == min_cost_second:
            # print(' -> mins : ' + str(min_cost_first) + ' second: ' + str(min_cost_second))
            return True
        return False
Пример #31
0
    def initialize(self, log_file):
        """
        Initialize rewards. We use here the same value,
        gained by calculating metrics on randomly assigned labels.
        """

        # Random initialization of cluster labels
        self.action.data = self.action.data.withColumn('labels', round(rand()*self.params.n_clusters_upper_bound)\
                                                       .cast(IntegerType()))

        res = Metric.metric(self.action.data, self.params.metric)

        for i in range(0, self.params.num_algos):
            self.rewards[i] = -res  # the smallest value is, the better.
        log_file.write("Init rewards: " + str(self.rewards) + '\n')
Пример #32
0
 def save_filter_values(self, DirectoryPath_str, FileName_str):
     '''A function that saves filter values, sorted in the same
     order as the initial PointCloud_npArray, to a file on a 
     given locantion.  '''
     if self.UnsortedFilterValues_npArray != None:
             np.save(DirectoryPath_str + FileName_str, 
                     self.UnsortedFilterValues_npArray)
     else:
         self.UnsortedFilterValues_npArray = \
         ff.FilterFunctions().apply_filter(self.PointCloud_npArray,
                                         me.Metric(self.MetricName_str, 
                                                 self), 
                                         self.LensName_str, 
                                         self.LensArguments_array)
         np.save(DirectoryPath_str + FileName_str, 
                 self.UnsortedFilterValues_npArray)
Пример #33
0
    def main(self):
        # Initialize Log File Format
        logging.basicConfig(handlers=[logging.FileHandler('LogFile.log', 'w', 'utf-8')], level=logging.INFO,
                            format='%(asctime)s - %(levelname)s - %(message)s')
        logging.info('Started')

        # Create Read File
        read = ReadFile()
        # Empty lists and paths to read files in working directory
        Polls = []
        BYSLIST = ""
        tempList = os.listdir(os.getcwd())

        # For each file if that file ends with csv and if it is a answer key then call readAnswerKey
        for files in tempList:
            if files.endswith(".csv"):
                if "AnswerKey" in files:
                    read.readAnswerKey(files)
                else:
                    # Else add it to Polls
                    Polls.append(files)
                    # If file ends with xls then it is the student list
            elif files.endswith(".xls"):
                BYSLIST = files

        # read student list by calling readStudentFile function
        students = read.readStudentFile(BYSLIST)

        # Initialize which poll is being used
        usedPolls = []
        for report in Polls:
            # Read report files and add them to used polls
            read.readReportFile(report, usedPolls)

        # For each student match their answers with correct answers
        for student in students:
            student.setCorrectAnswer()
            student.toString()
            
        # Create write Output object
        write = WriteOutput(students, usedPolls)
        # Write output of each students result for each Poll
        write.writeGlobalResult()

        # Create Metric
        metric = Metric(read)
        # Write results to the Global File
        metric.calculateMetrics(usedPolls)

        # Print results of each question and print pie charts and histograms to excel file
        metric.calculateQuestionDistrubition(usedPolls)

        # Print attendance
        write.writeAttandence(metric)
Пример #34
0
def __main__(args):
    """Input an RDG (and background), output a terms list"""
    logging.basicConfig(level=LEVEL)
    working_dir = '.'
    try:
        # First argument: RDG folder
        rdgfolder = args[1]
        # test if the folder is real
        if not os.path.isfile(rdgfolder):
            raise
        # Optional arguments:
        i = 2
        while i < len(args):
            # Optionally set measure
            if args[i] == '-m':
                measure = args[i+1]
                # check that the measure is real
                if measure not in MEASURES:
                    raise
                i += 2
            # Optionally set testing file
            elif args[i] ==  '-t':
                testfile = args[i+1]
                # check that the file is real
                if not os.path.isfile(testfile):
                    raise
                i += 2
            elif args[i] ==  '-d':
                working_dir = args[i+1]
                # check that the file is real
                if not os.path.isdir(working_dir):
                    if os.path.isfile(working_dir):
                        raise
                    else:
                        os.mkdir(working_dir)
                i += 2
            else:
                # Optionally set reference folder:
                reffolder = args[i]
                # test if the folder is real
                if not os.path.isfile(reffolder):
                    raise
                i += 1
        # default measure to 'Weighted'
        if 'measure' not in locals():
            measure = 'Weighted'
    except:
        # Remind the user what input is acceptable
        logging.error('Usage: '+args[0]+' rdg_folder [ref_folder] [-m measure] [-t testfile]')
        logging.error('Measures: '+str(MEASURES))
        exit(-1)
    # log parameters
    logging.info('RDG Folder: '+rdgfolder)
    if 'reffolder' in locals():
        logging.info('Reference Folder: '+reffolder)
    else:
        logging.info('Reference Folder: None')
    logging.info('Measure: ' + measure)
    if 'testfile' in locals():
        logging.info('Test Word List File: ' + testfile)
    else:
        logging.info('Test Word List File: None')
    # Set up the measurement class
    logging.debug('Loading Files...')
    if 'reffolder' in locals():
        metric = Metric(rdgfolder, reffolder, working_dir) # reference files given
    else:
        raise
        #metric = Metric(rdgfolder, refcorpus) # reference corpus assumed
    logging.debug('done')
    # Get rankings
    logging.debug('Ranking terms...')
    if 'testfile' in locals():
        ranking = metric.rankWordList(testfile, measure)
    else:
        ranking = metric.rankTerms(measure)
    logging.debug('done')
    # Print rankings
    #for r in ranking:
    #    print r[0]+'\t'+str(r[1])
    try:
        for i in range(len(ranking)):
            if (len(ranking[i][0]) > MAX_LEN):
                continue
            sys.stdout.write(ranking[i][0]+'\t'+str(ranking[i][1])+'\n')
    except IOError as e:
        if e.errno == errno.EPIPE: #no longer printing to stdout
            return
Пример #35
0
import sys, os, logging, errno
import Document
from Metric import *

rdgpath = '/misc/proteus107/zg440/test2/emerging/'
genpath = '/misc/proteus107/zg440/test2/random/'

measures = ['TFIDF', 'DRDC', 'KLDiv']

oldpath = os.path.abspath('.')
os.chdir(rdgpath)
temppath = 'temp1234'
os.makedirs(temppath)
metric = Metric(temppath, temppath)
os.remove(os.path.join(temppath, 'filter.save'))
os.rmdir(temppath)
os.chdir(oldpath)
print 'Getting stemming dictionary'
Filter._get_stemdict(os.path.join(genpath, 'filter.save'))
print 'Getting background'
metric.genDocs = Document()
genfiles = [genFile for genFile in os.listdir(genpath) if genFile[-4:]=='.txt']
for f in genfiles:
    d = Document(os.path.join(genpath, f))
    for w in d.counts:
        metric.genDocs.counts[w] += d.counts[w]
print 'Getting all RDG subfolders'
rdgdirs = [d for d in os.listdir(rdgpath) if os.path.isdir(os.path.join(rdgpath, d))]
for d in rdgdirs:
    print 'Computing metrics for '+d
    if os.path.exists(os.path.join(rdgpath, d, 'TFIDF.out')):
Пример #36
0
from Riemann import *
from Ricci import *
from Rscalar import *

B= Function('B')
A= Function('A')

t=Symbol('t')
r=Symbol('r')
theta=Symbol('theta')
phi=Symbol('phi')

#general, spherically symmetric metric


g=Metric(   (  (-B(r),0,0,0), (0, A(r), 0, 0), (0, 0, r**2, 0), (0, 0, 0, r**2*sin(theta)**2)   )  )
x=(t,r,theta,phi)
C=Christoffel(g,x)
Rie = Riemann(C,x)
Ric=Ricci( Rie,x)
Rs =Rscalar(Ric)

print 'Initial metric:'
pprint(g.matrix())
C.nonzero()
Ric.nonzero()
#Rie.nonzero()
Rs.printing() 

print '-'*40
#Solving EFE for A and B
Пример #37
0
from Riemann import *
from Ricci import *
from Rscalar import *
from ET import *

B= Function('B')
A= Function('A')

t=Symbol('t')
r=Symbol('r')
theta=Symbol('theta')
phi=Symbol('phi')

g=Metric(
    (-B(r),0,0,0),
    (0, A(r), 0, 0),
    (0, 0, r**2, 0),
    (0, 0, 0, r**2*sin(theta)**2)
    )
x=(t,r,theta,phi)
C=Christoffel(g,x)
Rie = Riemann(C,x)
Ric=Ricci( Rie,x)
Rs =Rscalar(Ric)
G = ET(Ric, g, Rs)

print 'Initial metric:'
pprint(g.matrix())
#C.nonzero()
Ric.nonzero()
#Rie.nonzero()
#Rs.printing() 
Пример #38
0
	def OnViewMetricClick(self, name):
		self.metric = Metric(name)
		self.viewMetric()
Пример #39
0
class TkMetricManager(TkPage):
	def __init__(self, parent, gui, **options):
		super(TkMetricManager,self).__init__(parent, gui, **options)
		self.m = Metric('placeholder', archive = False)
		self.index = self.m.getIndex()
		self.sessions = self.index['sessions']
		self.metrics = self.index['metrics']
		self.scales = {
			'hour': (23, 240),
			'minute': (59, 600),
			'second': (59, 600),
			'millisecond': (999, 1000)
		}
		self.shapes = {}
		self.resolutions = { 'day': 86400.0, 'hour': 3600.0, 'minute': 60.0, 'second': 1.0, 'millisecond': 0.001}
	def setup(self):
		self.gui.menus['metrics'] = Tkinter.Menu(self.gui.menubar, tearoff=0, bg=self.colours['menubg'], fg=self.colours['menufg'], activeforeground=self.colours['menuactivefg'], activebackground=self.colours['menuactivebg'])
		self.gui.menus['metrics'].add_command(label="Snapshot", command=self.OnSnapshotClick)
		self.gui.menus['metrics'].add_command(label="History", command=self.OnListMetricsClick)
		self.addMenu(label="Metrics", menu=self.gui.menus['metrics'])
	
	#=== VIEWS ===#
	def listMetrics(self):
		self.open()
		self.widgets['frameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metrics / History', anchor=NW, bg=self.colours['bg'], fg=self.colours['headingfg'], font=self.fonts['heading2'])
		self.widgets['frameLabel'].grid(column=0,row=self.gridrow,sticky='EW')
		self.widgets['hotvalues'] = Tkinter.Button(self.widgets['tframe'],text=u"Snapshot", image=self.images['ram'], command=self.OnSnapshotClick, bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
		self.widgets['hotvalues'].grid(column=1,row=self.gridrow)
		
		self.gridrow += 1
		
		if(len(self.metrics) > 0):
			keys = self.metrics.keys()
			keys.sort()
			
			self.widgets['nameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metric', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['nameLabel'].grid(column=0,row=self.gridrow,sticky='EW')
			self.widgets['sessionsLabel'] = Tkinter.Label(self.widgets['tframe'],text='Sessions', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['sessionsLabel'].grid(column=1,row=self.gridrow,sticky='EW')
			self.widgets['viewLabel'] = Tkinter.Label(self.widgets['tframe'],text='View', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['viewLabel'].grid(column=2,row=self.gridrow,sticky='EW')
			self.gridrow += 1
			
			for k in keys:
				self.widgets['{0}MetricLabel'.format(k)] = Tkinter.Label(self.widgets['tframe'],text=k, anchor=NW, bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['{0}MetricLabel'.format(k)].grid(column=0,row=self.gridrow,sticky='EW')
				self.widgets['{0}SessionLabel'.format(k)] = Tkinter.Label(self.widgets['tframe'],text=len(self.metrics[k]), anchor=NW, bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['{0}SessionLabel'.format(k)].grid(column=1,row=self.gridrow,sticky='EW')
				self.widgets['{0}View'.format(k)] = Tkinter.Button(self.widgets['tframe'],text=u"View", image=self.images['find'], command=lambda x = k:self.OnViewMetricClick(x), bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
				self.widgets['{0}View'.format(k)].grid(column=2,row=self.gridrow)
				self.gridrow += 1
	def viewMetric(self):
		self.open()
		self.widgets['frameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metrics / View Metric', anchor=NW, bg=self.colours['bg'], fg=self.colours['headingfg'], font=self.fonts['heading2'])
		self.widgets['frameLabel'].grid(column=0,row=self.gridrow, columnspan=2, sticky='EW')
		self.gridrow += 1
		self.widgets['nameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metric Name', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['nameLabel'].grid(column=0,row=self.gridrow,sticky='EW')
		self.widgets['nameData'] = Tkinter.Label(self.widgets['tframe'],text=self.metric.name, bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['nameData'].grid(column=1,row=self.gridrow,sticky='EW')
		self.gridrow += 1
		sessions = self.metrics[self.metric.name]
		if(any(sessions)):
			self.widgets['dayLabel'] = Tkinter.Label(self.widgets['tframe'],text='Day', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['dayLabel'].grid(column=0,row=self.gridrow,sticky='EW')
			self.widgets['monthLabel'] = Tkinter.Label(self.widgets['tframe'],text='Month', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['monthLabel'].grid(column=1,row=self.gridrow,sticky='EW')
			self.widgets['yearLabel'] = Tkinter.Label(self.widgets['tframe'],text='Year', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['yearLabel'].grid(column=2,row=self.gridrow,sticky='EW')
			self.widgets['yearLabel'] = Tkinter.Label(self.widgets['tframe'],text='Archive', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['yearLabel'].grid(column=3,row=self.gridrow,sticky='EW')
			self.widgets['viewLabel'] = Tkinter.Label(self.widgets['tframe'],text='View', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
			self.widgets['viewLabel'].grid(column=4,row=self.gridrow,sticky='EW')
			self.gridrow += 1
			for s in sessions:
				self.widgets['dLabel'] = Tkinter.Label(self.widgets['tframe'],text=s[1]['day'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['dLabel'].grid(column=0,row=self.gridrow,sticky='EW')
				self.widgets['mLabel'] = Tkinter.Label(self.widgets['tframe'],text=s[1]['month'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['mLabel'].grid(column=1,row=self.gridrow,sticky='EW')
				self.widgets['yLabel'] = Tkinter.Label(self.widgets['tframe'],text=s[1]['year'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['yLabel'].grid(column=2,row=self.gridrow,sticky='EW')
				self.widgets['yLabel'] = Tkinter.Label(self.widgets['tframe'],text='warm' if not s[2] else 'cold', bg=self.colours['bg'], fg=self.colours['fg'], height=2)
				self.widgets['yLabel'].grid(column=3,row=self.gridrow,sticky='EW')
				self.widgets['view'] = Tkinter.Button(self.widgets['tframe'],text=u"View", image=self.images['find'], command=lambda x = s[0]:self.OnViewMetricSessionClick(x), bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
				self.widgets['view'].grid(column=4,row=self.gridrow)
				self.gridrow += 1
		else:
			self.widgets['noLabel'] = Tkinter.Label(self.widgets['tframe'],text='This metric currently has no sessions.', bg=self.colours['bg'], fg=self.colours['fg'], height=2)
			self.widgets['noLabel'].grid(column=0,row=self.gridrow,sticky='EW')
			self.gridrow += 1
		self.widgets['optionsFrame'] = Tkinter.Frame(self.widgets['tframe'], bg=self.colours['bg'])
		self.widgets['optionsFrame'].grid(column=0,row=self.gridrow,columnspan=2, sticky='EW')
		
		self.gridrow = 0
		
		self.widgets['backlabel'] = Tkinter.Label(self.widgets['optionsFrame'],text="Back", bg=self.colours['bg'], fg=self.colours['fg'], height=2)
		self.widgets['backlabel'].grid(column=0,row=self.gridrow,sticky='EW')
		
		self.gridrow += 1
		
		self.widgets['back'] = Tkinter.Button(self.widgets['optionsFrame'],text=u"Cancel", image=self.images['back'], command=self.OnListMetricsClick, bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
		self.widgets['back'].grid(column=0,row=self.gridrow)
	def viewMetricSession(self):
		self.open()
		self.widgets['frameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metrics / View Metric', anchor=NW, bg=self.colours['bg'], fg=self.colours['headingfg'], font=self.fonts['heading2'])
		self.widgets['frameLabel'].grid(column=0,row=self.gridrow, columnspan=2, sticky='EW')
		self.gridrow += 1
		
		self.widgets['iframe'] = Tkinter.Frame(self.widgets['tframe'], bg=self.colours['bg'])
		self.widgets['iframe'].grid(column=0,row=self.gridrow, sticky='W')
		
		self.widgets['nameLabel'] = Tkinter.Label(self.widgets['iframe'],text='Metric Name', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['nameLabel'].grid(column=0,row=0,sticky='EW')
		self.widgets['nameData'] = Tkinter.Label(self.widgets['iframe'],text=self.metric.name, bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['nameData'].grid(column=1,row=0,sticky='EW')
		
		self.widgets['startLabel'] = Tkinter.Label(self.widgets['iframe'],text='Session Start', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['startLabel'].grid(column=0,row=1,sticky='EW')
		self.widgets['startData'] = Tkinter.Label(self.widgets['iframe'],text=str(self.sessionstart), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['startData'].grid(column=1,row=1,sticky='EW')
		
		self.widgets['endLabel'] = Tkinter.Label(self.widgets['iframe'],text='Session End', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['endLabel'].grid(column=2,row=1,sticky='EW')
		self.widgets['endData'] = Tkinter.Label(self.widgets['iframe'],text=str(self.sessionend), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['endData'].grid(column=3,row=1,sticky='EW')
		
		self.widgets['rangeStartLabel'] = Tkinter.Label(self.widgets['iframe'],text='Range Start', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['rangeStartLabel'].grid(column=0,row=2,sticky='EW')
		self.widgets['rangeStartData'] = Tkinter.Label(self.widgets['iframe'],text=str(datetime.datetime.fromtimestamp(self.times['rangestart'])), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['rangeStartData'].grid(column=1,row=2,sticky='EW')
		
		self.widgets['rangeEndLabel'] = Tkinter.Label(self.widgets['iframe'],text='Range End', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['rangeEndLabel'].grid(column=2,row=2,sticky='EW')
		self.widgets['rangeEndData'] = Tkinter.Label(self.widgets['iframe'],text=str(datetime.datetime.fromtimestamp(self.times['rangeend'])), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['rangeEndData'].grid(column=3,row=2,sticky='EW')
		
		self.widgets['resolutionLabel'] = Tkinter.Label(self.widgets['iframe'],text='Resolution', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['resolutionLabel'].grid(column=0,row=3,sticky='EW')
		self.widgets['resolutionData'] = Tkinter.Label(self.widgets['iframe'],text=self.resolution, bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['resolutionData'].grid(column=1,row=3,sticky='EW')
		
		self.widgets['resolutionLabel'] = Tkinter.Label(self.widgets['iframe'],text='Values in Range', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['resolutionLabel'].grid(column=2,row=3,sticky='EW')
		self.widgets['resolutionData'] = Tkinter.Label(self.widgets['iframe'],text=len(self.vals), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['resolutionData'].grid(column=3,row=3,sticky='EW')
		
		self.gridrow += 1
		
		self.widgets['tlframe'] = Tkinter.Frame(self.widgets['tframe'], bg=self.colours['bg'])
		self.widgets['tlframe'].grid(column=0,row=self.gridrow, sticky='W')
		
		self.widgets['valuemap'] = Tkinter.Canvas(self.widgets['tlframe'], borderwidth=0, bg=self.colours['trough'], highlightthickness=0, width=self.scales[self.resolution][1], height=20)
		self.widgets['valuemap'].grid(column=1,row=0, padx=2, sticky='W')
		
		self.variables['time'] = Tkinter.IntVar()
		self.widgets['timeline'] = Tkinter.Scale(self.widgets['tlframe'], from_=0, to=self.scales[self.resolution][0], variable=self.variables['time'], command=self.updateMetricValues, resolution=1, orient=Tkinter.HORIZONTAL, length = self.scales[self.resolution][1], bg=self.colours['inputbg'], fg=self.colours['fg'], activebackground=self.colours['handle'], troughcolor=self.colours['trough'])
		self.widgets['timeline'].grid(column=1,row=1, sticky='W')
		if(self.resolution != 'millisecond'):
			self.widgets['change'] = Tkinter.Button(self.widgets['tlframe'],text=u"Change", image=self.images['find'], command=self.OnRaiseResolutionClick, bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
			self.widgets['change'].grid(column=2,row=1, sticky='W')
		
		self.updateValueMap()
		
		self.gridrow += 1
		
		self.widgets['vframe'] = Tkinter.Frame(self.widgets['tframe'], bg=self.colours['bg'])
		self.widgets['vframe'].grid(column=0,row=self.gridrow, sticky='W')
		self.widgets['showingLabel'] = Tkinter.Label(self.widgets['vframe'],text='Now showing', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['showingLabel'].grid(column=0,row=0,sticky='EW')
		self.widgets['currentData'] = Tkinter.Label(self.widgets['vframe'],text=str(self.start), bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
		self.widgets['currentData'].grid(column=1,row=0,sticky='EW')
		self.widgets['dashLabel'] = Tkinter.Label(self.widgets['vframe'],text='-', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['dashLabel'].grid(column=2,row=0, padx=10, sticky='EW')
		self.widgets['recordData'] = Tkinter.Label(self.widgets['vframe'],text='No Record', bg=self.colours['bg'], fg=self.colours['fg'], height=2)
		self.widgets['recordData'].grid(column=3,row=0,sticky='EW')
		self.widgets['dataLabel'] = Tkinter.Label(self.widgets['vframe'],text='Value(s)',anchor=W, bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
		self.widgets['dataLabel'].grid(column=0,row=1, ipady=10, ipadx=10, sticky='NW')
		self.widgets['dframe'] = Tkinter.Frame(self.widgets['vframe'], bg=self.colours['bg'])
		self.widgets['dframe'].grid(column=1,row=1, sticky='W')
		self.gridrow += 1
	
		self.widgets['optionsFrame'] = Tkinter.Frame(self.widgets['tframe'], bg=self.colours['bg'])
		self.widgets['optionsFrame'].grid(column=0,row=self.gridrow,columnspan=2, sticky='EW')
		
		self.gridrow = 0
		
		self.widgets['backlabel'] = Tkinter.Label(self.widgets['optionsFrame'],text="Back", bg=self.colours['bg'], fg=self.colours['fg'], height=2)
		self.widgets['backlabel'].grid(column=0,row=self.gridrow,sticky='EW')
		
		self.gridrow += 1
		
		self.widgets['back'] = Tkinter.Button(self.widgets['optionsFrame'],text=u"Cancel", image=self.images['back'], command=self.OnLowerResolutionClick, bg=self.colours['buttonbg'], activebackground=self.colours['buttonhighlightbg'], highlightbackground=self.colours['buttonborder'])
		self.widgets['back'].grid(column=0,row=self.gridrow)
	def updateMetricValues(self, time):
		'''
		self.updateMetricValues - adds / updates the value of a metric given the time and resolution of the view
		'''
		time = int(time)
		self.times['currentstart'] = self.times['rangestart'] + time * self.resolutions[self.resolution]
		self.times['currentend'] = self.times['currentstart'] + self.resolutions[self.resolution]
		try:
			self.widgets['currentData'].configure(text=str(datetime.datetime.fromtimestamp(self.times['currentstart'])))
		except:
			return #first time round this has not been defined and the initial value is correct
		if(any(self.vals)):
			v = [x for x in self.vals if float(x.timestamp)/1000 >= self.times['currentstart'] and float(x.timestamp)/1000 <= self.times['currentend'] ]
			if(any(v)):
				self.wipeDataView()
				self.widgets['recordData'].configure(text='Recorded at: {}'.format(str(datetime.datetime.fromtimestamp(v[0].timestamp/1000))), fg=self.colours['valuefg'])
				self.widgets['dataview'] = self.genericView(self.widgets['dframe'], v[0].datavalue)
				self.widgets['dataview'].grid(column=0,row=0,sticky='EW')
			else:
				self.widgets['recordData'].configure(text='No Record', fg=self.colours['fg'])
				try:
					self.widgets['dataview']
				except:
					self.widgets['dataview'] = self.genericView(self.widgets['dframe'], 'TBD')
					self.widgets['dataview'].grid(column=0,row=0,sticky='EW')
		else:
			self.widgets['recordData'].configure(text='No Record', fg=self.colours['fg'])
			self.wipeDataView()
			self.widgets['dataview'] = self.genericView(self.widgets['dframe'], 'TBD')
			self.widgets['dataview'].grid(column=0,row=0,sticky='EW')
		self.updateValueMapMarker()
	def updateValueMap(self):
		'''
		adds shapes on the value map based on the time of each loaded MetricValue
		
		happens when the view is refreshed (change of resolution or first load
		'''
		unit = self.scales[self.resolution][1] / self.scales[self.resolution][0]
		for v in self.vals:
			indent = (v.timestamp / 1000.0 - self.times['rangestart'])
			if(self.resolution != 'millisecond'):
				indent /= self.resolutions[self.resolution]
			else:
				indent *= 1000
			units = 0
			while(units < indent):
				units += 1
			units -= 1
			if(self.resolution != 'millisecond'):
				indent = units * unit
			self.shapes['v{}'.format(indent)] = self.widgets['valuemap'].create_rectangle((indent,0,indent+10, 20), fill=self.colours['valuefg'], tags='value')
	def updateValueMapMarker(self):
		offset = float(self.variables['time'].get())
		if(self.resolution != 'millisecond'):
			unit = self.scales[self.resolution][1] / self.scales[self.resolution][0]
			offset *= unit
		else:
			unit = 10
		try:
			self.widgets['valuemap'].coords(self.shapes['marker'],offset,0,offset+unit,10)
		except:
			self.shapes['marker'] = self.widgets['valuemap'].create_rectangle((offset,0,offset+unit, 10), outline=self.colours['unitblue1'], tags='marker')
		self.widgets['valuemap'].tag_raise('marker')
		self.widgets['valuemap'].tag_lower('value')
	def wipeDataView(self):
		try:
			self.widgets['dataview'].grid_forget()
			del(self.widgets['dataview'])
		except:
			pass
	def showSnapshot(self):
		self.open()
		self.widgets['frameLabel'] = Tkinter.Label(self.widgets['tframe'],text='Metrics / Snapshot', anchor=NW, bg=self.colours['bg'], fg=self.colours['headingfg'], font=self.fonts['heading2'])
		self.widgets['frameLabel'].grid(column=0,row=self.gridrow,sticky='EW')
		
		self.gridrow += 1
		
		if(len(Metric.metrics) > 0):
			for k,v in Metric.metrics.iteritems():
				self.widgets['mframe'+k] = Tkinter.Frame(self.widgets['tframe'], borderwidth=0, highlightthickness=0, bg=self.colours['bg'])
				self.widgets['mframe'+k].grid(column=0,row=self.gridrow,sticky='EW')
				row = 0
				
				self.widgets['hframe'+k] = Tkinter.Frame(self.widgets['mframe'+k], borderwidth=0, highlightthickness=0, bg=self.colours['bg'])
				self.widgets['hframe'+k].grid(column=0,row=0, columnspan=2,sticky='EW')
				
				self.widgets['valuesLabel'+k] = Tkinter.Label(self.widgets['mframe'+k],text='Values', anchor='nw', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['valuesLabel'+k].grid(column=0,row=1,padx=10, sticky='NWSE')
				
				self.widgets['vframe'+k] = Tkinter.Frame(self.widgets['mframe'+k], borderwidth=0, highlightthickness=0, bg=self.colours['bg'])
				self.widgets['vframe'+k].grid(column=1,row=1,sticky='EW')
				
				info = v.getInfo()
				self.widgets['nameLabel'+k] = Tkinter.Label(self.widgets['hframe'+k],text='Name', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['nameLabel'+k].grid(column=0,row=row, padx=10, sticky='EW')
				self.widgets['nameData'+k] = Tkinter.Label(self.widgets['hframe'+k],text=info['name'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['nameData'+k].grid(column=1,row=row,sticky='EW')
				
				self.widgets['typeLabel'+k] = Tkinter.Label(self.widgets['hframe'+k],text='Type', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['typeLabel'+k].grid(column=2,row=row,padx=10, sticky='EW')
				self.widgets['typeData'+k] = Tkinter.Label(self.widgets['hframe'+k],text=info['type'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['typeData'+k].grid(column=3,row=row,sticky='EW')
				
				self.widgets['historyLabel'+k] = Tkinter.Label(self.widgets['hframe'+k],text='History', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['historyLabel'+k].grid(column=4,row=row,padx=10, sticky='EW')
				self.widgets['historyData'+k] = Tkinter.Label(self.widgets['hframe'+k],text=info['history'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['historyData'+k].grid(column=5,row=row,sticky='EW')
				
				self.widgets['archiveLabel'+k] = Tkinter.Label(self.widgets['hframe'+k],text='Archive', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['archiveLabel'+k].grid(column=6,row=row,padx=10, sticky='EW')
				self.widgets['archiveData'+k] = Tkinter.Label(self.widgets['hframe'+k],text=info['archive'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['archiveData'+k].grid(column=7,row=row,sticky='EW')
				
				self.widgets['batchLabel'+k] = Tkinter.Label(self.widgets['hframe'+k],text='Batch', bg=self.colours['bg'], fg=self.colours['headingfg'], height=2)
				self.widgets['batchLabel'+k].grid(column=8,row=row,padx=10, sticky='EW')
				self.widgets['batchData'+k] = Tkinter.Label(self.widgets['hframe'+k],text=info['batch'], bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['batchData'+k].grid(column=9,row=row,sticky='EW')
				row += 1
				
				self.widgets['noLabel'+k] = Tkinter.Label(self.widgets['vframe'+k],text='TBD', bg=self.colours['bg'], fg=self.colours['valuefg'], height=2)
				self.widgets['noLabel'+k].grid(column=0,row=0,padx=10, sticky='EW')
				
				self.gridrow += 1
			self.updateValues()
		else:
			self.widgets['noLabel'] = Tkinter.Label(self.widgets['tframe'],text='There are currently no metrics being monitored', anchor=NW, bg=self.colours['bg'], fg=self.colours['fg'])
			self.widgets['noLabel'].grid(column=0,row=self.gridrow,sticky='EW')
	def updateValues(self):
		for k,v in Metric.metrics.iteritems():
			vals = v.hotValues()
			if(len(vals) > 0):
				try:
					self.widgets['noLabel'+k].grid_forget()
					del(self.widgets['noLabel'+k])
				except:
					pass
				vcol = 0
				for i in vals:
					vindex = 'v{0}{1}'.format(k,vcol)
					self.widgets['time'+vindex] = Tkinter.Label(self.widgets['vframe'+k],text=datetime.datetime.fromtimestamp(i.timestamp/1000).strftime('%Y-%m-%d %H:%M:%S'), bg=self.colours['rowbg'], fg=self.colours['headingfg'], height=2)
					self.widgets['time'+vindex].grid(column=vcol,row=0, padx=10,sticky='EW')
					self.widgets['val'+vindex] = self.genericView(self.widgets['vframe'+k], i.datavalue)
					self.widgets['val'+vindex].grid(column=vcol,row=1, padx=10, sticky='EW')
					vcol += 1
	
	#=== ACTIONS ===#
	def OnListMetricsClick(self):
		self.listMetrics()
	def OnViewMetricClick(self, name):
		self.metric = Metric(name)
		self.viewMetric()
	def OnViewMetricSessionClick(self, datestring):
		self.session = [x for x in self.metrics[self.metric.name] if x[0] == datestring]
		self.sessionstart = self.start = datetime.datetime.strptime(datestring,'%Y-%m-%d')
		self.sessionend = self.end = self.start + datetime.timedelta(seconds=86399)
		self.resolution = 'hour'
		self.times = {
			'rangestart': self.__mktime(self.start),
			'rangeend': self.__mktime(self.end),
		}
		self.times['currentstart'] = self.times['rangestart']
		self.times['currentend'] = self.times['currentstart'] + self.resolutions[self.resolution]
		self.metric.clearValues()
		self.metric.loadValues(start=self.times['rangestart'], end=self.times['rangeend'], resolution=self.resolution)
		self.vals = self.metric.hotValues()
		self.viewMetricSession()
	def OnRaiseResolutionClick(self):
		self.times[self.resolution] = {
			'rangestart': self.times['rangestart'],
			'rangeend': self.times['rangeend'],
			'offset': float(self.variables['time'].get())
		}
		if(self.resolution == 'hour'):
			self.resolution = 'minute'
			self.times['rangestart'] = self.__mktime(self.sessionstart) + float(self.variables['time'].get()) * self.resolutions['hour']
			self.times['rangeend'] = self.times['rangestart'] + self.resolutions['hour']
		elif(self.resolution == 'minute'):
			self.resolution = 'second'
			self.times['rangestart'] += float(self.variables['time'].get()) * self.resolutions['minute']
			self.times['rangeend'] = self.times['rangestart'] + self.resolutions['minute']
		elif(self.resolution == 'second'):
			self.resolution = 'millisecond'
			self.times['rangestart'] += float(self.variables['time'].get()) * self.resolutions['second']
			self.times['rangeend'] = self.times['rangestart'] + self.resolutions['second']
		self.metric.clearValues()
		self.metric.loadValues(start=self.times['rangestart'], end=self.times['rangeend'], resolution=self.resolution)
		self.vals = self.metric.hotValues()
		del(self.shapes['marker']) #prevents canvas shape confusion
		self.viewMetricSession()
	def OnLowerResolutionClick(self):
		if(self.resolution == 'millisecond'):
			self.resolution = 'second'
		elif(self.resolution == 'second'):
			self.resolution = 'minute'
		elif(self.resolution == 'minute'):
			self.resolution = 'hour'
		elif(self.resolution == 'hour'):
			self.viewMetric() #go back to the list of sessions for this metric
			return
		self.times['rangestart'] = self.times[self.resolution]['rangestart']
		self.times['rangeend'] = self.times[self.resolution]['rangeend']
		self.metric.clearValues()
		self.metric.loadValues(start=self.times['rangestart'], end=self.times['rangeend'], resolution=self.resolution)
		self.vals = self.metric.hotValues()
		del(self.shapes['marker']) #prevents canvas shape confusion
		self.viewMetricSession()
		self.variables['time'].set(self.times[self.resolution]['offset'])
		self.updateMetricValues(self.times[self.resolution]['offset'])
	def OnViewSessionClick(self, datestring):
		self.start = datetime.datetime.strptime(datestring,'%Y-%m-%d')
		self.end = self.start + datetime.timedelta(seconds=86399)
		self.session = self.sessions[datestring]
		self.metrics = {}
		for s in self.session:
			self.metrics[s[0]['name']] = Metric(s[0]['name'], -1, False)
		self.viewSession()
	def OnViewHourClick(self, data):
		self.hour = data[0]
		self.metric = self.metrics[data[1]]
		datestring = '{0}-{1}-{2} {3}'.format(self.session[0][0]['year'], self.session[0][0]['month'], self.session[0][0]['day'], self.__formatMinute(self.hour,0))
		self.start = datetime.datetime.strptime(datestring,'%Y-%m-%d %H:%M')
		self.end = self.start + datetime.timedelta(seconds=3600)
		self.viewHour()
	def OnViewMinuteClick(self, data):
		self.hour = data[0]
		self.minute = data[1]
		self.metric = data[2]
		datestring = '{0}-{1}-{2} {3}'.format(self.session[0][0]['year'], self.session[0][0]['month'], self.session[0][0]['day'], self.__formatSecond(self.hour,self.minute,0))
		self.start = datetime.datetime.strptime(datestring,'%Y-%m-%d %H:%M:%S')
		self.end = self.start + datetime.timedelta(seconds=60)
		self.viewMinute()
	def OnViewSecondClick(self, data):
		self.hour = data[0]
		self.minute = data[1]
		self.second = data[2]
		self.metric = data[3]
		datestring = '{0}-{1}-{2} {3}'.format(self.session[0][0]['year'], self.session[0][0]['month'], self.session[0][0]['day'], self.__formatSecond(self.hour,self.minute,self.second))
		self.start = datetime.datetime.strptime(datestring,'%Y-%m-%d %H:%M:%S')
		self.end = self.start + datetime.timedelta(seconds=1)
		self.viewSecond()
	def OnSnapshotClick(self):
		self.showSnapshot()
	
	#=== UTILS ===#
	def __mktime(self, dt):
		return time.mktime(dt.timetuple())
	def __formatHour(self, hour):
		strtime = '{0}:00'
		if hour < 10:
			strtime = strtime.format('0{0}'.format(hour))
		else:
			strtime = strtime.format(hour)
		return strtime
	def __formatMinute(self, hour, minute):
		strtime = '{0}:{1}'
		strhour = str(hour) if hour >= 10 else '0{0}'.format(hour)
		strmin = str(minute) if minute >= 10 else '0{0}'.format(minute)
		return strtime.format(strhour, strmin)
	def __formatSecond(self, hour, minute, second):
		strtime = '{0}:{1}:{2}'
		strhour = str(hour) if hour >= 10 else '0{0}'.format(hour)
		strmin = str(minute) if minute >= 10 else '0{0}'.format(minute)
		strsec = str(second) if second >= 10 else '0{0}'.format(second)
		return strtime.format(strhour, strmin, strsec)
	def __formatMillisecond(self, hour, minute, second, ms):
		strtime = '{0}:{1}:{2}.{3}'
		strhour = str(hour) if hour >= 10 else '0{0}'.format(hour)
		strmin = str(minute) if minute >= 10 else '0{0}'.format(minute)
		strsec = str(second) if second >= 10 else '0{0}'.format(second)
		if(ms < 10):
			strms = '000{0}'.format(ms)
		elif(ms < 100):
			strms = '00{0}'.format(ms)
		else:
			strms = str(ms)
		return strtime.format(strhour, strmin, strsec, strms)