From eb30967e4ef3d45946c3509a4300b2fd92aae822 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 24 Mar 2010 10:05:08 +0200 Subject: [PATCH] Statistic updated, e-mails and many others.. Moving to production mode. --- online/app/controllers/admin_controller.rb | 69 +++++++++++++++++++++++++++--- online/app/controllers/application.rb | 10 ++--- online/app/controllers/user_controller.rb | 37 ++++++++-------- online/app/views/admin/_form.html.erb | 9 ++-- online/app/views/admin/index.html.erb | 44 +++++-------------- online/app/views/admin/stat.html.erb | 26 +++++------ online/config/initializers/constants.rb | 9 ++-- online/config/online.yml | 7 +++ online/config/routes.rb | 2 +- 9 files changed, 126 insertions(+), 87 deletions(-) rewrite online/app/views/admin/index.html.erb (72%) create mode 100644 online/config/online.yml diff --git a/online/app/controllers/admin_controller.rb b/online/app/controllers/admin_controller.rb index 41fad87..d6b12b4 100644 --- a/online/app/controllers/admin_controller.rb +++ b/online/app/controllers/admin_controller.rb @@ -1,6 +1,5 @@ class AdminController < ApplicationController -#require 'csv' -#================== +require 'csv' #administration controller def convert_birthday_to_number(db_birthday) @@ -138,6 +137,7 @@ class AdminController < ApplicationController #deleting from facebook call-back function def fbdelete + p "deleting" if params[:fb_sig_user] @fbuser = User.find(:first ,:conditions => ["uid = ?", params[:fb_sig_user]]) unless @fbuser.blank? @@ -160,7 +160,7 @@ class AdminController < ApplicationController def stat #Date statistics - current_date = Date.new(2010,3,3) + current_date = Date.new(2010,3,16) today_now = Time.now today = Date.new(today_now.year,today_now.month,today_now.day) @date_range = (current_date..today).to_a @@ -175,10 +175,10 @@ class AdminController < ApplicationController @statistic.each {|stat| case stat[:action] - when INVITED_NUMBER - one_pack[INVITED_NUMBER]+= stat[:extra] - @total [INVITED_NUMBER]+=stat[:extra] - when PERMISSION, DELETED, INSTALLED, ANSWERED_1QUESTION, PHONE_GIVEN,ATTEMPT + when INVITED_NUMBER, PUBLISHED + one_pack[stat[:action]]+= stat[:extra] + @total [stat[:action]]+=stat[:extra] + when PERMISSION, DELETED, INSTALLED one_pack[ stat[:action]]+= 1 @total [stat[:action]]+=1 when VISITED @@ -207,5 +207,60 @@ class AdminController < ApplicationController @hour_deleted_statistic.push hour_deleted_number } end + + def statistic_to_csv + stat + @data_pack.reverse! + + @titles = "Date,Installations,Disabled Users,Published,FB ads,A ads,B ads,FB status,FB feed,I,II,III".split(",") + report = StringIO.new + CSV::Writer.generate(report, ',') do |title| + title << @titles + + @data_pack.each_with_index {|data, i| + title << [@date_range[i],data[PERMISSION],data[DELETED],data[PUBLISHED],data[SHIFT + FROM_FB_ADS],data[SHIFT + FROM_PLAY_ADS],data[SHIFT + FROM_PLAY_SITE],data[SHIFT + FROM_STATUS],data[SHIFT + FROM_FEEDS],data[SHIFT + FROM_NOTIFICATIONS],data[SHIFT + FROM_OTHER1],data[SHIFT + FROM_OTHER2]] + + } + end + report.rewind + + time_now = Time.now.to_formatted_s(:number) + file = File.open("#{RAILS_ROOT}/public/#{time_now}.csv", "wb") + file.write(report.read) + file.close + + redirect_to "/#{time_now}.csv" + #end of statistic_to_csv + end + + def export_table_to_csv + query_prepary(params[:query_type].to_i) + + columns = "first_name,last_name,created_at,birthday,gender,usermail,relation,hometown_location,networking,deleted,uid,current_location,affiliations,friends_published" + @results = User.find(:all,:select => columns, :conditions => [@query_string ,@query_params],:order => "created_at") + @titles = "First name,Last name,Permission date,Birthday,Gender,e-mail,Relation,Hometown location,Networks,If deleted,Facebook id,Current location,Affiliations,Published on walls,Age".split(",") + report = StringIO.new + CSV::Writer.generate(report, ',') do |title| + title << @titles + @titles = columns.split(",") + @results.each do |result| + + result[:birthday] = result[:birthday] + z = @titles.map { |a| result.send(a) } + age = result[:birthday] ? convert_birthday_to_number(result[:birthday]) : nil + z = z + [age] + title << z + end + end + report.rewind + + time_now = Time.now.to_formatted_s(:number) + file = File.open("#{RAILS_ROOT}/public/#{time_now}.csv", "wb") + file.write(report.read) + file.close + + redirect_to "/#{time_now}.csv" + #end of export_table_to_csv + end end diff --git a/online/app/controllers/application.rb b/online/app/controllers/application.rb index 265d2b6..653d000 100644 --- a/online/app/controllers/application.rb +++ b/online/app/controllers/application.rb @@ -48,12 +48,10 @@ class ApplicationController < ActionController::Base when DELETED debug_message ("STAT UPDATED: #{uid} deleted application") - when ANSWERED_1QUESTION - debug_message ("STAT UPDATED: #{uid} answered on question") - when ATTEMPT - debug_message ("STAT UPDATED: #{uid} tried to answer") - when PHONE_GIVEN - debug_message ("STAT UPDATED: #{uid} gave their code") + + when PUBLISHED + debug_message ("STAT UPDATED: #{uid} published #{extra} fields") + when VISITED case extra when FROM_FB_ADS diff --git a/online/app/controllers/user_controller.rb b/online/app/controllers/user_controller.rb index 95b91b6..a3ce95e 100644 --- a/online/app/controllers/user_controller.rb +++ b/online/app/controllers/user_controller.rb @@ -3,9 +3,6 @@ class UserController < ApplicationController ensure_application_is_installed_by_facebook_user before_filter :source_statistic before_filter :loading_static - FB_app_link = "http://apps.facebook.com/friendshipchallenge" - Promotion1 = "Take the Nokia E72 friendship challenge now to know your friends better and win up to 6 Nokia E72 devices." - Pic_link = "http://img.gsmarena.com/vv/bigpic/nokia-e72.jpg" Feed_action = "Know better your friends" @@ -39,6 +36,12 @@ class UserController < ApplicationController @userF = session[:facebook_session].user if @userF.has_permission?("publish_stream") && session[:facebook_session].user.has_permission?("email") @fbuser = User.find(:first, :conditions => ["uid = ?", @userF.uid]) + + if @fbuser && @fbuser.deleted + debug_message("User #{session[:facebook_session].user.uid} was already exist but he was in deleted status. So now he is totally deleted and will be added soon") + @fbuser.destroy + @fbuser = nil + end #if user does not exist yet in DB inserting in DB if @fbuser == nil #getting user info @@ -75,7 +78,9 @@ class UserController < ApplicationController :last_name => @userF.last_name, :status => "WAS NOT SET YET" , :hometown_location => (@userF.hometown_location != nil) ? @userF.hometown_location.country.to_s + "/"+ @userF.hometown_location.state.to_s + "/" + @userF.hometown_location.city.to_s : "", - :affiliations => @affiliation + :affiliations => @affiliation, + :usermail => @userF.email + } rescue debug_message("Cannot get information about #{session[:facebook_session].user.uid}",false) @@ -113,17 +118,14 @@ class UserController < ApplicationController @time_counter = Time.now @time_counter0 = Time.now today_question_select - user_has_published_once = false user_has_published_once = question_processor 1 if user_has_published_once == true - render :action => "greetings" - + render :action => "greetings" end p " > > >FULL TIME: #{Time.now - @time_counter0}" end - - + def question2 user_has_published_once = false user_has_published_once = question_processor 2 @@ -150,15 +152,11 @@ class UserController < ApplicationController users_array = [] session_new = Facebooker::Session.create for i in 0...6 - if params["friend_sel0#{i}"] != nil && params["friend_sel0#{i}"] != "" - # begin + if params["friend_sel0#{i}"] != nil && params["friend_sel0#{i}"] != "" @userFB2 =Facebooker::User.new(params["friend_sel0#{i}"], session_new) time_counter ("Creating one user") users_array << @userFB2 user_has_published_once = true - #return - #rescue - #debug_message("Cannot publish or some problems with getting info from FB",false) #end of if end #end of for @@ -249,7 +247,11 @@ class UserController < ApplicationController #end of for i in 0..users_array.size end - + @user_local.friends_published += (user_names.size + 1) + @user_local.save + + add_stat(0, PUBLISHED, user_names.size + 1) + new_params = Hash.new(0) new_params = { :user_from => @userFB, @@ -265,8 +267,7 @@ class UserController < ApplicationController end time_counter ("Session batch") - debug_message scenario_themself - #publishing(@userFB,@userFB,scenario_themself,Feed_action,FB_app_link,@today_question.feedtext1,FB_app_link,@today_question.feedtext2,'image',Current_site + @today_question.feedpic.url(:normal),FB_app_link) + debug_message scenario_themself # if user_has_published_once == true end return user_has_published_once @@ -283,8 +284,6 @@ class UserController < ApplicationController scenario_themself = "#{@userFB2.first_name}, I picked up #{params[:self_publishing]} as my top friends to win Nokia E72. Sorry I didn't pick you, but you can try your luck here." debug_message scenario_themself - #publishing(@userFB,@userFB,scenario_themself,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) - end redirect_to "http://facebook.com" end diff --git a/online/app/views/admin/_form.html.erb b/online/app/views/admin/_form.html.erb index 03e2eb4..991071f 100644 --- a/online/app/views/admin/_form.html.erb +++ b/online/app/views/admin/_form.html.erb @@ -5,8 +5,9 @@ First Name Second Name Permission Day - Last Set Status + Birthday + E-mail Age
<%= select_tag(:age, options_for_select(@selectParams, params[:age] || cookies[:age] || "0")) %> Gender
<%= select_tag(:gender, options_for_select([['all',0],['male','male'],['female','female'],['Undefined','Undefined']], params[:gender] || cookies[:gender] || 0) )%> @@ -14,7 +15,7 @@ Relationship Status
<%= select_tag(:relation, options_for_select([['all',0],['Single','Single'],['It\'s complicated','It\'s complicated'],['Engaged','Engaged'],['Married','Married'],['In an Open Relationship','In an Open Relationship'],['Undefined','Undefined']], params[:relation] || cookies[:relation] || 0)) %> Location Networks - + Feeds was published <% @fbusers.each_with_index do |fbuser, i| %> @@ -23,13 +24,14 @@ <%=h fbuser.first_name %> <%=h fbuser.last_name %> <%=h fbuser.created_at.to_date.to_formatted_s(:long_ordinal)%> - <%= fbuser.status %> <%= fbuser.birthday %> <%=h fbuser.birthday ? convert_birthday_to_number(fbuser.birthday) : nil %> + <%=h fbuser.usermail %> <%=h fbuser.gender %> <%=h fbuser.relation %> <%=h fbuser.hometown_location %> <%=h fbuser.affiliations %> + <%=h fbuser.friends_published %> <% end %> @@ -38,4 +40,5 @@
<%= submit_tag "Sort" %>
+&query_type=<%=@query_type%>" target='_blank'">Export To CSV... diff --git a/online/app/views/admin/index.html.erb b/online/app/views/admin/index.html.erb dissimilarity index 72% index 26c55e7..5030697 100644 --- a/online/app/views/admin/index.html.erb +++ b/online/app/views/admin/index.html.erb @@ -1,33 +1,11 @@ -
- -

