Google Stackdriver: Group by distinct values - google-cloud-stackdriver

Lets say I have a number of requests in my stackdriver log. Each request is associated with a certain user. Naturally there are several requests for the same user at any time.
I now want to create a metric/chart in Google stackdriver which shows my the number of distinct users at any timeslot.
Example:
10:00:00 - user X
10:02:00 - user Y
10:10:00 - user X
10:12:00 - user X
10:12:00 - user Y
10:15:00 - user Z
The desired outcome is that for the timeslot 10:00 (10:00 - 10:59) a overall number of 3 users is shown. (user x, y and z have been active in this time range).

I believe that your best course of action with this will be to export the logs into something like big query and run a distinct count query on the timeframes you want to view seeing as stackdriver only has a count function and no count distinct

Related

Elastic search, prevent one user clogging up all the results

i have a campaigns that belong to users.
so my documents look something like this
campaign_id:1
user_id:1
date_created: 1234567890
now i want to show a list of campaigns sorted by newest. but right now if one user creates 100 campaigns my whole results for the first 4 pages will be the campaigns for this user.
What i am looking for is to spread out the campaigns so that it looks better
for example, if i have documents belonging to these user_ids
3,3,3,2,2,1,1,1,1,1,1,1,1,1
a query sorted by date_created will return me
1,1,1,1,1,1,1,1,2,2,3,3,3
what im looking for is this
1,2,3,1,2,3,1,3,1,1,1,1,1,1,1
user 1 is shown on top, then the latest of user 2 and 3, then we show the second latest of user 1,2,3 etc until user 2 and 3 have no documents left and all others from user 1 are at the bottom.
help?

Running Sum of Filtered Rows in Tableau

