Property observer not getting hit, but value is changing - swift

I have got a variable which seems to be changing throughout the app. I have confirmed this by when I originally change a value to be true and then print, it shows that it is then false, false, false, true, false, false, false and my property observed is hit so "It changed!" shows in the console.
However, I later print this out again and it has reverted back to false, despite nothing changing the value of it (that I can see) and the property observer is not hit. It does not print "It changed" but in the console, it then prints false, false, false, false, false, false, false.
var isPicked: [Bool] = [false, false, false, false, false, false, false] {
didSet {
print("It changed!")
}
}
Any help would be much appreciated.

Related

How to access the values only in flutter map

"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},
You can get the bool list like
final bools = data["turf_amenities"]?.values.toList();
print(bools);
final data = {
"turf_amenities": {
"turf_washroom": true,
"turf_water": true,
"turf_dressing": false,
"turf_parking": true,
"turf_gallery": true,
"turf_cafeteria": true
},
};
final values = data.values.toList();
print(
values); //[{turf_washroom: true, turf_water: true, turf_dressing: false, turf_parking: true, turf_gallery: true, turf_cafeteria: true}]
final bools = data["turf_amenities"]?.values.toList();
print(bools); //[true, true, false, true, true, true]

How to match two boolean tables and count match values and unmatch values

table_1
"mcqtest_id": 1,
"option_one_correct": true,
"option_two_correct": true,
"option_three_correct": true,
"option_four_correct": true,
"option_five_correct": false,
"option_six_correct": false,
"option_seven_correct": false,
"option_eight_correct": false,
"question_id": 1
table_2
"mcqtest_id": 1,
"option_one_correct": false,
"option_two_correct": true,
"option_three_correct": false,
"option_four_correct": true,
"option_five_correct": false,
"option_six_correct": false,
"option_seven_correct": false,
"option_eight_correct": false,
"question_id": 2
I want to find the match between this two boolean tables and if match count match values and else count unmatch values with postgresql query.
help me to understand and write this query

Find index of all true inside massive

I've an array of booleans there are 10 trues and falses and I want to know the index of all trues
var trueAndFalses = [false, false, true, false, false, false, true, false, false, false]
I tried firstIndex but it only returns the firstIndex ( yes kinda ironic ). now I wonder is there any built in functions to find all the indexes of true
print(trueAndFalses.firstIndex(of: true))
any solution will be appericated <3
You can try to find all index by visiting all elements and checking if its true like below:
var trueAndFalses = [false, false, true, false, false, false, true, false, false, false]
for var i in (0..<trueAndFalses.count){
if (trueAndFalses[i] == true)
{
print("true fount at index ",i)
}
}
Output:
true fount at index 2
true fount at index 6
Other way:
let indices = trueAndFalses.enumerated().compactMap { $1 == true ? $0 : nil }
print(indices)
Output:
[2, 6]

how to schedule a pgagent job through scripts/commandLine

I want to run jobs through PgAgent.
I am able to do that by creating a job in PgAgentJob through PgAdmin UI, as described here https://www.pgadmin.org/docs/pgadmin4/dev/pgagent_jobs.html.
But I want to use a sql script that can create a PgAgent job as we do in Oracle. Please suggest how I can achieve this.
To create a job in pgAgent use something like the following INSERT STATEMENTS (for a Routine Maintenance job) :
INSERT INTO pgagent.pga_job (jobid, jobjclid, jobname, jobdesc, jobenabled, jobhostagent)
SELECT jcl.jclid, 'MyJob', '', true, ''
FROM pgagent.pga_jobclass jcl WHERE jclname='Routine Maintenance';
To add a step to this job, which executes a SQL command ('delete from test where user_name=''test'';), use the following command:
INSERT INTO pgagent.pga_jobstep (jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname, jstconnstr)
SELECT (SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MyStep', '', true, 's', 'f', 'delete from test where user_name=''test'';', 'postgres', '';
To create a schedule for this job (every day at 08:45), use the following command:
INSERT INTO pgagent.pga_schedule (jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES((SELECT jobid
FROM pgagent.pga_job
WHERE jobname = 'MyJob'), 'MySchedule', '', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f}',
'{f,f,f,f,f,f,f,f,t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{t,t,t,t,t,t,t}', '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}',
'{t,t,t,t,t,t,t,t,t,t,t,t}', true, '2018-07-16 00:00:00', NULL);
Here a graphical representation of this schedule:
Here you can see a complete summary of these commands inside an anonymous block (generated by pgAdmin):
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'MyJob'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'MyStep'::text, true, 's'::character(1),
''::text, 'postgres'::name, 'f'::character(1),
'delete from test where user_name=''test'';'::text, ''::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'MySchedule'::text, ''::text, true,
'2018-07-16 00:00:00+02'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;

How to schedule timing for a JOB in Postgres using pgagent

I have created a job using pgagent which I have scheduled on every 5 mins for that below is the code:
DO $$
DECLARE
jid integer;
scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
1::integer, 'refresh_mobile'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;
-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
jstjobid, jstname, jstenabled, jstkind,
jstconnstr, jstdbname, jstonerror,
jstcode, jstdesc
) VALUES (
jid, 'refresh_mobile_mv_data'::text, true, 's'::character(1),
''::text, 'ICSPGD'::name, 'f'::character(1),
'SELECT refresh_materialized_views(''mobile'');'::text, 'Please check. Issue occired while refreshing Mobile Data'::text
) ;
-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
jscjobid, jscname, jscdesc, jscenabled,
jscstart, jscend, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
jid, 'minutly'::text, ''::text, true,
'2017-09-04 03:36:20-07'::timestamp with time zone, '2018-12-31 02:36:20-08'::timestamp with time zone,
-- Minutes
ARRAY[false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]::boolean[],
-- Hours
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Week days
ARRAY[true, true, true, true, true, true, true]::boolean[],
-- Month days
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]::boolean[],
-- Months
ARRAY[true, true, true, true, true, true, true, true, true, true, true, true]::boolean[]
) RETURNING jscid INTO scid;
END
$$;
But when I am checking its statistics(in pgadmin) or via query "select * from pgagent.pga_job;" it shows that job are running at an interval of 1 hour.
For example: If the last job run time is 2017-10-05 03:05:00.703287-07 , then the next run time it shows : 2017-10-05 04:05:00-07.
Kindly help with the timing parameter. I am suppose to run this job on an interval of every 5 mins on a daily basis throughout.
Regards,
Have you tried something like this?
INSERT INTO pgagent.pga_schedule
(jscid, jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)
VALUES(<SchId>, 29, 'minutly', '', '{t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', '{f,f,f,f,f,f,f,f,f,f,f,f}', true, '2017-10-07 00:00:00', NULL);
Basically, what this insert is doing is marking the minutes 0,5,10,15,20,25,30,35,40,45,50 and 55 for every hour.
I don't know why you're creating it using insert statements, since the GUI offers a pretty neat way to schedule jobs. The same configuration can be done using the GUI like this:
I hope it helps :-)