module PIM::Statistics::Utils
Public Instance Methods
collect_dates_from_history(item, attribute, min_date = nil, max_date = nil, format = '%Y-%m-%d')
click to toggle source
# File statistics.rb, line 27 def collect_dates_from_history item, attribute, min_date = nil, max_date = nil, format = '%Y-%m-%d' dates = [] date = to_date(item[attribute]) dates << date.strftime(format) if date_between?(date, min_date, max_date) history_records(item).each do |record| value = record[attribute] next if is_empty?(value) if is_array?(value) date = to_date(value['oldValue__']) else date = to_date(value) end next if !date_between?(date, min_date, max_date) date = formatted_date(date) dates << date if not dates.include?(date) end dates end
create_scope_block_for_item_scope_attribute_filter(&attribute_transformer)
click to toggle source
# File statistics.rb, line 69 def create_scope_block_for_item_scope_attribute_filter &attribute_transformer data_module = PIM.active_module return -> (scope, key, *dimensions) { matches_item_scope_attribute_filter?(data_module, scope, key, *dimensions, &attribute_transformer) } end
filter_by_scope?(scope, key, *dimensions, &scope_block)
click to toggle source
# File statistics.rb, line 64 def filter_by_scope? scope, key, *dimensions, &scope_block return true if scope_block.nil? return scope_block.call(scope, key, *dimensions) end
formatted_date(date, format = '%Y-%m-%d')
click to toggle source
# File statistics.rb, line 46 def formatted_date date, format = '%Y-%m-%d' date.strftime(format) end
get_array_param(params, key)
click to toggle source
# File statistics.rb, line 50 def get_array_param params, key param = params[key.to_sym] || params[key.to_s] || [] param = [param] if not is_array?(param) param end
get_item_values(item, keys)
click to toggle source
# File statistics.rb, line 56 def get_item_values item, keys values = [] keys.each do |key| values << item[key.to_s] end values end
history_records(item)
click to toggle source
# File statistics.rb, line 13 def history_records item return [] if is_empty?(item) or is_empty?(item['history__']) history = item['history__'] if history.is_a?(String) begin history = JSON.parse(history) rescue Exception => e log_error('Could not parse history', e) return [] end end return history['history'] end
matches_item_scope_attribute_filter?(data_module, scope, key, *dimensions, &attribute_transformer)
click to toggle source
# File statistics.rb, line 78 def matches_item_scope_attribute_filter? data_module, scope, key, *dimensions, &attribute_transformer # Always match 'nil' scope return true if scope.nil? # Transform to attribute and check, if attribute matches the item-scope filters attribute = attribute_transformer.call(key, *dimensions) return false if attribute.nil? return data_module.matches_item_scope_attribute_filter?(attribute, scope) end