Skip to content

Commit 921f461

Browse files
authored
Add more large data (#124)
1 parent 4cd4490 commit 921f461

33 files changed

+23931
-14
lines changed

apps/plotly_examples/python-scripts/generate_plotly_schema.py

+33-8
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,43 @@ def generate_visualization_schemas():
6969
id = call_llm_plotly_schema(json.dumps(scenario_data), id)
7070

7171
def generate_detailed_visualization_schemas():
72+
print('Generating detailed schemas')
7273
scenario_dir = 'generated_schema'
7374
if not os.path.exists(scenario_dir):
7475
print("Populate the schemas first by calling generate_visualization_schemas()")
75-
id = 253
76+
id = 303
7677
sample_size = min(25, len(os.listdir(scenario_dir)))
77-
random_files = random.sample(os.listdir(scenario_dir), sample_size)
78+
chart_types = {}
79+
for file_name in os.listdir(scenario_dir):
80+
json_data = read_json_file(os.path.join(scenario_dir, file_name))
81+
chart_type = json_data['data'][0]['type']
82+
if chart_type not in chart_types:
83+
chart_types[chart_type] = []
84+
chart_types[chart_type].append(file_name)
85+
86+
min_samples_per_chart_type = sample_size//len(chart_types)
87+
random_files = []
88+
for chart_type, files in chart_types.items():
89+
random_files.extend(random.sample(files, min(min_samples_per_chart_type, len(files))))
90+
91+
# keeping extra buffer data in case any one fails to generate
92+
buffer_data = 50
93+
if len(random_files) < sample_size + buffer_data:
94+
remaining_files = [file for file in os.listdir(scenario_dir) if file not in random_files]
95+
if len(remaining_files) > 0:
96+
random_files.extend(random.sample(remaining_files, ((sample_size+buffer_data)-len(random_files))))
97+
98+
count = 0
7899
for file_name in random_files:
100+
if count == sample_size:
101+
break
79102
json_data = read_json_file(os.path.join(scenario_dir, file_name))
80103
curr_id = json_data['id']
81104
file_name_prefix = file_name.split('.')[0]
82105
suffix = file_name_prefix.split(str(curr_id))[1]
83-
id = call_llm_detailed_plotly_schema(json.dumps(json_data), id, suffix)
106+
id, isSuccess = call_llm_detailed_plotly_schema(json.dumps(json_data), id, suffix)
107+
if isSuccess:
108+
count = count + 1
84109

85110
def generate_locale_visualization_schemas():
86111
if not os.path.exists(scenario_dir):
@@ -303,7 +328,7 @@ def call_llm_detailed_plotly_schema(scenario: str, id: int, suffix: str):
303328
# call only if the file does not exist
304329
if os.path.exists(f'generated_schema_detailed/data_{id}{suffix}.json'):
305330
print(f"Skipping {id}_{suffix}")
306-
return id+1
331+
return id+1, False
307332

308333
# in case text_output is not a valid json, it will retry 3 times
309334
retry_count=0
@@ -318,7 +343,7 @@ def call_llm_detailed_plotly_schema(scenario: str, id: int, suffix: str):
318343

319344
if retry_count == 3:
320345
print("Failed to generate schema")
321-
return id
346+
return id, False
322347

323348
output_dir = 'generated_schema_detailed'
324349
os.makedirs(output_dir, exist_ok=True)
@@ -329,7 +354,7 @@ def call_llm_detailed_plotly_schema(scenario: str, id: int, suffix: str):
329354
json.dump(data, file, indent=4)
330355
id=id+1
331356

332-
return id
357+
return id, True
333358

334359
def get_chart_type_from_image():
335360
directory_path = os.path.join('..', 'tests', 'Plotly.spec.ts-snapshots')
@@ -390,10 +415,10 @@ def get_chart_type_from_image():
390415
# generate_visualization_schemas()
391416

392417
# Generate detailed schemas
393-
# generate_detailed_visualization_schemas()
418+
generate_detailed_visualization_schemas()
394419

395420
# Generate locale based schemas
396421
# generate_locale_visualization_schemas()
397422

398423
# Generate chart types from screenshots taken by Playwright
399-
get_chart_type_from_image()
424+
# get_chart_type_from_image()

apps/plotly_examples/src/components/DeclarativeChart.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ type DataType =
4141
| 'localization';
4242

4343
const dataTypeRanges = {
44-
'general': { min: 1, max: 252 },
45-
'largeData': { min: 253, max: 277 },
46-
'localization': { min: 278, max: 302 }
44+
'general': [{ min: 1, max: 252 }],
45+
'largeData': [{ min: 253, max: 277 }, { min: 303, max: 332 }],
46+
'localization': [{ min: 278, max: 302 }]
4747
};
4848

4949
// Use require.context to load all JSON files from the split_data folder
@@ -128,8 +128,8 @@ const DeclarativeChartBasicExample: React.FC<IDeclarativeChartProps> = () => {
128128
.filter((data) => {
129129
const schemaId = parseInt((data.schema as { id: string }).id, 10);
130130
return selectedDataTypes.includes('All') || selectedDataTypes.some(dataType => {
131-
const range = dataTypeRanges[dataType as keyof typeof dataTypeRanges];
132-
return schemaId >= range.min && schemaId <= range.max;
131+
if (dataType === 'All') return true;
132+
return dataTypeRanges[dataType].some(range => schemaId >= range.min && schemaId <= range.max);
133133
});
134134
})
135135
.filter((data) => {

apps/plotly_examples/src/components/aggregated_chart_types.json

+31-1
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,35 @@
300300
"299": "GroupedVerticalBar",
301301
"300": "GroupedVerticalBar",
302302
"301": "GroupedVerticalBar",
303-
"302": "GroupedVerticalBar"
303+
"302": "GroupedVerticalBar",
304+
"303": "GroupedVerticalBar",
305+
"304": "VerticalBar",
306+
"305": "Pie",
307+
"306": "Donut",
308+
"307": "Line",
309+
"308": "Line",
310+
"309": "Line",
311+
"310": "Line",
312+
"311": "Heatmap",
313+
"312": "Others",
314+
"313": "Others",
315+
"314": "Others",
316+
"315": "Others",
317+
"316": "Others",
318+
"317": "GroupedVerticalBar",
319+
"318": "Line",
320+
"319": "GroupedVerticalBar",
321+
"320": "Line",
322+
"321": "GroupedVerticalBar",
323+
"322": "Others",
324+
"323": "Donut",
325+
"324": "GroupedVerticalBar",
326+
"325": "Pie",
327+
"326": "VerticalStackedBar",
328+
"327": "VerticalStackedBar",
329+
"328": "Area",
330+
"329": "Area",
331+
"330": "HorizontalBarWithAxis",
332+
"331": "HorizontalBarWithAxis",
333+
"332": "Sankey"
304334
}

0 commit comments

Comments
 (0)