Angular6 Date time check with ngIf inside html template - html

I am using Angular6.
Below is the ngfor with div. Here the api outputs the meeting date and time with status. Normally the status is upcoming.
If the date time is 09/18/2018. and Time is 5.30 Pm.
<div class="col-sm-12" *ngFor="let todayinfo of todaylist | paginate: { id: 'todaypage', itemsPerPage: itemperpage, currentPage: page, totalItems: todaytotal}">
<div class="meeting-date-time" title="Date Time" >
{{todayinfo.meeting_date | date: 'MMM d, y '}} <br>{{todayinfo.displayTime}}
</div>
<div>{{todayinfo.status}} </div>
</div>
The upcoming status should be changed as Join, before 15 minutes of the meeting time.
i.e at Sep 18 at 5.15pm the content need to change as Join. Here how to check the date time check condition. It is displayed inside the loop. If there is any click action we will check this with separate function. Without any events how to check the date time condition here?
Now the Output is
Sep 18 2018 5.30 PM --- Upcoming
Sep 4 2018 9.00 AM -- Completed
Spe 17 2018 7.15 PM -- Upcoming
These upcoming need to change to Join before 15 min of the corresponding date time.

There is simple solution how you can achieve that:
const meetings = [
{meeting_date: new Date(2018, 8, 17, 11, 44), status: null},
{meeting_date: new Date(2018, 8, 17, 12, 45), status: null}
];
const today = new Date();
meetings.filter(meeting => (meeting.meeting_date.getTime() - today.getTime()) <= 900000).forEach(meeting => meeting.status = 'Join');
It will check for meeting where time difference is less or equal to 900000(15min) and mark their status as 'Join'.

Related

How to get the day based on week number in flutter

So i have a json object which displays year, month and week of year:
{
"year": 2021,
"month": 8,
"week": 31,
},
{
"year": 2021,
"month": 8,
"week": 32,
}
My question is how can i iterate through the json object then convert the week of year into day of month where the day is the end of the week and then pass in the year, month and day of month into a DateTime object in flutter like this:
DateTime(2021,8,7)
DateTime(2021,8,14)
Multiply the week with a 7 to get the total number of days. Like
int totaldays = week*7;
final extraDuration = Duration(days: totaldays);
final startDate = DateTime(2021);
final newDateTime = startDate.add(extraDuration);
print(newDateTime);
print(newDateTime.next(DateTime.friday));

Convert numerical month to string using ionic 2 Pipe

How can I convert month to string in ionic 2 using Pipe? given the sample data below:
In my .ts file
let users = [
{
user: "A",
birthDate: "2017-08-01"
},
{
user: "B",
birthDate: "2017-08-02"
},
{
user: "C",
birthDate: "2017-08-03"
},
{
user: "D",
birthDate: "2017-08-04"
}
]
In my .html file
<ion-list>
<ion-item *ngFor="let user of users">
<div>Name: {{user.name}}</div>
<div>Birth Date: {{user.birthDate | date: "MM dd, yyyy"}}</div>
</ion-item>
</ion-list>
The sample output will be
Name: A
Birth Date: 08 01, 2017
Name: B
Birth Date: 08 02, 2017
Name: C
Birth Date: 08 03, 2017
Name: D
Birth Date: 08 04, 2017
Expected output will be
Name: A
Birth Date: August 01, 2017
Name: B
Birth Date: August 02, 2017
Name: C
Birth Date: August 03, 2017
Name: D
Birth Date: August 04, 2017
How can I achieve expected output?
Use MMMM instead of MM
<ion-list>
<ion-item *ngFor="let user of users">
<div>Name: {{user.name}}</div>
<div>Birth Date: {{user.birthDate | date: "MMMM dd, yyyy"}}</div>
</ion-item>
</ion-list>

Selecting all the records from table to which given number belongs to

