mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +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 'thread'
|
||||
gem 'scrypt'
|
||||
gem 'rack-cache'
|
||||
|
||||
platform :mri do
|
||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||
|
|
|
@ -122,6 +122,8 @@ GEM
|
|||
puma (2.8.1)
|
||||
rack (>= 1.1, < 2.0)
|
||||
rack (1.5.2)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-protection (1.5.2)
|
||||
rack
|
||||
rack-recaptcha (0.6.6)
|
||||
|
@ -238,6 +240,7 @@ DEPENDENCIES
|
|||
pry
|
||||
pry-byebug
|
||||
puma
|
||||
rack-cache
|
||||
rack-recaptcha
|
||||
rack-test
|
||||
rack_session_access
|
||||
|
|
30
app/stats.rb
30
app/stats.rb
|
@ -1,5 +1,5 @@
|
|||
get '/stats/?' do
|
||||
require_admin
|
||||
expires 14400, :public, :must_revalidate # 4 hours
|
||||
|
||||
@stats = {
|
||||
total_sites: Site.count,
|
||||
|
@ -41,19 +41,29 @@ get '/stats/?' do
|
|||
@stats[:total_recurring_revenue] = 0.0
|
||||
|
||||
subscriptions = []
|
||||
cancelled_subscriptions = 0
|
||||
@stats[:cancelled_subscriptions] = 0
|
||||
|
||||
customers.each do |customer|
|
||||
sub = {created_at: Time.at(customer.created)}
|
||||
if customer[:subscriptions]
|
||||
if customer[:subscriptions][:data].empty?
|
||||
sub[:status] = 'cancelled'
|
||||
else
|
||||
sub[:status] = 'active'
|
||||
sub[:amount] = (customer[:subscriptions][:data].first[:plan][:amount] / 100.0).round(2)
|
||||
@stats[:total_recurring_revenue] += sub[:amount]
|
||||
end
|
||||
|
||||
if customer[:subscriptions][:data].empty?
|
||||
@stats[:cancelled_subscriptions] += 1
|
||||
next
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,14 @@ if defined?(Unicorn)
|
|||
use Unicorn::PrereadInput
|
||||
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
|
||||
use Rack::Auth::Basic do |username, password|
|
||||
|
|
|
@ -69,7 +69,13 @@
|
|||
|
||||
<h2>Subscriptions</h2>
|
||||
<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">
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
|
@ -84,6 +90,7 @@
|
|||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
-->
|
||||
<p>
|
||||
</p>
|
||||
</article>
|
||||
|
|
Loading…
Add table
Reference in a new issue