Active Users

- - Total number of users: <%= @total_number %> users
- - <% form_tag({:controller => "admin", :action => "index"}, :method => "get") do %> - <%= render :partial => "form" %> - <% end %> -
-
- - - - <% form_tag({:controller => "admin", :action => "status_change"}, :method => "post") do %> - - - - <% end %> - -
- <%= label_tag(:new_status, "Set status") %> - - <%= text_area_tag(:new_status, nil, :rows => 4, :cols => 45) %> - - <%= submit_tag("Change Status") %> - <% if params[:gender] %> - <% params.each do |k, v| %> - - <% end %> - <% end %> -
-
+
+ +

Active Users

+ + Total number of users: <%= @total_number %> users
+ + <% form_tag({:controller => "admin", :action => "index"}, :method => "get") do %> + <%= render :partial => "form" %> + <% end %> + +
diff --git a/online/app/views/admin/stat.html.erb b/online/app/views/admin/stat.html.erb index 783c702..6784ac8 100644 --- a/online/app/views/admin/stat.html.erb +++ b/online/app/views/admin/stat.html.erb @@ -9,29 +9,27 @@ Date Installations - Status Permissions Disabled Users - Attempts - Right answers + Published feeds + FB ads A ads B ads FB status FB feed - Other0 - Other1 - Other2 + I + II + III Total - <%=@total[INSTALLED] %> + <%=@total[PERMISSION]%> <%=@total[DELETED]%> - <%=@total[ATTEMPT]%> - <%=@total[ANSWERED_1QUESTION]%> - + <%=@total[PUBLISHED]%> + <%=@total[SHIFT + FROM_FB_ADS ]%> <%=@total[SHIFT + FROM_PLAY_ADS]%> <%=@total[SHIFT + FROM_PLAY_SITE]%> @@ -44,13 +42,10 @@ <% @data_pack.each_with_index {|data, i| %> - <%=@date_range[@date_range.size-i -1] %> - <%=data[INSTALLED] %> + <%=@date_range[@date_range.size-i -1] %> <%=data[PERMISSION]%> <%=data[DELETED]%> - <%=data[ATTEMPT]%> - <%=data[ANSWERED_1QUESTION]%> - + <%=data[PUBLISHED]%> <%=data[SHIFT + FROM_FB_ADS ]%> <%=data[SHIFT + FROM_PLAY_ADS]%> @@ -63,6 +58,7 @@ <% }%> + Export To CSV...

