Created
January 3, 2018 08:57
-
-
Save arsatiki/e8e981adbfbb3970586c7a7e00c7df7c to your computer and use it in GitHub Desktop.
Kansalaisaloitteiden seurantaskripti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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