Skip to content

Instantly share code, notes, and snippets.

@minkymorgan
Created September 26, 2014 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minkymorgan/1dde65b654bf1c07ade3 to your computer and use it in GitHub Desktop.
Save minkymorgan/1dde65b654bf1c07ade3 to your computer and use it in GitHub Desktop.
GDELT Event File - some BigQuery SQL that smooths the goldstein scale over the last 28 days.
select
end_SQLDATE as SQLDATE
, AVG_GoldsteinScale
from
(
SELECT
ending_at_day AS end_SQLDATE
, ROUND(AVG(SUMG),5) AS AVG_GoldsteinScale
, COUNT(DISTINCT SQLDATE) as C
FROM
(
SELECT
GoldsteinScale AS SUMG
, SQLDATE-i AS ending_at_day
, SQLDATE
FROM [gdelt-bq:full.events] g
CROSS JOIN
( SELECT i
FROM [fh-bigquery:public_dump.numbers_255]
WHERE i<28
) b
WHERE (Actor1CountryCode='UKR' OR Actor2CountryCode='RUS' OR ActionGeo_CountryCode='UKR') AND
(Actor1CountryCode='RUS' OR Actor2CountryCode='UKR' or ActionGeo_CountryCode='UKR')
) q
GROUP BY end_SQLDATE
HAVING C=28
) b
ORDER BY SQLDATE
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment