private void ReadStatsLog()
        {
            var robotsByName = (from team in Teams
                                from robot in team.Robots
                                select robot).ToDictionary(r => r.Name);

            using (var statsLog = File.ReadAllLines(StatsLogFile).AsEnumerable().GetEnumerator()) {
                statsLog.SkipUntil(line => line.StartsWith("____Robots"));
                var robotLines = statsLog.Take(Int32.Parse(GetCsvValue(statsLog.Current, "____Robots")));

                var robotsById = (from line in robotLines
                                  let split = line.Split(',')
                                  select
                                      new {
                                          Id = Int32.Parse(split[4]),
                                          Robot = robotsByName[split[0]]
                                      })
                    .ToDictionary(r => r.Id, r => r.Robot);

                var headerLine = statsLog.Current.Split(',');
                foreach (var line in statsLog.TakeWhile(l => true)) {
                    var split = line.Split(',');
                    var values = headerLine.Zip(
                        split,
                        (header, value) =>
                        Tuple.Create(header, Int32.Parse(value)))
                        .ToDictionary(i => i.Item1, i => i.Item2);

                    var robot = robotsById[values["id"]];
                    var stats = new RobotGameStatistics {
                        Game = values["game"],
                        Place = values["_place"],
                        TotalKillsToRobots = values["_killstorobots[*]"],
                        TotalKillsFromRobots = values["_killsfromrobots[*]"],
                        KillsFromMines = values["_killsfrommines[*]"],
                        KillsFromWalls = values["_killsfromwalls[*]"],
                        KillsFromErrors = values["_killsfromerrors[*]"],
                        KillsFromMisc = values["_killsfrommisc[*]"],
                        KillsFromTimeouts = values["_killsfromtimeouts[*]"],
                        ShotsFired = values["_shotsfired[*]"],
                        HitsToMines = values["_hitstomines[*]"],
                        HitsToCookies = values["_hitstocookies[*]"],
                        TotalHitsToRobots = values["_hitstorobots[*]"],
                        TotalHitsFromRobots = values["_hitsfromrobots[*]"],
                        AverageHitStrengthToRobots = values["_hitstrtorobots[*]"],
                        TotalDamageToRobots = values["_dmgtorobots[*]"],
                        TotalDamageFromRobots = values["_dmgfromrobots[*]"],
                        TotalDamageFromMines = values["_dmgfrommines[*]"],
                        TotalDamageFromWalls = values["_dmgfromwalls[*]"],
                        TotalDamageFromJar = values["_dmgfromjar[*]"],
                        TotalBonusFromCookies = values["_bonusfromcookies[*]"],
                        TotalCollisionsWithRobots = values["_cldwithrobots[*]"],
                        Points = values["_points[*]"]
                    };
                    foreach (var otherRobot in robotsById) {
                        stats.HitsToRobots[otherRobot.Value] =
                            values[string.Format("_hitstorobots[*][{0}]", otherRobot.Key)];
                        stats.HitsFromRobots[otherRobot.Value] =
                            values[string.Format("_hitsfromrobots[*][{0}]", otherRobot.Key)];
                        stats.KillsToRobots[otherRobot.Value] =
                            values[string.Format("_killstorobots[*][{0}]", otherRobot.Key)];
                        stats.KillsFromRobots[otherRobot.Value] =
                            values[string.Format("_killsfromrobots[*][{0}]", otherRobot.Key)];
                        stats.DamageToRobots[otherRobot.Value] =
                            values[string.Format("_dmgtorobots[*][{0}]", otherRobot.Key)];
                        stats.DamageFromRobots[otherRobot.Value] =
                            values[string.Format("_dmgfromrobots[*][{0}]", otherRobot.Key)];
                        stats.CollisionsWithRobots[otherRobot.Value] =
                            values[string.Format("_cldwithrobots[*][{0}]", otherRobot.Key)];
                    }
                    robot.Statistics.Add(stats);
                }
            }
        }
