56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
namespace QuestionsApi.Models;
|
|
|
|
public class QuestionResponse
|
|
{
|
|
public string Id { get; set; } = "";
|
|
public string ExternalId { get; set; } = "";
|
|
public string Stem { get; set; } = "";
|
|
public string LeadIn { get; set; } = "";
|
|
public List<QuestionChoice> Choices { get; set; } = [];
|
|
public string CorrectChoiceId { get; set; } = "";
|
|
public string Explanation { get; set; } = "";
|
|
public Dictionary<string, string> ChoiceExplanations { get; set; } = [];
|
|
public Dictionary<string, int> ChoiceSelectionPercentages { get; set; } = [];
|
|
public string Discipline { get; set; } = "";
|
|
public string System { get; set; } = "";
|
|
public int Difficulty { get; set; }
|
|
public List<QuestionLab> Labs { get; set; } = [];
|
|
public List<string> Media { get; set; } = [];
|
|
public List<string> Tags { get; set; } = [];
|
|
|
|
public static QuestionResponse FromModel(Question question, Dictionary<string, int>? liveChoiceSelectionPercentages = null) => new()
|
|
{
|
|
Id = question.Id ?? "",
|
|
ExternalId = question.ExternalId,
|
|
Stem = question.Stem,
|
|
LeadIn = question.LeadIn,
|
|
Choices = question.Choices,
|
|
CorrectChoiceId = question.CorrectChoiceId,
|
|
Explanation = question.Explanation,
|
|
ChoiceExplanations = question.ChoiceExplanations,
|
|
ChoiceSelectionPercentages = BuildChoiceSelectionPercentages(question, liveChoiceSelectionPercentages),
|
|
Discipline = question.Discipline,
|
|
System = question.System,
|
|
Difficulty = question.Difficulty,
|
|
Labs = question.Labs,
|
|
Media = question.Media,
|
|
Tags = question.Tags
|
|
};
|
|
|
|
public static Dictionary<string, int> BuildChoiceSelectionPercentages(Question question, Dictionary<string, int>? liveChoiceSelectionPercentages)
|
|
{
|
|
if (liveChoiceSelectionPercentages is not { Count: > 0 })
|
|
return question.ChoiceSelectionPercentages;
|
|
|
|
return question.Choices.ToDictionary(
|
|
choice => choice.Id,
|
|
choice => liveChoiceSelectionPercentages.GetValueOrDefault(choice.Id, 0));
|
|
}
|
|
}
|
|
|
|
public class FirstQuestionAttemptResponse
|
|
{
|
|
public string QuestionExternalId { get; set; } = "";
|
|
public Dictionary<string, int> ChoiceSelectionPercentages { get; set; } = [];
|
|
}
|