From f39b31519df32ac45adb4c5aced25ced27921b26 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sun, 2 Oct 2016 19:28:25 +0000 Subject: [PATCH] used and recent --- app/models/user.rb | 22 ++++++++++++++++++ app/views/shared/_metacodeoptions.html.erb | 26 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 4da66e57..4f679c1b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,6 +64,28 @@ class User < ApplicationRecord json['rtype'] = 'mapper' json end + + def recentMetacodes + array = [] + self.topics.sort{|a,b| b.created_at <=> a.created_at }.each do |t| + if array.length < 5 and array.index(t.metacode_id) == nil + array.push(t.metacode_id) + end + end + array + end + + def mostUsedMetacodes + self.topics.to_a.reduce({}) { |memo, topic| + if memo[topic.metacode_id] == nil + memo[topic.metacode_id] = 1 + else + memo[topic.metacode_id] = memo[topic.metacode_id] + 1 + end + + memo + }.to_a.sort{ |a, b| b[1] <=> a[1] }.map{|i| i[0]}.slice(0, 5) + end # generate a random 8 letter/digit code that they can use to invite people def generate_code diff --git a/app/views/shared/_metacodeoptions.html.erb b/app/views/shared/_metacodeoptions.html.erb index a6092c3e..637a42a3 100644 --- a/app/views/shared/_metacodeoptions.html.erb +++ b/app/views/shared/_metacodeoptions.html.erb @@ -5,6 +5,32 @@