@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
73 lines (72 loc) • 2.58 kB
TypeScript
import { Schema } from '@sprucelabs/schema';
import { GraphicsInterface } from '../types/cli.types';
import FormComponent, { FormOptions, FormPresentationOptions } from './FormComponent';
interface QuizMultipleChoiceQuestion {
type: 'select';
question: string;
answers: string[];
}
interface QuizTextQuestion {
type: 'text';
question: string;
answer: string;
}
type QuizQuestions = Record<string, QuizMultipleChoiceQuestion | QuizTextQuestion>;
declare enum AnswerValidity {
Correct = "correct",
Incorrect = "incorrect"
}
interface QuizPresentationOptions<T extends Schema, Q extends QuizQuestions> extends Omit<FormPresentationOptions<T>, 'fields'> {
questions?: QuizAnswerFieldNames<Q>[];
randomizeQuestions?: boolean;
}
type QuizAnswerFieldNames<Q extends QuizQuestions> = Extract<keyof Q, string>;
type QuizAnswers<Q extends QuizQuestions> = {
[K in QuizAnswerFieldNames<Q>]: string;
};
type QuizAnswerValidities<Q extends QuizQuestions> = {
[K in QuizAnswerFieldNames<Q>]: AnswerValidity;
};
interface QuizPresentationResults<Q extends QuizQuestions> {
/** The answers that were given */
answers: QuizAnswers<Q>;
/** The answers right or wrong */
answerValidities: QuizAnswerValidities<Q>;
/** The percent of correct answers given */
percentCorrect: number;
/** How long it took them to take the quiz in ms */
time: {
startTimeMs: number;
endTimeMs: number;
totalTimeSec: number;
};
/** How many were correct */
totalCorrect: number;
/** How many were wrong */
totalWrong: number;
/** How many questions we ended up taking */
totalQuestions: number;
}
interface QuizOptions<T extends Schema, Q extends QuizQuestions> extends Omit<FormOptions<T>, 'schema'> {
/** Should we randomize the questions */
randomizeQuestions?: boolean;
/** The questions we are asking */
questions: Q;
}
export default class QuizComponent<T extends Schema, Q extends QuizQuestions> {
formBuilder: FormComponent<T>;
term: GraphicsInterface;
randomizeQuestions: boolean;
originalQuestions: QuizQuestions;
lastResults?: QuizPresentationResults<Q>;
constructor(options: QuizOptions<T, Q>);
/** Present the quiz */
present(options?: QuizPresentationOptions<T, Q>): Promise<QuizPresentationResults<Q>>;
scorecard(options?: {
results?: QuizPresentationResults<Q>;
headline?: string;
}): Promise<void>;
/** Takes questions and builds a schema */
private buildSchemaFromQuestions;
}
export {};