add --highlight-sponsors option to contributor report commands

When the option is specified contributions from organizations that are
not sponsors are combined into a single "*other" result to preserve
the overall relative contribution levels of the remaining companies
but to limit the number of names returned in the output.

The default is to show all sponsors, but a --sponsor-level option can
change that to specify only platinum or gold members.

Change-Id: I3062dc607ee2f35a73cfc2237a8f9c58df78af8e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-05-02 14:20:47 -04:00
parent 788fa577ef
commit abe733a245
5 changed files with 149 additions and 0 deletions

47
goal_tools/sponsors.py Normal file
View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import functools
import itertools
import logging
import pkgutil
import yaml
LOG = logging.getLogger(__name__)
_SPONSOR_DATA = yaml.load(
pkgutil.get_data('goal_tools',
'sponsors.yaml').decode('utf-8')
)
class Sponsors:
def __init__(self, level, data=_SPONSOR_DATA):
self._data = data
if level == 'all':
self._names = set(
n.lower()
for n in itertools.chain(*data.values())
)
else:
self._names = set(
n.lower()
for n in data[level]
)
@functools.lru_cache(maxsize=1024)
def __getitem__(self, name):
if name.lower() in self._names:
return name
return '*other'

30
goal_tools/sponsors.yaml Normal file
View File

@ -0,0 +1,30 @@
platinum:
- 'AT&T'
- Ericsson
- Huawei
- Intel
- Rackspace
- Red Hat
- SUSE
- Tencent
gold:
- 99Cloud
- Canonical
- 'China Mobile'
- 'China Telecom'
- 'China Unicorn'
- Cisco
- 'City Network'
- 'Dell EMC'
- 'Deutsche Telekom'
- EasyStack
- FiberHome
- Fujitsu
- Inspur
- inwinSTACK
- Mirantis
- NEC
- NetApp
- H3C
- UnitedStack
- 'ZTE Corporation'

View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from goal_tools import sponsors
from goal_tools.tests import base
class TestOrganizations(base.TestCase):
_data = {
'platinum': ['Org1', 'Org2'],
'gold': ['Org3'],
}
def setUp(self):
super().setUp()
self.all = sponsors.Sponsors(
'all',
self._data,
)
self.platinum = sponsors.Sponsors(
'platinum',
self._data,
)
self.gold = sponsors.Sponsors(
'gold',
self._data,
)
def test_known_org(self):
self.assertEqual('Org1', self.all['Org1'])
self.assertEqual('Org2', self.platinum['Org2'])
self.assertEqual('Org3', self.gold['Org3'])
def test_unknown_org(self):
self.assertEqual('*other', self.all['Org4'])
self.assertEqual('*other', self.platinum['Org4'])
self.assertEqual('*other', self.gold['Org4'])

View File

@ -15,6 +15,8 @@ import logging
from cliff import lister
from goal_tools import sponsors
LOG = logging.getLogger(__name__)
@ -29,6 +31,19 @@ class ContributionsReportBase(lister.Lister):
action='append',
help='filter to only include specific roles (may be repeated)',
)
parser.add_argument(
'--highlight-sponsors',
default=False,
action='store_true',
help=('highlight sponsor organizations and '
'combine stats for others'),
)
parser.add_argument(
'--sponsor-level',
default='all',
choices=('all', 'platinum', 'gold'),
help='limit sponsor highlights to a subset of sponsors',
)
parser.add_argument(
'contribution_list',
nargs='+',
@ -51,4 +66,13 @@ class ContributionsReportBase(lister.Lister):
if roles:
data = (d for d in data if d['Role'] in roles)
if parsed_args.highlight_sponsors:
sponsor_map = sponsors.Sponsors(parsed_args.sponsor_level)
def filter_sponsors(row):
row['Organization'] = sponsor_map[row['Organization']]
return row
data = (filter_sponsors(d) for d in data)
return data

View File

@ -14,6 +14,7 @@ do
who-helped --debug contributions list -f csv $txt_file | tee $csv_file
who-helped --debug contributions summarize $csv_file | tee $rpt_file
who-helped contributions summarize -f csv $csv_file | tee $rpt_file.contributions.csv
who-helped contributions summarize -f csv --highlight-sponsors $csv_file | tee $rpt_file.sponsor-contributions.csv
who-helped contributions summarize -f csv --anon $csv_file | tee $rpt_file.anon-contributions.csv
who-helped contributions distinct -f csv $csv_file | tee $rpt_file.organizations.csv
who-helped contributions summarize -f csv --count Name $csv_file | tee $rpt_file.people.csv