__main__.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from parser import parse_weights
  2. from pathlib import Path
  3. import pathlib
  4. import argparse
  5. from os import listdir
  6. import os
  7. from analysis import get_weight_info
  8. import json
  9. def main():
  10. arg_parser = argparse.ArgumentParser(description="Fee analysis")
  11. arg_parser.add_argument(
  12. 'weight_path', type=str, help='Path to weight files or directory with weights'
  13. )
  14. arg_parser.add_argument('-o', '--output', type=str,
  15. help='Path for csv file defaults to output.csv', default="output.csv")
  16. arg_parser.add_argument('-c', '--config', type=str,
  17. help='Path of a config file', default=Path(__file__).parent / "config.json")
  18. arg_parser.add_argument('-p', '--process-data', action='store_true',
  19. help='Process data given a config if not used only weights will be dumped into the csv output')
  20. args = arg_parser.parse_args()
  21. weight_path = args.weight_path
  22. output_file = args.output
  23. config_file = args.config
  24. process_data = args.process_data
  25. with open(config_file) as f:
  26. config = json.load(f)
  27. weight_coeff = config.get("weight_coefficient", 0)
  28. issuance = config.get("issuance", 0)
  29. length_coeff = config.get("length_coefficient", 0)
  30. min_market_cap = config.get("min_market_cap", 0)
  31. max_market_cap = config.get("max_market_cap", 0)
  32. lengths = config.get("lengths", {})
  33. params = config.get("params", {})
  34. w = {}
  35. if os.path.isdir(weight_path):
  36. for f in listdir(weight_path):
  37. path = weight_path + f
  38. if os.path.isfile(path):
  39. w |= parse_weights(weight_path + f)
  40. elif os.path.isfile(weight_path):
  41. w = parse_weights(weight_path)
  42. else:
  43. print("Error: ", weight_path, " is not a valid directory or file")
  44. df = get_weight_info(w, weight_coeff, issuance,
  45. length_coeff, min_market_cap, max_market_cap, params, lengths)
  46. if process_data:
  47. df.to_csv(output_file, index=False, )
  48. else:
  49. df.to_csv(output_file, index=False, columns=["Extrinsic", "Weight"])
  50. if __name__ == '__main__':
  51. main()