Permalink
Browse files

Set timezone to Europe/Paris for stats

  • Loading branch information...
Oumph authored and nono committed Apr 12, 2018
1 parent 6e81041 commit fe142ff55c6aa457dbee6e621b0e9c1765282829
@@ -36,7 +36,7 @@ def applications_by_year
return @applications_by_year if @applications_by_year
@applications_by_year = {}
entries = select_all("SELECT YEAR(oauth_applications.created_at) AS year, COUNT(*) AS cnt FROM oauth_applications GROUP BY year ORDER BY year")
entries = select_all("SELECT YEAR(CONVERT_TZ(oauth_applications.created_at, 'UTC', 'Europe/Paris')) AS year, COUNT(*) AS cnt FROM oauth_applications GROUP BY year ORDER BY year")
entries.each do |entry|
@applications_by_year[entry["year"]] = entry["cnt"]
end
@@ -48,7 +48,7 @@ def access_grants_by_year
return @access_grants_by_year if @access_grants_by_year
@access_grants_by_year = {}
entries = select_all("SELECT YEAR(oauth_access_grants.created_at) AS year, COUNT(*) AS cnt FROM oauth_access_grants GROUP BY year ORDER BY year")
entries = select_all("SELECT YEAR(CONVERT_TZ(oauth_access_grants.created_at, 'UTC', 'Europe/Paris')) AS year, COUNT(*) AS cnt FROM oauth_access_grants GROUP BY year ORDER BY year")
entries.each do |entry|
@access_grants_by_year[entry["year"]] = entry["cnt"]
end
@@ -60,7 +60,7 @@ def access_tokens_by_year
return @access_tokens_by_year if @access_tokens_by_year
@access_tokens_by_year = {}
entries = select_all("SELECT YEAR(oauth_access_tokens.created_at) AS year, IFNULL(revoked_at,now()+'1 year') < now() AS expired, COUNT(*) AS cnt FROM oauth_access_tokens GROUP BY year, expired ORDER BY year, expired")
entries = select_all("SELECT YEAR(CONVERT_TZ(oauth_access_tokens.created_at, 'UTC', 'Europe/Paris')) AS year, IFNULL(revoked_at,now()+'1 year') < now() AS expired, COUNT(*) AS cnt FROM oauth_access_tokens GROUP BY year, expired ORDER BY year, expired")
entries.each do |entry|
@access_tokens_by_year[entry["year"]] ||= {}
@access_tokens_by_year[entry["year"]][entry["expired"]] ||= 0
@@ -40,7 +40,7 @@ def contents_by_year
return @contents_by_year if @contents_by_year
@contents_by_year = {}
entries = select_all("SELECT YEAR(created_at) AS year, content_type, COUNT(*) AS cnt FROM nodes WHERE public=1 GROUP BY year, content_type ORDER BY year, content_type")
entries = select_all("SELECT YEAR(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')) AS year, content_type, COUNT(*) AS cnt FROM nodes WHERE public=1 GROUP BY year, content_type ORDER BY year, content_type")
entries.each do |entry|
@contents_by_year[entry["year"]] ||= {}
@contents_by_year[entry["year"]][entry["content_type"]] = entry["cnt"]
@@ -53,7 +53,7 @@ def contents_by_month
return @contents_by_month if @contents_by_month
@contents_by_month = {}
entries = select_all("SELECT CONCAT(SUBSTRING(created_at+0,1,6)) AS month, content_type, COUNT(*) AS cnt FROM nodes WHERE created_at > DATE_SUB(DATE_SUB(CURDATE(),INTERVAL 1 YEAR), INTERVAL DAY(CURDATE())-1 DAY) AND public=1 GROUP BY month, content_type ORDER BY month ASC, content_type")
entries = select_all("SELECT CONCAT(SUBSTRING(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')+0,1,6)) AS month, content_type, COUNT(*) AS cnt FROM nodes WHERE created_at > DATE_SUB(DATE_SUB(CURDATE(),INTERVAL 1 YEAR), INTERVAL DAY(CURDATE())-1 DAY) AND public=1 GROUP BY month, content_type ORDER BY month ASC, content_type")
entries.each do |entry|
@contents_by_month[entry["month"]] ||= {}
@contents_by_month[entry["month"]][entry["content_type"]] = entry["cnt"]
@@ -63,18 +63,18 @@ def contents_by_month
end
def contents_by_day
select_all "SELECT DAYNAME(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS d, WEEKDAY(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS day, COUNT(*) AS cnt FROM nodes WHERE public=1 GROUP BY d ORDER BY day ASC"
select_all "SELECT DAYNAME(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')) AS d, WEEKDAY(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')) AS day, COUNT(*) AS cnt FROM nodes WHERE public=1 GROUP BY d ORDER BY day ASC"
end
def news_size
select_all "SELECT YEAR(created_at) AS year,ROUND(AVG(LENGTH(body)+LENGTH(second_part))) AS cnt FROM news WHERE state='published' GROUP BY year ORDER BY year"
select_all "SELECT YEAR(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')) AS year,ROUND(AVG(LENGTH(body)+LENGTH(second_part))) AS cnt FROM news WHERE state='published' GROUP BY year ORDER BY year"
end
def contents_by_license
return @contents_by_license if @contents_by_license
@contents_by_license = {}
entries = select_all "SELECT YEAR(created_at) AS year, content_type, ROUND(AVG(100*cc_licensed)) AS pct FROM nodes WHERE (content_type='News' OR content_type='Diary') AND public=1 GROUP BY year, content_type HAVING (year>=2010 AND pct>0) ORDER BY year, content_type;"
entries = select_all "SELECT YEAR(CONVERT_TZ(created_at, 'UTC', 'Europe/Paris')) AS year, content_type, ROUND(AVG(100*cc_licensed)) AS pct FROM nodes WHERE (content_type='News' OR content_type='Diary') AND public=1 GROUP BY year, content_type HAVING (year>=2010 AND pct>0) ORDER BY year, content_type;"
entries.each do |entry|
@contents_by_license[entry["year"]] ||= {}
@contents_by_license[entry["year"]][entry["content_type"]] = entry["pct"]
@@ -4,8 +4,8 @@ class Statistics::Moderation < Statistics::Statistics
def by_day
select_all <<-EOS
SELECT content_type AS type,
DAYNAME(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS d,
WEEKDAY(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS day,
DAYNAME(CONVERT_TZ(created_at,'UTC','Europe/Paris')) AS d,
WEEKDAY(CONVERT_TZ(created_at,'UTC','Europe/Paris')) AS day,
COUNT(*) AS cnt
FROM nodes
WHERE (content_type='News' or content_type='Poll') AND public=1
@@ -30,12 +30,12 @@ def acts_by_year
end
def acts_by_year_and_log(log)
select_all("SELECT YEAR(created_at) AS year, COUNT(*) AS cnt FROM logs WHERE description LIKE '%#{log}%' GROUP BY year ORDER BY year;")
select_all("SELECT YEAR(CONVERT_TZ(created_at,'UTC','Europe/Paris')) AS year, COUNT(*) AS cnt FROM logs WHERE description LIKE '%#{log}%' GROUP BY year ORDER BY year;")
end
def average_time
select_all <<-EOS
SELECT YEAR(CONVERT_TZ(nodes.created_at,'+00:00','Europe/Paris')) AS year,
SELECT YEAR(CONVERT_TZ(nodes.created_at,'UTC','Europe/Paris')) AS year,
COUNT(*) AS cnt,
SUM(TIMESTAMPDIFF(SECOND,news.created_at,nodes.created_at)) AS duration,
STD(TIMESTAMPDIFF(SECOND,news.created_at,nodes.created_at)) AS std,
@@ -51,7 +51,7 @@ def average_time
end
def median_time(year, count, percentile)
count("SELECT TIMESTAMPDIFF(SECOND,news.created_at,nodes.created_at) AS duration FROM nodes, news WHERE nodes.content_id = news.id AND nodes.content_type='News' AND YEAR(CONVERT_TZ(nodes.created_at,'+00:00','Europe/Paris'))='#{year}' ORDER BY duration LIMIT #{(count*percentile).to_i},1;", "duration")
count("SELECT TIMESTAMPDIFF(SECOND,news.created_at,nodes.created_at) AS duration FROM nodes, news WHERE nodes.content_id = news.id AND nodes.content_type='News' AND YEAR(CONVERT_TZ(nodes.created_at,'UTC','Europe/Paris'))='#{year}' ORDER BY duration LIMIT #{(count*percentile).to_i},1;", "duration")
end
def top_amr(sql_criterion="")
@@ -105,15 +105,15 @@ def last_news_at(user_id)
def news_by_week(user_id)
select_all <<-EOS
SELECT COUNT(news.created_at) AS cnt, WEEK(now(),3) AS weeks FROM news,nodes WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(news.created_at)=YEAR(now()) AND user_id=#{user_id};
SELECT COUNT(news.created_at) AS cnt, WEEK(now(),3) AS weeks FROM news,nodes WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(CONVERT_TZ(news.created_at,'UTC','Europe/Paris'))=YEAR(now()) AND user_id=#{user_id};
EOS
end
def news_by_day
count "SELECT COUNT(*) AS cnt FROM news,nodes WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(news.created_at)=YEAR(now());"
count "SELECT COUNT(*) AS cnt FROM news,nodes WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(CONVERT_TZ(news.created_at,'UTC','Europe/Paris'))=YEAR(now());"
end
def amr_news_by_day
count "SELECT COUNT(*) AS cnt FROM news,nodes,accounts WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(news.created_at)=YEAR(now()) AND accounts.user_id=nodes.user_id AND (accounts.role='moderator' OR accounts.role='admin');"
count "SELECT COUNT(*) AS cnt FROM news,nodes,accounts WHERE nodes.content_type='News' AND news.id=nodes.content_id AND state='published' AND YEAR(CONVERT_TZ(news.created_at,'UTC','Europe/Paris'))=YEAR(now()) AND accounts.user_id=nodes.user_id AND (accounts.role='moderator' OR accounts.role='admin');"
end
end
@@ -11,7 +11,7 @@ def initialize(month)
end
def current_month
@current_month ||= @month.beginning_of_month .. @month.next_month.beginning_of_month
@current_month ||= @month.in_time_zone('Europe/Paris').beginning_of_month .. @month.in_time_zone('Europe/Paris').next_month.beginning_of_month
end
def best_score(type, nb)
@@ -38,7 +38,7 @@ def taggings_by_year
return @taggings_by_year if @taggings_by_year
@taggings_by_year = {}
entries = select_all("SELECT YEAR(taggings.created_at) AS year, content_type, COUNT(*) AS cnt FROM taggings,nodes WHERE taggings.node_id=nodes.id GROUP BY year, content_type ORDER BY year, content_type")
entries = select_all("SELECT YEAR(CONVERT_TZ(taggings.created_at, 'UTC', 'Europe/Paris')) AS year, content_type, COUNT(*) AS cnt FROM taggings,nodes WHERE taggings.node_id=nodes.id GROUP BY year, content_type ORDER BY year, content_type")
entries.each do |entry|
@taggings_by_year[entry["year"]] ||= taggings_hash
@taggings_by_year[entry["year"]][entry["content_type"]] = entry["cnt"]
@@ -51,7 +51,7 @@ def taggings_by_month
return @taggings_by_month if @taggings_by_month
@taggings_by_month = {}
entries = select_all("SELECT CONCAT(SUBSTRING(taggings.created_at+0,1,6)) AS month, content_type, COUNT(*) AS cnt FROM taggings,nodes WHERE taggings.node_id=nodes.id AND taggings.created_at > DATE_SUB(DATE_SUB(CURDATE(),INTERVAL 1 YEAR), INTERVAL DAY(CURDATE())-1 DAY) GROUP BY month, content_type ORDER BY month ASC, content_type")
entries = select_all("SELECT CONCAT(SUBSTRING(CONVERT_TZ(taggings.created_at, 'UTC', 'Europe/Paris')+0,1,6)) AS month, content_type, COUNT(*) AS cnt FROM taggings,nodes WHERE taggings.node_id=nodes.id AND taggings.created_at > DATE_SUB(DATE_SUB(CURDATE(),INTERVAL 1 YEAR), INTERVAL DAY(CURDATE())-1 DAY) GROUP BY month, content_type ORDER BY month ASC, content_type")
entries.each do |entry|
@taggings_by_month[entry["month"]] ||= taggings_hash
@taggings_by_month[entry["month"]][entry["content_type"]] = entry["cnt"]
@@ -61,6 +61,6 @@ def taggings_by_month
end
def taggings_by_day
select_all "SELECT DAYNAME(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS d, WEEKDAY(CONVERT_TZ(created_at,'+00:00','Europe/Paris')) AS day, COUNT(*) AS cnt FROM taggings GROUP BY d ORDER BY day ASC"
select_all "SELECT DAYNAME(CONVERT_TZ(created_at,'UTC','Europe/Paris')) AS d, WEEKDAY(CONVERT_TZ(created_at,'UTC','Europe/Paris')) AS day, COUNT(*) AS cnt FROM taggings GROUP BY d ORDER BY day ASC"
end
end
@@ -37,7 +37,7 @@ def by_year
return @by_year if @by_year
@by_year = {}
entries = select_all("SELECT YEAR(trackers.created_at) AS year, state, COUNT(*) AS cnt FROM trackers, nodes WHERE nodes.content_id=trackers.id AND nodes.content_type='Tracker' AND public=1 GROUP BY year, state ORDER BY year, state")
entries = select_all("SELECT YEAR(CONVERT_TZ(trackers.created_at, 'UTC', 'Europe/Paris')) AS year, state, COUNT(*) AS cnt FROM trackers, nodes WHERE nodes.content_id=trackers.id AND nodes.content_type='Tracker' AND public=1 GROUP BY year, state ORDER BY year, state")
entries.each do |entry|
@by_year[entry["year"]] ||= { "opened" => 0, "fixed" => 0, "invalid" => 0 }
@by_year[entry["year"]][entry["state"]] = entry["cnt"]
@@ -50,7 +50,7 @@ def by_month
return @by_month if @by_month
@by_month = {}
entries = select_all("SELECT state, SUBSTRING(trackers.created_at+0,1,6) AS created, SUBSTRING(trackers.updated_at+0,1,6) AS updated FROM trackers, nodes WHERE nodes.content_id=trackers.id AND nodes.content_type='Tracker' AND public=1")
entries = select_all("SELECT state, SUBSTRING(CONVERT_TZ(trackers.created_at, 'UTC', 'Europe/Paris')+0,1,6) AS created, SUBSTRING(trackers.updated_at+0,1,6) AS updated FROM trackers, nodes WHERE nodes.content_id=trackers.id AND nodes.content_type='Tracker' AND public=1")
entries.each do |entry|
@by_month[entry["created"]] ||= {}
@by_month[entry["created"]]["opened"] ||= 0
@@ -84,7 +84,7 @@ def by_style
end
def by_year
select_all "SELECT YEAR(accounts.created_at) AS year, COUNT(*) AS cnt FROM accounts WHERE current_sign_in_at > DATE_SUB(CURDATE(),INTERVAL 90 DAY) AND role<>'inactive' GROUP BY year ORDER BY year ASC"
select_all "SELECT YEAR(CONVERT_TZ(accounts.created_at, 'UTC', 'Europe/Paris')) AS year, COUNT(*) AS cnt FROM accounts WHERE current_sign_in_at > DATE_SUB(CURDATE(),INTERVAL 90 DAY) AND role<>'inactive' GROUP BY year ORDER BY year ASC"
end
ACCOUNT_SLOT=5000

0 comments on commit fe142ff

Please sign in to comment.