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.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.chartObject (readonly)

Returns the value of attribute chart


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

def chart
  @chart
end

Class Method Details

.fetch(*args) ⇒ Object


16
17
18
19
# File 'lib/yinx_st.rb', line 16

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

.last_n_days(n) ⇒ Object


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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/yinx_st.rb', line 21

def last_n_days n
  batches = Batches.new(n + 1)
  duration = "最近#{n}"

  time_line = batches.time_line

  all = batches.all_notes
  unwind_tags = batches.unwind_tags

  yesterday = all.select{|note| note.dump_id == batches.latest_id}
  yesterday_unwind_tags = unwind_tags.select{|note| note.dump_id == batches.latest_id}

  changed_content = all.select{|note| note.status != :remained}
  moved_book = all.select &:moved_book?
  changed_tags = all.select &:changed_tags?

  @chart = MyChartkick.bundle do |s|
    s.my_line_chart all,
      title: "#{duration}总数变化",
      x: :dump_day,
      min: batches.smallest_batch_size.floor(-1),
      asc: :key,
      last: n

    s.my_line_chart changed_content,
      title: "#{duration}新建/修改/删除",
      x: :dump_day, y: :status,
      keys: time_line,
      asc: :key,
      last: n

    s.my_line_chart moved_book,
      title: "#{duration}移动笔记本",
      x: :dump_day,
      keys: time_line,
      asc: :key,
      last: n

    s.my_line_chart changed_tags,
      title: "#{duration}更改标签",
      x: :dump_day,
      keys: time_line,
      asc: :key,
      last: n

    s.my_column_chart yesterday,
      title: "目前最大的10个笔记本",
      x: :stack_book,
      desc: :count,
      first: 10

    s.my_line_chart all,
      title: "#{duration}笔记本体积变化",
      x: :dump_day, y: :stack_book,
      asc: :key,
      height: '540px',
      last: n

    s.my_column_chart yesterday,
      title: "目前最大的10个笔记本组",
      x: :stack_name,
      desc: :count,
      first: 10

    s.my_line_chart all,
      title: "#{duration}笔记本组体积变化",
      x: :dump_day, y: :stack_name,
      asc: :key,
      last: n

    s.my_pie_chart yesterday_unwind_tags,
      title: "目前使用最多的15个标签",
      x: :tags,
      desc: :count,
      first: 15

    s.my_column_chart yesterday,
      title: "目前每篇笔记的标签数",
      x: :tags_count,
      asc: :key

    s.my_line_chart unwind_tags,
      title: "#{duration}标签数变化",
      x: :dump_day, y: :tags,
      asc: :key,
      height: '740px',
      last: n

  end

end