Skip to content

Commit

Permalink
Splitting dataset into files and adding prompts and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
srmukher committed Dec 6, 2024
2 parents 37e5a17 + 100a00f commit d6af2a5
Show file tree
Hide file tree
Showing 18 changed files with 4,900 additions and 42 deletions.
16 changes: 16 additions & 0 deletions apps/plotly_examples/scripts/add-id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# python script to add ID for each dataset
import json

# Load the JSON data from a file
with open('parsed_data.json', 'r') as file:
data = json.load(file)

# Add an id tag to each data entry
for index, entry in enumerate(data):
entry['id'] = index + 1

# Write the modified data back to a JSON file
with open('parsed_data_with_ids.json', 'w') as file:
json.dump(data, file, indent=2)

print("IDs added successfully.")
29 changes: 29 additions & 0 deletions apps/plotly_examples/scripts/parseJson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Parses the json out of the dataset generated by LLM
import json
import re

# Read the file content
with open('dataset.json', 'r') as file:
content = file.read()

# Extract JSON strings using regular expressions
json_strings = re.findall(r'```json\n(.*?)\n```', content, re.DOTALL)

# Initialize an empty list to store parsed data
parsed_data = []

# Parse the JSON strings, ensuring to check for None or empty strings
for json_str in json_strings:
if json_str and json_str.strip():
try:
parsed_data.append(json.loads(json_str))
except json.JSONDecodeError as e:
print(f"Failed to parse JSON string: {json_str}")
print(f"Error: {e}")

# Save the parsed data to a new file
output_file = 'parsed_data.json'
with open(output_file, 'w') as file:
json.dump(parsed_data, file, indent=2)

print(f"Parsed data has been saved to {output_file}")
50 changes: 50 additions & 0 deletions apps/plotly_examples/scripts/prompts.txt

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions apps/plotly_examples/scripts/splitData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import os

# Load the JSON data from a file
with open('parsed_data_with_ids.json', 'r') as file:
data = json.load(file)

# Create a directory to store the split files
output_dir = 'split_data'
os.makedirs(output_dir, exist_ok=True)

# Split each data entry into a new file
for index, entry in enumerate(data):
output_file = os.path.join(output_dir, f'data_{index + 1}.json')
with open(output_file, 'w') as file:
json.dump(entry, file, indent=2)

print("Data split into separate files successfully.")
8 changes: 4 additions & 4 deletions apps/plotly_examples/src/components/DeclarativeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const schemasData = requireContext.keys().map((fileName: string) => ({
}));

const options: IDropdownOption[] = schemasData.map((data) => ({
key: data.fileName,
key: (data.schema as { id: string }).id,
text: data.fileName,
}));

Expand All @@ -26,15 +26,15 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
constructor(props: DeclarativeChartProps) {
super(props);
this.state = {
selectedChoice: schemasData[0]?.fileName || 'unknown', // Set the first file as the default choice if available
selectedChoice: (schemasData[0].schema as { id: string }).id || 'unknown', // Set the first file as the default choice if available
selectedSchema: schemasData[0]?.schema || null,
schemasData: schemasData,
};
}

private _onChange = (ev: any, option?: IDropdownOption): void => {
const selectedChoice = option?.key as string;
const selectedSchema = this.state.schemasData.find((data) => data.fileName === selectedChoice)?.schema;
const selectedSchema = this.state.schemasData.find((data) => (data.schema as { id: string }).id === selectedChoice)?.schema;
this.setState({ selectedChoice, selectedSchema });
};

Expand Down Expand Up @@ -65,4 +65,4 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
public render(): JSX.Element {
return <div>{this._createDeclarativeChart()}</div>;
}
}
}
24 changes: 12 additions & 12 deletions apps/plotly_examples/src/data/data_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"type": "scatter",
"name": "Product Category",
"x": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
"2023-01-01",
"2023-02-01",
"2023-03-01",
"2023-04-01",
"2023-05-01",
"2023-06-01",
"2023-07-01",
"2023-08-01",
"2023-09-01",
"2023-10-01",
"2023-11-01",
"2023-12-01"
],
"y": [
5000,
Expand Down
46 changes: 46 additions & 0 deletions apps/plotly_examples/src/data/data_17.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,52 @@
20,
10
]
],
"colorscale": [
[
0.0,
"rgb(158,1,66)"
],
[
0.1,
"rgb(213,62,79)"
],
[
0.2,
"rgb(244,109,67)"
],
[
0.3,
"rgb(253,174,97)"
],
[
0.4,
"rgb(254,224,139)"
],
[
0.5,
"rgb(255,255,191)"
],
[
0.6,
"rgb(230,245,152)"
],
[
0.7,
"rgb(171,221,164)"
],
[
0.8,
"rgb(102,194,165)"
],
[
0.9,
"rgb(50,136,189)"
],
[
1.0,
"rgb(94,79,162)"
]
]
}
],
Expand Down
48 changes: 24 additions & 24 deletions apps/plotly_examples/src/data/data_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"mode": "lines",
"name": "Category A",
"x": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
"2023-01-01",
"2023-02-01",
"2023-03-01",
"2023-04-01",
"2023-05-01",
"2023-06-01",
"2023-07-01",
"2023-08-01",
"2023-09-01",
"2023-10-01",
"2023-11-01",
"2023-12-01"
],
"y": [
4000,
Expand All @@ -38,18 +38,18 @@
"mode": "lines",
"name": "Category B",
"x": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
"2023-01-01",
"2023-02-01",
"2023-03-01",
"2023-04-01",
"2023-05-01",
"2023-06-01",
"2023-07-01",
"2023-08-01",
"2023-09-01",
"2023-10-01",
"2023-11-01",
"2023-12-01"
],
"y": [
6000,
Expand Down
46 changes: 46 additions & 0 deletions apps/plotly_examples/src/data/data_25.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,52 @@
"Product B",
"Product C",
"Product D"
],
"colorscale": [
[
0.0,
"rgb(158,1,66)"
],
[
0.1,
"rgb(213,62,79)"
],
[
0.2,
"rgb(244,109,67)"
],
[
0.3,
"rgb(253,174,97)"
],
[
0.4,
"rgb(254,224,139)"
],
[
0.5,
"rgb(255,255,191)"
],
[
0.6,
"rgb(230,245,152)"
],
[
0.7,
"rgb(171,221,164)"
],
[
0.8,
"rgb(102,194,165)"
],
[
0.9,
"rgb(50,136,189)"
],
[
1.0,
"rgb(94,79,162)"
]
]
}
],
Expand Down
46 changes: 46 additions & 0 deletions apps/plotly_examples/src/data/data_35.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,52 @@
"Spring",
"Summer",
"Fall"
],
"colorscale": [
[
0.0,
"rgb(158,1,66)"
],
[
0.1,
"rgb(213,62,79)"
],
[
0.2,
"rgb(244,109,67)"
],
[
0.3,
"rgb(253,174,97)"
],
[
0.4,
"rgb(254,224,139)"
],
[
0.5,
"rgb(255,255,191)"
],
[
0.6,
"rgb(230,245,152)"
],
[
0.7,
"rgb(171,221,164)"
],
[
0.8,
"rgb(102,194,165)"
],
[
0.9,
"rgb(50,136,189)"
],
[
1.0,
"rgb(94,79,162)"
]
]
}
],
Expand Down
Loading

0 comments on commit d6af2a5

Please sign in to comment.