extract_solution_log.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import argparse
  2. import os
  3. def main():
  4. parser = argparse.ArgumentParser(description="Train and find best filters to use for model")
  5. parser.add_argument('--log', type=str, help='log file attribute', required=True)
  6. parser.add_argument('--output', type=str, help='output solution choice', required=True)
  7. args = parser.parse_args()
  8. p_log = args.log
  9. p_output = args.output
  10. with open(p_log, 'r') as f:
  11. lines = f.readlines()
  12. for line in lines:
  13. if 'Current Binary solution' in line:
  14. score = float(line.split('SCORE')[-1])
  15. solution = list(map(int, line.split('[')[-1].split(']')[0].split(' ')))
  16. with open(p_output, 'a') as f:
  17. line = ''
  18. for index, v in enumerate(solution):
  19. line += str(v)
  20. if index < len(solution) - 1:
  21. line += ','
  22. line += ';' + str(score)
  23. f.write(line + '\n')
  24. if __name__ == "__main__":
  25. main()