Class: Hubba::ReportTrending

Inherits:
Report
  • Object
show all
Defined in:
lib/hubba/reports/reports/trending.rb

Instance Method Summary collapse

Methods inherited from Report

#initialize, #save

Constructor Details

This class inherits a constructor from Hubba::Report

Instance Method Details

#buildObject



5
6
7
8
9
10
11
12
13
14
15
16
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
# File 'lib/hubba/reports/reports/trending.rb', line 5

def build

## note: orgs is orgs+users e.g. geraldb, yorobot etc
buf = String.new('')
buf << "# Trending"
buf << " - #{@stats.repos.size} Repos @ #{@stats.orgs.size} Orgs"
buf << "\n\n"

###
## todo:
##   use calc per month (days: 30)
##   per week is too optimistic (e.g. less than one star/week e.g. 0.6 or something)

repos = @stats.repos.sort do |l,r|
  ## note: use reverse sort (right,left) - e.g. most stars first
  ## r[:stars] <=> l[:stars]

  ## sort by created_at (use julian days)
  ## r[:created_at].to_date.jd <=> l[:created_at].to_date.jd

  res = r.diff <=> l.diff
  res = r.stats.stars <=> l.stats.stars  if res == 0
  res = r.stats.created.jd <=> l.stats.created.jd  if res == 0
  res
end


## pp repos


repos.each_with_index do |repo,i|
  if repo.diff == 0
    buf << "-  -/- "
  else
    buf << "- #{repo.diff}/month "
  end

  buf <<  "#{repo.stats.stars} **#{repo.full_name}** (#{repo.stats.size} kb) - "
  buf <<  "#{repo.stats.history_str}\n"
end


buf
end