Joining Meteor collections for scoring - join

Let's say I have two collections: "Movies" and "Reviews." Users write reviews about movies and assign each movie a review score from 0 to 10. I want to make a list of the top 20 movies, based on each movie's average review score. Does anyone know how to set up the publish/subscription code? It's giving me the blues now. Everything I've read suggests this is a weak area for Meteor, and I can't seem to find a comparable example.

The solution is to store the average review score directly in the Movies collection and update it when a new review is added. This can be achieved by storing the total review score and number of reviews, which lets you update the average without having to retrieve all of the other reviews.

Update the average for a movie each time a review is posted and store that average in the movie document. It is more work at the time of creating the review, but querying the top 20 movies becomes trivial after that.

Related

Google Datastudio show empty row combinations

I am creating a Google Data Studio report for a car dealership and I have a problem.
I have made these 3 screenshots to illustrate:
If you see on the first screenshot, the datasource is pretty simple, used/new indicates weather the car being sold is new or used and if it is a sportscar or family car, and exchange/clean deal indicates weather the dealership takes/buys the customers old car in for a trade off in price. The rest should be self explanatory.
On screenshot2-3 you see my report, I have one table for each salesperson and it shows the amount of sales for each combination that has sales.
The problem is this, I want the tables to show each combination even if it does not have any sales at all, it should just show 0 then in record count. Like Mike on the left has more combinations than john, I still want Johns table to show those combinations just with a 0 then, and it should be sorted the same on each table so they look the same, just different data in the cells.
Is this possible to do?
To solve this problem, you need to make a combination of data, from the database with itself. Your main analysis dimension, which will generate your combinations, is used/new and Exchange/Clean deal. So your combination should be:
The filter defined in the second database (right base) must contain a filter telling which person the table will be destined for. So, for each table, you must make a new combination that contains the person-specific filter.
I just took a sample from your original database (10 first lines) and the result is:

Need a SUMIF =SUM(C3-(SUM(E3:N3))) but if E14<0 dont subtract

I have simple problem which I can't get the right twist on it.
I have a list of "products" with their stock in the range of D3:D13 with a set price, an original stock and a list of "customers" in the range of E3:L3.
Each customer can take a product and the updated stock currently is:
[=SUM(C3-(SUM(E3:L3))) ]
If we take one person he has his combined cost for how many products he took on E14
If a person pays their cost (E14 > 0) and nulls the products he took currently the updated stock gets rested. That is what I dont want.
Basically: SUM Stock IF (any of E14:L14) > 0 THEN =SUM(C3-(SUM(E3:N3)))
Update:
Example:
https://docs.google.com/spreadsheets/d/1SEssivZ8jCbqedc8TG_PO4uWLN_QzpRQwxJ_bGwHvQg/edit?usp=sharing Hope the link works.
That is basically everything and this works for me currently.
The issue is if a user decides to pay their dept.
For example User 1 pays.
Then the currently calculated price for the user (E14) get's nulled and also the cells for how much products they took (E3:E12).
But then because how it is done currently the updated stock gets updated again with the items the user1 took previously because we nulled the E3:E12. But the products where already taken. That is what I want to prevent.

Count total games played in a league standings template

I'm working in Google sheets
I've created a league standings template here:
https://docs.google.com/spreadsheets/d/1aTJsKkORRka1f4Z3Ibb87XGq-6Sv3qFaCYSsW8D3kHM/edit?usp=sharing
The last thing I'm really hung up on is calculating the amount of games that each team has played. Basically I need the G column to use the formula for each cell to see if the corresponding team has completed their games from the 'League Scores' table.
I currently have this formula:
=countif(filter($C4:$C, $B4:$B=$J$4), "<>") + countif(filter($D4:$D, $E4:$E=$J$4), "<>")
Each team could play on either side of the league score sheet throughout the season. So my logic is that the first 'countif' function would search through the first Team name column and Scores column to see if the team name was mentioned. If it was, it would then check to see if there was any score listed at all. If true, then it would add one to the Games played counter. The second half of the formula is to check the right side of the leagues team and score columns repeating the same process.
You can see however, that the 'GP' (games played) column lists an inaccurate amount of games played per team and even saying that teams which haven't yet played a game are at 2 games played.
What am I missing?
The extra count is coming from the case when the filter returns no rows and you get #N/A. The Countif still counts it as 1.
Suggest using Countifs instead, something like
=countifs(B:B,J4,C:C,"<>") + countifs(E:E,J4,D:D,"<>")

Algorithm for tracking changes in value over time

