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

rubys 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 5d05547  make the inactive page work (at least to the point of showing 
data)
5d05547 is described below

commit 5d05547470d685f0a45818b4741eae0fd48f7515
Author: Sam Ruby <[email protected]>
AuthorDate: Tue Mar 22 09:44:00 2022 -0400

    make the inactive page work (at least to the point of showing data)
---
 www/members/inactive.cgi         | 27 ++++++++++++++------
 www/members/meeting-util.rb      | 51 ++++++++++++++++++++++++++++++++++++++
 www/members/non-participants.cgi | 53 ++++------------------------------------
 3 files changed, 76 insertions(+), 55 deletions(-)

diff --git a/www/members/inactive.cgi b/www/members/inactive.cgi
index 6420b88..b25a575 100755
--- a/www/members/inactive.cgi
+++ b/www/members/inactive.cgi
@@ -29,16 +29,27 @@ _html do
     MEETINGS = ASF::SVN['Meetings']
     attendance = MeetingUtil.get_attendance(MEETINGS)
     latest = MeetingUtil.get_latest(MEETINGS)
-    # determine user's name as found in members.txt
-    name = ASF::Member.find_text_by_id($USER).to_s.split("\n").first
-    matrix = attendance['matrix'][name]
+
+    # get static/dynamic tracker
     begin
       tracker = JSON.parse(IO.read(File.join(latest, 'non-participants.json')))
     rescue Errno::ENOENT => err
-      # Fallback to reading previous meeting's data, and reset variable
-      latest = MeetingUtil.get_previous(MEETINGS)
-      tracker = JSON.parse(IO.read(File.join(latest, 'non-participants.json')))
+      meetingsMissed = (@meetingsMissed || 3).to_i
+      _attendance, matrix, _dates, _nameMap = 
MeetingUtil.get_attend_matrices(MEETINGS)
+      inactive = matrix.select do |id, _name, _first, missed|
+        id and missed >= meetingsMissed
+      end
+    
+      current_status = MeetingUtil.current_status(latest)
+      tracker = inactive.map {|id, name, _first, missed|
+        [id, {name: name, missed: missed, status: current_status[id]}]
+      }.to_h
     end
