Author Topic: Estimated Blood Alcohol Calculator (Text-Based, All Platforms)  (Read 3368 times)

0 Members and 1 Guest are viewing this topic.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Here is the text-based version o the Estimated Blood Alcohol program.

For more on this (most of it will apply, see post: https://www.qb64.org/forum/index.php?topic=4003.msg133420#msg133420)

Code: QB64: [Select]
  1. _TITLE "EBAC Calculator"
  2. '------------------------------------------------------------------------------------------------
  3. ' EBAC Calculator v1.0 by George McGinn, MAY, 2021
  4. ' Copyright (C)2021 by George McGinn/Linux Software Systems
  5. '                      All Rights Reserved.
  6. '
  7. ' Program is designed to run as an App in iTunes to run specifically
  8. ' on an iPhone so those who would like to know their esitmate BAC and
  9. ' how long it will take to get to a level to drive safely and legally.
  10. '
  11. ' Blood alcohol content (BAC) can be estimated by a method developed by
  12. ' Swedish professor Erik Widmark in the 1920s.
  13. '
  14. ' Gives the estimated BAC (EBAC), algorhithm reduced as:
  15. '    EBAC=A/(r*Wt)*1.055-B*T (verified by Wiki source listed below)
  16. ' Where:
  17. '    EBAC: Estimated Blood Alcohol Content (%)
  18. '        A: Alcohol consumed (in ounces to grams) or FLoz
  19. '        r: Ratio of body water to total weight (men: .68, women: .55)
  20. '      Wt: Body weight (in pounds to kilograms)
  21. '        B: Rate alcohol metabolized (men: .019/hr, women: .017/hr)
  22. '        T: Time alcohol in blood or time since consumption began
  23. '    1.055: Constant value of density of blood
  24. '
  25. ' The formula can also be reduced as follows (called the 8/10 formula):
  26. '    For Men:   EBAC = 7.97*A/Wt-B*T
  27. '    For Women: EBAC = 9.86*A/Wt-B*T
  28. '
  29. ' Factors 7.97 and 9.86 are derived from "r" and 1.055.
  30. ' Also, this formula is geared to fluid ounces and pounds, not
  31. ' grams and kilograms. While the suggested values were 8 and 10,
  32. ' testing showed the results were not accurate. So I reworked it
  33. ' and found that 7.97 and 9.86 gives better results.
  34. '
  35. ' It will be this reduced formula the program will use.
  36. '
  37. ' Each shot, wine glass and bottle/can of beer contains .6oz of
  38. ' alcohol. User records the number of drinks, which will then be
  39. ' converted to ounces (drinks * .6)
  40. '
  41. ' *** Formulas created/translated by George McGinn using the following sources:
  42. '    * Blood alcohol content can be estimated by a method developed
  43. '      by Swedish professor Erik Widmark [sv] in the 1920s.
  44. '      (https://web.archive.org/web/20031202155933/http://www.dui-law.com/810art.htm)
  45. '    * https://www.ou.edu/police/faid/blood-alcohol-calculator
  46. '    * https://www.gambonelaw.com/faqs/the-widmark-formula-and-calculating-your-bac-level/
  47. '    * https://en.wikipedia.org/wiki/Blood_alcohol_content
  48. '    * https://en.wikipedia.org/wiki/Binge_drinking
  49. '    * https://en.wikipedia.org/wiki/Alcohol_intoxication
  50. '    * https://en.wikipedia.org/wiki/Breathalyzer
  51. '    * https://ndaa.org/wp-content/uploads/toxicology_final.pdf
  52. '    * http://njlaw.rutgers.edu/collections/courts/supreme/a-96-06.doc.html
  53. '    * https://www.researchgate.net/profile/Alan-Jones-14/publication/318055507_Profiles_in_Forensic_Toxicology_Professor_Erik_Widmark_1889-1945/links/595794330f7e9ba95e0fd91d/Profiles-in-Forensic-Toxicology-Professor-Erik-Widmark-1889-1945.pdf?origin=publication_detail
  54. '    * https://www.cdc.gov/alcohol
  55. '------------------------------------------------------------------------------------------------
  56. '
  57. ' PROGRAM NOTES:
  58. ' --------------
  59. ' This blood alcohol content or BAC, for short, calculator can estimate
  60. ' your blood alcohol levels. Metabolism, body fat percentage and
  61. ' medication are other factors that can affect the rate of absorption
  62. ' by the body, and these are not considered in this calculation.
  63. '
  64. ' Blood alcohol content (BAC) or blood alcohol level is the
  65. ' concentration of alcohol in the bloodstream. It is usually measured
  66. ' as mass per volume. For example, a Blood alcohol content BAC of
  67. ' 0.04% means 0.4% (permille) or 0.04 grams of alcohol per 100 grams
  68. ' of individual’s blood. Use this BAC Calculator for informational
  69. ' purposes only, and not to drink and drive or drink and work.
  70. '
  71. ' Important Note: There is no BAC calculator that is 100% accurate.
  72. ' This is due to the number of factors that come into play regarding
  73. ' the consumption and alcohol processing rates of different people.
  74. ' Factors include the gender of the drinker (biologic, not identity),
  75. ' their differing metabolism rates, various health issues, and the
  76. ' combination of medications and supplements that might be taken by
  77. ' the drinker, drinking frequency, amount of food in the stomach and
  78. ' small intestine and when it was eaten, elapsed time, and other
  79. ' factors. The best that can be done is a rough estimation of the
  80. ' bloodstreams alcohol content or the BAC level based on known inputs.
  81. '
  82. ' Every state in the U.S. has a legal Blood Alcohol (BAC) limit of
  83. ' 0.05% or 0.08%, (depending on the state you are driving in). Most
  84. ' states also have lower legal BAC limits for young and inexperienced
  85. ' drivers, professional drivers and commercial drivers. Sentences for
  86. ' drunk driving include imprisonment, large fines, lengthy drivers
  87. ' license suspension and/or revocation, house arrest, community
  88. ' service, DUI schools, alcohol treatment programs, vehicle forfeiture
  89. ' and ignition interlock restrictions.
  90. '
  91. '------------------------------------------------------------------------------------------------
  92. ' Program Copyright (C)2021 by George McGinn/Pyramid Software Systems
  93. ' All Rights Reserved.
  94. '
  95. ' EBAC Calculator by George McGinn is licensed under a Creative Commons
  96. ' Attribution-NonCommercial 4.0 International License.
  97. '
  98. ' Full License Link: https://creativecommons.org/licenses/by-nc/4.0/
  99. '
  100. '
  101. ' You are free to (For non-commerical purposes only):
  102. '     Share          - copy and redistribute the material in any medium or format.
  103. '     Adapt          - remix, transform, and build upon the material.
  104. '     Attribution    - You must give appropriate credit, provide a link to
  105. '     the license, and indicate if changes were made. You may do so in any
  106. '     reasonable manner, but not in any way that suggests the licensor
  107. '     endorses you or your use.
  108. '     Non Commercial - You may not use the material for commercial purposes.
  109. '
  110. ' *** None of this code is considered in the Public Domain. Rights granted under CC 4.0
  111. '     are outlined as above and the disclaimer below:
  112. '
  113. ' *** DISCLAIMER ***
  114. ' Unless otherwise separately undertaken by the Licensor, to the extent possible,
  115. ' the Licensor offers the Licensed Material as-is and as-available, and makes no
  116. ' representations or warranties of any kind concerning the Licensed Material, whether
  117. ' express, implied, statutory, or other. This includes, without limitation, warranties
  118. ' of title, merchantability, fitness for a particular purpose, non-infringement, absence
  119. ' of latent or other defects, accuracy, or the presence or absence of errors, whether or
  120. ' not known or discoverable. Where disclaimers of warranties are not allowed in full or
  121. ' in part, this disclaimer may not apply to You.
  122. '
  123. ' To the extent possible, in no event will the Licensor be liable to You on any legal theory
  124. ' (including, without limitation, negligence) or otherwise for any direct, special, indirect,
  125. ' incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages
  126. ' arising out of this Public License or use of the Licensed Material, even if the Licensor has
  127. ' been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation
  128. ' of liability is not allowed in full or in part, this limitation may not apply to You.
  129. '
  130. ' The disclaimer of warranties and limitation of liability provided above shall be interpreted
  131. ' in a manner that, to the extent possible, most closely approximates an absolute disclaimer and
  132. '  waiver of all liability.
  133. '------------------------------------------------------------------------------------------------
  134.  
  135.  
  136. '--------------------------------
  137. '*** Initialize SCREEN
  138. 'SCREEN 12
  139. SCREEN _NEWIMAGE(800, 600, 32)
  140.  
  141. '*** Setup Font Type and Size
  142. fontpath$ = "Verdana.ttf"
  143. font& = _LOADFONT(fontpath$, 8, "")
  144.  
  145.  
  146. QBMain:
  147. DIM B, OZ AS SINGLE
  148.  
  149. '*** Setup constant variables
  150. A = 0
  151. Wt = 0
  152. B = .0
  153. T = 0: St = 0
  154. I = 0
  155. Bdl = 1.055
  156. OZ = .5
  157. TRUE = 1: FALSE = 0
  158. SOBER = FALSE
  159.  
  160. '*** Get INPUT for values for calculations
  161. PRINT "BLOOD ALCOHOL CALCULATOR"
  162. PRINT "------------------------"
  163. INPUT "YOUR SEX (M/F): "; SEX$
  164. SEX$ = UCASE$(SEX$)
  165. IF SEX$ <> "M" AND SEX$ <> "F" THEN GOTO QBMain
  166. INPUT "YOUR WEIGHT (lbs): "; Wt
  167. INPUT "NUMBER OF DRINKS: "; A
  168. INPUT "TIME (HRS) SINCE CONSUMPTION BEGAN: "; T
  169.  
  170. '*** Convert Drinks into Fluid Ounces of EtOH (Pure Alcohol).
  171. '*** A is number of drinks. 1 drink is about .6 FLoz of alcohol
  172. FLoz = A * OZ
  173.  
  174. '*** Set/calculate EBAC values based on SEX$
  175.     CASE "M"
  176.         B = .017
  177.         EBAC = 7.97 * FLoz / Wt - B * T
  178.     CASE "F"
  179.         B = .019
  180.         EBAC = 9.86 * FLoz / Wt - B * T
  181.  
  182. IF EBAC < 0 THEN EBAC = 0
  183.  
  184. '*** DISPLAY RESULTS
  185. PRINT USING "ESTIMATED BLOOD ALCOHOL CONTENT (EBAC) in g/dL = #.###"; EBAC
  186.  
  187.  
  188. '*** IF DRUNK DISPLAY WARNING (.10 WAS DRUNK IN 1984, .08 IN 2003/2004)
  189.     CASE .500 TO 1.9999
  190.         PRINT: PRINT "*** ALERT: CALL AN AMBULANCE, DEATH LIKELY"
  191.         PRINT "Unconsious/coma, unresponsive, high likelihood of death. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  192.     CASE .400 TO .4999
  193.         PRINT: PRINT "*** ALERT: CALL AN AMBULANCE, DEATH POSSIBLE"
  194.         PRINT "Onset of coma, and possible death due to respiratory arrest. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  195.     CASE .350 TO .3999
  196.         PRINT: PRINT "*** ALERT: CALL AN AMBULANCE, SEVERE ALCOHOL POISONING"
  197.         PRINT " Coma is possible. This is the level of surgical anesthesia. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  198.     CASE .300 TO .3499
  199.         PRINT: PRINT "*** ALERT: YOU ARE IN A DRUNKEN STUP0R, AT RISK TO PASSING OUT"
  200.         PRINT "STUPOR. You have little comprehension of where you are. You may pass out suddenly and be difficult to awaken. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  201.     CASE .250 TO .2999
  202.         PRINT: PRINT "*** ALERT: SEVERLY IMPAIRED - DRUNK ENOUGH TO CAUSE SEVERE INJURY/DEATH TO SELF"
  203.         PRINT "All mental, physical and sensory functions are severely impaired. Increased risk of asphyxiation from choking on vomit and of seriously injuring yourself by falls or other accidents. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  204.     CASE .200 TO .2499
  205.         PRINT: PRINT "YOU ARE EXTREMELY DRUNK"
  206.         PRINT "Feeling dazed/confused or otherwise disoriented. May need help to stand/walk. If you injure yourself you may not feel the pain. Some people have nausea and vomiting at this level. The gag reflex is impaired and you can choke if you do vomit. Blackouts are likely at this level so you may not remember what has happened. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  207.     CASE .160 TO .1999
  208.         PRINT: PRINT "YOUR ARE SEVERLY DRUNK - ENOUGH TO BECOME VERY SICK"
  209.         PRINT "Dysphoria predominates, nausea may appear. The drinker has the appearance of a 'sloppy drunk.' It is illegal to operate a motor vehicle at this level of intoxication in all states."
  210.         PRINT: PRINT "* Dysphoria: An emotional state of anxiety, depression, or unease."
  211.     CASE .130 TO .1599
  212.         PRINT: PRINT "YOU ARE VERY DRUNK - ENOUGH TO LOSE PHYSICAL & MENTAL CONTROL"
  213.         PRINT "Gross motor impairment and lack of physical control. Blurred vision and major loss of balance. Euphoria is reduced and dysphoria* is beginning to appear. Judgment and perception are severely impaired. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  214.         PRINT: PRINT "* Dysphoria: An emotional state of anxiety, depression, or unease."
  215.     CASE .100 TO .1299
  216.         PRINT: PRINT "YOU ARE LEGALLY DRUNK"
  217.         PRINT "Significant impairment of motor coordination and loss of good judgment. Speech may be slurred; balance, vision, reaction time and hearing will be impaired. Euphoria. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  218.     CASE .070 TO .0999
  219.         PRINT: PRINT "YOU MAY BE LEGALLY DRUNK"
  220.         PRINT "Slight impairment of balance, speech, vision, reaction time, and hearing. Euphoria. Judgment and self-control are reduced, and caution, reason and memory are impaired (in some* states .08 is legally impaired and it is illegal to drive at this level). You will probably believe that you are functioning better than you really are."
  221.         PRINT: PRINT "(*** As of July, 2004 ALL states had passed .08 BAC Per Se Laws. The final one took effect in August of 2005.)"
  222.     CASE .040 TO .0699
  223.         PRINT: PRINT "YOU MAY BE LEGALLY BUZZED"
  224.         PRINT "Feeling of well-being, relaxation, lower inhibitions, sensation of warmth. Euphoria. Some minor impairment of reasoning and memory, lowering of caution. Your behavior may become exaggerated and emotions intensified (Good emotions are better, bad emotions are worse)"
  225.     CASE .020 TO .0399
  226.         PRINT: PRINT "YOU MAY BE OK TO DRIVE, BUT IMPAIRMENT BEGINS"
  227.         PRINT "No loss of coordination, slight euphoria and loss of shyness. Depressant effects are not apparent. Mildly relaxed and maybe a little lightheaded."
  228.     CASE .000 TO .0199
  229.         PRINT: PRINT "YOU ARE OK TO DRIVE"
  230.  
  231.  
  232. '*** Determine if Drunk (>.08 EBAC) and calculate:
  233. '***    - When user will be less than .08
  234. '***    - How long it will take to become completely sober
  235. IF EBAC > .08 THEN
  236.     SOBER = FALSE
  237.     CEBAC = EBAC
  238.     St = T
  239.     DO UNTIL SOBER = TRUE
  240.         T = T + 1
  241.         IF CEBAC > .0799 THEN I = I + 1
  242.  
  243.         SELECT CASE SEX$
  244.             CASE "M"
  245.                 B = .015
  246.                 CEBAC = 7.97 * FLoz / Wt - B * T
  247.             CASE "F"
  248.                 B = .015
  249.                 CEBAC = 9.86 * FLoz / Wt - B * T
  250.         END SELECT
  251.  
  252.         IF legalToDrive = FALSE THEN
  253.             IF CEBAC < .08 THEN
  254.                 IF I > 9 THEN
  255.                     PRINT USING "It will take ## hours from your last drink to be able to drive."; I
  256.                 ELSE
  257.                     PRINT USING "It will take # hours from your last drink to be able to drive."; I
  258.                 END IF
  259.                 legalToDrive = TRUE
  260.             END IF
  261.         END IF
  262.  
  263.         IF CEBAC <= 0 THEN
  264.             IF T - St > 9 THEN
  265.                 PRINT USING "It will take you ## hours from your last drink to be completely sober."; T - St
  266.             ELSE
  267.                 PRINT USING "It will take you # hours from your last drink to be completely sober."; T - St
  268.             END IF
  269.             SOBER = TRUE
  270.         END IF
  271.     LOOP
  272.  
  273.  
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Estimated Blood Alcohol Calculator (Text-Based, All Platforms)
« Reply #1 on: June 21, 2021, 09:13:10 pm »
It doesn't work. I blew as hard as I could into the USB port on my laptop, and nothing registered.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Estimated Blood Alcohol Calculator (Text-Based, All Platforms)
« Reply #2 on: June 21, 2021, 09:21:28 pm »
It doesn't work. I blew as hard as I could into the USB port on my laptop, and nothing registered.

Pete

What? are you drunk? ;-))


Someone wrote code to measure reaction time in JB, and advised from that test whether to risk driving or not.

For the sober made a game of it. I don't think anyone drunk would bother, so there's another test!
« Last Edit: June 21, 2021, 09:36:32 pm by bplus »

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Estimated Blood Alcohol Calculator (Text-Based, All Platforms)
« Reply #3 on: June 21, 2021, 10:27:49 pm »
I had to read the post again. For a second, I thought I screwed up (I'll never code again three sheets to the wind, I, hiccup, promise!)
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)