コード例 #1
0
 def write(self):
     # Build result table 
     names = 'STRATEGY_PLACEMENT \t STRATEGY_REALLOCATION \t max. servers \t avg. srv. count'
     res_reservation = 'LowerBound \t None \t %f \t %f' % (self.lb_max_srv, self.lb_avg_srv)
     res_demand = 'LowerBoundDemand \t None \t %f \t %f' % (self.lb_demand_max_srv, self.lb_demand_avg_srv)
     
     # Build header and values for this experiment
     conf_head, conf_values = clparams.build_result_log_title()
     names = '%s \t %s' % ('\t'.join(conf_head), names)
     res_reservation = '%s \t %s' % ('\t'.join(conf_values), res_reservation)
     res_demand = '%s \t %s' % ('\t'.join(conf_values), res_demand)
     
     # Append results to file
     filename = configuration.path(clparams.CL_RESULT_FILE, 'csv')
     with FileLock(filename):
         # Add header only if file is new
         try:
             # Check if file already exists
             with open(filename):
                 pass
         except IOError:
             # Create a new file and append header row
             f = open(filename, 'w')
             f.write(names)
             f.write('\n')
             f.close()
         
         # Append row information 
         with open(filename, 'a') as f:
             f.write(res_reservation)
             f.write('\n')
             f.write(res_demand)
             f.write('\n')
コード例 #2
0
from filelock.fl import FileLock
import clparams
import configuration
import controller
import traceback

if __name__ == "__main__":
    if configuration.PRODUCTION != False:
        print "Configuration is set to PRODUCTION MODE"
        print "Change configuration.PRODUCTION = False for simulations"
    else:
        try:
            names, res = controller.start()

            # Build header and values for this experiment
            conf_head, conf_values = clparams.build_result_log_title()
            names = "%s \t %s" % ("\t".join(conf_head), names)
            res = "%s \t %s" % ("\t".join(conf_values), res)

            # Append results to file
            filename = configuration.path(clparams.CL_RESULT_FILE, "csv")
            with FileLock(filename):
                # Add header only if file is new
                try:
                    with open(filename):
                        pass
                except IOError:
                    f = open(filename, "w")
                    f.write(names)
                    f.write("\n")
                    f.close()