66import pandas as pd
77import pathlib
88import sys
9+ import textwrap
910# import pprint
1011# pp = pprint.PrettyPrinter(indent=4)
1112
@@ -59,11 +60,25 @@ def make_url_dict(branch:str,file_paths:list):
5960 else :
6061 print ("An error occurred. Ensure file_paths are generated." )
6162
63+ def truncate_text (text ):
64+ wrapper = textwrap .fill (text ,
65+ initial_indent = '' ,
66+ width = 50 ,
67+ max_lines = 3 ,
68+ placeholder = "..." ,
69+ break_long_words = True ,
70+ drop_whitespace = True ,
71+ break_on_hyphens = True ,
72+ replace_whitespace = True )
73+ return wrapper
74+
75+
6276def df_sort_filter ():
6377 '''Import JSON to DF; sort by name col; filter only records w/ expertise; drop unused columns; add url col.'''
6478 raw_data = pd .read_json ("sample_db_pre.json" )
6579 df = pd .DataFrame (raw_data )
6680 df = df .sort_values (by = ['name' ], ignore_index = True ,key = lambda x : x .str .lower ())
81+ df ['description' ] = df ['description' ].apply (truncate_text ) # truncate sample description to achieve uniform card height
6782 df = df .dropna (subset = ['expertise' ]) # DROP row if 'expertise' shows "NaN"
6883 df = df .drop (["guid" ,"toolchain" , "os" , "builder" , "ciTests" ,"commonFolder" , "dependencies" , "categories" ], axis = 1 )
6984 df ['url' ] = df .insert (2 , 'url' , 'np.Nan' )
@@ -79,7 +94,8 @@ def df_add_urls(file_paths:list):
7994def df_to_db (file_paths :list ):
8095 '''Create prod database, combining df_add_urls(); output for frontend display'''
8196 df = df_add_urls (file_paths )
82- # filepath below must match steps in assoc CI Job, 'with: path: app/dev'
97+ # filepath below must match steps in assoc CI Job, 'with path: app/dev'
98+ # for testing use: ("./sample_db_prd.json")
8399 rev_json = Path ('src/docs/_static/sample_db_prd.json' )
84100 db = df .to_json (rev_json , orient = 'records' )
85101 return db
@@ -95,9 +111,10 @@ def count_json_recs(filename:str):
95111def main ():
96112 '''Orchestrate sequence of steps to output sample_db_prd.json'''
97113 rootdir = sys .argv [- 1 ]
98- file_paths = make_json_list (rootdir )
114+ file_paths = make_json_list ("./oneAPI-samples" )
99115 merge_json_files (file_paths )
100116 json_db = df_to_db (file_paths )
117+ # for testing use: ("./sample_db_prd.json")
101118 count_json_recs ("src/docs/_static/sample_db_prd.json" )
102119 return json_db
103120
0 commit comments