diff --git a/app/assets/stylesheets/application/layout/_fitbit.sass b/app/assets/stylesheets/application/layout/_fitbit.sass deleted file mode 100644 index 3be3a7b..0000000 --- a/app/assets/stylesheets/application/layout/_fitbit.sass +++ /dev/null @@ -1,19 +0,0 @@ -.fitbit__download-button - width: 175px - margin-bottom: 10px - -.fitbit__download-text - font-size: 10px - -.fitbit__download-container - margin-top: 30px - -.fitbit__table - clear: both - margin-top: 30px - -.fitbit__form - margin: 30px 0 - -.fitbit__form-submit-button - margin-top: 20px diff --git a/app/controllers/fitbit_profiles_controller.rb b/app/controllers/fitbit_profiles_controller.rb deleted file mode 100644 index 25b29bd..0000000 --- a/app/controllers/fitbit_profiles_controller.rb +++ /dev/null @@ -1,138 +0,0 @@ -# frozen_string_literal: true -class FitbitProfilesController < ApplicationController - before_action :require_user, except: [:show, :index] - helper_method :sort_column, :sort_direction - - def index - @title = 'Listing all connected Fitbit accounts' - @fitbit_profiles = FitbitProfile - .includes(:user) - .order("#{sort_column} #{sort_direction}") - .paginate(page: params[:page], per_page: 15) - end - - def show - @fitbit_profile = FitbitProfile.find_by_id(params[:id]) || not_found - @title = 'Fitbit profile' - - #grab activity measures for graphs - if @fitbit_profile.activities - @activity = FitbitActivity - .where(fitbit_profile_id: @fitbit_profile.id) - .order(:date_logged) - @total_length = 0 # sum of all steps which are not 0 and not nil - - @total_floors = [] - @total_steps = [] - @floors = [] - @steps = [] - @floor_counter = 0 - @step_counter = 0 - - @activity.each do |a| - # Sometimes, floors is nil and not a number - API problem? - # Dismiss these entries - if a.steps.nil? or a.floors.nil? - next - end - - if a.steps != 0 - @total_length += 1 - end - - @total_floors << [a.date_logged, @floor_counter += a.floors] - @floors << [a.date_logged, a.floors] - @steps << [a.date_logged, a.steps] - @total_steps << [a.date_logged, @step_counter += a.steps] - end - - if not @total_steps.empty? - begin - @mean_steps = @total_steps[-1][-1] / @total_length #@activity.length - rescue - end - end - end - - #grab body measurements for graphs - if @fitbit_profile.body - @body = FitbitBody - .where(fitbit_profile_id: @fitbit_profile.id) - .order(:date_logged) - @bmi = @body.map {|fa| [fa.date_logged, fa.bmi]} - end - - #grab sleep measurements for graphs - if @fitbit_profile.sleep - @sleep = FitbitSleep - .where(fitbit_profile_id: @fitbit_profile.id) - .order(:date_logged) - - @total_minutes_asleep = [] - @total_minutes_to_sleep = [] - @minutes_asleep = [] - @minutes_to_sleep = [] - @awakenings = [] - @total_to_sleep_counter = 0 - @total_asleep_counter = 0 - @no_sleep = 0 - - @sleep.each do |s| - # Here again, some have nils - # Skip these - if s.minutes_to_sleep.nil? or s.minutes_asleep.nil? - next - end - - if s.minutes_asleep == 0 - @no_sleep += 1 - end - - @total_minutes_to_sleep << [s.date_logged, @total_to_sleep_counter += s.minutes_to_sleep] - @total_minutes_asleep << [s.date_logged, @total_asleep_counter += s.minutes_asleep] - @minutes_asleep << [s.date_logged, s.minutes_asleep] - @minutes_to_sleep << [s.date_logged, s.minutes_to_sleep] - @awakenings << [s.date_logged, s.number_awakenings] - end - - if not @total_minutes_asleep.empty? - begin - @mean_sleep = @total_minutes_asleep[-1][-1] / (@sleep.length - @no_sleep) - rescue - end - end - end - end - - def dump - @fitbit_profile = FitbitProfile.find_by_id(params[:id]) || not_found - FitbitDump.perform_async(@fitbit_profile.id,current_user.id) - end - - def info - end - - private - - def require_owner - unless current_user == FitbitProfile.find(params[:fitbit_profile][:id]).user.id - store_location - if current_user - return true - else - flash[:notice] = 'You need to be logged in' - redirect_to '/signin' - end - return false - end - end - - def sort_column - Genotype.column_names.include?(params[:sort]) ? params[:sort] : 'created_at' - end - - def sort_direction - %w[desc asc].include?(params[:direction]) ? params[:direction] : 'desc' - end - -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 32751cc..3f8f3af 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -127,7 +127,7 @@ class UsersController < ApplicationController @user = User.find(params[:id]) if params[:user][:user_phenotypes_attributes].present? - params[:user][:user_phenotypes_attributes].each do |p| + params[:user][:user_phenotypes_attributes].each do |p| @phenotype = UserPhenotype.find(p[1]["id"]).phenotype @old_variation = UserPhenotype.find_by_id(p[1]["id"]).variation end @@ -186,10 +186,6 @@ class UsersController < ApplicationController flash[:notice] = 'Thank you for using openSNP. Goodbye!' - # disconnect from fitbit if needed - if @user.fitbit_profile != nil - Sidekiq::Client.enqueue(FitbitEndSubscription, @user.fitbit_profile.id) - end @user.destroy diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index a29fc63..527f537 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -114,13 +114,6 @@ class UserMailer < ActionMailer::Base mail(subject: 'openSNP.org: Sorry, there is no data to be dumped', to: target_address) end - def fitbit_dump(link, user_id) - @link = link - @user = User.find(user_id) - mail(subject: 'openSNP.org: The Fitbit-data you requested is now ready for download', - to: @user.email) - end - def finished_parsing(genotype_id, stats) genotype = Genotype.find(genotype_id) @user = genotype.user diff --git a/app/models/fitbit_activity.rb b/app/models/fitbit_activity.rb deleted file mode 100644 index 786bae2..0000000 --- a/app/models/fitbit_activity.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -class FitbitActivity < ActiveRecord::Base - belongs_to :fitbit_profile - - def self.find_or_create_by_fitbit_profile_id_and_date_logged(fitbit_profile_id, date_logged) - obj = self.find_by_fitbit_profile_id_and_date_logged( fitbit_profile_id, date_logged ) || self.new(fitbit_profile_id: fitbit_profile_id, date_logged: date_logged) - obj - end - -end \ No newline at end of file diff --git a/app/models/fitbit_body.rb b/app/models/fitbit_body.rb deleted file mode 100644 index 3b4d4f6..0000000 --- a/app/models/fitbit_body.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -class FitbitBody < ActiveRecord::Base - belongs_to :fitbit_profile - - def self.find_or_create_by_fitbit_profile_id_and_date_logged(fitbit_profile_id, date_logged) - obj = self.find_by_fitbit_profile_id_and_date_logged( fitbit_profile_id, date_logged ) || self.new(fitbit_profile_id: fitbit_profile_id, date_logged: date_logged) - obj - end - -end \ No newline at end of file diff --git a/app/models/fitbit_profile.rb b/app/models/fitbit_profile.rb deleted file mode 100644 index ea98cc1..0000000 --- a/app/models/fitbit_profile.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true -class FitbitProfile < ActiveRecord::Base - belongs_to :user - has_many :fitbit_bodies, dependent: :destroy - has_many :fitbit_activities, dependent: :destroy - has_many :fitbit_sleeps, dependent: :destroy -end \ No newline at end of file diff --git a/app/models/fitbit_sleep.rb b/app/models/fitbit_sleep.rb deleted file mode 100644 index 4ecf6e6..0000000 --- a/app/models/fitbit_sleep.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -class FitbitSleep < ActiveRecord::Base - belongs_to :fitbit_profile - - def self.find_or_create_by_fitbit_profile_id_and_date_logged(fitbit_profile_id, date_logged) - obj = self.find_by_fitbit_profile_id_and_date_logged( fitbit_profile_id, date_logged ) || self.new(fitbit_profile_id: fitbit_profile_id, date_logged: date_logged) - obj - end - -end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index cb2c282..001d762 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,7 +35,6 @@ class User < ActiveRecord::Base has_many :snp_comments # these shouldn't be deleted, but orphaned has_many :phenotype_comments, dependent: :destroy has_many :picture_phenotype_comments, dependent: :destroy - has_one :fitbit_profile, dependent: :destroy has_one :open_humans_profile, dependent: :destroy # needed to edit several user_phenotypes at once, add and delete, and not empty diff --git a/app/views/fitbit_profiles/index.html.erb b/app/views/fitbit_profiles/index.html.erb deleted file mode 100644 index 12bd6a7..0000000 --- a/app/views/fitbit_profiles/index.html.erb +++ /dev/null @@ -1,43 +0,0 @@ -
Includes all genotyping files plus a CSV with all phenotypes of those users
-| User | -# | -<%= sortable "fitbit_user_id", "Fitbit ID"%> | -<%= sortable "activities", "Shares Activities"%> | -<%= sortable "body", "Shares Body Data"%> | -<%= sortable "sleep", "Shares Sleep Data"%> | -View Profile | -
|---|---|---|---|---|---|---|
| <%= link_to(image_tag(fitbit_profile.user.avatar.url(:head), :class => "img-circle", :width => "50px") + " #{fitbit_profile.user.name}", fitbit_profile.user) %> | -<%= table_row_sequence_number(@fitbit_profiles, i) %> | -<%= link_to(fitbit_profile.fitbit_user_id, {:controller => "fitbit_profiles", :action => "show", :id => fitbit_profile.id}) %> | -<%if fitbit_profile.activities == true%><%else%><%end%> | -<%if fitbit_profile.body == true%><%else%><%end%> | -<%if fitbit_profile.sleep == true%><%else%><%end%> | -<%= link_to("View", {:controller => "fitbit_profiles", :action => "show", :id => fitbit_profile.id}, class: "btn btn-default")%> | -
<%=link_to("Download dump",{:controller => "fitbit_profiles", :action => "dump", :id => @fitbit_profile.id}, class: "btn btn-default")%>
- <%else%> -If you log in to openSNP, you can download a CSV file with all the data.
- <%end%> - - <%if @activity != nil%> - - - - -<%end%> - -<%if @body and @body != [] %> - - - -<%end%> - -<%if @sleep and @sleep != [] %> - - - - -<%end%> - -- Fitbit is a wearable gadget which allows you to track your activities (How many steps have you taken? How many floors have you climbed?) and your sleep (How long did you sleep? How often have you awoken at night?). The tracker displays this information on the Fitbit website and calculates how efficient you sleep and many calories you have burned. Their website also allows you to track your body-development (i.e. your weight/BMI) and how much food you have eaten. -
-
- If you connect your Fitbit account with openSNP we will save data for up to three different categories: Activities, Body and Sleep. In the activity category we will save your step-count and the number of floors you've climbed for each day. For the body category we will save your Body Mass Index and your weight for each day. In the sleep category we will save how many minutes you have slept, how many minutes you were awake while you tried to sleep, how long it took you to fall asleep and the number of times you awoke for each night.
If you connect your Fitbit account we will also save as much data of past days as it's possible to get through the API of Fitbit. This data is as public as are the genotyping datasets or all standard phenotypes which are entered into openSNP. So please be sure you want the world to be able to see this data.
-
- Yes, you can choose which for which categories we should save the data. For example you can share our activity-data, so people can see the number of steps you have taken for each day, along with the floors you have climbed, but keep your body and sleep data on FitBit.Two things you should keep in mind: You can (de)activate the saving of data for different categories at any time.
1. If you deactivate a category we will delete all of your data of this category from openSNP (but of course not on Fitbit).
2. If activate a category we will try to save as many data from the past as possible. So if there is past data you don't want to share you probably should not activate it (or delete the data from Fitbit).
-
- No, if you connect your Fitbit account with openSNP we only have read-access. The read-access gives us access to all data you have in your Fitbit account, but we will only read and save the data for which you have given us permission. We're sorry that you have to trust us in this point but the Fitbit API currently doesn't allow for a more granular setting. -
-- Yes, once your Fitbit account is connected and set up we will get an notification from Fitbit each time you enter or change any data in their system. So each time your tracker uploads new data to Fitbit we will get those changes as well. This also works for past records. So if you change or delete entries on the Fitbit website those changes will be reflected on openSNP as well. -
-- the Fitbit data you requested for - "> - download from openSNP is now available as a CSV (Comma-separated value) file. - -
-- Have fun with it! -
diff --git a/app/views/user_mailer/fitbit_dump.text.erb b/app/views/user_mailer/fitbit_dump.text.erb deleted file mode 100644 index a675b80..0000000 --- a/app/views/user_mailer/fitbit_dump.text.erb +++ /dev/null @@ -1,4 +0,0 @@ -the Fitbit data you requested for download from openSNP is now available as a -CSV (Comma-separated value) file. To download them just visit: - -<%="http://"+ActionMailer::Base.default_url_options[:host]+@link%> diff --git a/app/views/users/_user_is_not_user.html.erb b/app/views/users/_user_is_not_user.html.erb index cc5f1c9..413f4d0 100644 --- a/app/views/users/_user_is_not_user.html.erb +++ b/app/views/users/_user_is_not_user.html.erb @@ -3,9 +3,6 @@ <%= image_tag @user.avatar.url(:thumb), class: "hidden-xs pull-left userpage__profile-picture"%>