protected void LoadData(string filePath, string key) { Records = new List <InterviewProblem>(); if (!filePath.EndsWith(".json")) { Console.WriteLine("[DEBUG] The passed file is not json."); return; } string jsonString = File.ReadAllText(filePath); JObject jsonObject = JObject.Parse(jsonString); foreach (int id in jsonObject[key]) { try { InterviewProblem interviewProblem = InterviewProblemsDB.GetProblem(id); if (interviewProblem != null) { Records.Add(interviewProblem); } } catch (Exception ex) { Console.WriteLine($"[DEBUG] Not able to get problem id: {id}: " + ex.Message); } } }
public string GetValueByField(InterviewProblem interviewProblem, Field field) { switch (field) { case Field.ProblemID: return(interviewProblem.AlgorithmProblem.ID.ToString()); case Field.ProblemTitle: return(interviewProblem.AlgorithmProblem.Title.ToString()); case Field.ProblemDifficulty: return(interviewProblem.AlgorithmProblem.Difficulty.ToString()); case Field.ProblemAcceptanceRate: return(((double)interviewProblem.AlgorithmProblem.Accepted / interviewProblem.AlgorithmProblem.Submitted).ToString()); case Field.ProblemSolvedDate: return(interviewProblem.SolvedDate.ToString()); case Field.ProblemSolvingTime: return(interviewProblem.SolvingTime.ToString()); case Field.InterviewerName: return(interviewProblem.Interviewer.Name.ToString()); case Field.IntervieweeName: return(interviewProblem.Interviewee.Name.ToString()); } return(null); }
public static List <InterviewProblem> GetProblems(List <int> ids) { List <InterviewProblem> problems = new List <InterviewProblem>(); foreach (int id in ids) { InterviewProblem problem = GetProblem(id); if (problem == null) { return(null); } problems.Add(problem); } return(problems); }
private static void LoadData(string filePath) { if (!filePath.EndsWith(".json")) { Console.WriteLine("[DEBUG] The passed file is not json."); return; } string jsonString = File.ReadAllText(filePath); JObject jsonObject = JObject.Parse(jsonString); foreach (JObject problemJson in jsonObject["stat_status_pairs"]) { if ((bool)problemJson["paid_only"]) { continue; } AlgorithmProblem problem = new AlgorithmProblem(); JObject stat = (JObject)problemJson["stat"]; problem.ID = (int)stat["question_id"]; problem.Title = (string)stat["question__title"]; problem.Url = (string)stat["question__title_slug"]; problem.Accepted = (int)stat["total_acs"]; problem.Submitted = (int)stat["total_submitted"]; var difficultyLevel = AlgorithmProblem.DifficultyLevel.Invalid; switch ((int)((JObject)(problemJson["difficulty"]))["level"]) { case 1: difficultyLevel = AlgorithmProblem.DifficultyLevel.Easy; break; case 2: difficultyLevel = AlgorithmProblem.DifficultyLevel.Medium; break; case 3: difficultyLevel = AlgorithmProblem.DifficultyLevel.Hard; break; } problem.Difficulty = difficultyLevel; InterviewProblem interviewProblem = new InterviewProblem(); interviewProblem.AlgorithmProblem = problem; _cachedData.Add(interviewProblem.AlgorithmProblem.ID, interviewProblem); } }