I am writing a rails app that deals with product inventory. I would like to include the following features, and am struggling with developing an efficient algorithm:
View stock history (how many were in stock on each date)
Quantity removed from warehouse, and quantity added to warehouse over specific periods of time
Amount of time the product was out of stock in any given period
My questions are as follows:
What is the best way of tracking changes? In addition to my Products
table, should I create another table called
HistoricProductQuantities, and insert a new record each time there
is a change in the quantity?
What number should I track? The historic stock quantity (i.e. 50 in
stock on this day, 24 in stock on that day), or the CHANGE in stock
quantity i.e. -5 (5 sold) or 15 (15 added to inventory)? Or do I
track both in separate tables?
Thanks for your help.
First of all I recommend implementing Date Dimensions on your application, as it seems like you will be doing a lot of Time related calculations. Search on Google for date dimensions as it's beyond the scope of your questions. That said, I believe it will be of great benefit for your app to implement and use date dimensions.
As far as your direct questions go:
What is the best way of tracking changes? In addition to my Products table, should I create another table called HistoricProductQuantities, and insert a new record each time there is a change in the quantity?
Yes you could do this, I would probably call it HistoricProductSnapshot and keep track of the product activity in there on daily basis. With this information as well as time dimensions you could do calculations such as "how many of Product X Did we have 5 days ago or a month ago etc etc."
What number should I track? The historic stock quantity (i.e. 50 in stock on this day, 24 in stock on that day), or the CHANGE in stock quantity i.e. -5 (5 sold) or 15 (15 added to inventory)? Or do I track both in separate tables?
I do not have experience writing inventory control software but I believe with the Snapshot table I mentioned on the question above you would only have to keep track of quantities per day. The Change in product counts could then be calculated from your snapshot table. You could for example have a function that will output the product amount in a given time range as an array. Example: From March 1 to March 7 these were the stock amounts for Product Y [45,40,39,27,22,45,44].
Hope that helps. As I said I am not a product inventory guy but I have worked with Point of Sales Systems and the procedure above should give you a could enough start for what you are trying to do.
This gem could be usefull for tracking changes in models https://github.com/collectiveidea/audited
Keep the data raw. I would personally create a new data entry every day, displaying how much items you have in stock per day. Or you can make the interval much shorter, such as every 12 hours.
For our particular use case:
We had a table called Days, which had a many to many relationship with products, and each "relationship" will have a value called quantity (to keep track of quantity of product per day). Additionally per relationship, we had another value for the relationship with transactions (a one to many relationship) that has the entries for the time of transaction and remaining stocks.
I would personally advise you to use the quantity of stock as the raw data, as it will enable you to gather the data such as how much items were removed during a certain transaction, when the item was out of stock and when it became in stock, all through the data. When you have data in which you need to perform statistical calculations on, it's best to store this data as raw values (quantity of the item).

"Relationship may be needed" although relationship is set

I have two simple table in Excel 2010 - Products and Sales:
I then linked them into PowerPivot - and here created the relationship from Sales.ProductId to Products.Id - like this:
Now I'm trying to build a Pivot that for each productId in the Sales table also shows me the Category and the PurchasePrice from the ProductTable. However, here I'm stuck - because the relationship is somehow faulty. When configuring the Pivot, I get a message Relationship may be needed even if the relationship already exists. The resulting - wrong - pivot table looks like this:
though I'm actually trying to achieve this:
I know that I could create calculated columns in the Sales table of PowerPivot and pull all required data using the RELATED DAX function - but as the real world project requires a lot of joins and fields I'm hoping that there's a better solution than this workaround...
I uploaded the example file here.
Peter,
Your question was a bit more tricky than I first though and I spent quite some time digging around, but I think I found the solution after reading this article about making distinct count in related tables.
I have updated your source file (so that Sales table contains more than 1 sales per product) and uploaded it to my public Dropbox folder.
You can see that I created 4 new calculated measures to illustrate my solution and to make it a bit easier to understand (Excel 2010 terminology, in 2013 it's Calculated Field):
Sales Price Total
=SUM(Sales[SalesPrice])
Products Sold
=COUNT(Sales[ProductId])
Purchase Price per Item
=CALCULATE(SUM(Products[PurchasePrice]),Sales)
Purchase Price Total
=[Purchase Price per Item] * [Product Sold]
The key difference here is the formula for calculating purchase price per item. The reason why you should SUM the product purchase price within CALCULATE function is explained in great detail in the linked article (even though in a bit different context):
In this way, any filter active on Sales (the related table) propagates
to the lookup table.
There might be some other parts I missed, but I have tried this in couple other examples and it simply works as it should:

Resources