Skip to content

Instantly share code, notes, and snippets.

@arsatiki
Created January 3, 2018 08:57
Show Gist options
  • Save arsatiki/e8e981adbfbb3970586c7a7e00c7df7c to your computer and use it in GitHub Desktop.
Save arsatiki/e8e981adbfbb3970586c7a7e00c7df7c to your computer and use it in GitHub Desktop.
Kansalaisaloitteiden seurantaskripti
ALOITE_ID=2730
RESOLUTION=300
(while true; do
curl -w "\n" -s https://www.kansalaisaloite.fi/api/v1/supports/$ALOITE_ID;
sleep $RESOLUTION;
done)|jq -rf total.jq
def as_hours: . * 3600|floor;
def esum($t_diff; $c_diff; $old_rate):
([$t_diff / 3600, 1]|min) as $w |
($c_diff / $t_diff) as $new_rate |
if $old_rate == 0 then $new_rate else $w * $new_rate + (1 - $w) * $old_rate end;
foreach inputs as $x (
{count: 0, timestamp: now};
{count: $x.supportCount,
timestamp: now,
rate: (if .count == 0
then 0
else esum(now - .timestamp; $x.supportCount - .count; .rate)
end)
};
"\(.timestamp|todate) \(.count) \(.rate|as_hours)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment