public FetchFreq(ITaskHelper taskHelper, IElexonDownloader downloader, IDirectory dir, ITime time)
 {
     _taskHelper = taskHelper;
     _time       = time;
     _scheduler  = new Scheduler(time, taskHelper);
     _freq       = new Freq(taskHelper, downloader);
     _reader     = new Freq.Reader(taskHelper, dir);
     _writer     = new Freq.Writer(taskHelper, dir);
 }
Exemple #2
0
        static async Task <int> ShowFreq(ShowFreqOptions opts)
        {
            var taskHelper = SystemTaskHelper.Instance;
            var dir        = new SystemDirectory(taskHelper, opts.DataDirectory);
            var reader     = new Freq.Reader(taskHelper, dir);
            var count      = opts.Count;
            var totalCount = (int)await reader.CountAsync();

            Console.WriteLine($"Grid Frequency count: {totalCount}");
            Console.WriteLine($"Latest {count} data readings:");
            var data = await reader.ReadAsync(totalCount - count, totalCount);

            data.ForEach(r => Console.WriteLine(r));
            return(0);
        }
Exemple #3
0
        public void Fetch()
        {
            TimeRunner.Run(async(time, th) =>
            {
                var downloader = new FakeElexonDownloader();
                var dir        = new FakeDirectory(th);
                var fetcher    = new FetchFreq(th, downloader, dir, time);

                var cts     = new CancellationTokenSource();
                Task unused = th.Run(async() =>
                {
                    await th.Delay(NodaTime.Duration.FromMinutes(3)).ConfigureAwait(th);
                    cts.Cancel();
                });
                await fetcher.Start(false, cts.Token).ConfigureAwaitHideCancel(th);

                var reader = new Freq.Reader(th, dir);
                Assert.Equal((60 + 2) * 4, await reader.CountAsync().ConfigureAwait(th));
                var data = await(await reader.ReadAsync().ConfigureAwait(th)).ToList().ConfigureAwait(th);
                Assert.Equal((60 + 2) * 4, data.Count);
                Assert.Equal(new Freq.Data(NodaTime.Instant.FromUtc(2017, 8, 2, 11, 0, 15), Frequency.FromHertz(49.910)), data.First());
                Assert.Equal(new Freq.Data(NodaTime.Instant.FromUtc(2017, 8, 2, 12, 2, 0), Frequency.FromHertz(50.040)), data.Last());
            }, startInstant: NodaTime.Instant.FromUtc(2017, 8, 2, 12, 0));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddResponseCompression(options =>
            {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });

            services.AddSingleton <ITime>(SystemTime.Instance);
            services.AddSingleton <ITaskHelper>(SystemTaskHelper.Instance);

            services.AddSingleton <Db <FuelInstHhCur.Data> >(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var options    = svcs.GetRequiredService <CmdLineOptions>();
                var dir        = new SystemDirectory(taskHelper, options.FuelInstHhCurDataDirectory);
                var reader     = new FuelInstHhCur.Reader(taskHelper, dir);
                return(new Db <FuelInstHhCur.Data>(taskHelper, reader));
            });
            services.AddSingleton <Db <Freq.Data> >(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var options    = svcs.GetRequiredService <CmdLineOptions>();
                var dir        = new SystemDirectory(taskHelper, options.FreqDataDirectory);
                var reader     = new Freq.Reader(taskHelper, dir);
                return(new Db <Freq.Data>(taskHelper, reader));
            });
            services.AddSingleton <InstantaneousFlow.Reader>(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var options    = svcs.GetRequiredService <CmdLineOptions>();
                var dir        = new SystemDirectory(taskHelper, options.GasFlowDataDirectory);
                return(new InstantaneousFlow.Reader(taskHelper, dir));
            });
            services.AddSingleton <Db <InstantaneousFlow.Data> >(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var reader     = svcs.GetRequiredService <InstantaneousFlow.Reader>();
                return(new Db <InstantaneousFlow.Data>(taskHelper, reader));
            });
            services.AddSingleton <Db <B1610.Data> >(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var options    = svcs.GetRequiredService <CmdLineOptions>();
                var dir        = new SystemDirectory(taskHelper, options.B1610DataDirectory);
                var reader     = new B1610.Reader(taskHelper, dir);
                return(new Db <B1610.Data>(taskHelper, reader));
            });
            services.AddSingleton <Db <PhyBmData.FpnData> >(svcs =>
            {
                var taskHelper = svcs.GetRequiredService <ITaskHelper>();
                var options    = svcs.GetRequiredService <CmdLineOptions>();
                var dir        = new SystemDirectory(taskHelper, options.FpnDataDirectory);
                var reader     = new PhyBmData.FpnReader(taskHelper, dir);
                return(new Db <PhyBmData.FpnData>(taskHelper, reader, pollInterval: Duration.FromMinutes(5)));
            });

            services.AddSingleton <PostBag>();
        }