What is the appropriate SQL statement/s to produce a stacked bar chart for multiple random variable distributions?


The Objective

Graph the difference between the probability distributions of sets of random variables that come from a number of different sources using a stacked bar chart (or another type of graph suited for such visualization).

The Problem

I’m not sure of the right combination of SQL SELECT statement(s)/condition(s) to present the data to the graphing tool in the right way to achieve the objective above.

The Method

Summary

Feed the source data stored in Google Cloud Platform (GCP)’s BigQuery into Google Data Studio and use a stacked bar graph to visualize the numerous probability distributions.

The Source Data

I’m dealing with simple binary outcomes, either a heads or tails. One trial (== one second) per source yields between 0 to 200 how many heads (1s) were counted.

The schema of the data we have stored in BigQuery is as follows:

time      | source1 | source 2 | ... sourceN --------------------------------------------- 09:00:00  | 99      | 110      | 95         | 09:00:01  | 101     | 115      | 107        | 09:00:02  | 99      | 91       | 97         | 

For a Single Source

The following works fine if I’m trying to graph the results from just a single source. And as the law of probability would say, the graphed distribution is moreorless in fit with the expected bell curve.

SELECT   source1 AS src1,   COUNT(source1) AS count FROM   `rnddata` WHERE   recorded_at >= "2021-03-11 08:45:00" AND   recorded_at < "2021-03-11 09:45:00" GROUP BY src1 ORDER BY src1 
src1 | count 75   | 1 77   | 2 80   | 2 81   | 5 82   | 6 83   | 20 84   | 10 85   | 14 86   | 31 87   | 33 88   | 48 89   | 74 90   | 74 91   | 89 92   | 107 93   | 133 94   | 135 95   | 168 96   | 160 97   | 192 98   | 190 99   | 195 100  | 189 101  | 197 102  | 191 103  | 188 104  | 180 105  | 201 106  | 130 107  | 128 108  | 107 109  | 96 110  | 64 111  | 65 112  | 45 113  | 40 114  | 19 115  | 22 116  | 18 117  | 9 118  | 8 119  | 6 120  | 3 121  | 4 125  | 1 

For Multiple Sources

I’m thinking that if I can have multiple dimensions (src1, src2… srcN) with a single count column for the metric, then I will be able to graph the dimensions as stacked bars on the X axis and have the count metric set to the X axis.

I imagine the output could be something like this:

src1 | src2 | count 75   | null | 1 77   | 77   | 2 80   | 00   | 2 null | 80   | 5 82   | 82   | 6 83   | null | 20 83   | 11   | null 84   | 84   | 10 

I did a bit of research and experimenting with UNIONS and JOINS and INTERSECTS but couldn’t quiet get the above output. Any advice on how to form such an SQL statement to do that, or offer a better presentation (schema) of the data for the graphing purposes, would be greatly appreciated.

Whenevent how to use Mod multiple times

I need to use Whenevent inside NDSolve. The event is formed by Mod[t,ST1] && !Mod[t, ST2]. I’ve already read the documentation and previous questions about how Whenevent manages the event trigger.
What I need is that the action happens when Mod[t, ST1] is True but not when Mod[t, ST2] is True. Here is a simple code to represent the issue:

