Esempio n. 1
0
        public void Store(TelemetryLogger logger, LogFileWriter writer)
        {
            var suggestedPath = GetPath(logger);

            // Any directories that do not exist yet?
            var directoryParts  = suggestedPath.Split(new [] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var cumalativeParts = new string[directoryParts.Length];
            var i = 0;

            foreach (var part in directoryParts)
            {
                if (i + 1 == directoryParts.Length)
                {
                    break;
                }
                if (i > 0)
                {
                    cumalativeParts[i] = cumalativeParts[i - 1] + "/" + part;
                }
                else
                {
                    cumalativeParts[i] = part;
                }

                if (Directory.Exists(cumalativeParts[i]) == false)
                {
                    Directory.CreateDirectory(cumalativeParts[i]);
                }
                i++;
            }

            // TODO: get configuration file Telemetry directory
            File.Move("./tmp.zip", suggestedPath);
        }
Esempio n. 2
0
 public bool QualifiesForStorage(TelemetryLogger logger)
 {
     if (logger.TimeLine.Count() == 0)
     {
         return(false);
     }
     return((logger.TimeLine.Max() - logger.TimeLine.Min()) >= 10000);
 }
        public void QualifyTest()
        {
            var dummyDataSource = new MockDataSource();

            var archive = new TelemetryArchive();
            var loggerFromZero = new TelemetryLogger("test", new TelemetryLoggerConfiguration(true, true, true, true));
            loggerFromZero.SetDatasource(dummyDataSource);
            GlobalEvents.Fire(new SessionStarted(), true);

            Assert.False(archive.QualifiesForStorage(loggerFromZero));

            loggerFromZero.Update(0);

            Assert.False(archive.QualifiesForStorage(loggerFromZero));

            loggerFromZero.Update(1000);

            Assert.False(archive.QualifiesForStorage(loggerFromZero));

            loggerFromZero.Update(5000);

            Assert.False(archive.QualifiesForStorage(loggerFromZero));

            loggerFromZero.Update(10000);

            Assert.True(archive.QualifiesForStorage(loggerFromZero));

            loggerFromZero.Close();

            var loggerFromElse = new TelemetryLogger("test", new TelemetryLoggerConfiguration(true, true, true, true));
            loggerFromElse.SetDatasource(dummyDataSource);
            GlobalEvents.Fire(new SessionStarted(), true);

            Assert.False(archive.QualifiesForStorage(loggerFromElse));

            loggerFromElse.Update(10000);

            Assert.False(archive.QualifiesForStorage(loggerFromElse));

            loggerFromElse.Update(13000);

            Assert.False(archive.QualifiesForStorage(loggerFromElse));

            loggerFromElse.Update(0);

            Assert.False(archive.QualifiesForStorage(loggerFromElse));

            loggerFromElse.Update(20000);

            Assert.True(archive.QualifiesForStorage(loggerFromElse));

            loggerFromElse.Update(24*3600*1000);

            Assert.True(archive.QualifiesForStorage(loggerFromElse));
        }
Esempio n. 4
0
        public string GetPath(TelemetryLogger logger)
        {
            var track = (logger.Track == null)?"Track" : logger.Track.Name;
            var session = (logger.Session == null)?"Session" : logger.Session.Type.ToString();
            var simulator = logger.Simulator;
            var date = DateTime.Now.Year.ToString("0000") + "-" +
                       DateTime.Now.Month.ToString("00") + "-" +
                       DateTime.Now.Day.ToString("00") + "-" +
                       DateTime.Now.Hour.ToString("00") + "-" +
                       DateTime.Now.Minute.ToString("00");

            var suggestedPath = "Logs/" + simulator + "/" + track + "/" + date + " - " + session +".zip";

            Path.GetInvalidPathChars().ToList().ForEach(x => suggestedPath = suggestedPath.Replace(x, '_'));

            return suggestedPath;
        }
Esempio n. 5
0
        public string GetPath(TelemetryLogger logger)
        {
            var track     = (logger.Track == null)?"Track" : logger.Track.Name;
            var session   = (logger.Session == null)?"Session" : logger.Session.Type.ToString();
            var simulator = logger.Simulator;
            var date      = DateTime.Now.Year.ToString("0000") + "-" +
                            DateTime.Now.Month.ToString("00") + "-" +
                            DateTime.Now.Day.ToString("00") + "-" +
                            DateTime.Now.Hour.ToString("00") + "-" +
                            DateTime.Now.Minute.ToString("00");

            var suggestedPath = "Logs/" + simulator + "/" + track + "/" + date + " - " + session + ".zip";

            Path.GetInvalidPathChars().ToList().ForEach(x => suggestedPath = suggestedPath.Replace(x, '_'));

            return(suggestedPath);
        }
        public void StoreLogFile()
        {
            var dummyDataSource = new MockDataSource();

            var archive =  new TelemetryArchive();
            var loggerFromZero = new TelemetryLogger("test", new TelemetryLoggerConfiguration(true, true, true, true));
            loggerFromZero.SetDatasource(dummyDataSource);
            loggerFromZero.SetAnnotater(archive);
            var logWriter = new LogFileWriter("test.zip","TelemetryArchiveTestsStoreLogFile");

            GlobalEvents.Fire(new SessionStarted(), true);

            loggerFromZero.Update(0);
            loggerFromZero.Update(10000);
            loggerFromZero.Update(20000);

            GlobalEvents.Fire(new SessionStopped(), true);

            Thread.Sleep(5000);
        }
Esempio n. 7
0
        public void Store(TelemetryLogger logger, LogFileWriter writer)
        {
            var suggestedPath = GetPath(logger);

            // Any directories that do not exist yet?
            var directoryParts = suggestedPath.Split(new [] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var cumalativeParts = new string[directoryParts.Length];
            var i = 0;
            foreach(var part in directoryParts)
            {
                if (i + 1 == directoryParts.Length) break;
                if (i > 0)
                    cumalativeParts[i] = cumalativeParts[i - 1] + "/" + part;
                else
                    cumalativeParts[i] = part;

                if (Directory.Exists(cumalativeParts[i]) == false)
                    Directory.CreateDirectory(cumalativeParts[i]);
                i++;
            }

            // TODO: get configuration file Telemetry directory
            File.Move("./tmp.zip", suggestedPath);
        }
Esempio n. 8
0
 public bool QualifiesForStorage(TelemetryLogger logger)
 {
     if (logger.TimeLine.Count() == 0) return false;
     return (logger.TimeLine.Max() - logger.TimeLine.Min()) >= 10000;
 }
Esempio n. 9
0
        public void RecordTestData()
        {
            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] {fakeDriver});

            TelemetryLogger logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            logger.SetAnnotater( new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for(int i = 0 ; i  <1024;i++)
                logger.Update(i*25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            ZipStorer checkFile = ZipStorer.Open("tmp.zip", FileAccess.Read);

            var files = checkFile.ReadCentralDir();
            Assert.AreEqual(3, files.Count);
            Assert.AreEqual(1024 * 2 * 12 + 2 * 8, files.Where(x => x.FilenameInZip.Contains("Data.bin")).FirstOrDefault().FileSize);
            Assert.AreEqual(1024*8, files.Where(x => x.FilenameInZip.Contains("Time.bin")).FirstOrDefault().FileSize);
        }
Esempio n. 10
0
        public void Record()
        {
            if (Process.GetProcessesByName("rfactor").Length == 0) Assert.Ignore();
            var rFactorProcess = Process.GetProcessesByName("rfactor")[0];

            IntPtr alloc = Marshal.AllocHGlobal(512 * 1024 * 1024);

            using (var host = new Plugins())
            {
                host.PluginDirectory = TestConstants.SimulatorsBinFolder;

                host.Load();

                // Simulators are now loaded

                var testPlugin = host.Simulators.Where(x => x.Name == "Test simulator").FirstOrDefault();
                testPlugin.SimulatorStart(rFactorProcess);

                var telSource = new Domain.Aggregates.Telemetry(testPlugin.TelemetryProvider, rFactorProcess);
                var telLogger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, false, true, false));
                telLogger.SetAnnotater(new TelemetryArchive());
                telSource.SetLogger(telLogger);

                Thread.Sleep(15000);

                telLogger.Close();
                telSource = null;
            }

            Marshal.FreeHGlobal(alloc);
        }
