Only record visit stats for now, need to rethink

This commit is contained in:
Kyle Drake 2015-06-17 16:29:57 -07:00
parent c9b4393dce
commit a9e142dee0
3 changed files with 40 additions and 32 deletions

View file

@ -85,6 +85,7 @@ class Stat < Sequel::Model
stat.id stat.id
].first ].first
=begin
site_log[:referrers].each do |referrer, views| site_log[:referrers].each do |referrer, views|
stat_referrer = StatReferrer.create_or_get site_log[:id], referrer stat_referrer = StatReferrer.create_or_get site_log[:id], referrer
DB['update stat_referrers set views=views+? where site_id=?', views, site_log[:id]].first DB['update stat_referrers set views=views+? where site_id=?', views, site_log[:id]].first
@ -101,6 +102,7 @@ class Stat < Sequel::Model
next if site_path.nil? next if site_path.nil?
DB['update stat_paths set views=views+? where id=?', views, site_path.id].first DB['update stat_paths set views=views+? where id=?', views, site_path.id].first
end end
=end
end end
end end

View file

@ -36,8 +36,8 @@ describe 'stats' do
Stat.parse_logfiles STAT_LOGS_PATH Stat.parse_logfiles STAT_LOGS_PATH
@site.stats.first.bandwidth.must_equal 612917*2 @site.stats.first.bandwidth.must_equal 612917*2
@site.stat_referrers.first.url.must_equal 'http://derp.com' #@site.stat_referrers.first.url.must_equal 'http://derp.com'
@site.stat_locations.first.city_name.must_equal 'Menlo Park' #@site.stat_locations.first.city_name.must_equal 'Menlo Park'
end end
it 'deals with spaces in referrer' do it 'deals with spaces in referrer' do
@ -112,23 +112,24 @@ describe 'stats' do
stat.hits.must_equal 4 stat.hits.must_equal 4
stat.views.must_equal 2 stat.views.must_equal 2
stat.bandwidth.must_equal 20_000 stat.bandwidth.must_equal 20_000
@site_one.stat_referrers.count.must_equal 1
stat_referrer = @site_one.stat_referrers.first
stat_referrer.url.must_equal 'http://example.com'
stat_referrer.created_at.must_equal @time.to_date
stat_referrer.views.must_equal 2
@site_one.stat_paths.length.must_equal 1 #@site_one.stat_referrers.count.must_equal 1
stat_path = @site_one.stat_paths.first #stat_referrer = @site_one.stat_referrers.first
stat_path.name.must_equal '/' #stat_referrer.url.must_equal 'http://example.com'
stat_path.views.must_equal 4 #stat_referrer.created_at.must_equal @time.to_date
#stat_referrer.views.must_equal 2
@site_one.stat_locations.length.must_equal 2 #@site_one.stat_paths.length.must_equal 1
stat_location = @site_one.stat_locations.first #stat_path = @site_one.stat_paths.first
stat_location.country_code2.must_equal 'US' #stat_path.name.must_equal '/'
stat_location.region_name.must_equal 'CA' #stat_path.views.must_equal 4
stat_location.city_name.must_equal 'Menlo Park'
stat_location.views.must_equal 1 #@site_one.stat_locations.length.must_equal 2
#stat_location = @site_one.stat_locations.first
#stat_location.country_code2.must_equal 'US'
#stat_location.region_name.must_equal 'CA'
#stat_location.city_name.must_equal 'Menlo Park'
#stat_location.views.must_equal 1
@site_two.reload @site_two.reload
@site_two.hits.must_equal 3 @site_two.hits.must_equal 3
@ -137,15 +138,15 @@ describe 'stats' do
stat.hits.must_equal 3 stat.hits.must_equal 3
stat.views.must_equal 3 stat.views.must_equal 3
stat.bandwidth.must_equal 15_000 stat.bandwidth.must_equal 15_000
@site_two.stat_referrers.count.must_equal 2 #@site_two.stat_referrers.count.must_equal 2
stat_referrer = @site_two.stat_referrers.first #stat_referrer = @site_two.stat_referrers.first
stat_referrer.url.must_equal 'http://example.com' #stat_referrer.url.must_equal 'http://example.com'
stat_referrer.views.must_equal 2 #stat_referrer.views.must_equal 2
stat_paths = @site_two.stat_paths #stat_paths = @site_two.stat_paths
stat_paths.length.must_equal 2 #stat_paths.length.must_equal 2
stat_paths.first.name.must_equal '/' #stat_paths.first.name.must_equal '/'
stat_paths.last.name.must_equal '/derp.html' #stat_paths.last.name.must_equal '/derp.html'
# [geoip.city('67.180.75.140'), geoip.city('172.56.16.152')] # [geoip.city('67.180.75.140'), geoip.city('172.56.16.152')]
end end

View file

@ -18,8 +18,10 @@
<div class="content misc-page columns right-col"> <div class="content misc-page columns right-col">
<div class="col-left"> <div class="col-left">
<div class="col col-66"> <div class="col col-66">
<!--
<div class="row"> <div class="row">
<div class="col col-100 globe"> <div class="col col-100 globe">
<div id="earth_div"></div> <div id="earth_div"></div>
</div> </div>
@ -130,8 +132,9 @@
</tbody> </tbody>
</table> </table>
</div> </div>
-->
</div> </div>
-->
<h2>Total Visitors <small>last 7 days</small></h2> <h2>Total Visitors <small>last 7 days</small></h2>
@ -151,6 +154,7 @@
<canvas id="myChart" style="width:100%;height:300px;display:block"></canvas> <canvas id="myChart" style="width:100%;height:300px;display:block"></canvas>
<!--
<div class="row"> <div class="row">
<div class="col col-50"> <div class="col col-50">
<h2>Top Paths <small>last 7 days</small></h2> <h2>Top Paths <small>last 7 days</small></h2>
@ -219,6 +223,7 @@
</div> </div>
<% end %> <% end %>
-->
</div> </div>
<div class="col col-33"> <div class="col col-33">
@ -250,11 +255,12 @@
</div> </div>
</div> </div>
<script src="//www.webglearth.com/v2/api.js"></script> <!-- <script src="//www.webglearth.com/v2/api.js"></script> -->
<script src="/js/Chart.min.js"></script> <script src="/js/Chart.min.js"></script>
<script> <script>
//OpenGL globe //OpenGL globe
$(document).ready(function() { $(document).ready(function() {
/*
var options = { var options = {
sky: true, sky: true,
atmosphere: false, atmosphere: false,
@ -267,11 +273,9 @@
var earth = new WE.map('earth_div', options) var earth = new WE.map('earth_div', options)
earth.setView([20, -100], 2.07) earth.setView([20, -100], 2.07)
/* // WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{ // attribution: '© OpenStreetMap'
attribution: '© OpenStreetMap' //}).addTo(earth);
}).addTo(earth);
*/
WE.tileLayer('http://data.webglearth.com/natural-earth-color/{z}/{x}/{y}.jpg', { WE.tileLayer('http://data.webglearth.com/natural-earth-color/{z}/{x}/{y}.jpg', {
tileSize: 256, tileSize: 256,
@ -298,6 +302,7 @@
earth.setCenter([c[0], c[1] + 0.1*(elapsed/30)]) earth.setCenter([c[0], c[1] + 0.1*(elapsed/30)])
requestAnimationFrame(animate) requestAnimationFrame(animate)
}); });
*/
//chart.js //chart.js
var data = { var data = {