-
Notifications
You must be signed in to change notification settings - Fork 13
/
logger.py
52 lines (44 loc) · 1.65 KB
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from configs import config
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
node_number = 0
memory = 0
clustering_time = 0
group_num = 0
iteration = 0
def write_result(result_msg, result, operation='a'):
"""Writing message and result value to file
Args:
result_msg (str): Message
result (Any): The result
operation (str): The operation of file access
"""
result_path = config.RESULTS_DIR
try:
result_path +='{}-{}/'.format(group_num, memory)
os.mkdir(result_path)
except FileExistsError:
pass
result_file = result_path+'{}node-{}-{}-{}-{}-result.txt'.format(node_number, group_num, memory, config.CLUSTERING,
iteration)
try:
with open(result_file, operation) as f:
f.write("{}: {} \n".format(result_msg, str(result)))
if 'clustering' in result_msg:
global clustering_time
clustering_time = clustering_time + result
if 'Total' in result_msg and config.CLUSTERING:
f.write("{}: {} \n".format('Total clustering time', str(clustering_time)))
f.write("{}: {} \n".format('Total schedule time', str(result-clustering_time)))
except Exception as e:
print(e)
def convert_to_int(resource_string):
if 'Ki' in resource_string:
return int(resource_string.split('K')[0])*1024
elif 'Mi' in resource_string:
return int(resource_string.split('M')[0])*(1024**2)
elif 'Gi' in resource_string:
return int(resource_string.split('G')[0])*(1024**3)