Esempio n. 11
0
 public void SetLogger(TelemetryLogger logger)
 {
     Logger = logger;
     Logger.SetDatasource(Memory);
 }
Esempio n. 12
0
        public void LapTests()
        {
            var lapsRecorded = new List<Lap>();

            GlobalEvents.Hook<TelemetryLapComplete>(lap => lapsRecorded.Add(lap.Lap),true);

            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldFunc<float>("Laps", (pool) =>
                                                                {
                                                                    if(index <= 100)
                                                                        return 0;
                                                                    if (index > 100 && index <= 225)
                                                                        return 1;
                                                                    if (index > 225 && index <= 325)
                                                                        return 2;
                                                                    if (index > 325 && index <= 500)
                                                                        return 3;
                                                                    if (index > 500 && index <= 575)
                                                                        return 4;
                                                                    if (index > 575 && index <= 1024)
                                                                        return 5;

                                                                        return -1;
                                                                }, true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] { fakeDriver });

            var logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            //logger.SetAnnotater(new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for (int i = 0; i < 1024; i++)
                logger.Update(i * 25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            Assert.AreEqual(6, lapsRecorded.Count);
            Assert.AreEqual(0, lapsRecorded[0].LapNumber);
            Assert.AreEqual(1, lapsRecorded[1].LapNumber);
            Assert.AreEqual(2, lapsRecorded[2].LapNumber);
            Assert.AreEqual(3, lapsRecorded[3].LapNumber);
            Assert.AreEqual(4, lapsRecorded[4].LapNumber);
            Assert.AreEqual(5, lapsRecorded[5].LapNumber);

            Assert.AreEqual(100, lapsRecorded[0].Total);
            Assert.AreEqual(125, lapsRecorded[1].Total);
            Assert.AreEqual(100, lapsRecorded[2].Total);
            Assert.AreEqual(175, lapsRecorded[3].Total);
            Assert.AreEqual(75, lapsRecorded[4].Total);
            Assert.AreEqual(-1, lapsRecorded[5].Total);
        }