Module: YinxSt

Defined in:
lib/yinx_st.rb,
lib/yinx_st/batches.rb,
lib/yinx_st/version.rb

Defined Under Namespace

Classes: Batches

Constant Summary collapse

VERSION =
"0.1.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.chartObject (readonly)

Returns the value of attribute chart.



76
77
78
# File 'lib/yinx_st.rb', line 76

def chart
  @chart
end

Class Method Details

.fetch(*args) ⇒ Object



12
13
14
15
# File 'lib/yinx_st.rb', line 12

def fetch *args
  Yinx::SQL.connect(*args)
  self
end

.generate_html(erb_file = File.expand_path('../yinx_st/chart.erb', __FILE__)) ⇒ Object



78
79
80
81
# File 'lib/yinx_st.rb', line 78

def generate_html(erb_file=File.expand_path('../yinx_st/chart.erb', __FILE__))
  template = File.read erb_file
  html = ERB.new(template).result(binding)
end

.last_n_days(n) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/yinx_st.rb', line 17

def last_n_days n
  batches = Batches.new n
  duration = "最近#{n}日"

  @chart = MyChart.js do
    material batches.all_notes
    material batches.unwind_tags, name: :unwind_tags

    select :yesterday do |note|
      note.dump_id == batches.latest_id
    end

    select :yesterday, from: :unwind_tags do |note|
      note.dump_id == batches.latest_id
    end

    select :changed_content do |note|
      note.status == :created or note.status == :updated
    end

    select :moved_book do |note|
      note.moved_book?
    end

    select :changed_tags do |note|
      note.changed_tags?
    end

    group_by :stack_book do |note|
      stack = note.stack.nil? ? '' : "#{note.stack}/"
      "#{stack}#{note.book}"
    end

    group_by(:stack){|note| note.stack or 'NO_STACK'}

    group_by :number_of_tags do |note|
      note.tags.count
    end

    plainBar :dump_day, name: "#{duration}总数变化", w: 1000, h:240, asc: :key
    line :dump_day, :status, name: "#{duration}新建/修改", from: :changed_content, w: 1000, h:240, asc: :key, keys: batches.time_line
    line :dump_day, name: "#{duration}移动笔记本", from: :moved_book, w: 1000, h:240, asc: :key, keys: batches.time_line
    line :dump_day, name: "#{duration}更改标签", from: :changed_tags, w: 1000, h:240, asc: :key, keys: batches.time_line

    bar :stack_book, name: '目前最大的10个笔记本', from: :yesterday, w:1400 ,h: 540, desc: :count, first: 10
    line :dump_day, :stack_book, name: "#{duration}笔记本体积变化", w: 1200, h:540, asc: :key, keys: batches.time_line

    bar :stack, name: '目前最大的10个笔记本组', from: :yesterday, w:1400 ,h: 240, desc: :count, first: 10
    line :dump_day, :stack, name: "#{duration}笔记本组体积变化", w: 1000, h:340, asc: :key, keys: batches.time_line

    pie :tags, name: '目前使用最多的15个标签', from: :yesterday__from__unwind_tags, w:1400 ,h: 340, desc: :count, first: 15
    bar :number_of_tags, name: '目前每篇笔记的标签数', from: :yesterday, w: 800, h: 240, asc: :key
    line :dump_day, :tags, name: "#{duration}标签数变化", from: :unwind_tags, w: 1400, h:740, asc: :key, keys: batches.time_line

  end

  self
end