eqTime = {time'[t] == 1, time[0] == 0}; update = WhenEvent[Mod[t, 0.1] && !Mod[t,0.2], { a[t] -> a[t] + 0.1, Sow@a[t]}]; (*Not Working*) ic = a[0] == 0; {sol, data} =    NDSolveValue[{eqTime, update, ic}, a[t], {t, 0, 1},      DiscreteVariables -> a[t]] // Reap;  Plot[sol, {t, t0, 1}] 

The output should be a step function that increases at {0.1, 0.3, 0.5, 0.7, 0.9} which should also be the list stored in data variable.

Plotting multiple dependent variables with DSolve (projectile motion with air resistance)

I wrote a working code that plots what I need using DSolve and parametric plot. Here’s an example of what it plots (and code is at the bottom).

Parametric

However, I want to be able to plot multiple graphs on the same plot with k = 0, 0.01, 0.05… Something like this Intended

I’m not sure where to vary the code without changing it too much so I can do this.

Original Code

(* Constants *) g = 9.8;  (* Differential Equation *) xcomp := x''[t] == -k x'[t]; ycomp := y''[t] == -k y'[t] - g; diff := {xcomp, ycomp}  (* Initial Conditions *) v0 = 600; \[Theta] = 60 Degree; k = 0.05; initcond = {x[0] == 0, x'[0] == v0 Cos[\[Theta]], y[0] == 0,    y'[0] == v0 Sin[\[Theta]]}  (* Solve *) eqn := Append[diff, initcond]; s = DSolve[eqn, {x[t], y[t]}, t] // Simplify y[t_] = y[t] /. s[[1]]  (* Time of Flight *) tof = Solve[y[t] == 0, t]; // Quiet T = t /. tof[[2]]  (* Plot *) ParametricPlot[{x[t], y[t]} /. s, {t, 0, T}, PlotRange -> All] 

Non cluster indexing with combination or on single entity for multiple columns

I am new to db design I also read concepts of non cluster indexing and know about the combined non cluster indexing but in my scenario I am having user table with multiple search on column

table column as follows   userName  fatherName  empId  cardNumber and so on. (above all 4 no one column is PK) 

I am having around 50 millions records over here due to large data search take huge time due to that I am thinking to create indexes in table but these all 4 searches are optional means possible user can fill all four or may be one or two of them but I was confused if I make all four separate index and one for all 4 then it might be creating issue on performance of while entering/inserting the data I created even a single index for all 4 column in combined but while I am searching with only card number then it takes huge time shall I created all four separate indexes would this work in combined search of empId and cardNumber

If I created separated once then what about combined searches If I create combinations then indices are 15 which obviously not a good way for insertion… lot of confusion I have can anyone help me thanks in advance

Table scan instead of index seeks happening when where clause filters across multiple tables in join using OR

We have an application generated query using a view that has two tables joined on a LEFT OUTER join. When filtering by fields from just one table (either table) an index seek happens and it’s reasonably fast. When the where clause includes conditions for fields from both tables using an OR the query plan switches to a table scan and doesn’t utilize any of the indexes.

All four fields that are being filtered on are indexed on their respective tables.

Fast query plan where I filter on 3 fields from one table: https://www.brentozar.com/pastetheplan/?id=Hym_4PRSO

Slow query plan where I filter on four fields…three from one table and one from another table: https://www.brentozar.com/pastetheplan/?id=r1dVNDRHO

Ideally I would like to understand why this is happening and how to nudge the query engine to utilize all the indexes.

ECS multiple materials per mesh (sub-mesh)

In my toy engine I currently have a MeshComponent and a MaterialComponent.

psuedo:

struct MeshComponent {     Ptr<Mesh> Mesh; };  struct MaterialComponent {     Ptr<Texture> DiffuseTexture;     Ptr<Texture> NormalsTexture; }; 

This is fine, for when a single mesh uses a single material.

pseudo:

Entity entity = CreateEntity(); AddComponentToEntity(entity, meshComponent); AddComponentToEntity(entity, materialComponent); 

But now I want to consider the concept of "sub-meshes" (regions of a mesh that are rendered with a different material, but each sub-mesh shares the parent vertex list). I don’t want my Mesh class to know anything about materials, and vice-versa.

What good approaches are there for "joining" multiple MaterialComponent to a single MeshComponent?

I’ve considered having an entity for each sub-mesh, but that seems brittle (not to mention overkill, as I’m only interested in MaterialComponents).

pseudo:

struct MeshComponent {     Ptr<Mesh> Mesh;     std::vector<Entity> SubMeshEntities; // Would need to ensure the indices match those of the sub-meshes }; 

What other approaches are there?

How does a Battle Master’s Parry work with multiple damage types? [duplicate]

Suppose an attack does 5 piercing and 5 poison damage (or 5 slashing and 5 fire, etc.) and the player parries the attack, and rolls to reduce 6 points of damage. Which type of damage is reduced first? Would the answer be different if it were 9 weapon damage and 1 elemental, or vice versa?

Parry:

When another creature damages you with a melee attack, you can use your reaction and expend one superiority die to reduce the damage by the number you roll on your superiority die + your Dexterity modifier.

This matters if, for example, the character has resistance to one of the damage types.

The kindest interpretation (and one that does make some “sense”) would be that it reduces weapon damage first, and if it reduces the weapon damage to zero, none of the additional damage is done either, but that seems over powered. Unless someone can unambiguously point me to rules that support this interpretation, I prefer an interpretation where the total damage reduced is as rolled.

Bane: multiple saves for same creature?

Jed the cleric is standing next to Gideon, his enemy. Jed casts Bane; Gideon succeeds at his saving throw. On Jed’s next turn, he uses the concentrate action to expand the aura and cause all creatures not yet affected to make a save. From Bane:

Once per turn, starting the turn after you cast bane, you can use a single action, which has the concentrate trait, to increase the emanation’s radius by 5 feet and force enemies in the area that weren’t yet affected to attempt another saving throw. Bane can counteract bless.

Gideon already succeeded once. Does he have to make another saving throw?

Download multiple images into a folder from listview

I am displaying multiple images in listview from database and is working fine, the problem am having is when ever I wan’t to download multiple selected images into any folder on my desktop computer, only one image is downloaded not multiple selected images : check my codes Code for retrieving rom database:::

listView1.View = View.LargeIcon;         listView1.LargeImageList = largeImage;         {             connect.Open();             SqlCommand cmd = new SqlCommand("SELECT name,data FROM gallery", connect);             SqlDataReader reader = cmd.ExecuteReader();                 listView1.Items.Clear();                 largeImage.Images.Clear();                  while (reader.Read())                 {                     if (!reader.IsDBNull(1))                     {                         Bitmap bm = BytesToImage((byte[])reader.GetValue(1));                         float source_aspect = bm.Width / (float)bm.Height;                       AddImageToImageList(largeImage, bm, reader[0].ToString(), largeImage.ImageSize.Width, largeImage.ImageSize.Height);                 }                    listView1.AddRow(reader[0].ToString(), reader[0].ToString());                 }             connect.Close();         } 

Code for downloading (My Problem)

    FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog() == DialogResult.OK) {   if (listView1.Items.Count > 0) {     listView1.FocusedItem = listView1.Items[0];     listView1.Items[0].Selected = true;     listView1.Select();     SqlCommand cmd = new SqlCommand("SELECT Name,Data FROM ", connect);     cmd.CommandType = CommandType.Text;     connect.Open();     SqlDataReader sdr = cmd.ExecuteReader();     if (sdr.Read()) {       byte[] bytes = (byte[]) sdr["Data"];       string fileName = sdr["Name"].ToString();       string path = Path.Combine(folderBrowserDialog.SelectedPath, fileName);       File.WriteAllBytes(path, bytes);     }     connect.Close();   } } 

what i have tried

if (sdr.HasRows) { while (sdr.Read()) {   byte[] bytes = (byte[]) sdr["Data"];   string fileName = sdr["Name"].ToString();   string path = Path.Combine(folderBrowserDialog.SelectedPath, fileName);   File.WriteAllBytes(path, bytes); } }  for (int I=0; I<listView1.Items.Count; I++)   {     listView1.FocusedItem = listView1.Items[I];     listView1.Items[I].Selected = true;   }