class Qwik::SiteTimeLine

Attributes

days[R]
page_max[R]
page_min[R]
pages_history[R]
site_duration[R]
site_max[R]
site_min[R]
times[R]

Public Class Methods

new(site) click to toggle source
# File vendor/qwik/lib/qwik/site-timeline.rb, line 23
def initialize(site)
  @site = site
  @times = nil
  @days = nil
  @site_min = nil
  @site_max = nil
  @page_min = nil
  @page_max = nil
  @pages_history = nil
  @site_duration = nil
  @site_last_modified = nil
end

Public Instance Methods

calc_history() click to toggle source
# File vendor/qwik/lib/qwik/site-timeline.rb, line 39
def calc_history
  if_sites_update? {
    @times, @days, @page_min, @page_max, @site_min, @site_max,
    @pages_history, @site_duration = calc_history_internal(@site)
  }
end
calc_history_internal(site) click to toggle source
# File vendor/qwik/lib/qwik/site-timeline.rb, line 56
def calc_history_internal(site)
  keys = site.map {|page| page.key }
  return nil if keys.empty?

  times = Hash.new {|h, k| h[k] = []}
  days = Hash.new {|h, k| h[k] = []}
  site_min = nil    # FIXME: site_min should be cached.
  site_max = nil
  page_min = {}     # FIXME: page_min should be cached.
  page_max = {}

  site.backupdb.each {|key, v, time|
    next if times[key].nil?        # Calc only for existing pages.
    times[key] << time
    days[time.ymd_s] << [key, time]
    site_min = time if site_min.nil? || time < site_min
    site_max = time if site_max.nil? || site_max < time
    page_min[key] = time if page_min[key].nil? || time < page_min[key]
    page_max[key] = time if page_max[key].nil? || page_max[key] < time
  }

  page_min_days = Hash.new {|h, k| h[k] = []}
  page_min.each {|key, time|
    page_min_days[time.ymd_s] << [key, time]
    


  }


  # Calc history from older to newer.
  pages_history = page_min.to_a.sort {|a, b|
    a[1] <=> b[1]
  }.map {|a|
    a[0]
  }

  # Count second when the page is created to the last update.
  site_max = Time.at(1) if site_max.nil?
  site_min = Time.at(0) if site_min.nil?

  site_duration = site_max - site_min

  return times, days, page_min, page_max, site_min, site_max, pages_history, site_duration
end
get_keys_by_day(ymd) click to toggle source
# File vendor/qwik/lib/qwik/site-timeline.rb, line 102
def get_keys_by_day(ymd)
  day = @days[ymd]
  return nil if day.empty?
  day = day.sort_by {|key, time| time }
  keys = day.map {|key, time| key }.uniq
  return keys
end
if_sites_update?() { || ... } click to toggle source
# File vendor/qwik/lib/qwik/site-timeline.rb, line 46
def if_sites_update?
  # Check last update from pages
  last_modified = @site.last_modified
  return if last_modified.nil?      # No page.
  if @site_last_modified.nil? || @site_last_modified < last_modified
    yield
  end
  @site_last_modified = last_modified
end