class test_API_Hugo_OSS(TestCase): def setUp(self): self.api = API_Hugo_OSS() self.result = None def tearDown(self): if self.result is not None: Dev.pprint(self.result) def test_md_files_in_folder(self): assert len(self.api.md_files_in_folder('content/participant')) > 50 def test_md_files_participants(self): assert len(self.api.md_files_participants()) >50 def test_participants(self): participants = self.api.participants() assert len(participants) > 50 assert set(participants.values().__iter__().__next__()) == {'content', 'path', 'metadata'} def test_participants_metadatas(self): assert len(self.api.participants_metadatas()) > 50
class OSS_Schedule: def __init__(self): self.hugo = API_Hugo_OSS() def sessions_mapped_by_size(self): mapping = [] for path, session in self.hugo.sessions().items(): content = session.get('content') metadata = session.get('metadata') page_type = metadata.get('type') title = metadata.get('title') track = metadata.get('track') organizers = metadata.get('organizers') participants = metadata.get('participants') if not organizers: organizers = [] if not participants: participants = [] if type(organizers) is str: organizers = organizers.split(',') if type(participants) is str: participants = participants.split(',') if 'TBD' in organizers: organizers.remove('TBD') if 'Pending' in organizers: organizers.remove('Pending') if 'you ?' in participants: participants.remove('you ?') if title and page_type: item = { 'title': title, 'track': track, 'page_type': page_type, 'organizers': organizers, 'participants': participants, 'content': len(content), 'path': path } mapping.append(item) df_mappings = pd.DataFrame(mapping) df_mappings = df_mappings[[ 'title', 'track', 'page_type', 'content', 'organizers', 'participants' ]] df_sessions = df_mappings[df_mappings['page_type'] != 'track'] df_sessions = df_sessions.sort_values( ['content'], ascending=False).reset_index(drop=True) return df_sessions
def setUp(self): self.api = API_Hugo_OSS() self.result = None
class test_API_Hugo_OSS(TestCase): def setUp(self): self.api = API_Hugo_OSS() self.result = None def tearDown(self): if self.result is not None: Dev.pprint(self.result) def test_df_field(self): df = self.api.df_field('chapter_leader').set_index('title') data = df.to_dict()['chapter_leader'] assert data['Sebastien Deleersnyder'] == 'Belgium' def test_md_files_in_folder(self): assert len(self.api.md_files_in_folder('content/participant')) > 50 def test_md_files_participants(self): assert len(self.api.md_files_participants()) > 50 def test_md_files_sessions(self): assert len(self.api.md_files_sessions()) > 50 def test_participants(self): participants = self.api.participants() assert len(participants) > 50 assert set(participants.values().__iter__().__next__()) == { 'content', 'path', 'metadata' } def test_participants__return_oss_participants(self): participants = self.api.participants(return_oss_participants=True) assert len(participants) > 50 assert type(list(participants.values())[0]) == OSS_Participant assert 'Dinis Cruz' in set(participants) def test_participants_metadatas(self): assert len(self.api.participants_metadatas()) > 50 def test_sessions(self): sessions = self.api.sessions() assert len(sessions) > 50 assert set(sessions.values().__iter__().__next__()) == { 'content', 'path', 'metadata' } def test_sessions__return_oss_sessions(self): sessions = self.api.sessions(return_oss_sessions=True) assert len(sessions) > 50 assert type(list(sessions.values())[0]) is OSS_Session assert 'Threat Model' in set(sessions) def test_sessions_metadatas(self): assert len(self.api.sessions_metadatas()) > 50 def test_sessions_oss(self): assert len(self.api.sessions_oss()) > 50
def __init__(self): self.hugo = API_Hugo_OSS()
class OSS_Schedule: def __init__(self): self.hugo = API_Hugo_OSS() def sessions_mapped_by_size(self): mapping = [] for path, session in self.hugo.sessions().items(): content = session.get('content') metadata = session.get('metadata') page_type = metadata.get('type') title = metadata.get('title') track = metadata.get('track') organizers = metadata.get('organizers') participants = metadata.get('participants') if not organizers: organizers = [] if not participants: participants = [] if type(organizers) is str: organizers = organizers.split(',') if type(participants) is str: participants = participants.split(',') if 'TBD' in organizers: organizers.remove('TBD') if 'Pending' in organizers: organizers.remove('Pending') if 'you ?' in participants: participants.remove('you ?') if title and page_type: item = { 'title': title, 'track': track, 'page_type': page_type, 'organizers': organizers, 'participants': participants, 'content': len(content), 'path': path } mapping.append(item) df_mappings = pd.DataFrame(mapping) df_mappings = df_mappings[[ 'title', 'track', 'page_type', 'content', 'organizers', 'participants' ]] df_sessions = df_mappings[df_mappings['page_type'] != 'track'] df_sessions = df_sessions.sort_values( ['content'], ascending=False).reset_index(drop=True) return df_sessions #todo get the result below using pandas def df_sessions_registered_participants(self): results = {} for key, value in self.hugo.df_participants().to_dict( orient='index').items(): title = value.get('title') sessions = value.get('sessions') for session in sessions: if results.get(session) is None: results[session] = [] results[session].append(title) mappings = [] for key, value in results.items(): mappings.append({ 'title': key, 'participants': value, 'participants_count': len(value) }) df_mappings = pd.DataFrame(mappings) df_mappings = df_mappings[[ 'title', 'participants_count', 'participants' ]].sort_values(['participants_count'], ascending=False) return df_mappings
import sys; #from IPython import get_ipython #ipython = get_ipython() #ipython.magic('load_ext autoreload') #ipython.magic('autoreload') sys.path.insert(0,'./api') sys.path.insert(0,'../api') sys.path.insert(0,'../../api') sys.path.insert(0,'../../../api') import qgrid import pandas as pd oss_version = 0.41 from oss_hugo.API_Hugo_OSS import API_Hugo_OSS hugo = API_Hugo_OSS()