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 24 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
formatted_date(date, format = '%Y-%m-%d')
click to toggle source
# File statistics.rb, line 43 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 47 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 53 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 10 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