I have a table of challenge submissions (that records the time of submission of a challenge in a competition by different players, and whether the submission was correct or not) -
and another table that has the points associated with each challenge -
How do I plot a graph of running sum of points earned by the top 3 players in the competition over time (for last 24 hours only)? The catch here is that I only need to consider the first successful submission in case there are more than one successful submissions for a challenge in the competition (eg. Challenge #17 for Player A).
EDIT:
Dummy Data
Desired Output:
I am proposing a solution/answer assuming a few things-
Challenge acceptance time ends at 17:00 everyday
Different lines represent different challenges
Step-1 Create a CF to adjust date/time by calendar date - adjusted date as
DATEADD('hour', 7, [Date])
Note that I have added 7 hours to make the last calendar date/time for submission as 00 AM next day.
Step-2 Create another CF win_loss as
If [Success]='W' then 1 ELSE 0 end
step-3 create another CF game points as
[win_loss]*[Points (Points)]
Step-4 create another CF first win or loss as (don't worry about loss here)
{FIXED [Player], [Challenge], [success] : MIN([Date])} = [Date]
Step-5 create a set on 'players' field with TOP-3 with this formula (select top 3) by
sum(
IF [first win or loss]= TRUE
then [game points] END)
Step-6 build your view by dragging
set, MDY(adjusted date) & first win or loss on filters shelf/card
add mdy filter to context
[date] with exact date and discreet to columns
sum(game points) to rows
adding table calculation on measure - running total
right click sum(game points) click edit in shelf and replace the existing calculation by this one-
RUNNING_SUM(ZN(SUM([game points])))
(Note this will ensure your lines start at f(x)=0 always)
challenge on colors in marks card
sum(game points) to text in marks card.
Note- filters on (i) Set will ensure the top 3 players are in view only
(ii) adjusted date will ensure view for 24 hour challenge submission time
(iii) first win or loss will eliminate second and subsequent win(s) by same player for same challenge
I hope this will also make things clear to you.
You should get your desired view
OR change the date field to seconds to get a view like this

How to Sum last value of all users in database

I have a database with different users, with an amount column....all this user all have different value in their amount colume, but i want to pick all the last amount for each user and sum it.
i tried it like this but game an error
$returned = DB::table('sales')->sum('returned')->last();
pls, i dont want the total sum of the amount column....because some users have more than one amount, so i want to pick the last one for each user and sum it
Use this,
DB::table('sales')->latest()->get()->unique('user_id')->sum('returned');
if you have sales Model use
Sales::latest()->get()->unique('user_id')->sum('returned');
Note the code is updated

PowerBI filter table based on value of measure_A OR measure_B [duplicate]

We are trying to implement a dashboard that displays various tables, metrics and a map where the dataset is a list of customers. The primary filter condition is the disjunction of two numeric fields. We want to the user to be able to select a threshold for [field 1] and a separate threshold for [field 2] and then impose the condition [field 1] >= <threshold> OR [field 2] >= <threshold>.
After that, we want to also allow various other interactive slicers so the user can restrict the data further, e.g. by country or account manager.
Power BI naturally imposes AND between all filters and doesn't have a neat way to specify OR. Can you suggest a way to define a calculation using the two numeric fields that is then applied as a filter within the same interactive dashboard screen? Alternatively, is there a way to first prompt the user for the two threshold values before the dashboard is displayed -- so when they click Submit on that parameter-setting screen they are then taken to the main dashboard screen with the disjunction already applied?
Added in response to a comment:
The data can be quite simple: no complexity there. The complexity is in getting the user interface to enable a disjunction.
Suppose the data was a list of customers with customer id, country, gender, total value of transactions in the last 12 months, and number of purchases in last 12 months. I want the end-user (with no technical skills) to specify a minimum threshold for total value (e.g. $1,000) and number of purchases (e.g. 10) and then restrict the data set to those where total value of transactions in the last 12 months > $1,000 OR number of purchases in last 12 months > 10.
After doing that, I want to allow the user to see the data set on a dashboard (e.g. with a table and a graph) and from there select other filters (e.g. gender=male, country=Australia).
The key here is to create separate parameter tables and combine conditions using a measure.
Suppose we have the following Sales table:
Customer Value Number
-----------------------
A 568 2
B 2451 12
C 1352 9
D 876 6
E 993 11
F 2208 20
G 1612 4
Then we'll create two new tables to use as parameters. You could do a calculated table like
Number = VALUES(Sales[Number])
Or something more complex like
Value = GENERATESERIES(0, ROUNDUP(MAX(Sales[Value]),-2), ROUNDUP(MAX(Sales[Value]),-2)/10)
Or define the table manually using Enter Data or some other way.
In any case, once you have these tables, name their columns what you want (I used MinNumber and MinValue) and write your filtering measure
Filter = IF(MAX(Sales[Number]) > MIN(Number[MinCount]) ||
MAX(Sales[Value]) > MIN('Value'[MinValue]),
1, 0)
Then put your Filter measure as a visual level filter where Filter is not 0 and use MinCount and MinValues column as slicers.
If you select 10 for MinCount and 1000 for MinValue then your table should look like this:
Notice that E and G only exceed one of the thresholds and tha A and D are excluded.
To my knowledge, there is no such built-in slicer feature in Power BI at the time being. There is however a suggestion in the Power BI forum that requests a functionality like this. If you'd be willing to use the Power Query Editor, it's easy to obtain the values you're looking for, but only for hard-coded values for your limits or thresh-holds.
Let me show you how for a synthetic dataset that should fit the structure of your description:
Dataset:
CustomerID,Country,Gender,TransactionValue12,NPurchases12
51,USA,M,3516,1
58,USA,M,3308,12
57,USA,M,7360,19
54,USA,M,2052,6
51,USA,M,4889,5
57,USA,M,4746,6
50,USA,M,3803,3
58,USA,M,4113,24
57,USA,M,7421,17
58,USA,M,1774,24
50,USA,F,8984,5
52,USA,F,1436,22
52,USA,F,2137,9
58,USA,F,9933,25
50,Canada,F,7050,16
56,Canada,F,7202,5
54,Canada,F,2096,19
59,Canada,F,4639,9
58,Canada,F,5724,25
56,Canada,F,4885,5
57,Canada,F,6212,4
54,Canada,F,5016,16
55,Canada,F,7340,21
60,Canada,F,7883,6
55,Canada,M,5884,12
60,UK,M,2328,12
52,UK,M,7826,1
58,UK,M,2542,11
56,UK,M,9304,3
54,UK,M,3685,16
58,UK,M,6440,16
50,UK,M,2469,13
57,UK,M,7827,6
Desktop table:
Here you see an Input table and a subset table using two Slicers. If the forum suggestion gets implemented, it should hopefully be easy to change a subset like below to an "OR" scenario:
Transaction Value > 1000 OR Number or purchases > 10 using Power Query:
If you use Edit Queries > Advanced filter you can set it up like this:
The last step under Applied Steps will then contain this formula:
= Table.SelectRows(#"Changed Type2", each [NPurchases12] > 10 or [TransactionValue12] > 1000
Now your original Input table will look like this:
Now, if only we were able to replace the hardcoded 10 and 1000 with a dynamic value, for example from a slicer, we would be fine! But no...
I know this is not what you were looking for, but it was the best 'negative answer' I could find. I guess I'm hoping for a better solution just as much as you are!

Kibana - How to create a visualization to show a duration per user?

I have four columns :
timestamp
username
action
session_id
I would like to show / visualize for each user the average duration for all sessions.
That means that I have multiple lines for one session and that I have to get the duration per session to compute the average.
An example of data :
User Action Session_id timestamp
Fernando Login 1 1469087288
Fernando Draw Circle 1 1469087322
Fernando Draw Rectangle 1 1469087354
Fernando Login 1 1469087288
Chris Login 2 1469087323
Chris Draw Square 2 1469087424
Chris Draw Rectangle 2 1469087888
What I want is to get : User | Session_id | Duration
And the final result I want : User | Average duration / session
Is it possible easily ?
Upto the last vesion of kibana They didn't provided the facility to calculate the time duration of each term.
We can get aggregated count for the particular duration.

Resources