private ProblemListItem CreateItem(ProblemSpec problem) { var res = new ProblemListItem() { Id = problem.id, Spec = problem }; var resp = repo.FindResponse(problem.id); if (resp != null) { var json = Read(resp); res.OurResemblance = json.resemblance; } if (problemsJson.ContainsKey(problem.id)) { res.json = problemsJson[problem.id]; res.ExpectedScore = problemsJson[problem.id].ExpectedScore(); } return(res); }
public void PostSolutionsForSameProblems2() { var repo = new ProblemsRepo(); var directories = Directory.GetDirectories(@"c:\Work\icfpc\other\icfp-2016\data\problems\", "*"); var otherProblems = directories.Select(x => { int result; if (int.TryParse(Path.GetFileName(x), out result)) { return(result); } return(-1); }).Where(x => x != -1); foreach (var otherProblem in otherProblems) { if (repo.FindResponse(otherProblem) == null) { Console.Out.WriteLine(otherProblem); } } }
public static void Run() { var pr = new ProblemsRepo(); var problemSpecs = pr.GetAllProblemSpecContentAndId().ToList(); var specSolutionResponse = problemSpecs.ToDictionary(p => p.Item2, p => Tuple.Create( p.Item1, //spec pr.FindSolution(p.Item2), //sln pr.FindResponse(p.Item2), //resp p.Item2 )); var sameSpecs = new Dictionary <string, List <Tuple <string, string, string, int> > >(); foreach (var pair in specSolutionResponse) { if (!sameSpecs.ContainsKey(pair.Value.Item1)) { sameSpecs[pair.Value.Item1] = new List <Tuple <string, string, string, int> >(); } sameSpecs[pair.Value.Item1].Add(pair.Value); } var toSolve = new Dictionary <int, List <int> >(); foreach (var taskInfos in sameSpecs) { var sln = ""; var id = 0; foreach (var taskInfo in taskInfos.Value) { if (sln != "" || taskInfo.Item3 != null && !taskInfo.Item3.Contains("\"resemblance\":1.0")) { continue; } sln = taskInfo.Item3; id = taskInfo.Item4; } if (sln == "") { continue; } var list = taskInfos.Value .Where(taskInfo => taskInfo.Item3 == null || !taskInfo.Item3.Contains("\"resemblance\":1.0")) .Select(taskInfo => taskInfo.Item4) .ToList(); if (list.Count != 0) { toSolve[id] = list; } } var client = new ApiClient(); foreach (var kvp in toSolve) { if (kvp.Value.Count == 0) { continue; } var sln = pr.FindSolution(kvp.Key); if (sln == null) { continue; } foreach (var id in kvp.Value) { try { var response = client.PostSolution(id, sln); pr.PutResponse(id, response); pr.PutSolution(id, sln); Console.WriteLine(JObject.Parse(response)["resemblance"].Value <double>()); } catch (Exception e) { Console.WriteLine(); Console.WriteLine(e); Console.WriteLine(0); } }