summaryrefslogtreecommitdiff
path: root/rushs/data-clash/step-3/napoleon_timeline.sql
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/data-clash/step-3/napoleon_timeline.sql
add: graphs et rushs
Diffstat (limited to 'rushs/data-clash/step-3/napoleon_timeline.sql')
-rw-r--r--rushs/data-clash/step-3/napoleon_timeline.sql85
1 files changed, 85 insertions, 0 deletions
diff --git a/rushs/data-clash/step-3/napoleon_timeline.sql b/rushs/data-clash/step-3/napoleon_timeline.sql
new file mode 100644
index 0000000..eff8be1
--- /dev/null
+++ b/rushs/data-clash/step-3/napoleon_timeline.sql
@@ -0,0 +1,85 @@
+WITH rapports_valides AS (
+ SELECT
+ id,
+ location,
+ start_time,
+ end_time,
+ latitude,
+ longitude
+ FROM napoleon_data.public_reports
+ WHERE location IS NOT NULL
+ AND start_time IS NOT NULL
+ AND end_time IS NOT NULL
+ AND latitude IS NOT NULL
+ AND longitude IS NOT NULL
+),
+rapports_ordonnes AS (
+ SELECT
+ id,
+ location,
+ start_time,
+ end_time,
+ latitude,
+ longitude,
+ LAG(id) OVER (ORDER BY start_time) AS pid,
+ LAG(location) OVER (ORDER BY start_time) AS ploc,
+ LAG(start_time) OVER (ORDER BY start_time) AS pstart,
+ LAG(end_time) OVER (ORDER BY start_time) AS pend,
+ LAG(latitude) OVER (ORDER BY start_time) AS plat,
+ LAG(longitude) OVER (ORDER BY start_time) AS plong
+ FROM rapports_valides
+),
+diffrapports AS (
+ SELECT
+ id,
+ location,
+ start_time,
+ end_time,
+ latitude,
+ longitude,
+ pid,
+ ploc,
+ pstart,
+ pend,
+ plat,
+ plong,
+ extract(EPOCH from (start_time - pend)) AS tdiff,
+ (6371 * ACOS(
+ COS(RADIANS(latitude)) * COS(RADIANS(plat))
+ * COS(RADIANS(plong) - RADIANS(longitude))
+ + SIN(RADIANS(latitude)) * SIN(RADIANS(plat))
+ )) AS d
+ FROM rapports_ordonnes
+),
+analyse_rapports AS (
+ SELECT
+ id,
+ location,
+ start_time,
+ end_time,
+ latitude,
+ longitude,
+ pid,
+ ploc,
+ pstart,
+ pend,
+ plat,
+ plong,
+ tdiff,
+ d,
+ CASE
+ WHEN start_time < pend THEN 'overlapping_timeframes'
+ WHEN tdiff < 7200 AND d > 500 THEN 'moving_fast'
+ WHEN extract(EPOCH from (end_time - start_time)) > 86400 THEN 'long_duration'
+ WHEN d IS NULL OR tdiff IS NULL THEN 'missing_data'
+ WHEN d > 500 THEN 'long_distance'
+ ELSE 'clear'
+ END AS issue
+ FROM diffrapports
+)
+SELECT
+ tdiff AS time_difference,
+ d AS distance,
+ issue
+FROM analyse_rapports
+ORDER BY start_time