← Back to Upcase

Insights based on user activity


(Charlieanna) #1

This is the bare bones method I wrote based on a flowchart.

def insights
    if signed_in?
      if user.slab == 1
        if user.current_activity.challenge.number_of_steps == 80000
          if day_of_challenge < 31 && activity_data < 5
            message = 0
          end
          if day_of_challenge < 31 && activity_data >= 5 && percent_completion < 50
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 5 && percent_completion > 50 && percent_completion < 80 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 5 && percent_completion > 80 && percent_completion < 100 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 5 && percent_completion > 100
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 10 && percent_completion < 50
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 10 && percent_completion > 50 && percent_completion < 80 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 10 && percent_completion > 80 && percent_completion < 100 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 10 && percent_completion > 100
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 15 && percent_completion < 50
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 15 && percent_completion > 50 && percent_completion < 80 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 15 && percent_completion > 80 && percent_completion < 100 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 15 && percent_completion > 100
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 20 && percent_completion < 50
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 20 && percent_completion > 50 && percent_completion < 80 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 20 && percent_completion > 80 && percent_completion < 100 
            message = 0
          end 
          if day_of_challenge < 31 && activity_data >= 20 && percent_completion > 100
            message = 0
          end 
           if day_of_challenge > 29 && percent_completion < 50
            message = 0
          end 
          if day_of_challenge > 29 && percent_completion > 50 && percent_completion < 80 
            message = 0
          end 
          if day_of_challenge  > 29 && percent_completion > 80 && percent_completion < 100 
            message = 0
          end 
          if day_of_challenge  > 29 && percent_completion > 100
            message = 0
          end 
        end
      end
    end

And this might have hundreds of if conditions. What is the best way to deal with this situation?

Thanks


(Ben Orenstein) #2

Can you talk a little more generally about what you’re trying to accomplish? Are there really hundreds of messages you may want to display for the user based on how they’re doing on a challenge?


(Charlieanna) #3

@benorenstein The user is first given a warm up for 7 days and we track his activities for a minimum of 4 data inputs. These are the steps he walks daily and the calories he burns based on the exercises he does. And then after 7 days, based on his activities we profile him in 5 slabs right now. And depending on his slab we assign him a new 30 day challenge with a target of steps he needs to wall the whole month. For example a user who is moderately active will come in profile 4 and given a target of 240000 steps in 30 days which 8k per day. And this profiling could be unlimited based on the other parameters we talk from him like calories burnt, his diet, other exercises he does which we cant track using a pedometer.

Now after the user has started the 30 day challenge, we need to show him relevant message according to what his challenge is, and what he has already done and based on that show him a message which itself is dynamic like “You are lagging behind behind by X steps and you can cover them by doing Y more minutes of walking everyday.”

So this is why I wrote that the number of messages could be many which I have no idea how many. That depends on the input from dieticians and personal trainers we have hired who will writing the messages for us. Is there way a way to extract all the dynamic business logic and rules engine outside and place it so that whenever there is a new rule we dont have to end up writing that in logic but maybe write the rules in an excel file?

Thanks