RUBY: most common number for Users [closed] - ruby-on-rails

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Hi I'm new to Ruby on Rails. I created Users with device, on profile creation the user enters a numeric field that's limited to 5 numbers. Now I need to get the most common numbers from all users. How could I do that?
I want to show most common numbers in my admin controller, please help.

You can get the array of numeric fields by doing
array = User.all.map(&:numeric_field) # assuming there is a numeric_field column
Then you can get the most common number (called the "mode") with several different methods, referenced by this post: Ruby: How to find item in array which has the most occurrences?
If you have a lot of users, this approach can hog memory, in which case you can do the operation in batches:
array = []
User.find_in_batches do |users|
array += users.map(&:numeric_field)
end
And then just use the array as before.

Related

Scrape from website and save into different columns in a spreadsheet [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
Suppose there's a website that has a list of details of some companies, for example, name, HQ area, turnover, etc. How do I scrape that data and fill it into different columns (like name, turnover) with each row having the details of a separate company?
Google Sheets allow you to import html tables or list with the IMPORTHTML(url, query, index) function.
For example, using the Wikipedia page List of largest companies by revenue as an example.
We want the data from the main table, so the first thing that we have to do, is to know what index it occupies in the page. To do this, we can use document.querySelectorAll('table') or $$('table'), as you can see from the result, the table that we want is in the position 5 of the array, so inside our google sheet we can use:
=IMPORTHTML("https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue","table",5)
From here, you should change the query parameter to list and find what index it occupies within the page using the method described above. In any case, you could always use IMPORTXML(url, xpath_query), and knowing the XPath of the information, you could come up with a similar solution.

External API link is broken and I can not get any data from bad API's in Json file in iOS development [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to make an API call and was given three links at which I need to reference as end points but both of these links are broken or return no values.
It's unlikely that your issue has anything to do with iOS.
If I follow your first "End point" it returns a json formatted string of "categories"
If I then take the first Category "Beef" and call:
https://www.themealdb.com/api/json/v1/1/filter.php?c=Beef
it returns a json formatted string of "meals"
If I then take the first Meal ID "52874" and call:
https://www.themealdb.com/api/json/v1/1/lookup.php?i=52874
it returns a json formatted string for the "Beef and Mustard Pie" meal.

google sheet vlookup a cell that do not contain multiple value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
How can I list all the buyer names who has not buy Prodct "Phone" or Brand"Sony" or Seller" Ebay". Thank you so much for your help.
Assuming your "Date" header is in A1:
=FILTER(B2:B10, C2:C10<>"Phone", D2:D10<>"Sony", E2:E10<>"Ebay")
It's a simple FILTER.

How can you map IDs even when duplicates are eliminated? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I currently have a large set of objects in SAS (>100000) each with about 60 columns of data, including an ID number. There are many duplicate ID numbers in this set of data. My goal is to convert the ID numbers that I currently have into another form of ID number using a piece of software that I have. The problem is that when I input the ID numbers into the software, the converted output comes back without the duplicates, which I need. Is there any way to use the output ID numbers to somehow create a list of output IDs except with the duplicates that the original set of data had. Any language or piece of software would be fine.
Here is a illustration of what I described above.
Original IDs: 086516 677240 449370 677240 941053 449370
Output: 147244 147947 147957 148021
Preferred Output: 147244 147947 147957 147947 148021 147957
You can merge on the ID using a MERGE statement, and it will append the value to each of the records with the same ID value.
data want;
merge have(in=a) newIDs(in=b);
by id;
if a and b;
run;

How to calculate a record's ranking compared to others based on a single column in Rails? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Assuming I have User model with a column called point.
How can I get an instance's ranking compared to all other User rows.
The user's rank can be thought of as the number other users with more points than them, plus 1. As Mischa pointed out in the comments, an appropriate place for this would be in the User model itself, as in:
def ranking
User.where('point > ?', point).count + 1
end
You would then call it as:
Rank: <%= #user.ranking %>
This has the downside of ranking users with the same number of points at the same rank. You'll have to decide on a "tiebreaker" for that case.

Resources