I am trying to build a timetable setup to work in conjunction with one of my Models. Before I state my question, I will give some context into the problem.
I have a Model called Appointments with the following columns:
Name(String)
Start_time(time)
End_time(time)
Appt_Date(date)
Now I can have multiple appointments in 1 day.
For Example, let's say I have the following 2 Appointment objects:
Appointment 1:
Name: Makeup Appointment
Start_time: 11:00 am
End_time: 1:00 pm
Date: March 30, 2016
Appointment 2:
Name: Daily Meetup
Start-time: 2:00 pm
End_time: 3:00 pm
Date: March 30, 2016
I would like to implement a date-picker form where you can select a date and it would render 24 rows(1 for each hour of the day) and fill in the rows with the times not available based on the appointments on that day.
For example, if I select March 30, 2016 from the date-picker, I would like to render the 24 rows and have the rows for 11am-1pm and 2:00pm-3:00pm shaded out.
The setup is like google calendars(how time slots are colored in) but with a day-to-day basis. I don't need to be able to edit these rows. I just need to view them and have them rendered with colored cells based on Appointment objects for that specific day.
My issue is, I don't know where to begin to be able to design these 24 rows that interact with appointment objects. I was thinking that perhaps I build a helper method, however even that I am pretty lost. I would appreciate some guidance on how to approach this.
Below will help you:
1.Create a file in initializer which contains list of available time slots like 10 am to 10 pm.
2.For displaying date time field , use some jquery date time picker plugin.
3.Fire an ajax when clicked on datetime picker.
4.Ajax request will come on the controller & where you have to create an active record query which will fetch all apointments according to the particular date.
5.MAke an array variable & store the time which are already booked in the above appointments.
6.Compare the available time with the booked time & edit datetimepikcer.js to shaded the booked date.
Related
I have created a parameter in Tableau called Fiscal Start Month and it represents an integer for the beginning month of my fiscal year which is May. The integer is set to -8. I created this calculation to show the dates in the relative time frame which should be May 1 - December 31, 2022. The "DOS" is a date field for Date of Service, and I created another calculated field called "date" for today's date:
IF [DOS] >=DATE(DATEADD('month',[Fiscal Year Start],[Date])) AND [DOS] <=DATE(DATEADD('month',1,DATETRUNC('month',[Date])))
THEN 'Show'
ELSE 'Hide'
END
When I filter my data I am getting items from May 5th and it is hiding May 1 - 4. Can someone help me understand why this calculation might not bring in the appropriate dates?
I tried the formula above and this is what I am expecting
enter image description here
I am developing an automated calendar for a school on AirTable, but I am struggling to add if there is a bank holiday between the start date and end date. If the bank holiday falls on a weekday, it needs to add +1 day to the end date.
I have created a "bank holiday" table, as well as a full calendar table (containing everyday of the year and what weekday it falls on).
I'd like for the user to have the end date generated automatically by only writing the start date.
For example:
I have a session starting on Monday, 7th of march. The "session type" would be "Course 1", which has a duration of 10 days (two weeks, monday to friday - I don't know if the duration should be 14 days instead?). If there's a bank holiday in the 10 days after the start date, and it's on a weekday, it needs to add +1 to the end date. If the end date falls on a sunday, it needs to add +2 so that it ends on a Monday.
The course is divided in multiple classes, it would also be awesome to have a timeline view with the full Course and all the classes.
Here are some screenshots of my tables :
I know there is a possibility to write a script in Python with an AirTable API... but is there an easier way ?
I've dealt with a problem like this before: when an event happened in relation to other events mattered.
You'd think by the use of the words "in relation" that you could deal with this in a relational way, but I see it as a rule:
If Event A happens at Time 1, and it's so much or so little time from Event B, then do with Event A...
And, again by my way of thinking, rules are expressed in code.
And if you actually even can express that with a relation, I think it'd be very convoluted.
So, for your problem, you need to encode every schedule-able day that's 10 working days or less before a Bank Holiday (BH) so that if the day is selected you know it's less than 10 days from a BH and can conditionally add another day to the end date.
I looked at your examples, and here's my solution. I have a Calendar table which has all days, and two supporting "Bank Holiday" fields: does the date fall on a BH, and if not, is the date 10 days or less from a BH. We're looking at my All view, here:
I also have the view, Weekday, not bank holiday, and that's the view that you can pick a day from to schedule an event from the Event table.
The Event table:
You pick a day from the Start day field. Start day < 10 work days to Bank holiday? is a lookup field from the Calendar table for that day. End day is this formula:
DATETIME_FORMAT(
DATEADD(
{Start date},
IF(
{Start day < 10 work days to Bank holiday?},
14,
13),
'day'),
'ddd, MMM Do')
I have a Google Sheet with data like this:
Date
In
Out
July 13
£40
July 21
£60
etc.
I'd like to add another column "month" which specifies what month the entry was made in. Only problem is I can't use the standard MONTH() function because for accounting purposes, the tax month is 16th - 15th. So July 13 would be considered to be in the June/July tax month, while July 21 would be considered to be in the July/August tax month.
I'm assuming I will need to maintain a table of the specific cut off dates like so:
Month
Start
End
Jun/July
16th June
15th July
etc.
But I can't work out how to use this as a lookup table to achieve what I want. Any thoughts appreciated.
I think this should work if your date is in A1:
=IF(DAY(A1)>15,TEXT(A1,"MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MMMM")&"/"&TEXT(A1,"MMMM"))
If sort order is important (e.g. in a subsequent pivot table) I would use this:
=IF(DAY(A1)>15,TEXT(A1,"MM MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MM MMMM")&"/"&TEXT(A1,"MMMM"))
Another way to specify the sort order is maintaining a separate table with sort order column. It's a completely different approach.
use:
=ARRAYFORMULA(IF(A2:A="",,IF(DAY(A2:A)<16,
TEXT("1/"&MONTH(A2:A)-1, "mmmm")&"/"&TEXT("1/"&MONTH(A2:A), "mmmm"),
TEXT("1/"&MONTH(A2:A), "mmmm")&"/"&TEXT("1/"&MONTH(A2:A)+1, "mmmm"))))
TL;DR:
I have a database with thousands of appointments that have start_time and end_time attributes. Given a date range (May 26-June 31), how do I find
every appointment that happens throughout this range?
Appointment from May 15 to May 25 NOT included
Appointment from May 15 to May 29 needs to be included
Appointment from June 1 to June 3 needs to be included
Appointment from June 20 to July 5 needs to be included
Appointment from May 15 to July 15 needs to be included (most difficult part of the problem)
Appointment from July 1 to July 4 NOT included
We have an appointment model that has a start_time and an end_time. If an appointment occurs on any days during the monthly view, it needs to be loaded into the instance variable (#monthly_appointments) so that the simple_calendar gem can display it on the calendar.
Example: An appointment from June 1 to June 3 needs to show up when the user views the "June 2020" calendar. An appointment from May 15 to July 15 also needs to show up every single day during June.
There's 6-day padding on each side of the calendar dates, since if the week starts on a Saturday (June 1), you'll have May 26 - May 31 showing on the June calendar (see picture).
You'd think it was just as easy as saying "If an appointment starts or ends during the given month, add that appointment to the instance variable. However, there are cases when an appointment starts on May 15 and goes for 60 days, until July 15. The appointment neither starts nor ends during June, but it needs to still show up on the calendar.
Originally, we told users, "appointments cannot last longer than 6 months" and then we used this lookup where we assumed, "if the appointment started during the last 6 months, include it in the variable and then we'll let the calendar gem work out the rest."
#monthly_appointments = current_user.appointments.includes(:pet).where(start_time: (Time.zone.now).beginning_of_month - 6.months..(Time.zone.now).end_of_month + 6.days))
However, this query can sometimes save 3,000+ appointments in the variable, when, in reality, there are only 50-70 appointments that NEED to be shown for that month.
So, I wrote up the following code, and it succeeds in finding appointments that occur on at least one day during the calendar's timeframe. It compares the monthly calendar's range(May 26..June 31) and an appointment's range(June 1..June 3), and then looks for any dates that occur in both arrays (&). It works well, but it takes a bit of time because it needs to load ALL the appointments for a user (thousands) and then goes through each one to see if it occurs during that month.
Does anyone have any other clever solutions to this query issue? I'm sure something exists out there, but I haven't found it yet. Thanks!
month_dates = ((Time.zone.now.beginning_of_month - 6.days)..(Time.zone.now.end_of_month + 6.days)).to_a
#monthly_appointments = current_user.appointments.includes(:pet).select do |appt|
#create array of appointment dates and see if it intersects any of the monthly date array
appt_dates = (appt.start_time.to_date..appt.end_time.to_date).to_a
(month_dates & appt_dates).present?
end
Models:
Appointment(start_time, end_time, note, user_id, pet_id)
Pet
has_many appointments
User
has_many appointments
Here's an example.
carley = Pet.find(12)
Appointment.create(pet_id: carley.id, start_time: "May 15 2020 06:00:00", end_time: "July 15 2020 06:00:00"...)
When I'm looking at the June 2020 calendar, this appointment needs to show up on every single day.
from_time = '2019-05-26'.to_date
to_time = '2919-06-30'.to_date
#appointments = Appointment.where('start_time <= ? AND end_time >= ?', to_time, from_time)
The above will select all appointments that are included in or overlap the from_time and to_time range, and also appointments that start before the range and end after the range.
I have an app where users can view sporting events for today's date or a given date (if the user manually enters it in the URL). A user can navigate sporting events by date with a UI control, which crudely looks like this:
Tue Nov. 27 | Wed Nov. 28 | Thu Nov. 29
(The dates are links except the current active one in the middle.)
This date nav control works great for sporting events that occur nearly every day. The user is never staring at a blank page of events. However, for sporting events such as the NFL, events only occur on Monday, Thursday, Sunday (sometimes Saturday) and it becomes cumbersome for the user to use the date nav UI control.
What I'd like to do is to change the logic behind the creation of the date nav UI links to include only those dates that have events. The logic would be something like:
Given today's date or a date supplied by the user, return the nearest date which has events (current_date)
Given a current_date, find the nearest previous date which has events (previous_date)
Given a current_date, find the nearest next date which has events (next_date)
So, in the case of the NFL, the date nav UI control might look like, assuming today's date is Nov 27:
Mon Nov. 25 | Thu Nov. 29 | Sun Dec. 2
The way in which to tell if there are any events for a given date is by start_time field in the DB.
I don't like to post a question without some code, but I'm looking for some guidance as to how I should approach this without having to hit the DB a ton of times.
NOTE #1: When you click on a date for a sport, it returns all the events for that date. The date nav is not used for viewing individual events.
Create a scope method in your model that grabs the next two start dates for the given sport, and the most recent start date. Limit it to return only three records.
Use this scope in your controller to fetch only those three game objects. With those three game objects in the controller, pass them to a view partial as an instance variable (e.g. render #games), and in the partial, write the generic link code <%= link_to "#{#games.start_time}", your_path(#game) %>. Rails will automatically iterate this partial for the number of objects in the collection (the three games).
Source: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials