Skip to main content
added 4 characters in body; edited title
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

split Split point track based on time

theThe track_id is a non-sequential large intervals HEX number, so no issues on adding a few additional units (1 to 2 gaps per track) to it.

The actual location geom is irrelevant in the analysis, since the points in the gap can be close (time spent on the same position) or far apart (loose of reception).

tableTable example:

itIt copies the TRUE from chk_dif to chk_dif2, but not repeat the chk_dif2 on the next rows, has applicable.

toTo change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

theThe problem is on the second step, to copy the TRUE for the next rows, as applicable to the second part of the segment.

split point track based on time

the track_id is a non-sequential large intervals HEX number, so no issues on adding a few additional units (1 to 2 gaps per track) to it.

The actual location geom is irrelevant in the analysis, since the points in the gap can be close (time spent on same position) or far apart (loose of reception).

table example:

it copies the TRUE from chk_dif to chk_dif2, but not repeat the chk_dif2 on the next rows, has applicable.

to change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

the problem is on the second step, to copy the TRUE for the next rows, as applicable to the second part of the segment.

Split point track based on time

The track_id is a non-sequential large intervals HEX number, so no issues on adding a few additional units (1 to 2 gaps per track) to it.

The actual location geom is irrelevant in the analysis, since the points in the gap can be close (time spent on the same position) or far apart (loose of reception).

Table example:

It copies the TRUE from chk_dif to chk_dif2, but not repeat the chk_dif2 on the next rows, has applicable.

To change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

The problem is on the second step, to copy the TRUE for the next rows, as applicable to the second part of the segment.

added 256 characters in body
Source Link

to calculate time difference between rowsverify that time_dif is bigger than treshold:

SELECTUPDATE *,
CASEtable SET
   WHEN time-LAG(time) OVER chk_dif=(PARTITION BY track_id ORDER BY time)CASE >WHEN '00time_dif>'00:10' 
   THEN TRUE 
   END) AS chk_diff

to populate tehthe row after the true : but seems notnot working

SELECT *,
UPDATE table SET
chk_dif2=(CASE WHEN chk_diff=TRUEchk_dif=TRUE THEN TRUE
  ELSE             WHEN chk_dif IS NULL THEN (SELECT LAG(chk_dif2) OVER (PARTITION BY track_id ORDER BY time) END) 
 as chk_dif2             ELSE FALSE END)

it copies the TRUE from chk_dif to chk_dif2, but not repeat the chk_dif2 on the next rows, has applicable.

to change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

UPDATE table SET
new_track_id =
CASE WHEN chk_dif2=TRUE THEN CONCAT(LEFT(track_id,LENGTH(track_id)),'X') as new_track_idEND)

how to pass to inside a column?the problem is on the second step, to copy the TRUE for the next rows, as applicable to the second part of the segment.

to calculate time difference between rows

SELECT *,
CASE 
   WHEN time-LAG(time) OVER (PARTITION BY track_id ORDER BY time) > '00:10' 
   THEN TRUE 
   END) AS chk_diff

to populate teh row after the true : but seems not working

SELECT *,
  (CASE WHEN chk_diff=TRUE THEN TRUE
  ELSE LAG(chk_dif2) OVER (PARTITION BY track_id ORDER BY time) END) as chk_dif2

to change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

CONCAT(LEFT(track_id,LENGTH(track_id)),'X') as new_track_id

how to pass to inside a column?

to verify that time_dif is bigger than treshold:

UPDATE table SET
chk_dif=(CASE WHEN time_dif>'00:10' THEN TRUE END) 

to populate the row after the true : not working

UPDATE table SET
chk_dif2=(CASE WHEN chk_dif=TRUE THEN TRUE
               WHEN chk_dif IS NULL THEN (SELECT LAG(chk_dif2 OVER (PARTITION BY track_id ORDER BY time)) 
               ELSE FALSE END)

it copies the TRUE from chk_dif to chk_dif2, but not repeat the chk_dif2 on the next rows, has applicable.

to change the track_id (simplify for now, change the last digit to 'x' : is not more an HEX, and only allows for a gap) looking for better

UPDATE table SET
new_track_id =
CASE WHEN chk_dif2=TRUE THEN CONCAT(LEFT(track_id,LENGTH(track_id)),'X') END)

the problem is on the second step, to copy the TRUE for the next rows, as applicable to the second part of the segment.

deleted 12 characters in body
Source Link

create table public.testtime (id SERIAL primary key, track_id varchar, time1 time);

Test data:

create table public.testtime
        (id SERIAL primary key,
        track_id varchar,
        time1 time);

--Test data:

    insert into public.testtime (track_id, time1)
        values (123,    '10:01:00'),
               (123,    '10:02:00'),
               (123,    '10:05:00'),
               (123,    '10:45:00'),
               (123,    '10:47:00'),
               (123,    '10:49:00'),
               (234,    '10:52:00'),
               (234,    '10:55:00'),
               (234,    '10:58:00');
SELECT *,
 MAX(chk_diff) FROM table(CASE t2
WHEN WHEREchk_diff=TRUE t2.track_id=table.track_idTHEN ANDTRUE
    ELSE LAG(chk_dif2) OVER t2.time>(CASEPARTITION WHENBY chk_diff=TRUEtrack_id thenORDER table.BY time) END) as chk_dif2

EDIT2:

how to pass to inside a column?

create table public.testtime (id SERIAL primary key, track_id varchar, time1 time);

Test data:

insert into public.testtime (track_id, time1)
    values (123,    '10:01:00'),
           (123,    '10:02:00'),
           (123,    '10:05:00'),
           (123,    '10:45:00'),
           (123,    '10:47:00'),
           (123,    '10:49:00'),
           (234,    '10:52:00'),
           (234,    '10:55:00'),
           (234,    '10:58:00');
SELECT *,
 MAX(chk_diff) FROM table t2
 WHERE t2.track_id=table.track_id AND
       t2.time>(CASE WHEN chk_diff=TRUE then table.time END)
create table public.testtime
        (id SERIAL primary key,
        track_id varchar,
        time1 time);

--Test data:

    insert into public.testtime (track_id, time1)
        values (123,    '10:01:00'),
               (123,    '10:02:00'),
               (123,    '10:05:00'),
               (123,    '10:45:00'),
               (123,    '10:47:00'),
               (123,    '10:49:00'),
               (234,    '10:52:00'),
               (234,    '10:55:00'),
               (234,    '10:58:00');
SELECT *,
  (CASE WHEN chk_diff=TRUE THEN TRUE
  ELSE LAG(chk_dif2) OVER (PARTITION BY track_id ORDER BY time) END) as chk_dif2

EDIT2:

how to pass to inside a column?

added 224 characters in body
Source Link
Loading
added 224 characters in body
Source Link
Loading
added 436 characters in body
Source Link
Loading
added 427 characters in body
Source Link
Bera
  • 77.9k
  • 14
  • 78
  • 188
Loading
Source Link
Loading