1
1
defmodule ProgressAnalyzer do
2
2
@ moduledoc false
3
- def analyze_file ( path ) do
3
+ require Logger
4
+
5
+ def analyze_file ( path , verbose \\ false ) do
4
6
stats =
5
7
path
6
8
|> File . read! ( )
7
9
|> YamlElixir . read_from_string! ( )
8
10
|> count_statuses ( )
9
11
10
- display_stats ( stats )
12
+ display_stats ( stats , verbose )
11
13
end
12
14
13
15
defp count_statuses ( yaml ) do
14
16
# Initialize counters
15
- initial_counts = % { completed: 0 , skipped: 0 , remaining: 0 , undecided: 0 }
17
+ initial_counts = % { completed: 0 , skipped: 0 , remaining: 0 , undecided: 0 , remaining_columns: [ ] }
16
18
17
19
# Flatten and count all column statuses
18
20
Enum . reduce ( yaml , initial_counts , fn table , acc ->
19
21
columns = table |> Map . values ( ) |> List . first ( )
20
22
21
23
Enum . reduce ( columns , acc , fn column , inner_acc ->
22
- { _col , status } = Enum . at ( Map . to_list ( column ) , 0 )
24
+ { col , status } = Enum . at ( Map . to_list ( column ) , 0 )
23
25
24
26
case status do
25
- 1 -> Map . update! ( inner_acc , :completed , & ( & 1 + 1 ) )
26
- - 2 -> Map . update! ( inner_acc , :undecided , & ( & 1 + 1 ) )
27
- - 1 -> Map . update! ( inner_acc , :skipped , & ( & 1 + 1 ) )
28
- 0 -> Map . update! ( inner_acc , :remaining , & ( & 1 + 1 ) )
27
+ 1 ->
28
+ Map . update! ( inner_acc , :completed , & ( & 1 + 1 ) )
29
+
30
+ - 2 ->
31
+ Map . update! ( inner_acc , :undecided , & ( & 1 + 1 ) )
32
+
33
+ - 1 ->
34
+ Map . update! ( inner_acc , :skipped , & ( & 1 + 1 ) )
35
+
36
+ 0 ->
37
+ inner_acc
38
+ |> Map . update! ( :remaining , & ( & 1 + 1 ) )
39
+ |> Map . update! ( :remaining_columns , & ( & 1 ++ [ "#{ table |> Map . keys ( ) |> List . first ( ) } .#{ col } " ] ) )
29
40
end
30
41
end )
31
42
end )
32
43
end
33
44
34
- defp display_stats ( % { completed: done , skipped: skipped , remaining: todo , undecided: undecided } ) do
45
+ defp display_stats (
46
+ % {
47
+ completed: done ,
48
+ skipped: skipped ,
49
+ remaining: todo ,
50
+ undecided: undecided ,
51
+ remaining_columns: remaining_columns
52
+ } ,
53
+ verbose
54
+ ) do
35
55
total = done + skipped + todo + undecided
36
56
done_pct = percentage ( done , total )
37
57
skipped_pct = percentage ( skipped , total )
38
58
todo_pct = percentage ( todo , total )
39
59
undecided_pct = percentage ( undecided , total )
40
60
41
- IO . puts ( """
61
+ base_output = """
42
62
Migration Progress Report
43
63
========================
44
64
@@ -56,7 +76,22 @@ defmodule ProgressAnalyzer do
56
76
Progress:
57
77
---------
58
78
[#{ progress_bar ( done_pct , skipped_pct , todo_pct , undecided_pct ) } ]
59
- """ )
79
+ """
80
+
81
+ if_result =
82
+ if verbose do
83
+ base_output <>
84
+ """
85
+
86
+ Remaining Columns:
87
+ ------------------
88
+ #{ Enum . join ( remaining_columns , "\n " ) }
89
+ """
90
+ else
91
+ base_output
92
+ end
93
+
94
+ IO . puts ( if_result )
60
95
end
61
96
62
97
defp percentage ( part , total ) when total > 0 do
@@ -77,10 +112,22 @@ defmodule ProgressAnalyzer do
77
112
end
78
113
79
114
case System . argv ( ) do
115
+ [ filename , "-v" ] ->
116
+ ProgressAnalyzer . analyze_file ( filename , true )
117
+
118
+ [ "-v" , filename ] ->
119
+ ProgressAnalyzer . analyze_file ( filename , true )
120
+
80
121
[ filename ] ->
81
- ProgressAnalyzer . analyze_file ( filename )
122
+ ProgressAnalyzer . analyze_file ( filename , false )
82
123
83
124
_ ->
84
- IO . puts ( "Usage: elixir analyze_progress.exs <filename>" )
125
+ IO . puts ( """
126
+ Usage: elixir analyze_progress.exs [-v] <filename>
127
+
128
+ Options:
129
+ -v Show detailed remaining columns list
130
+ """ )
131
+
85
132
System . halt ( 1 )
86
133
end
0 commit comments