Suppose I have following three records in my model :
#<Rda:0xf6e8a0c
id: 1,
age_group: "18-100",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
#<Rda:0xf6e8a0c
id: 2,
age_group: "10-15",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
#<Rda:0xf6e8a0c
id: 3,
age_group: "20-100",
weight: "60",
nutrient: "energy(kcal/day)",
value: "2730",
created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00,
updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00>
Now, I want to get all those records in which my given value falls in a 'age_group' columns ranges. For example: suppose my age is 25 then I should get records with ids 1 & 3 from the above records because '25' falls in between '18-100' and '20-100'
You might do
def self.foo(age)
all.select { |rda| Range.new(*rda.age_group.split('-').map(&:to_i)).cover? age }
end

How to check one specific field is null or not using laravel

I have a database table Wys_teachers with the following table fields
id
t_adate
t_amonth
t_ayear
t_attendance
I am inserting the following values:
1, 15, 07, 2015, 1
2, 15, 07, 2015, 1
3, 15, 07, 2015, 1
4, 15, 07, 2015, 0, go to hospital
5, 15, 07, 2015, 1
Then I want to update id=4 so that t_attendance becomes 1 at a time plus the t_areason field is empty (remove go to hospital).
My contrller update code is:
`if(!$teachers->isEmpty()) {
foreach ($teachers as $teacher) {
$updatet_attendance = WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->update(array(
't_attendance'=>Input::get($teacher->user_id),
));
$allattendance= WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->get();
$reason=$allattendance->t_areason;
if(!$allattendance->isEmpty()) {
DB::table('wys_teacherattendances')
->where('t_auserid',$teacher->user_id)
->where('t_adate','=',$date_exploded[0])
->where('t_amonth','=',$date_exploded[1])
->where('t_ayear','=',$date_exploded[2])
->where('t_aresaon','!=',NULL)
->delete();
}
}
//return Redirect::route('GetTeachersearchAttendence')
// ->with('success','update teacher exist');
}
}`
Update condition is fine - the t_attendance = 0-value becomes t_attendance = 1. But t_areason is not deleted.
This Part of code is not working:
`$allattendance= WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->get();
$reason=$allattendance->t_areason;
if(!$allattendance->isEmpty()) {
DB::table('wys_teacherattendances')
->where('t_auserid',$teacher->user_id)
->where('t_adate','=',$date_exploded[0])
->where('t_amonth','=',$date_exploded[1])
->where('t_ayear','=',$date_exploded[2])
->where('t_aresaon','!=',NULL)
->delete();
}`
I dont know if this is correct or wrong.
How to solve this problem?
And how to check if one specific field is null or not?

R data.frame to JSON with child nodes / hierarchical

