Generate realistic sample data
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
import { fetchCategoryMetadata } from "./metadata";
|
||||
import { ResponseData } from "./parser";
|
||||
|
||||
export function getSampleData(): Promise<ResponseData[]> {
|
||||
const questions = [
|
||||
"Service Quality",
|
||||
"Value for Money",
|
||||
"Ease of Use",
|
||||
"Recommendation",
|
||||
"Overall Satisfaction",
|
||||
"Customer Support",
|
||||
"Product Features",
|
||||
];
|
||||
function randInt(min: number, max: number): number {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
export async function getSampleData(): Promise<ResponseData[]> {
|
||||
// Use the actual categories
|
||||
const questions = (await fetchCategoryMetadata()).map(
|
||||
(metadata) => metadata.category
|
||||
);
|
||||
const sampleData: ResponseData[] = [];
|
||||
let id = 1;
|
||||
questions.forEach((question) => {
|
||||
const numResponses = Math.floor(Math.random() * 50) + 30;
|
||||
for (let i = 0; i < numResponses; i++) {
|
||||
const response = Math.floor(Math.random() * 5);
|
||||
const numResponses = randInt(10, 20);
|
||||
for (let i = 0; i < numResponses; i++) {
|
||||
questions.forEach((question) => {
|
||||
const response = randInt(0, 4); // Likert scale response (0-4)
|
||||
sampleData.push({
|
||||
timestamp: id++,
|
||||
position: "",
|
||||
timestamp: i, // Group all responses by the same timestamp to mimic Google Forms behavior
|
||||
question: question,
|
||||
response: response,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// Simulate a delay to mimic fetching actual data
|
||||
return new Promise<ResponseData[]>((resolve) => {
|
||||
setTimeout(() => resolve(sampleData), 500);
|
||||
|
||||
Reference in New Issue
Block a user