Coverage for sparkle/CLI/help/system_status.py: 62%

32 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-05 14:48 +0000

1#!/usr/bin/env python3 

2# -*- coding: UTF-8 -*- 

3"""Helper functions to inform about Sparkle's system status.""" 

4from pathlib import Path 

5 

6from sparkle.structures import FeatureDataFrame, PerformanceDataFrame 

7 

8 

9def print_sparkle_list(objects: list[any], type: str, details: bool = False) -> None: 

10 """Print a list of sparkle objects. 

11 

12 Args: 

13 objects: The objects to print 

14 type: The name of the object type 

15 details: Indicating if output should be detailed 

16 """ 

17 print(f"\nCurrently Sparkle has {len(objects)} {type}(s)" 

18 + (":" if details else "")) 

19 

20 if details: 

21 for i, object in enumerate(objects): 

22 print(f"[{i + 1}]: {type}: {Path(object).name}") 

23 

24 

25def print_feature_computation_jobs(feature_data_csv: Path, 

26 verbose: bool = False) -> None: 

27 """Print a list of remaining feature computation jobs. 

28 

29 Args: 

30 feature_data_csv: Path to the feature data csv 

31 verbose: Indicating, if output should be verbose 

32 """ 

33 if not feature_data_csv.exists(): 

34 print("\nNo feature data found, cannot determine remaining jobs.") 

35 

36 feature_data = FeatureDataFrame(feature_data_csv) 

37 jobs = feature_data.remaining_jobs() 

38 

39 print(f"\nCurrently Sparkle has {len(jobs)} remaining feature computation " 

40 "jobs that need to be performed before creating an algorithm selector" 

41 + (":" if verbose else "")) 

42 

43 if verbose: 

44 for i, job in enumerate(jobs): 

45 print(f"[{i + 1}]: Extractor: {Path(job[1]).name}, Group: {job[2]}, " 

46 f"Instance: {Path(job[0]).name}") 

47 print() 

48 

49 

50def print_performance_computation_jobs(performance_data_csv_path: Path, 

51 verbose: bool = False) -> None: 

52 """Print a list of remaining performance computation jobs. 

53 

54 Args: 

55 performance_data_csv_path: Path to the performance data csv 

56 verbose: Indicating, if output should be verbose 

57 """ 

58 if not performance_data_csv_path.exists(): 

59 print("\nNo performance data found, cannot determine remaining jobs.") 

60 return 

61 performance_data_csv = PerformanceDataFrame(performance_data_csv_path) 

62 jobs = performance_data_csv.remaining_jobs() 

63 total_job_num = sum([len(jobs[instance]) for instance in jobs.keys()]) 

64 

65 print(f"\nCurrently Sparkle has {total_job_num} remaining performance computation" 

66 " jobs that need to be performed before creating an algorithm selector" 

67 + (":" if verbose else "")) 

68 

69 if verbose: 

70 i = 0 

71 for instance in jobs.keys(): 

72 for extractor in jobs[instance]: 

73 print(f"[{i + 1}]: Solver: " 

74 f"{Path(extractor).name}, Instance: " 

75 f"{Path(instance).name}") 

76 i += 1 

77 

78 print()