I am trying to write a data.frame from R into a JSON file, but in a hierarchical structure with child nodes within them. I found examples and JSONIO but I wasn't able to apply it to my case.
This is the data.frame in R
> DF
Date_by_Month CCG Year Month refYear name OC_5a OC_5b OC_5c
1 2010-01-01 MyTown 2010 01 2009 2009/2010 0 15 27
2 2010-02-01 MyTown 2010 02 2009 2009/2010 1 14 22
3 2010-03-01 MyTown 2010 03 2009 2009/2010 1 6 10
4 2010-04-01 MyTown 2010 04 2010 2010/2011 0 10 10
5 2010-05-01 MyTown 2010 05 2010 2010/2011 1 16 7
6 2010-06-01 MyTown 2010 06 2010 2010/2011 0 13 25
In addtion to writing the data by month, I would also like to create an aggregate child, the 'yearly' one, which holds the sum (for example) of all the months that fall in this year. This is how I would like the JSON file to look like:
[
{
"ccg":"MyTown",
"data":[
{"period":"yearly",
"scores":[
{"name":"2009/2010","refYear":"2009","OC_5a":2, "OC_5b": 35, "OC_5c": 59},
{"name":"2010/2011","refYear":"2010","OC_5a":1, "OC_5b": 39, "OC_5c": 42},
]
},
{"period":"monthly",
"scores":[
{"name":"2009/2010","refYear":"2009","month":"01","year":"2010","OC_5a":0, "OC_5b": 15, "OC_5c": 27},
{"name":"2009/2010","refYear":"2009","month":"02","year":"2010","OC_5a":1, "OC_5b": 14, "OC_5c": 22},
{"name":"2009/2010","refYear":"2009","month":"03","year":"2010","OC_5a":1, "OC_5b": 6, "OC_5c": 10},
{"name":"2009/2010","refYear":"2009","month":"04","year":"2010","OC_5a":0, "OC_5b": 10, "OC_5c": 10},
{"name":"2009/2010","refYear":"2009","month":"05","year":"2010","OC_5a":1, "OC_5b": 16, "OC_5c": 7},
{"name":"2009/2010","refYear":"2009","month":"01","year":"2010","OC_5a":0, "OC_5b": 13, "OC_5c": 25}
]
}
]
},
]
Thank you so much for your help!
Expanding on my comment:
The jsonlite package has a lot of features, but what you're describing doesn't really map to a data frame anymore so I doubt any canned routine has this functionality. Your best bet is probably to convert the data frame to a more general list (FYI data frames are stored internally as lists of columns) with a structure that matches the structure of the JSON exactly, then just use the converter to translate
This is complicated in general but in your case should be fairly simple. The list will be structured exactly like the JSON data:
list(
list(
ccg = "Town1",
data = list(
list(
period = "yearly",
scores = yearly_data_frame_town1
),
list(
period = "monthly",
scores = monthly_data_frame_town1
)
)
),
list(
ccg = "Town2",
data = list(
list(
period = "yearly",
scores = yearly_data_frame_town2
),
list(
period = "monthly",
scores = monthly_data_frame_town2
)
)
)
)
Constructing this list should be a straightforward case of looping over unique(DF$CCG) and using aggregate at each step, to construct the yearly data.
If you need performance, look to either the data.table or dplyr packages to do the looping and aggregating all at once. The former is flexible and performant but a little esoteric. The latter has relatively easy syntax and is similarly performant, but is designed specifically around building pipelines for data frames so it might take some hacking to get it to produce the right output format.
Looks like ssdecontrol has you covered... but here's my solution. Need to loop over unique CCG and Years to create the entire data set...
df <- read.table(textConnection("Date_by_Month CCG Year Month refYear name OC_5a OC_5b OC_5c
2010-01-01 MyTown 2010 01 2009 2009/2010 0 15 27
2010-02-01 MyTown 2010 02 2009 2009/2010 1 14 22
2010-03-01 MyTown 2010 03 2009 2009/2010 1 6 10
2010-04-01 MyTown 2010 04 2010 2010/2011 0 10 10
2010-05-01 MyTown 2010 05 2010 2010/2011 1 16 7
2010-06-01 MyTown 2010 06 2010 2010/2011 0 13 25"), stringsAsFactors=F, header=T)
library(RJSONIO)
to_list <- function(ccg, year){
df_monthly <- subset(df, CCG==ccg & Year==year)
df_yearly <- aggregate(df[,c("OC_5a", "OC_5b", "OC_5c")] ,df[,c("name", "refYear")], sum)
l <- list("ccg"=ccg,
data=list(list("period" = "yearly",
"scores" = as.list(df_yearly)
),
list("period" = "monthly",
"scores" = as.list(df[,c("name", "refYear", "OC_5a", "OC_5b", "OC_5c")])
)
)
)
return(l)
}
toJSON(to_list("MyTown", "2010"), pretty=T)
Which returns this:
{
"ccg" : "MyTown",
"data" : [
{
"period" : "yearly",
"scores" : {
"name" : [
"2009/2010",
"2010/2011"
],
"refYear" : [
2009,
2010
],
"OC_5a" : [
2,
1
],
"OC_5b" : [
35,
39
],
"OC_5c" : [
59,
42
]
}
},
{
"period" : "monthly",
"scores" : {
"name" : [
"2009/2010",
"2009/2010",
"2009/2010",
"2010/2011",
"2010/2011",
"2010/2011"
],
"refYear" : [
2009,
2009,
2009,
2010,
2010,
2010
],
"OC_5a" : [
0,
1,
1,
0,
1,
0
],
"OC_5b" : [
15,
14,
6,
10,
16,
13
],
"OC_5c" : [
27,
22,
10,
10,
7,
25
]
}
}
]
}