mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
make the stats public, and cache
This commit is contained in:
parent
b7fe2ab8ee
commit
50bedaa442
5 changed files with 40 additions and 12 deletions
1
Gemfile
1
Gemfile
|
@ -25,6 +25,7 @@ gem 'dav4rack'
|
||||||
gem 'filesize'
|
gem 'filesize'
|
||||||
gem 'thread'
|
gem 'thread'
|
||||||
gem 'scrypt'
|
gem 'scrypt'
|
||||||
|
gem 'rack-cache'
|
||||||
|
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -122,6 +122,8 @@ GEM
|
||||||
puma (2.8.1)
|
puma (2.8.1)
|
||||||
rack (>= 1.1, < 2.0)
|
rack (>= 1.1, < 2.0)
|
||||||
rack (1.5.2)
|
rack (1.5.2)
|
||||||
|
rack-cache (1.2)
|
||||||
|
rack (>= 0.4)
|
||||||
rack-protection (1.5.2)
|
rack-protection (1.5.2)
|
||||||
rack
|
rack
|
||||||
rack-recaptcha (0.6.6)
|
rack-recaptcha (0.6.6)
|
||||||
|
@ -238,6 +240,7 @@ DEPENDENCIES
|
||||||
pry
|
pry
|
||||||
pry-byebug
|
pry-byebug
|
||||||
puma
|
puma
|
||||||
|
rack-cache
|
||||||
rack-recaptcha
|
rack-recaptcha
|
||||||
rack-test
|
rack-test
|
||||||
rack_session_access
|
rack_session_access
|
||||||
|
|
30
app/stats.rb
30
app/stats.rb
|
@ -1,5 +1,5 @@
|
||||||
get '/stats/?' do
|
get '/stats/?' do
|
||||||
require_admin
|
expires 14400, :public, :must_revalidate # 4 hours
|
||||||
|
|
||||||
@stats = {
|
@stats = {
|
||||||
total_sites: Site.count,
|
total_sites: Site.count,
|
||||||
|
@ -41,19 +41,29 @@ get '/stats/?' do
|
||||||
@stats[:total_recurring_revenue] = 0.0
|
@stats[:total_recurring_revenue] = 0.0
|
||||||
|
|
||||||
subscriptions = []
|
subscriptions = []
|
||||||
cancelled_subscriptions = 0
|
@stats[:cancelled_subscriptions] = 0
|
||||||
|
|
||||||
customers.each do |customer|
|
customers.each do |customer|
|
||||||
sub = {created_at: Time.at(customer.created)}
|
sub = {created_at: Time.at(customer.created)}
|
||||||
if customer[:subscriptions]
|
|
||||||
if customer[:subscriptions][:data].empty?
|
if customer[:subscriptions][:data].empty?
|
||||||
sub[:status] = 'cancelled'
|
@stats[:cancelled_subscriptions] += 1
|
||||||
else
|
next
|
||||||
sub[:status] = 'active'
|
|
||||||
sub[:amount] = (customer[:subscriptions][:data].first[:plan][:amount] / 100.0).round(2)
|
|
||||||
@stats[:total_recurring_revenue] += sub[:amount]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
next if customer[:subscriptions][:data].first[:plan][:amount] == 0
|
||||||
|
|
||||||
|
sub[:status] = 'active'
|
||||||
|
plan = customer[:subscriptions][:data].first[:plan]
|
||||||
|
|
||||||
|
sub[:amount] = (plan[:amount] / 100.0).round(2)
|
||||||
|
|
||||||
|
if(plan[:interval] == 'year')
|
||||||
|
sub[:amount] = (sub[:amount] / 12).round(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
@stats[:total_recurring_revenue] += sub[:amount]
|
||||||
|
|
||||||
subscriptions.push sub
|
subscriptions.push sub
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,14 @@ if defined?(Unicorn)
|
||||||
use Unicorn::PrereadInput
|
use Unicorn::PrereadInput
|
||||||
end
|
end
|
||||||
|
|
||||||
map('/') { run Sinatra::Application }
|
map('/') do
|
||||||
|
use(Rack::Cache,
|
||||||
|
verbose: false,
|
||||||
|
metastore: 'file:/tmp/neocitiesrackcache/meta',
|
||||||
|
entitystore: 'file:/tmp/neocitiesrackcache/body'
|
||||||
|
)
|
||||||
|
run Sinatra::Application
|
||||||
|
end
|
||||||
|
|
||||||
map '/webdav' do
|
map '/webdav' do
|
||||||
use Rack::Auth::Basic do |username, password|
|
use Rack::Auth::Basic do |username, password|
|
||||||
|
|
|
@ -69,7 +69,13 @@
|
||||||
|
|
||||||
<h2>Subscriptions</h2>
|
<h2>Subscriptions</h2>
|
||||||
<h3>Current Recurring Revenue: <strong><%= format("$%.2f", @stats[:total_recurring_revenue]) %> (<%= format("$%.2f", @stats[:total_recurring_revenue]/12.0) %>/month)</strong>
|
<h3>Current Recurring Revenue: <strong><%= format("$%.2f", @stats[:total_recurring_revenue]) %> (<%= format("$%.2f", @stats[:total_recurring_revenue]/12.0) %>/month)</strong>
|
||||||
<br>Active Subscriptions: <strong><%= @stats[:subscriptions].select {|s| s[:status] == 'active' }.length %></strong></h3>
|
<br>
|
||||||
|
Active Subscriptions: <strong><%= @stats[:subscriptions].select {|s| s[:status] == 'active' }.length %></strong>
|
||||||
|
<br>
|
||||||
|
Cancelled Subscriptions: <strong><%= @stats[:cancelled_subscriptions] %></strong>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<!--
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
|
@ -84,6 +90,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
-->
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
</article>
|
</article>
|
||||||
|
|
Loading…
Add table
Reference in a new issue