+
+    # determine user's name as found in members.txt
+    name = ASF::Member.find_text_by_id($USER).to_s.split("\n").first
+    matrix = attendance['matrix'][name]
+
     # defaults for active users
     tracker[$USER] ||= {
       'missed' => 0,
@@ -80,7 +91,7 @@ _html do
           matrix.each do |date, status|
             if %w(A V P).include? status
               att += 1
-            else
+            elsif date != 'active'
               miss += 1
             end
           end
@@ -170,6 +181,8 @@ _html do
           end
           matrix.sort.reverse.each do |date, status|
             next if status == ' '
+            next if date == 'active'
+
             color = 'bg-danger'
             color = 'bg-warning' if %w(e).include? status
             color = 'bg-success' if %w(A V P).include? status
diff --git a/www/members/meeting-util.rb b/www/members/meeting-util.rb
index 5faaa08..27c9690 100644
--- a/www/members/meeting-util.rb
+++ b/www/members/meeting-util.rb
@@ -143,6 +143,57 @@ class MeetingUtil
       f.puts JSON.pretty_generate(attendance)
     end
   end
+
+  # Precompute matrix and dates from attendance
+  def self.get_attend_matrices(dir)
+    attendance = MeetingUtil.get_attendance(dir)
+
+    # extract and format dates
+    dates = attendance['dates'].sort.
+      map {|date| Date.parse(date).strftime('%Y-%b')}
+
+    # compute mappings of names to ids
+    members = ASF::Member.list
+    active = Hash[members.select {|_id, data| not data['status']}]
+    nameMap = Hash[members.map {|id, data| [id, data[:name]]}]
+    idMap = Hash[nameMap.to_a.map(&:reverse)]
+
+    # analyze attendance
+    matrix = attendance['matrix'].map do |name, meetings|
+      id = idMap[name]
+      next unless id and active[id]
+
+      # exclude 'active entry'
+      data = meetings.select {|key, value| key.start_with? '20'}.
+        sort.reverse.map(&:last)
+
+      first = data.length
+      missed = (data.index {|datum| datum != '-'} || data.length)
+
+      [id, name, first, missed]
+    end
+
+    return attendance, matrix.compact, dates, nameMap
+  end
+
+  # return a function to determine the current status of a member by id
+  def self.current_status(cur_mtg_dir)
+    proxies = Dir["#{cur_mtg_dir}/proxies-received/*"].
+      map {|file| File.basename(file, '.*')}
+
+    _tag,emeritus = ASF::SVN.getlisting('emeritus-requests-received')
+    emeritus.map! {|file| File.basename(file, '.*')}
+
+    lambda do |id|
+      if emeritus.include? id
+        'Emeritus request received'
+      elsif proxies.include? id
+        'Proxy received'
+      else
+        'No response'
+      end
+    end
+  end
 end
 
 # ## ### #### ##### ######
diff --git a/www/members/non-participants.cgi b/www/members/non-participants.cgi
index 78476b9..197d31c 100755
--- a/www/members/non-participants.cgi
+++ b/www/members/non-participants.cgi
@@ -17,21 +17,7 @@ today = Date.today.strftime('%Y%m%d')
 
 # look for recent activity if there is an upcoming meeting
 if meeting > today
-  proxies = Dir["#{cur_mtg_dir}/proxies-received/*"].
-    map {|file| File.basename(file, '.*')}
-
-  _tag,emeritus = ASF::SVN.getlisting('emeritus-requests-received')
-  emeritus.map! {|file| File.basename(file, '.*')}
-
-  current_status = lambda do |id|
-    if emeritus.include? id
-      'Emeritus request received'
-    elsif proxies.include? id
-      'Proxy received'
-    else
-      'No response'
-    end
-  end
+  current_status = MeetingUtil.current_status(cur_mtg_dir)
 else
   current_status = lambda {'No response'}
 end
@@ -42,41 +28,10 @@ if not ENV['QUERY_STRING'] or ENV['QUERY_STRING'].include? 
'json'
   ENV['HTTP_ACCEPT'] = 'application/json' 
 end
 
-# Precompute matrix and dates from attendance
-def get_attend_matrices(dir)
-  attendance = MeetingUtil.get_attendance(dir)
-
-  # extract and format dates
-  dates = attendance['dates'].sort.
-  map {|date| Date.parse(date).strftime('%Y-%b')}
-
-  # compute mappings of names to ids
-  members = ASF::Member.list
-  active = Hash[members.select {|_id, data| not data['status']}]
-  nameMap = Hash[members.map {|id, data| [id, data[:name]]}]
-  idMap = Hash[nameMap.to_a.map(&:reverse)]
-
-  # analyze attendance
-  matrix = attendance['matrix'].map do |name, meetings|
-    id = idMap[name]
-    next unless id and active[id]
-
-    # exclude 'active entry'
-    data = meetings.select {|key, value| key.start_with? '20'}.
-      sort.reverse.map(&:last)
-
-    first = data.length
-    missed = (data.index {|datum| datum != '-'} || data.length)
-
-    [id, name, first, missed]
-  end
-  return attendance, matrix, dates, nameMap
-end
-
 # produce HTML
 _html do
   _body? do
-    attendance, matrix, dates, nameMap = get_attend_matrices(MEETINGS)
+    attendance, matrix, dates, nameMap = 
MeetingUtil.get_attend_matrices(MEETINGS)
     _whimsy_body(
       title: PAGETITLE,
       subtitle: 'Select A Date:',
@@ -146,6 +101,8 @@ _html do
       end
     end
 
+    _div matrix.compact.length
+
     _div.count "Count: #{count} members inactive for #{@meetingsMissed} 
meetings:"
 
     summary = matrix.
@@ -172,7 +129,7 @@ end
 
 _json do
   meetingsMissed = (@meetingsMissed || 3).to_i
-  _attendance, matrix, _dates, _nameMap = get_attend_matrices(MEETINGS)
+  _attendance, matrix, _dates, _nameMap = 
MeetingUtil.get_attend_matrices(MEETINGS)
   inactive = matrix.select do |id, _name, _first, missed|
     id and missed >= meetingsMissed
   end

Reply via email to