def points_reduction_vm(timestamp_begin,timestamp_end,resource_id):
    dh = DataHandler()
    old_data = json.loads(dh.cpu_util_from(timestamp_begin,timestamp_end,resource_id))
    key2 = "cpu_util_percent"
    print type(old_data[0])
    data  =  points_reduction(old_data,key2)
    return data
def points_reduction_by_server_disk(timestamp_begin, timestamp_end, hosts):
    data_handler = DataHandler()
    data = []
    old_data = data_handler.hosts_disk(timestamp_begin, timestamp_end)
    for host in range(len(hosts)):
        dict_host = {}
        dict_host["host_address"] = hosts[host]
        dict_host['data'] = points_reduction_disk(old_data[host]['data'])
        data.append(dict_host)
    return data
def points_reduction_by_server_memory(timestamp_begin, timestamp_end, hosts):
    data_handler = DataHandler()
    data = []
    old_data = data_handler.hosts_memory(timestamp_begin, timestamp_end)
    key = 'data'
    for host in range(len(hosts)):
        dict_host = {}
        dict_host["host_address"] = hosts[host]
        dict_host['data'] = points_reduction_for_percent(old_data[host]['data'],key)
        data.append(dict_host)
    return data
def start_bench_th(projeto):
    dados = DataHandler()
    bench = BenchmarkDataHandler()
    dados.start_instance_bench('admin')

    while True:
        try:
            if dados.get_benchmark_status('admin') == 'True':
                break
            time.sleep(5)
        except:
            continue

    read_benchmark = json.loads(dados.get_benchmark('admin')[0])
    read_benchmark['Host'] = '150.165.15.4'
    
    bench.save_data_db(read_benchmark)
    dados.remove_benchmark_instance()
    return read_benchmark
def start_bench_th(projeto, host):
    config = ConfigParser.ConfigParser()
    config.read("environment.conf")
    dados = DataHandler(config)
    bench = BenchmarkDataHandler()
    dados.start_instance_bench('admin', host)
    while True:
        try:
            if dados.get_benchmark_status('admin', host) == 'True':
                break
            time.sleep(5)
        except:
            continue

    read_benchmark = json.loads(dados.get_benchmark('admin', host)[0])
    read_benchmark['Host'] = host
    
    bench.save_data_db(read_benchmark)
    dados.remove_benchmark_instance(host)
    return read_benchmark
def points_reduction_vm_network_outgoing(timestamp_begin,timestamp_end,resource_id):
    dh = DataHandler()
    old_data = json.loads(dh.network_outgoing_bytes_rate_from(timestamp_begin,timestamp_end,resource_id))
    key2 = "network_outgoing_bytes_rate"
    data  =  points_reduction(old_data,key2)
    return data