How to create mutes leaderboard using JSON - discord

i have a JSON file and it has number of mutes thats staff members have,
and i want to create a LeaderBoard command names $top mutes shows the top of staff member by mutes.
Also i want to create a command names $top mutes weekly and $top mutes monthly thats shows the weekly and monthly mutes LeaderBoard.
How?
i didn't try anything beacuse i don't know how to make it
JSON file:
{
"``HERE IS THE STAFF MEMBER ID``":{"mutes":0,"bans":0,"warns":0,"tickets":0,"appeals":0,"support":2,"WarnedTimes":0}
}

Your JSON file does not have enough information stored to do weekly and monthly top mutes. In order to do those your JSON also has to store mutes in the past week and past month. However, you can refer to the following code to get an array in the form [[id1, muteCount1], [id2, muteCount2], [id3, muteCount3], ...] which is sorted with the largest muteCount first and the smallest last.
// data should contain the parsed JSON data
var sorted = Object.entries(data) // split the Object into an array in the form [[key, value], [key, value], ...]
.map(v => [v[0], v[1].mutes]) // replace the object with mutes, warns, bans, etc., into a single number representing the mute count
.sort((a, b) => b[1] - a[1]); // sort in descending order by number of mutes

Related

How to create new object for a new date in mongodb?

I want to change the value of a variable named count in mongodb. Count is needed for every day.
For example, if count changes from 15 to 17 in one day, i want to update the existing object. Again start the next day with 0 and keep track of it.
This way I will have 365 objects(in a year) for a user which has the count value for each day.
How to do it in mongodb? or is relational db more suitable for this?
Create an array of objects (counters) in the document and save the counter in a specific object.

Pandas making a new list from groupby object

My data has a country column and 'Clicked on Ad' column which has boolean value for customers preference for ad. I want to groupby my list to see the number of clicks based on countries. Then I want to cut (4,8) clicks which represent highest clicks per country. I want to cut these rows and create a new list while keeping all features of rows
ad_country=ad_data.groupby('Country')
Country_sum=[]
for i in range(4,8):
if ad_country['Clicked on Ad']==i:
Country_sum.append(iloc[ad_country])
SAMPLE
Daily >>>>> Age >>Daily Internet Usage >>> Country >>>> Clicked on Ad(Boolean)
68.95 >>>>>>35 >>>>>> 256.09 >>>>>>>>> Tunisia>>>>>>>>>>>> 0
75,78>>>>>>28>>>>>>>>214.9>>>>>>>>>>Mexico>>>>>>>>>>>>1
My result should have a Dataframe containing rows with Country names as index, while having total clicked on ad feature totals and other features(though not important for analysis) totals values in the columns.
ad_country=ad_data.groupby('Country')['Clicked on Ad'].sum()
I could get a country lists using groupby and sum(). I can also see max sample size w count()
I am still looking to find if I can slice a groupby object for max counts like value_counts().

Excel formula for creating a list using predefined criteria

The array formula I need is to create a list of unique divisions based on the country that is entered in cell (A1) for only divisions that have forecasted sales. The raw data sheet the list is pulling off is called 'Forecast' and has the following information:
Column A = Country, Column B = Division, Column C = Forecasted Sales, Column D = Forecast month
As the forecast data is broken into months, each division is repeated 24 times (for the 24 month forecast) so the formula will need to be able to return one record while eliminating the rest.
The closest solution I have found is this entry however I was unable to tailor it to my situation: Create a dynamic list from multiple criteria in data block

Navision 5.0 Report Sort TotalFields

I'm new to MS Dynamics NAV 5.0, I have created new Purchase Inventory Line Report using Report Designer. I have also group the line per item and total the quantity and the amount. What I trying to achieve is to sort the amount descending order.
This are my settings for the report.
DataItem: Purch. Inv Line
Properties:
GroupTotalFields = No.
TotalFields = Quantity, Amount
Sections:
Purch. Inv. Line, Header
Purch. Inv. Line, GroupFooter
Now how do I sort the TotalField: Amount by descending order?
You can't sort data by totals using report properties. But you could do this manually. Just iterate through inventory lines and save grouped and totaled results to temporary table variable. Then create new dataitem with base table called "Integer" and use it to print out the results in sections. You can find examples of this trick in many standard reports.

