public async Task AddUserBannedEventAsync(GuildBanAddEventArgs args) { UserEvent userEvent = new UserEvent() { UserId = args.Member.Id, Username = args.Member.Username, Nickname = args.Member.Nickname, Discriminator = args.Member.Discriminator, AvatarId = args.Member.AvatarHash.ToString(), AccountCreated = args.Member.CreationTimestamp.UtcDateTime, Bot = args.Member.IsBot, Event = Event.Banned, Timestamp = DateTime.Now, }; try { using IServiceScope scope = this.scopeFactory.CreateScope(); using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>(); db.UserEvents.Add(userEvent); await db.SaveChangesAsync(); } catch (Exception e) { Log.Error(e, $"Failed to add new user event {userEvent.Username}#{userEvent.Discriminator} | {userEvent.UserId}"); return; } }
private async Task OnSlashCommandExecuted(SlashCommandsExtension sender, DSharpPlus.SlashCommands.EventArgs.SlashCommandExecutedEventArgs args) { string logMessage = $"`{args.Context.User.Username}` ran `/{args.Context.CommandName}` in **[{(args.Context.Guild != null ? $"{args.Context.Guild.Name} - {args.Context.Channel.Name}" : "DM")}]**"; this.bloonLog.Information(LogConsole.Commands, CommandEmojis.Run, logMessage); Log.Debug(logMessage); using IServiceScope scope = this.scopeFactory.CreateScope(); using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>(); db.Commands.Add(new Analytics.Commands() { Command = args.Context.CommandName, Guild = args.Context.Guild != null ? args.Context.Guild.Id : ulong.MinValue, Channel = args.Context.Channel != null ? args.Context.Channel.Id : ulong.MinValue, UserId = args.Context.User.Id, Link = args.Context.Guild != null ? $"https://discord.com/channels/{args.Context.Guild.Id}/{args.Context.Channel.Id}/{args.Context.User.Id}" : "DM", Timestamp = DateTime.Now, }); await db.SaveChangesAsync(); return; }
public void Clear() { var ctx = new AnalyticsContext(); ctx.BpmSolution.RemoveRange(ctx.BpmSolution.ToArray()); ctx.SaveChanges(); }
private async Task BloonsideEmbed(DiscordClient dClient, GuildMemberAddEventArgs args) { DiscordChannel sbgChannel = await this.dClient.GetChannelAsync(SBGChannels.Bloonside); // If guild isn't SBG, just ignore this user join event. if (args.Guild.Id != Variables.Guilds.SBG) { return; } DiscordEmbedBuilder embed = this.BuildEmbed(args.Member); using IServiceScope scope = this.provider.CreateScope(); using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>(); List <UserEvent> userEvents = await db.UserEvents .Where(u => u.UserId == args.Member.Id) .OrderByDescending(u => u.Timestamp) .Take(10) .ToListAsync(); embed.AddField( "Events", string.Join( "\n", userEvents.Select(u => $"{DiscordEmoji.FromGuildEmote(this.dClient, this.eventEmotes[u.Event])} {u.Event.ToString().PadRight(8, '\u2000')} - {u.Timestamp.ToString("ddd, dd MMM yyyy, hh:mm:ss tt", CultureInfo.InvariantCulture)}"))); // Post embed to #bloonside await sbgChannel.SendMessageAsync(embed); }
private void InsertSolutions(IEnumerable <BpmSolution> s) { var ctx = new AnalyticsContext(); ctx.BpmSolution.AddRange(s); ctx.SaveChangesAsync(); }
public List <double> AvgFitnessValidOnly() { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.Where(x => x.ValidGenome) .GroupBy(x => x.Generation) .Select(y => y.Average(z => z.Fitness)) .ToList()); }
public BpmSolution BestSolution() { var ctx = new AnalyticsContext(); var s = ctx.BpmSolution .OrderByDescending(x => x.Fitness) .ToList() .Where(x => x.ValidGenome) .DefaultIfEmpty(null) .First(); return(s); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder().AddJsonFile("gasettings.json"); var config = builder.Build(); var viewId = Convert.ToUInt32(config["profile:view_id"]); var serviceAccountEmail = config["profile:service_account_email"]; var applicationName = config["profile:application_name"]; var keyFilePath = Directory.GetCurrentDirectory() + "\\" + config["profile:key_file_name"]; var profile = new AnalyticsProfile(serviceAccountEmail, keyFilePath, applicationName); var googleAnalytics = new AnalyticsContext(profile); var records = googleAnalytics.Records // View Id .Where(x => x.ViewId == viewId) // Start Date, End Date .Where(x => x.RecordDate == DateTime.Today.AddDays(-1)) // Include Dimensions .Include(x => x.Source) .Include(x => x.Medium) // Include Metrics .Include(x => x.Pageviews) .Include(x => x.Sessions) .Include(x => x.SessionDuration) // Filters .Where(x => x.Country == "India" && x.Medium == new Regex("organic")) .Where(x => x.Source.Contains("a") && !x.Source.Contains("x")) .Where(x => x.SessionDuration > TimeSpan.FromMinutes(1)) // Sort .OrderByDescending(x => x.SessionDuration) .ThenBy(x => x.Source) // Skip 1 record .Skip(1) // Take only 5 records .Take(5); foreach (var record in records) { Console.WriteLine(record.ToStringRepresentation()); } Task.Run(async() => { var list = await records.ToListAsync(); foreach (var item in list) { Console.WriteLine(item.ToStringRepresentation()); } }).Wait(); Console.ReadLine(); }
public List <double> ValidGenomes() { var ctx = new AnalyticsContext(); var groups = ctx.BpmSolution.GroupBy(x => x.Generation); var valid = groups.Select(y => y.Count(z => z.ValidGenome)).ToList(); var all = groups.Select(y => y.Count(z => true)).ToList(); var percentage = new List <double>(); for (var i = 0; i < Math.Min(valid.Count, all.Count); i++) { percentage.Add((double)valid[i] / all[i]); } return(percentage); }
public List <BpmSolution> GetTopSolutions(int count) { if (count < 1) { return new List <BpmSolution> { BestSolution() } } ; var ctx = new AnalyticsContext(); var list = ctx.BpmSolution .OrderByDescending(x => x.Fitness) .ToList() .Where(x => x.ValidGenome) .DistinctBy(x => x.Process) .Take(count) .DefaultIfEmpty(null) .ToList(); return(list); }
public List <UserEvent> QueryEventReportAsync(ulong discordId) { List <UserEvent> dbUserEvents = new List <UserEvent>(); using IServiceScope scope = this.scopeFactory.CreateScope(); using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>(); try { DbSet <UserEvent> dbQuery = db.UserEvents; foreach (UserEvent events in dbQuery.Where(x => x.UserId == discordId)) { dbUserEvents.Add(events); } return(dbUserEvents); } catch (Exception e) { Log.Error(e, "Failed to query all user events!"); } return(dbUserEvents); }
public SensorRepository(AnalyticsContext context, AnalyticsService serv) { _context = context; _service = serv; }
public AnalyticsController(AnalyticsContext context) { _context = context; }
public MuteUser(AnalyticsContext db) { this.db = db; }
public KickUser(AnalyticsContext db) { this.db = db; }
public BanUser(AnalyticsContext db) { this.db = db; }
protected BaseRepository() { _context = new AnalyticsContext(); }
public IEnumerable <BpmSolution> GetAll() { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.Select(x => x).ToList()); }
public int GetNumberOfEvolvedGenerations() { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.Select(x => x.Generation).Distinct().Count()); }
public List <double> MaxRuntime() { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.GroupBy(x => x.Generation).Select(y => y.Max(z => z.EvaluationTime)).ToList()); }
public List <double> MaxFitness() { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.GroupBy(x => x.Generation).Select(y => y.Max(z => z.Fitness)).ToList()); }
/// <summary> /// </summary> /// <param name="id"></param> /// <returns></returns> public Solution Get(Guid id) { var ctx = new AnalyticsContext(); return(ctx.BpmSolution.FirstOrDefault(x => x.Id.Equals(id.ToString()))); }
public IndexModel(ILogger <IndexModel> logger, AnalyticsContext db) { _logger = logger; _db = db; }