Using {{#each}} to fill a calendar with reservations: best practices - mongodb

I'm building an html table with dates as columns and hotel rooms as rows.
I'm fairly new to Meteor and have had headaches over this.
Because a html table is build by rows, I need to iterate over the rooms. So, if I am not mistaking this limits me to choosing the following file structure in MongoDB:
Room Collection:[
{Room1:[{"31/03/2015", "2/04/2015",....]},
{Room2:["22/03/2015",...]},
...]
Before this I had a reservation object where every reservation had the name of the room in it. Because there is no way I can group these dates over different collections, I changed it to the above structure.
So, okay, now I am able to move the cursor from room to room and build table rows.
Bigger problem now is that I then would iterate over 7 days (lets just say, for now I only retrieve queries for the current week). If I now get three days back from the database that are booked. I am only able to loop three times. Which is bad news because I need to fill 7 td elements. So somehow I should Identify which days of the week are taken by the reservation.
Is it a possibility to just store every date of the year in MongoDB and indicate wether there is a booking for that date? That seems far from elegant.
Or should I compare the dates of the week with the dates retrieved from the server, so on the client side?
I think I am looking at this problem the wrong way. I would love to here somebody else's opinion on this. :)
Kind regards

I always start off with an ER model of what I have & what I want.
How I think you currently have it: 1 Room has many Reservations. 1 Reservation has 1 datetime.
How you want to access it: 1 Day has many Reservations. 1 Reservation has 1 datetime & 1 room.
The Mongo way to do it: 1 Reservation has 1 room & 1 date.
So your original idea was correct (I'm not sure what you mean by not being able to group in other collections, we can tackle that in comments if you like):
Reservations = {
name: 'The Johnson Family Reunion',
room: 'Grand Ballroom',
datetime: new Date
}
For simplicity, we'll assume you aren't changing months in this example & I assume you've already got the code down to assign days to those squares.
Each square in the calendar should follow a dayofMonth template.
That will afford you a this that has the date in your helper, so you can write something like this:
Template.dayOfMonth.helpers({
reservations: function() {
return Reservations.find({datetime.getDate():
this.datetime.getDate()}).sort(datetime);
}
}
Then, your template is something simple like:
{{#each reservations}}
{{reservations.name}}
{{/each}}
Hope it helps!

Related

Power BI: Filter sales table with multiple locations on respective start dates from different table

I've tried to find a similiar thread on this, but have not been able to do so. Im pretty new to Power BI, so i might not know what im looking for. I could really use some advise.
I have a sales table ('SalesTable') that contains all the sales from different store locations. The table includes all the sales from each store beginning in january 2021, but the stores was incorporated on different dates in 2021, and so i need to be able to make a filter to only return the sales for each store from when the stores was incorporated respectivaly.
Simplified, the tables looks like this:
'SalesTable'
'SalesTable'
'Stores'
'Stores'
The two tables are joined on storeID. SalesTable is also connected to a dax-created Calender table. The stores table is not connected to the calender table (Maybe it should??).
I need to be able to filter the report so that it only returns sales dated on or after the respective incorporateddate.
Like this:
'Desired output'
I am not sure whats the optimal way to go about this. If i should make a calculated table of the SalesTable, or if a measure is sufficient to filter the report. Any suggestions, tips or solutions would be highly appreciated :)
You can use this measure:
sumIncorp =
var __maxIncorp = CALCULATE(max(inc[IncorporatedDate]), FILTER(inc, inc[StoreID] = SELECTEDVALUE(IncSale[StoreID])))
return
CALCULATE(SUM(IncSale[Amount]), FILTER(IncSale, IncSale[Date] >= __maxIncorp))

How do I use Tableau to populate the count of each dimension over a time period?

How do I populate the number of purchases and sales per day in tableau?
Here is my Sample Data:
In my first attempt, sales numbers are not counted to the exact date.
In my second attempt, I tried to tabulate by dropping sales date into the rows. However, it returned two figures - purchases and sales.
I have also tried Calculated Field but Tableau is unable to do a "for loop" like python.
First attempt:
After dropping Sales Date into the Rows. This is what I get:
Is there any way to populate it like this? Please help, I am still new to tableau. Special thanks to Fabio Fantoni for the first solution!
Desired Format:
I have another sample data (refer to sample data 2) which I would like to populate in the desired format (refer to desired format 2). In Sample Data 2, the purchase date "15/12/2020" is not reflected in sold dates.
My apologies but I may require some guidance as I am still new to tableau. Thank you in advance.
Sample Data 2:
Desired Format 2:
Based on this sample:
In order to bypass your double count for two different date columns, you may want to cross join your original data with a copy of it on original.Purchase = support.Sold, like this:
Doing so, you just have to create two calculated fields:
count Purchase:
count([Purchase Date])
count Sold:
Count([Purchase Date (Foglio11)])
The only thing you have to pay attention to is that in the second calculus you have to count Purchase date due to your "inverted" cross join.
You should get something like this:

filemaker pro 16 creating records that share a date (work rota)

I am currently trying to create a rota within filemaker 16 and I can't figure out how to create records that share a date.
I want to be able to have people assigned to jobs and jobs assigned to dates but currently when I create jobs with the same date it creates a new record instead of assigning it to the one already existing.
I have 3 tables currently jobs, date and people. I have a 4th layout with a portal where I wanted to view records related to jobs that are set for a certain day.
Any help would be much appreciated.
Many thanks.
I am not 100% convinced you need a Dates table. Do you have anything specific to record about a date, other than its existence?
However, you certainly need a join table of Assignments, with fields for:
PersonID
JobID
Date
(this is assuming your rota is daily, otherwise you will need to indicate the shift or hours too).
I think your structure should change on this.
So instead have:
Parent:
ProjectId
Date
PersonId
JobId
Date
Then make the project Id your 'Primary Key' so your parent record.
Then you are just assigning the person, job & date as the child.
That way you can always add to the previous record without relying on date field.
You could then filter via dates etc.

Count # of records by grouped date?

I'm a novice Tableau user, trying to help my organization to analyze phone traffic. My data source of incoming phone calls is in an Excel spreadsheet, and is listed like this:
TRANSACTION ID DATETIME
151313:179805 1/2/2018 9:57
151340:108017 1/2/2018 17:27
151395:176211 1/3/2018 15:27
Our total calls per day range from 10 to 50.
I'd like to count days with an identical # of calls, and probably make a Histogram sorted by # of calls on the X-Axis, and # of days w/ that many calls on the Y-Axis.
I feel like this would be a simple Calculated Field, but for the life of me, I'm not getting what I'd do here.
Help! :)
One solution is to define an LOD calc, calls_per_day, as
{ FIXED DateTrunc('day', [DATETIME]) : COUNT("*") }
which in effect, prebuilds a little table in space showing the number of data rows for each day. That works if you have one data row in your input per transaction id.
If transaction ids are repeated, and instead you want the number of transactions for each day, you can use the following variation.
{ FIXED DateTrunc('day', [DATETIME]) : COUNTD([TRANSACTION ID]) }
COUNTD() can be expensive on large data sets, so its better to use an alternative when you have the option.
You can use LoD
{Fixed TRANSACTION ID : Count(Day(DATETIME))}
Try this and post the result

How to get all missing days between two dates

I will try to explain the problem on an abstract level first:
I have X amount of data as input, which is always going to have a field DATE. Before, the dates that came as input (after some process) where put in a table as output. Now, I am asked to put both the input dates and any date between the minimun date received and one year from that moment. If there was originally no input for some day between this two dates, all fields must come with 0, or equivalent.
Example. I have two inputs. One with '18/03/2017' and other with '18/03/2018'. I now need to create output data for all the missing dates between '18/03/2017' and '18/04/2017'. So, output '19/03/2017' with every field to 0, and the same for the 20th and 21st and so on.
I know to do this programmatically, but on powercenter I do not. I've been told to do the following (which I have done, but I would like to know of a better method):
Get the minimun date, day0. Then, with an aggregator, create 365 fields, each has that "day0"+1, day0+2, and so on, to create an artificial year.
After that we do several transformations like sorting the dates, union between them, to get the data ready for a joiner. The idea of the joiner is to do an Full Outer Join between the original data, and the data that is going to have all fields to 0 and that we got from the previous aggregator.
Then a router picks with one of its groups the data that had actual dates (and fields without nulls) and other group where all fields are null, and then said fields are given a 0 to finally be written to a table.
I am wondering how can this be achieved by, for starters, removing the need to add 365 days to a date. If I were to do this same process for 10 years intead of one, the task gets ridicolous really quick.
I was wondering about an XOR type of operation, or some other function that would cut the number of steps that need to be done for what I (maybe wrongly) feel is a simple task. Currently I now need 5 steps just to know which dates are missing between two dates, a minimun and one year from that point.
I have tried to be as clear as posible but if I failed at any point please let me know!
Im not sure what the aggregator is supposed to do?
The same with the 'full outer' join? A normal join on a constant port is fine :) c
Can you calculate the needed number of 'dublicates' before the 'joiner'? In that case a lookup configured to return 'all rows' and a less-than-or-equal predicate can help make the mapping much more readable.
In any case You will need a helper table (or file) with a sequence of numbers between 1 and the number of potential dublicates (or more)
I use our time-dimension in the warehouse, which have one row per day from 1753-01-01 and 200000 next days, and a primary integer column with values from 1 and up ...
You've identified you know how to do this programmatically and to be fair this problem is more suited to that sort of solution... but that doesn't exclude powercenter by any means, just feed the 2 dates into a java transformation, apply some code to produce all dates between them and for a record to be output for each. Java transformation is ideal for record generation
You've identified you know how to do this programmatically and to be fair this problem is more suited to that sort of solution... but that doesn't exclude powercenter by any means, just feed the 2 dates into a java transformation, apply some code to produce all dates between them and for a record to be output for each. Java transformation is ideal for record generation
Ok... so you could override your source qualifier to achieve this in the selection query itself (am giving Oracle based example as its what I'm used to and I'm assuming your data in is from a table). I looked up the connect syntax here
SQL to generate a list of numbers from 1 to 100
SELECT (MIN(tablea.DATEFIELD) + levquery.n - 1) AS Port1 FROM tablea, (SELECT LEVEL n FROM DUAL CONNECT BY LEVEL <= 365) as levquery
(Check if the query works for you - haven't access to pc to test it at the minute)