pydfnWorks
python wrapper for dfnWorks
general_functions.py
Go to the documentation of this file.
1 import os
2 import sys
3 
4 
5 def dump_time(self, function_name, time):
6  '''Write run time for a funcion to the jobname_run_time.txt file
7 
8  Parameters
9  ----------
10  self : object
11  DFN Class
12  function_name : string
13  Name of function that was timed
14  time : float
15  Run time of function in seconds
16 
17  Returns
18  ----------
19  None
20 
21  Notes
22  ---------
23  While this function is working, the current formulation is not robust through the entire workflow
24  '''
25  run_time_file = self.jobname + os.sep + self.local_jobname + "_run_time.txt"
26  # Check if time file exists, if not create it
27  if not os.path.isfile(run_time_file):
28  f = open(run_time_file, "w")
29  f.write("Runs times for " + self.local_jobname + "\n")
30  else:
31  f = open(run_time_file, "a")
32  # Write Time
33  if time < 60.0:
34  f.write(function_name + " : %0.2f seconds\n" % time)
35  else:
36  f.write(function_name + " : %0.2f minutes\n" % (time / 60.0))
37  f.close()
38 
39 
40 def print_run_time(self):
41  '''Read in run times from file and and print to screen with percentages
42 
43  Parameters
44  ---------
45  self : object
46  DFN Class
47 
48  Returns
49  --------
50  None
51 
52  Notes
53  --------
54  This will dump out all values in the run file, not just those from the most recent run
55  '''
56  run_time_file = self.jobname + os.sep + self.local_jobname + "_run_time.txt"
57  f = open(run_time_file).readlines()
58  unit = f[-1].split()[-1]
59  total = float(f[-1].split()[-2])
60  if unit == 'minutes':
61  total *= 60.0
62 
63  print('Runs times for ', f[0])
64  percent = []
65  name = []
66  for i in range(1, len(f)):
67  unit = f[i].split()[-1]
68  time = float(f[i].split()[-2])
69 
70  if unit == 'minutes':
71  time *= 60.0
72  percent.append(100.0 * (time / total))
73  name.append(f[i].split(':')[1])
74  print(f[i], '\t--> Percent if total %0.2f \n' % percent[i - 1])
75 
76  #print("Primary Function Percentages")
77  #for i in range(1,len(f) - 1):
78  # if name[i-1] == ' dfnGen ' or name[i-1] == ' dfnFlow ' or name[i-1] == ' dfnTrans ':
79  # tmp = int(percent[i-1])/10
80  # print(name[i-1]+"\t"+"*"tmp)
81  print("\n")
def dump_time(self, function_name, time)