From 68b025edde418a2cbbe731ad7ee985fcfd67f812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C3=B1o=20Sempere?= Date: Tue, 7 Apr 2020 09:58:31 +0200 Subject: [PATCH] Add files via upload --- maths-prog/BDI.rb | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 maths-prog/BDI.rb diff --git a/maths-prog/BDI.rb b/maths-prog/BDI.rb new file mode 100644 index 0000000..a9ab59f --- /dev/null +++ b/maths-prog/BDI.rb @@ -0,0 +1,74 @@ +# Source: *Feeling Good* +# libgen: https://libgen.is/book/index.php?md5=C125D95C465F61F9D97A1F7A8709B82A +# page 49-50 of the pdf. + +# Note: to create a bash utility, add the following: +# alias bdi='ruby /home/nuno/Documents/Workspace/WEBDEV/RubyOnRails/BDI.rb' +# (or whatever the full path to this file is) +# to the end of your .bashrc file, +# which should be in your ~ (home) folder (check with ls -a) +# alias bdi='ruby /home/nuno/Documents/Workspace/WEBDEV/RubyOnRails/BDI.rb' + +questions = [ +"Feeling sad or down in the dumps", +"Feeling unhappy or blue", +"Crying spells or tearfulness", +"Feeling discouraged", +"Feeling hopeless", +"Low self-esteem", +"Feeling worthless or inadequate", +"Guilt or shame", +"Criticizing yourself or blaming yourself", +"Difficulty making decisions", +"Loss of interest in family, friends or colleagues", +"Loneliness", +"Spending less time with family or friends", +"Loss of motivation", +"Loss of interest in work or other activities", +"Avoiding work or other activities", +"Loss of pleasure or satisfaction in life", +"Feeling tired", +"Difficulty sleeping or sleeping too much", +"Decreased or increased appetite", +"Loss of interest in sex", +"Worrying about your health", +"Do you have any suicidal thoughts?", +"Would you like to end your life?", +"Do you have a plan for harming yourself?" +] + +fileName = "/home/nuno/Documents/Workspace/WEBDEV/RubyOnRails/ BDI.txt" +fileTargetStream = open(fileName, "a") + +total = 0 +scoreList = [] + +instructions = """ +Write a number to indicate how much you have experienced each symptom today +\t* 0 - Not at all +\t* 1 - Somewhat +\t* 2 - Moderately +\t* 3 - A lot +\t* 4 - Extremely + +""" + +puts instructions + +for question in questions + puts question + print "> " + answer = $stdin.gets.chomp.to_i + total+=answer + scoreList.push(answer) +end + +scoreListPretty = scoreList.join(', ') +puts "Total: #{total}" +puts "List: #{scoreListPretty}" + +fileTargetStream.write("\n\nTimestamp: #{Time.now}") +fileTargetStream.write("\nTotal: #{total}") +fileTargetStream.write("\nList: #{scoreListPretty}") + +fileTargetStream.close