public static async Task <IEnumerable <(int Hour, long Served)> > HourlyServed
     (this IAnalyticStore analyticStore, DateTime from, DateTime to)
 {
     return((await analyticStore.InTimeRange(from, to))
            .GroupBy(x => x.Timestamp.Hour)
            .Select(x => (x.Key, x.LongCount())));
 }
 public static async Task <IEnumerable <(string Url, long Served)> > UrlServed
     (this IAnalyticStore analyticStore, DateTime from, DateTime to)
 {
     return((await analyticStore.InTimeRange(from, to))
            .GroupBy(x => x.Path)
            .Select(x => (x.Key, x.LongCount())));
 }
 public static async Task <IEnumerable <(string Country, long Served)> > ServedByCountry
     (this IAnalyticStore analyticStore, DateTime from, DateTime to)
 {
     return((await analyticStore.InTimeRange(from, to))
            .GroupBy(x => x.CountryCode)
            .Select(x => (Country.FromCode(x.Key).CommonName, x.LongCount())));
 }
예제 #4
0
        public static async Task TestCount(IAnalyticStore store)
        {
            foreach (var request in MatteoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            Assert.Equal(MatteoRequests.Length, await store.CountAsync(DateTime.MinValue, DateTime.MaxValue));
        }
예제 #5
0
        public static async Task TestIpAddress(IAnalyticStore store)
        {
            foreach (var request in MatteoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            var ips = (await store.IpAddressesAsync(DateTime.Today));

            Assert.Single(ips);
            Assert.Single((await store.IpAddressesAsync(DateTime.MinValue, DateTime.MaxValue)));
        }
예제 #6
0
        public static async Task TestGeoResolve(IAnalyticStore store)
        {
            await store.StoreGeoIpRangeAsync(IPAddress.Parse("86.44.0.0"), IPAddress.Parse("86.49.47.255"),
                                             CountryCode.Cz);

            await store.StoreGeoIpRangeAsync(IPAddress.Parse("85.44.0.0"), IPAddress.Parse("86.43.255.255"),
                                             CountryCode.Sk);

            await store.StoreGeoIpRangeAsync(IPAddress.Parse("86.49.48.0"), IPAddress.Parse("86.86.255.255"),
                                             CountryCode.It);

            Assert.Equal(CountryCode.Cz, await store.ResolveCountryCodeAsync(IPAddress.Parse("86.49.47.89")));
        }
예제 #7
0
        public static async Task TestRequestByIdentity(IAnalyticStore store)
        {
            foreach (var request in MatteoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            foreach (var request in FrancoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            Assert.Equal(MatteoRequests.Length, (await store.RequestByIdentityAsync("MATTEO")).Count());
            Assert.Equal(FrancoRequests.Length, (await store.RequestByIdentityAsync("FRANCO")).Count());
        }
예제 #8
0
        public static async Task TestCountIdentities(IAnalyticStore store)
        {
            foreach (var request in MatteoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            Assert.Equal(1, await store.CountUniqueIndentitiesAsync(DateTime.Today));
            Assert.Equal(1, await store.CountUniqueIndentitiesAsync(DateTime.MinValue, DateTime.MaxValue));

            foreach (var request in FrancoRequests)
            {
                await store.StoreWebRequestAsync(request);
            }

            Assert.Equal(2, await store.CountUniqueIndentitiesAsync(DateTime.Today));
            Assert.Equal(2, await store.CountUniqueIndentitiesAsync(DateTime.MinValue, DateTime.MaxValue));
        }
        private static async Task LoadDemoData(IAnalyticStore analyticStore)
        {
            var countries = Enum.GetValues(typeof(CountryCode)).Cast <CountryCode>().ToArray();
            var methods   = new[] { "GET", "POST", "DELETE", "CHICKEN" };
            var urls      = new[] { "/", "/home", "/contact", "/about" };
            var rand      = new Random();

            for (int i = 0; i < 250; i++)
            {
                await analyticStore.StoreWebRequestAsync(new WebRequest
                {
                    CountryCode     = countries[rand.Next(countries.Length - 1)],
                    Identity        = Guid.NewGuid().ToString("N"),
                    IsWebSocket     = rand.Next() % 2 == 0,
                    Method          = methods[rand.Next(methods.Length - 1)],
                    Path            = urls[rand.Next(urls.Length - 1)],
                    Referer         = "",
                    RemoteIpAddress = IPAddress.Loopback,
                    Timestamp       = DateTime.Now - TimeSpan.FromSeconds(rand.Next(3600 * 24 * 12)),
                    UserAgent       = "Demo data"
                });
            }
        }
예제 #10
0
 public static async Task TestStorage(IAnalyticStore store)
 {
     await store.StoreWebRequestAsync(MatteoRequests[0]);
 }
예제 #11
0
        public static async Task <IEnumerable <(string Country, long Served)> > ServedByCountry(this IAnalyticStore analyticStore, DateTime from, DateTime to)
        {
            if (analyticStore == null)
            {
                throw new ArgumentNullException(nameof(analyticStore));
            }

            var r = (await analyticStore.InTimeRange(from, to)
                     .ConfigureAwait(true)).ToArray();

            return(r.Length > 0
                ? r.GroupBy(x => x.CountryCode)
                   .Select(x => (Country.FromCode(x.Key).CommonName, x.LongCount()))
                : Array.Empty <(string Country, long Served)>());
        }
 public IpInfoAnalyticStore(IAnalyticStore store, string token = "")
 {
     this.token = token;
     this.store = store;
 }
예제 #13
0
        public static FluidAnalyticBuilder UseServerSideAnalytics(this IApplicationBuilder app, IAnalyticStore repository)
        {
            var builder = new FluidAnalyticBuilder(repository);

            app.Use(builder.Run);
            return(builder);
        }
        public static async Task <double> DailyAverage(this IAnalyticStore analyticStore, DateTime from, DateTime to)
        {
            var seq = (await DailyServed(analyticStore, from, to)).ToArray();

            return(seq.Length > 0 ? seq.Average(x => x.Served) : 0);
        }
        public static async Task <IEnumerable <(DateTime Day, long Served)> > DailyServed(this IAnalyticStore analyticStore, DateTime from, DateTime to)
        {
            var r = (await analyticStore.InTimeRange(from, to)).ToArray();

            return(r.Length > 0
                ? r.GroupBy(x => x.Timestamp.Date)
                   .Select(x => (x.Key, x.LongCount()))
                : new (DateTime Day, long Served)[0]);
 public static IAnalyticStore UseIpApiFailOver(this IAnalyticStore store)
 {
     return(new IpApiAnalyticStore(store));
 }
예제 #17
0
 public IpApiAnalyticStore(IAnalyticStore store)
 {
     _store = store;
 }
예제 #18
0
 public HomeController(IAnalyticStore analyticStore)
 {
     _analyticStore = analyticStore;
 }
예제 #19
0
 internal FluidAnalyticBuilder(IAnalyticStore store)
 {
     _store = store;
 }
예제 #20
0
 public IpApiAnalyticStore(IAnalyticStore store)
 {
     this.store = store;
 }
 public static async Task <double> DailyAverage(this IAnalyticStore analyticStore,
                                                DateTime from, DateTime to)
 {
     return((await DailyServed(analyticStore, from, to)).Average(x => x.Served));
 }
예제 #22
0
        public static async Task <IEnumerable <(int Hour, long Served)> > HourlyServed(this IAnalyticStore analyticStore, DateTime from, DateTime to)
        {
            if (analyticStore == null)
            {
                throw new ArgumentNullException(nameof(analyticStore));
            }

            var r = (await analyticStore.InTimeRange(from, to).ConfigureAwait(true)).ToArray();

            return(r.Length > 0
                ? r.GroupBy(x => x.Timestamp.Hour)
                   .Select(x => (x.Key, x.LongCount()))
                : Array.Empty <(int Hour, long Served)>());
        }
 public IpInfoAnalyticStore(IAnalyticStore store, string token = "")
 {
     _token = token;
     _store = store;
 }
예제 #24
0
 public IpStackAnalyticStore(IAnalyticStore store, string token)
 {
     this.accessKey = token;
     this.store     = store;
 }
 public static IAnalyticStore UseIpStackFailOver(this IAnalyticStore store, string key)
 {
     return(new IpStackAnalyticStore(store, key));
 }
 public IpStackAnalyticStore(IAnalyticStore store, string token)
 {
     _accessKey = token;
     _store     = store;
 }
예제 #27
0
 public StatController(IAnalyticStore store)
 {
     _store = store;
 }