Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 18655
1
import numpy as np
2
import pandas as pd
3
import qgrid
4
from pbx_gs_python_utils.utils.Files import Files
5
from oss_hugo.Files_Utils import Files_Utils
6
7
from oss_hugo.Hugo_Page import Hugo_Page
8
from oss_hugo.OSS_GSheet_Data import OSS_GSheet_Data
9
from oss_hugo.OSS_Participant import OSS_Participant
10
11
12
class API_Hugo_OSS:
13
14
def __init__(self):
15
self.folder_oss = Hugo_Page().folder_oss
16
self._participants = None
17
18
def md_files_in_folder(self, target):
19
path = Files.path_combine(self.folder_oss, target)
20
return Files_Utils.all_files_recursive_with_extension(path,'.md')
21
22
def md_files_participants(self):
23
return self.md_files_in_folder(OSS_Participant().base_folder)
24
25
26
def load_files(self,paths,index_by_title=False):
27
results = {}
28
for path in paths:
29
data = Hugo_Page().load(path)
30
if data:
31
if index_by_title:
32
results[data.get('metadata').get('title')] = data
33
else:
34
results[data.get('path')] = data
35
return results
36
37
def load_oss_participants(self,paths):
38
results = {}
39
for path in paths:
40
participant = OSS_Participant(name=path)
41
if participant.exists():
42
results[participant.name] = participant
43
return results
44
45
#def save_file(self, data):
46
#@use_local_cache_if_available
47
def participants(self,reload=True, return_oss_participants=False):
48
if self._participants is None or reload:
49
if return_oss_participants is False: # this was the original workflow (before the creation of the OSS_Participant class)
50
self._participants = self.load_files(self.md_files_participants())
51
else:
52
self._participants = self.load_oss_participants(self.md_files_participants())
53
return self._participants
54
55
def participants_oss(self, reload=True):
56
return self.participants(reload=reload,return_oss_participants=True)
57
58
def participants_metadatas(self):
59
#return self.participants()
60
return [participant.get('metadata') for participant in self.participants().values()]
61
62
def gsheet_data(self):
63
return OSS_GSheet_Data()
64
65
def df_field(self,field):
66
df = self.df_participants(['title', field])
67
df[field].replace('', np.nan, inplace=True)
68
df = df.dropna().reset_index(drop=True)
69
df.index += 1
70
return df
71
72
def df_merged_gsheet_and_hugo_data(self,reload=False):
73
df_hugo = pd.DataFrame(self.participants_metadatas())
74
df_gsheet = self.gsheet_data().df_participants_onsite(reload)
75
df_gsheet['GSheet'] = True
76
df_hugo ['Hugo' ] = True
77
df_hugo ['Name' ] = df_hugo['title']
78
df_hugo = df_hugo[['Name', 'status', 'company', 'Hugo']]
79
df_both = pd.merge(df_hugo, df_gsheet, on='Name', how='outer').fillna('')
80
#df_both.fillna('*')
81
df_both = df_both[['Name', 'company', 'Company', 'Payment Status', 'GSheet', 'Hugo']]
82
df_both = df_both[df_both['Name'] != '']
83
return df_both
84
85
def df_participants(self,columns=None):
86
return pd.DataFrame(self.participants_metadatas(),columns=columns)
87
88
def qgrid_merged_gsheet_and_hugo_data(self,reload=False):
89
df_both = self.df_merged_gsheet_and_hugo_data(reload)
90
return qgrid.show_grid(df_both)
91
92
def qgrid_participants(self,columns=None):
93
return qgrid.show_grid(self.df_participants(columns))
94