Exemple #2
0
        private void ReadStatsLog()
        {
            var robotsByName = (from team in Teams
                                from robot in team.Robots
                                select robot).ToDictionary(r => r.Name);

            using (var statsLog = File.ReadAllLines(StatsLogFile).AsEnumerable().GetEnumerator()) {
                statsLog.SkipUntil(line => line.StartsWith("____Robots"));
                var robotLines = statsLog.Take(Int32.Parse(GetCsvValue(statsLog.Current, "____Robots")));

                var robotsById = (from line in robotLines
                                  let split = line.Split(',')
                                              select
                                              new {
                    Id = Int32.Parse(split[4]),
                    Robot = robotsByName[split[0]]
                })
                                 .ToDictionary(r => r.Id, r => r.Robot);

                var headerLine = statsLog.Current.Split(',');
                foreach (var line in statsLog.TakeWhile(l => true))
                {
                    var split  = line.Split(',');
                    var values = headerLine.Zip(
                        split,
                        (header, value) =>
                        Tuple.Create(header, Int32.Parse(value)))
                                 .ToDictionary(i => i.Item1, i => i.Item2);

                    var robot = robotsById[values["id"]];
                    var stats = new RobotGameStatistics {
                        Game  = values["game"],
                        Place = values["_place"],
                        TotalKillsToRobots         = values["_killstorobots[*]"],
                        TotalKillsFromRobots       = values["_killsfromrobots[*]"],
                        KillsFromMines             = values["_killsfrommines[*]"],
                        KillsFromWalls             = values["_killsfromwalls[*]"],
                        KillsFromErrors            = values["_killsfromerrors[*]"],
                        KillsFromMisc              = values["_killsfrommisc[*]"],
                        KillsFromTimeouts          = values["_killsfromtimeouts[*]"],
                        ShotsFired                 = values["_shotsfired[*]"],
                        HitsToMines                = values["_hitstomines[*]"],
                        HitsToCookies              = values["_hitstocookies[*]"],
                        TotalHitsToRobots          = values["_hitstorobots[*]"],
                        TotalHitsFromRobots        = values["_hitsfromrobots[*]"],
                        AverageHitStrengthToRobots = values["_hitstrtorobots[*]"],
                        TotalDamageToRobots        = values["_dmgtorobots[*]"],
                        TotalDamageFromRobots      = values["_dmgfromrobots[*]"],
                        TotalDamageFromMines       = values["_dmgfrommines[*]"],
                        TotalDamageFromWalls       = values["_dmgfromwalls[*]"],
                        TotalDamageFromJar         = values["_dmgfromjar[*]"],
                        TotalBonusFromCookies      = values["_bonusfromcookies[*]"],
                        TotalCollisionsWithRobots  = values["_cldwithrobots[*]"],
                        Points = values["_points[*]"]
                    };
                    foreach (var otherRobot in robotsById)
                    {
                        stats.HitsToRobots[otherRobot.Value] =
                            values[string.Format("_hitstorobots[*][{0}]", otherRobot.Key)];
                        stats.HitsFromRobots[otherRobot.Value] =
                            values[string.Format("_hitsfromrobots[*][{0}]", otherRobot.Key)];
                        stats.KillsToRobots[otherRobot.Value] =
                            values[string.Format("_killstorobots[*][{0}]", otherRobot.Key)];
                        stats.KillsFromRobots[otherRobot.Value] =
                            values[string.Format("_killsfromrobots[*][{0}]", otherRobot.Key)];
                        stats.DamageToRobots[otherRobot.Value] =
                            values[string.Format("_dmgtorobots[*][{0}]", otherRobot.Key)];
                        stats.DamageFromRobots[otherRobot.Value] =
                            values[string.Format("_dmgfromrobots[*][{0}]", otherRobot.Key)];
                        stats.CollisionsWithRobots[otherRobot.Value] =
                            values[string.Format("_cldwithrobots[*][{0}]", otherRobot.Key)];
                    }
                    robot.Statistics.Add(stats);
                }
            }
        }