Пример #1
0
        /*static void LoadAndDisplayRun(GraphForm Frm, string InputName, string RunName, Color Clr) {
         *      IEnumerable<CSVEntry> PowerRunNew = LoadRun(InputName, false);
         *      Frm.LoadGraph(PowerRunNew, Clr, RunName);
         * }*/

        static IEnumerable <CSVEntry> LoadRun(string InputName, bool UseNewMethod)
        {
            string[]        InputLines    = File.ReadAllLines(InputName);
            List <CSVEntry> ParsedEntries = new List <CSVEntry>();

            for (int i = 0; i < InputLines.Length; i++)
            {
                if (i == 0)
                {
                    string[] Names = InputLines[i].Split(new[] { ',' }).Select(StripQuotes).ToArray();

                    for (int j = 0; j < Names.Length; j++)
                    {
                        switch (Names[j])
                        {
                        case "Fuel/Air commanded equivalence ratio ()":
                            AFR_Idx = j;
                            break;

                        case "Throttle position (%)":
                            TPS_Idx = j;
                            break;

                        case "Engine RPM (rpm)":
                            RPM_Idx = j;
                            break;

                        case "Vehicle speed (km/h)":
                            SPD_Idx = j;
                            break;

                        case "Intake manifold absolute pressure (kPa)":
                            MAP_Idx = j;
                            break;
                        }
                    }
                }
                else
                {
                    CSVEntry Ent = new CSVEntry(InputLines[i]);

                    if (Ent.IsValid())
                    {
                        ParsedEntries.Add(Ent);
                    }
                }
            }

            ParsedEntries.OrderBy(E => E.Time);
            float MinTime     = ParsedEntries.Min(E => E.DeviceTime);
            float MaxThrottle = ParsedEntries.Max(E => E.TPS);

            while (RunFixup(ParsedEntries))
            {
                ;
            }

            //float FROM = 140.42f;
            //float TO = 152.46f;

            float FROM = 0;
            float TO   = 0;

            for (int i = 0; i < ParsedEntries.Count; i++)
            {
                ParsedEntries[i].TPS = ParsedEntries[i].TPS * (100.0f / MaxThrottle);

                if (!ParsedEntries[i].FixupTime(MinTime, FROM, TO))
                {
                    ParsedEntries[i].MarkInvalid();
                }

                if (i >= 1)
                {
                    if (ParsedEntries[i].RPM == ParsedEntries[i - 1].RPM)
                    {
                        ParsedEntries[i].MarkInvalid();
                    }
                }
            }

            for (int i = ParsedEntries.Count - 2; i >= 0; i--)
            {
                if (ParsedEntries[i].TPS >= 99 && ParsedEntries[i + 1].TPS < 99)
                {
                    ParsedEntries[i].TPS += 10;
                }
            }

            ParsedEntries = new List <CSVEntry>(ParsedEntries.Where(E => E.IsValid()));


            for (int i = 1; i < ParsedEntries.Count; i++)
            {
                float CurRPM  = ParsedEntries[i].RPM;
                float PrevRPM = ParsedEntries[i - 1].RPM;

                float CurTime  = ParsedEntries[i].DeviceTime;
                float PrevTime = ParsedEntries[i - 1].DeviceTime;

                float CurSpeed  = ParsedEntries[i].SPD;
                float PrevSpeed = ParsedEntries[i - 1].SPD;

                float HP = 0;

                if (UseNewMethod)
                {
                    HP = Calculator.Calculate(CurSpeed, PrevSpeed, CurTime, PrevTime);
                }
                else
                {
                    HP = Calculator.Calculate(2, CurRPM, PrevRPM, CurTime, PrevTime, out CurSpeed);
                }

                ParsedEntries[i].HP  = HP;
                ParsedEntries[i].SPD = CurSpeed;
            }

            if (File.Exists("out.csv"))
            {
                File.Delete("out.csv");
            }

            string OutText = CSVEntry.GetFormat() + "\n" + string.Join("\n", ParsedEntries.Select(E => E.ToString()));

            File.WriteAllBytes("out.csv", Encoding.UTF8.GetBytes(OutText));

            Console.WriteLine(CSVEntry.GetFormat());
            IEnumerable <CSVEntry> PowerRun = ParsedEntries.Where(E => E.TPS >= 99 && E.TPS <= 101);

            Console.WriteLine(string.Join("\n", PowerRun.Select(E => string.Format("{0} => {1} whp", E.ToString(), E.HP)).ToArray()));

            CSVEntry MaxHP = PowerRun.OrderByDescending(Run => Run.HP).First();

            Console.WriteLine("Max {0} whp @ {1} RPM", MaxHP.HP, MaxHP.RPM);

            return(PowerRun);
        }