Statistics by hour

diff --git a/online/config/initializers/constants.rb b/online/config/initializers/constants.rb index 2f121a0..ab6aa32 100644 --- a/online/config/initializers/constants.rb +++ b/online/config/initializers/constants.rb @@ -1,7 +1,9 @@ +c = YAML.load_file(File.join(Rails.root, "config", "online.yml")) +Jawaker_link = c[Rails.env]["current_site"] + FBlogin = "admin" FBpassword = "friendS33" - FROM_FB_ADS = 1 FROM_PLAY_ADS = 2 FROM_PLAY_SITE = 3 @@ -41,9 +43,10 @@ ANSWERED_1QUESTION = 2 DELETED = 3 INVITED_NUMBER = 4 VISITED = 5 -PHONE_GIVEN = 6 +PUBLISHED = 6 ATTEMPT = 7 -Current_site ="http://109.87.128.9:3000" +Current_site = c[Rails.env]["current_site"] +FB_app_link = c[Rails.env]["facebook_app"] Debug_message_on = true diff --git a/online/config/online.yml b/online/config/online.yml new file mode 100644 index 0000000..84d25b6 --- /dev/null +++ b/online/config/online.yml @@ -0,0 +1,7 @@ +development: + current_site: "http://test.levelup.com.ua:3000" + facebook_app: "http://apps.facebook.com/onlineprojecttest" +production: + current_site: "http://friends.levelup.com.ua:3000" + facebook_app: "http://apps.facebook.com/friendshipchallenge" + diff --git a/online/config/routes.rb b/online/config/routes.rb index 5b62573..3195331 100644 --- a/online/config/routes.rb +++ b/online/config/routes.rb @@ -48,7 +48,7 @@ ActionController::Routing::Routes.draw do |map| map.deleted '/deleted', :controller => 'admin', :action => 'deleted' map.stat '/stat', :controller => 'admin', :action => 'stat' map.signout '/signout', :controller => 'admin', :action => 'sign_out' - + map.fbdel '/fbdel', :controller => 'admin', :action => 'fbdelete' map.product '/product', :controller => 'user', :action => 'product' map.greetings '/greetings', :controller => 'user', :action => 'greetings' map.fanpage '/fanpage', :controller => 'user', :action => 'fanpage' -- 2.11.4.GIT