couchdb map / reduce multiple keys filtering by date

I have a view setup with a map reduce. Right now this code works great:
function(doc) {
if (doc.type == 'test'){
if(doc.trash != 1){
for (var id in doc.items) {
emit([id,doc.items[id].name], 1);
}
}
}
}
function(keys,prices){
return (keys, sum(prices));
}
I get a return and when using the group parameter, it condenses everything just fine.
My issue/question, I want to add a third key.... DATE, so I may only reduce records from certain dates. So for example:
function(doc) {
if (doc.type == 'test'){
if(doc.trash != 1){
for (var id in doc.items) {
emit([date,id,doc.items[id].name], 1);
}
}
}
}
My issue is that since date is at the beginning of the array, the reduce groups by date, id etc. I know I use group_level and say just take the first key from the array or the first 2 keys, but that doesn't help either because afaik, group_level goes from left to right in the array. I could put the date on the end of the emit array, but that doesn't help either because I need to have values at the beginning of my startkey and endkey to search on.
Here is an example of the output of data:
{"key":["2012-03-13","356752b8a5f6871f3","Apple"],"value":1},
{"key":["2012-03-20","123752b8a76986857","Pear"],"value":1},
{"key":["2012-04-12","3013531de05871194","Grapefruit"],"value":1},
{"key":["2012-04-12","356752b8a5f6871f3","Apple"],"value":1},
I want APPLE to be added up in one row, here it's adding up apples by date first. I was able to successfully just add up all the apples if I remove DATE as the first key in the array, but then I can't search by date range.
Any ideas on how to accomplish this?
If I correctly understand what you want to do, then you'd want to put the date as the first element of your array, and use group_level as well as start_key and end_key.
Eg. startkey=[1, "someid"] endkey=[1,"someid",{}] group_level=2
Will get you all items from date 1 (obviously choose your own format here), with id "someid" and any name. It seems funny that you emit id's before names, and without having more information about what you're actually trying to accomplish, it's hard to advise your general data model. If ID is a "type" id meaning that many items share the same ID then this makes sense. If ID is a unique per item ID, then it does not. In that case, you'd want to emit "name" before ID...
Edit 1
As per your comment, to do a range of dates you do this:
startkey=[1] endkey=[5,{}] group_level=2
You will get everything from date 1 to date 5 grouped by id ie. apples, oranges etc. I use this exact technique in a very large scale production application. I actually formatted the dates as an easily human readable integers of the format yyyymmdd, so 20140624 would sort to the top. If I want everything from the start of the month till now grouped by my group ids, I call
startkey=[20140601] endkey=[20140624,{}] group_level=2
It works perfectly and as far as I can tell that's what you're looking to do. I also have a third key layer "detail" which allows me to provide a deeper level of grouping for items that need it. I can then call
startkey=[20140601, "someid"] endkey=[20140624, "someid",{}] group_level=3
To drill to the detail level for a particular id, or just use the previous query with group_level=3 if I want the details for every id. I'm certain you can make this work - I've solved this exact problem in a production application using the techniques described.
Edit 2
If you want to group all apples regardless of date, then you'll need to let apples be the first element in the key. You can then get all apples over all time as a single row in the view result using group_level=1, and Apples over a date range using group_level=2. The difference here is that you'll only be able to do the group_level=2 query on a single item type at a time. If you want the best of both worlds, you unfortunately just need to make 2 views. That's just how key ordering works... If you need fast response times for both types of queries, all item types over a date range, and all of a particular item not grouped by date, I believe 2 views is the only way to achieve that.
Note
Another thing to note is about your reduce function. Wherever possible it is highly recommended that you use the built in reduce functions. They're implemented in erlang and are highly optimized compared to custom javascript reduce functions.
In your case, just replace your reduce function with this
_sum
Easy hey?
If you post more info about your application, data model etc. then I'd be happy to help out more with your database design.

Resources