11require 'kraken-mobile/constants'
22require 'digest'
3+ require 'json'
34
45module KrakenMobile
56 class Reporter
@@ -19,6 +20,22 @@ def initialize(execution_id, options)
1920 #-------------------------------
2021 # Generator
2122 #-------------------------------
23+ def generate_general_report
24+ erb_file = File . join ( File . expand_path ( "../../../../reporter/" , __FILE__ ) , "index.html.erb" )
25+ html_file = File . join ( File . expand_path ( "#{ KrakenMobile ::Constants ::REPORT_PATH } /#{ @execution_id } /" ) , "index.html" )
26+ # Variables
27+ @devices = [ { "user" :1 , "id" :"93c6af52" , "model" :"ONEPLUS_A6013" } , { "user" :2 , "id" :"emulator-5554" , "model" :"Android_SDK_built_for_x86" } ]
28+ devices_report = report_by_devices ( @devices )
29+ @features_report = fetures_from_report_by_devices devices_report
30+ @branches = branches ( @features_report ) . to_json # TODO
31+ template = File . read ( erb_file )
32+ result = ERB . new ( template ) . result ( binding )
33+ # write result to file
34+ File . open ( html_file , 'w+' ) do |f |
35+ f . write result
36+ end
37+ end
38+
2239 def generate_device_report device
2340 @apk_path = device . config [ "apk_path" ] ? device . config [ "apk_path" ] : @options [ :apk_path ]
2441 report_file = open ( "#{ KrakenMobile ::Constants ::REPORT_PATH } /#{ @execution_id } /#{ device . id } /#{ KrakenMobile ::Constants ::REPORT_FILE_NAME } .json" )
@@ -42,6 +59,34 @@ def generate_device_report device
4259 generate_features_report @features , device
4360 end
4461
62+ def report_by_devices devices
63+ devices_report = { }
64+ devices . each do |device |
65+ next if !File . exists? ( "#{ KrakenMobile ::Constants ::REPORT_PATH } /#{ @execution_id } /#{ device [ :id ] } /#{ KrakenMobile ::Constants ::REPORT_FILE_NAME } .json" )
66+ report_file = open ( "#{ KrakenMobile ::Constants ::REPORT_PATH } /#{ @execution_id } /#{ device [ :id ] } /#{ KrakenMobile ::Constants ::REPORT_FILE_NAME } .json" )
67+ content = report_file . read
68+ devices_report [ device [ :user ] ] = JSON . parse ( content )
69+ devices_report [ device [ :user ] ] . each do |d | d [ "device_id" ] = device [ :id ] if !d [ "device_id" ] end
70+ end
71+ devices_report
72+ end
73+
74+ def fetures_from_report_by_devices report_by_devices
75+ features = { }
76+ report_by_devices . keys . each do |user_key |
77+ report = report_by_devices [ user_key ]
78+ report . each do |feature |
79+ features [ feature [ "id" ] ] = { } if !features [ feature [ "id" ] ]
80+ features [ feature [ "id" ] ] [ "name" ] = feature [ "name" ] if !features [ feature [ "id" ] ] [ "name" ] && feature [ "name" ]
81+ features [ feature [ "id" ] ] [ "uri" ] = feature [ "uri" ] if !features [ feature [ "id" ] ] [ "uri" ] && feature [ "uri" ]
82+ features [ feature [ "id" ] ] [ "hash" ] = feature_id ( feature ) if !features [ feature [ "id" ] ] [ "hash" ]
83+ features [ feature [ "id" ] ] [ "devices" ] = { } if !features [ feature [ "id" ] ] [ "devices" ]
84+ features [ feature [ "id" ] ] [ "devices" ] [ user_key ] = feature [ "elements" ] if feature [ "elements" ]
85+ end
86+ end
87+ features
88+ end
89+
4590 def generate_features_report features , device
4691 features . each do |feature |
4792 generate_feature_report feature , device
@@ -63,6 +108,27 @@ def generate_feature_report feature, device
63108 end
64109 end
65110
111+ # 0: create 1: commit 2: merge
112+ def branches features_report
113+ branches = { }
114+ features_report . keys . each do |key |
115+ report = features_report [ key ]
116+ branches [ report [ "hash" ] ] = { } if !branches [ report [ "hash" ] ]
117+ branches [ report [ "hash" ] ] [ "steps" ] = [ ] if !branches [ report [ "hash" ] ] [ "steps" ]
118+ devices = report [ "devices" ]
119+ devices . keys . each do |device_key |
120+ branches [ report [ "hash" ] ] [ "steps" ] << { type : 0 , name : device_key }
121+ feature_steps = devices [ device_key ] [ 0 ] [ "steps" ] if devices [ device_key ] . count > 0 && devices [ device_key ] [ 0 ] [ "steps" ]
122+ feature_steps . each do |step |
123+ hash_step = { type : 1 , name : device_key }
124+ hash_step [ :image ] = step [ "after" ] [ 0 ] [ "embeddings" ] [ 0 ] if step [ "after" ] . count > 0 && step [ "after" ] [ 0 ] [ "embeddings" ] && step [ "after" ] [ 0 ] [ "embeddings" ] . count > 0
125+ branches [ report [ "hash" ] ] [ "steps" ] << hash_step
126+ end
127+ end
128+ end
129+ branches
130+ end
131+
66132 #-------------------------------
67133 # Helpers
68134 #-------------------------------
0 commit comments