Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in the database when using the append function. #139

Open
ggilestro opened this issue Jan 2, 2021 · 1 comment
Open

Problem in the database when using the append function. #139

ggilestro opened this issue Jan 2, 2021 · 1 comment
Assignees

Comments

@ggilestro
Copy link
Member

Commit 7853b44 created an issue.
When data are appended to an existing database, the variable t restarts from 0 and that creates a wrong series in the column.

A workaround for existing databases is to open the db file and issue the following SQL:

UPDATE ROI_1 SET t = t + ( SELECT MAX(t) from ROI_1 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_1));
UPDATE ROI_2 SET t = t + ( SELECT MAX(t) from ROI_2 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_2)); 
UPDATE ROI_3 SET t = t + ( SELECT MAX(t) from ROI_3 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_3)); 
UPDATE ROI_4 SET t = t + ( SELECT MAX(t) from ROI_4 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_4)); 
UPDATE ROI_5 SET t = t + ( SELECT MAX(t) from ROI_5 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_5)); 
UPDATE ROI_6 SET t = t + ( SELECT MAX(t) from ROI_6 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_6)); 
UPDATE ROI_7 SET t = t + ( SELECT MAX(t) from ROI_7 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_7)); 
UPDATE ROI_8 SET t = t + ( SELECT MAX(t) from ROI_8 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_8)); 
UPDATE ROI_9 SET t = t + ( SELECT MAX(t) from ROI_9 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_9)); 
UPDATE ROI_10 SET t = t + ( SELECT MAX(t) from ROI_10 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_10)); 
UPDATE ROI_11 SET t = t + ( SELECT MAX(t) from ROI_11 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_11)); 
UPDATE ROI_12 SET t = t + ( SELECT MAX(t) from ROI_12 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_12)); 
UPDATE ROI_13 SET t = t + ( SELECT MAX(t) from ROI_13 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_13)); 
UPDATE ROI_14 SET t = t + ( SELECT MAX(t) from ROI_14 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_14)); 
UPDATE ROI_15 SET t = t + ( SELECT MAX(t) from ROI_15 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_15)); 
UPDATE ROI_16 SET t = t + ( SELECT MAX(t) from ROI_16 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_16)); 
UPDATE ROI_17 SET t = t + ( SELECT MAX(t) from ROI_17 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_17)); 
UPDATE ROI_18 SET t = t + ( SELECT MAX(t) from ROI_18 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_18)); 
UPDATE ROI_19 SET t = t + ( SELECT MAX(t) from ROI_19 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_19)); 
UPDATE ROI_20 SET t = t + ( SELECT MAX(t) from ROI_20 ) WHERE id > (SELECT id from (SELECT id, MAX(t) from ROI_20)); 

However, this needs to be fixed in the code by inheriting and maintaining the same t0 . We also need to add a new metadata table with a different name (such as metadata_1) rather than simply overwrite the content of the metadata table.

@ggilestro
Copy link
Member Author

The script above will not work if the t value is largest at the end of the experiment, for instance in cases like the one below.
image

What we need to identify is the first peak, which is the only point where id.t < id.t+1 with the following script:

SELECT t FROM (
	SELECT
		g1.id,
		g1.t,
		(g2.t - g1.t) as delta
	FROM
		ROI_1 g1
			INNER JOIN
		ROI_1 g2 on g2.id = g1.id + 1
	WHERE
		delta < 0
)

Which in one row becomes

UPDATE ROI_1 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_1 g1 INNER JOIN ROI_1 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_1 g1 INNER JOIN ROI_1 g2 on g2.id = g1.id + 1 WHERE delta < 0));

And this solves the issue
image

So the full sequence to use is the following:

UPDATE ROI_1 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_1 g1 INNER JOIN ROI_1 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_1 g1 INNER JOIN ROI_1 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_2 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_2 g1 INNER JOIN ROI_2 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_2 g1 INNER JOIN ROI_2 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_3 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_3 g1 INNER JOIN ROI_3 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_3 g1 INNER JOIN ROI_3 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_4 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_4 g1 INNER JOIN ROI_4 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_4 g1 INNER JOIN ROI_4 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_5 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_5 g1 INNER JOIN ROI_5 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_5 g1 INNER JOIN ROI_5 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_6 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_6 g1 INNER JOIN ROI_6 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_6 g1 INNER JOIN ROI_6 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_7 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_7 g1 INNER JOIN ROI_7 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_7 g1 INNER JOIN ROI_7 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_8 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_8 g1 INNER JOIN ROI_8 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_8 g1 INNER JOIN ROI_8 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_9 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_9 g1 INNER JOIN ROI_9 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_9 g1 INNER JOIN ROI_9 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_10 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_10 g1 INNER JOIN ROI_10 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_10 g1 INNER JOIN ROI_10 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_11 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_11 g1 INNER JOIN ROI_11 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_11 g1 INNER JOIN ROI_11 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_12 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_12 g1 INNER JOIN ROI_12 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_12 g1 INNER JOIN ROI_12 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_13 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_13 g1 INNER JOIN ROI_13 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_13 g1 INNER JOIN ROI_13 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_14 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_14 g1 INNER JOIN ROI_14 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_14 g1 INNER JOIN ROI_14 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_15 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_15 g1 INNER JOIN ROI_15 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_15 g1 INNER JOIN ROI_15 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_16 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_16 g1 INNER JOIN ROI_16 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_16 g1 INNER JOIN ROI_16 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_17 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_17 g1 INNER JOIN ROI_17 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_17 g1 INNER JOIN ROI_17 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_18 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_18 g1 INNER JOIN ROI_18 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_18 g1 INNER JOIN ROI_18 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_19 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_19 g1 INNER JOIN ROI_19 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_19 g1 INNER JOIN ROI_19 g2 on g2.id = g1.id + 1 WHERE delta < 0));
UPDATE ROI_20 SET t = t + (SELECT FIT from (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_20 g1 INNER JOIN ROI_20 g2 on g2.id = g1.id + 1 WHERE delta < 0)) WHERE id > (SELECT FID FROM (SELECT g1.id as FID, g1.t as FIT, (g2.t - g1.t) as delta FROM ROI_20 g1 INNER JOIN ROI_20 g2 on g2.id = g1.id + 1 WHERE delta < 0));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant