Last active
March 2, 2020 22:43
-
-
Save mbauman/36a6f6fe472c045871157dce49aac6c3 to your computer and use it in GitHub Desktop.
Cumulative discourse stats
This file contains 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
using HTTP, JSON, DataFrames, Dates, CSV | |
function cumulative(dates) | |
start_date = Dates.format(minimum(dates)-step(dates), "YYYY-mm-dd") | |
end_date = Dates.format(maximum(dates), "YYYY-mm-dd") | |
colnames = [] | |
cols = [] | |
for report in ("signups", "posts", "likes", "page_view_total_reqs", "topics") | |
r = HTTP.get("https://discourse.julialang.org/admin/reports/$report.json?end_date=$end_date&start_date=$start_date", | |
["Api-Key"=> ENV["JULIA_DISCOURSE_API_KEY"], "Api-Username"=> ENV["JULIA_DISCOURSE_USERNAME"]]) | |
d = JSON.parse(String(r.body)) | |
xs = Date.(getindex.(d["report"]["data"], "x"))::Vector{Date} | |
ys = Int.(getindex.(d["report"]["data"], "y"))::Vector{Int} | |
push!(colnames, report) | |
push!(cols, vec(sum(ys .* (xs .< reshape(dates, 1, :)), dims=1))) | |
end | |
return DataFrame(; date=dates, (Symbol.(colnames) .=> cols)...) | |
end | |
stats = cumulative(Date(2016, 10, 1):Month(1):Date(now())) | |
if isempty(ARGS) | |
CSV.write(stdout, stats) | |
else | |
open(x->CSV.write(x, stats), ARGS[1], "w") | |
end | |
stats |
This file contains 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
# This file is machine-generated - editing it directly is not advised | |
[[Base64]] | |
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | |
[[BinaryProvider]] | |
deps = ["Libdl", "Logging", "SHA"] | |
git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648" | |
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" | |
version = "0.5.6" | |
[[CSV]] | |
deps = ["CategoricalArrays", "DataFrames", "Dates", "Mmap", "Parsers", "PooledArrays", "Profile", "Tables", "Unicode", "WeakRefStrings"] | |
git-tree-sha1 = "35205137ee2f5a9c1f358407e9ed0f1a17878919" | |
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | |
version = "0.5.11" | |
[[CategoricalArrays]] | |
deps = ["Compat", "DataAPI", "Future", "JSON", "Missings", "Printf", "Reexport"] | |
git-tree-sha1 = "13240cfcc884837fc1aa89b60d500a652bcc3f10" | |
uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" | |
version = "0.5.5" | |
[[Compat]] | |
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] | |
git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f" | |
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" | |
version = "2.1.0" | |
[[DataAPI]] | |
git-tree-sha1 = "8903f0219d3472543fc4b2f5ebaf675a07f817c0" | |
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" | |
version = "1.0.1" | |
[[DataFrames]] | |
deps = ["CategoricalArrays", "Compat", "DataAPI", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] | |
git-tree-sha1 = "934b75a90b6cb315f9ea0df961768a02c1da1612" | |
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | |
version = "0.19.3" | |
[[DataStructures]] | |
deps = ["InteractiveUtils", "OrderedCollections"] | |
git-tree-sha1 = "0809951a1774dc724da22d26e4289bbaab77809a" | |
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | |
version = "0.17.0" | |
[[DataValueInterfaces]] | |
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" | |
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" | |
version = "1.0.0" | |
[[Dates]] | |
deps = ["Printf"] | |
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" | |
[[DelimitedFiles]] | |
deps = ["Mmap"] | |
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" | |
[[Distributed]] | |
deps = ["Random", "Serialization", "Sockets"] | |
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" | |
[[Future]] | |
deps = ["Random"] | |
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" | |
[[HTTP]] | |
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] | |
git-tree-sha1 = "c4a527dba1d26add0e85946e1a53f42a1b343acc" | |
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" | |
version = "0.8.5" | |
[[IniFile]] | |
deps = ["Test"] | |
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" | |
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" | |
version = "0.5.0" | |
[[InteractiveUtils]] | |
deps = ["Markdown"] | |
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | |
[[InvertedIndices]] | |
deps = ["Test"] | |
git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc" | |
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" | |
version = "1.0.0" | |
[[IteratorInterfaceExtensions]] | |
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" | |
uuid = "82899510-4779-5014-852e-03e436cf321d" | |
version = "1.0.0" | |
[[JSON]] | |
deps = ["Dates", "Mmap", "Parsers", "Unicode"] | |
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" | |
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" | |
version = "0.21.0" | |
[[LibGit2]] | |
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" | |
[[Libdl]] | |
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | |
[[LinearAlgebra]] | |
deps = ["Libdl"] | |
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | |
[[Logging]] | |
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | |
[[Markdown]] | |
deps = ["Base64"] | |
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | |
[[MbedTLS]] | |
deps = ["BinaryProvider", "Dates", "Libdl", "Random", "Sockets"] | |
git-tree-sha1 = "85f5947b53c8cfd53ccfa3f4abae31faa22c2181" | |
uuid = "739be429-bea8-5141-9913-cc70e7f3736d" | |
version = "0.7.0" | |
[[Missings]] | |
git-tree-sha1 = "29858ce6c8ae629cf2d733bffa329619a1c843d0" | |
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" | |
version = "0.4.2" | |
[[Mmap]] | |
uuid = "a63ad114-7e13-5084-954f-fe012c677804" | |
[[OrderedCollections]] | |
deps = ["Random", "Serialization", "Test"] | |
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" | |
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | |
version = "1.1.0" | |
[[Parsers]] | |
deps = ["Dates", "Test"] | |
git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" | |
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" | |
version = "0.3.7" | |
[[Pkg]] | |
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] | |
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | |
[[PooledArrays]] | |
git-tree-sha1 = "6e8c38927cb6e9ae144f7277c753714861b27d14" | |
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" | |
version = "0.5.2" | |
[[Printf]] | |
deps = ["Unicode"] | |
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | |
[[Profile]] | |
deps = ["Printf"] | |
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" | |
[[REPL]] | |
deps = ["InteractiveUtils", "Markdown", "Sockets"] | |
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" | |
[[Random]] | |
deps = ["Serialization"] | |
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | |
[[Reexport]] | |
deps = ["Pkg"] | |
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" | |
uuid = "189a3867-3050-52da-a836-e630ba90ab69" | |
version = "0.2.0" | |
[[SHA]] | |
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" | |
[[Serialization]] | |
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | |
[[SharedArrays]] | |
deps = ["Distributed", "Mmap", "Random", "Serialization"] | |
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" | |
[[Sockets]] | |
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" | |
[[SortingAlgorithms]] | |
deps = ["DataStructures", "Random", "Test"] | |
git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" | |
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" | |
version = "0.3.1" | |
[[SparseArrays]] | |
deps = ["LinearAlgebra", "Random"] | |
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | |
[[Statistics]] | |
deps = ["LinearAlgebra", "SparseArrays"] | |
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | |
[[TableTraits]] | |
deps = ["IteratorInterfaceExtensions"] | |
git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" | |
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" | |
version = "1.0.0" | |
[[Tables]] | |
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] | |
git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" | |
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" | |
version = "0.2.11" | |
[[Test]] | |
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] | |
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |
[[UUIDs]] | |
deps = ["Random", "SHA"] | |
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | |
[[Unicode]] | |
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" | |
[[WeakRefStrings]] | |
deps = ["Random", "Test"] | |
git-tree-sha1 = "9a0bb82eede528debe631b642eeb48a631a69bc2" | |
uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" | |
version = "0.6.1" |
This file contains 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
[deps] | |
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | |
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | |
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | |
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" | |
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment