You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2021/04/28 21:28:13 UTC

[whimsy] branch master updated: Add function to get summary statistics

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 429b539  Add function to get summary statistics
429b539 is described below

commit 429b53986d4d3c98dc4918c04d50ed971bcab4cb
Author: Sebb <se...@apache.org>
AuthorDate: Wed Apr 28 22:28:04 2021 +0100

    Add function to get summary statistics
---
 tools/ponyapi.rb | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/ponyapi.rb b/tools/ponyapi.rb
index 889e30e..5ae880f 100755
--- a/tools/ponyapi.rb
+++ b/tools/ponyapi.rb
@@ -13,6 +13,7 @@ module PonyAPI
   PONYHOST = ENV['PONYHOST'] || 'https://lists.apache.org/'
   PONYSTATS = PONYHOST + 'api/stats.lua?list=%{list}&domain=%{domain}&d=%{year}-%{month}' # board&domain=apache.org&d=2017-04 becomes board-apache-org-201704-stats.json
   STATSMBOX = "%{list}-%{domNoDot}-%<year>.04d%<month>.02d-stats.json" # used to generate output file name
+  SUMMARYJSON = "%{list}-%{domNoDot}-%<year>.04d%<month>.02d-summary.json" # used to generate output file name
   PONYMBOX  = PONYHOST + 'api/mbox.lua?list=%{list}@%{domain}&date=%{year}-%{month}' # board@apache.org&date=2016-06 becomes board-apache-org-201707.mbox
   FILEMBOX  = "%{list}-%{domNoDot}-%<year>.04d%<month>.02d.mbox" # used to generate output file name
   PONYPREFS = PONYHOST + 'api/preferences.lua' # => preferences.json
@@ -95,6 +96,7 @@ module PonyAPI
     args = make_args(list, subdomain, year, month)
     uri, _request, response = fetch_pony(PONYSTATS % args, cookie)
     if response.code == '200' then
+      return JSON.parse(response.body), args if dir.nil?
       openfile(dir, STATSMBOX % args) do |f|
         begin
           jzon = JSON.parse(response.body)
@@ -127,6 +129,22 @@ module PonyAPI
     end
   end
 
+  # get summary stats; exclude details
+  def get_pony_summary(dir, list, subdomain, year, month, cookie=nil, sort_list=false)
+    res, args = get_pony_stats(nil, list, subdomain, year, month, cookie, sort_list)
+    return nil unless res
+    jzon = {}
+    %w(list domain name firstYear firstMonth lastYear lastMonth numparts hits no_threads unixtime max).each { |k| jzon[k] = res[k]}
+    %w(participants emails thread_struct).each { |k| jzon["#{k}.size"] = res[k].size}
+    if dir
+      openfile(dir, SUMMARYJSON % args) do |f|
+        jzon = Hash[jzon.sort] if sort_list
+        f.puts JSON.pretty_generate(jzon)
+      end
+    end
+    jzon
+  end
+
   # Download one month as mbox
   # Caveats: uses response's encoding; overwrites existing .json file
   # Must supply cookie = 'ponymail-logged-in-cookie' if a private list