Author Topic: Estimated Blood Alcohol Calculator (LINUX/Zenity Only)  (Read 3261 times)

0 Members and 1 Guest are viewing this topic.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Estimated Blood Alcohol Calculator (LINUX/Zenity Only)
« on: June 20, 2021, 11:16:12 pm »
This program was originally written by me in Objective-C for mobile devices. That is until Apple decided to ban all these programs from the iTunes store. (From their 6/7 update: 4.3: Added drinking game apps as a saturated category.).

After learning Zenity, I decided to convert this program to QB64 and give this GUI a test, and I am pleased with the results.

Back when I was a police officer, this formula, in a more advanced form, was used by defense attorneys in the 70's through parts of the 90's when defending their clients on DUI charges. I can tell you that a breathlizer does not accurately measure blood alcohol content, a requirement to convict someone in court. What it does measure is the amount of alcohol that is leaving the body. Which is why the must draw blood to get an accurate BAC figure, which is done today, but wasn't standard back when I was in law enforcement.

I offer this program as a novelty, and if you host parties, you could use it to guide your decision on guests who may drink too much. I do. However, remember that when I created this, I used only the averages for males and females. Many factors are specific to an individual such as metabolism rate, which your doctor can tell you what it is after conducting tests. The comments in the program and the help file lists some of the many factors that are not considered by this program.

The program itself is well documented and lots of comments to help anyone looking to understand how Zenity works with QB64. I use both pipecom and SHELL to serve the GUI, and I am using most of the funtionality of Zenity with some exceptions.

This program will only run on Linux. I have a version for all platforms that uses the QB64 screen for input and output. I will post this program seperately.

To run this program, there is a HELP file that must be loaded in the same directory as the binary executable. The program, due to the constraints of Zenity's Text Information Dialog, the output into the GUI can only come from this file. Also, the program will write out the results of the calculation to a temporary file called "tempfile" that resides in the same directory as the executable. The program removes this file when it ends. If the file somehow exists when the program starts, it will be replaced. So make sure you do not have a file by that name in the directory you plan to run this.

Attached to this post is a compressed file that has both the source code and the help file. I also have the latest pipecom utility by Spriggs in this archive as well. This is for those who do not want to cut/paste a 400+ line program (150 lines consists of the comments at the beginning of the program).

Since this may still be a commercially viable program for me (in that I plan to market it for free), it is provided under the Creative Commons Attribution License. You are free to do what you want with it as long as: 1) I am credited with it, and 2) For your protection, keep the disclaimer intact.

Enjoy. Those who wish to learn about Zenity will find this program very educational.


*** You can find the latest version of Pipecom here: https://www.qb64.org/forum/index.php?topic=3641.msg129938#msg129938

Code: QB64: [Select]
  1. _TITLE "ebacCalculator.bas"
  2. '------------------------------------------------------------------------------------------------
  3. ' EBAC Calculator v1.0 by George McGinn, APRIL, 2021
  4. ' Copyright (C)2021 by George McGinn
  5. '                      All Rights Reserved.
  6. '
  7. ' 6/19/2021 - Updated To use Zenity and SHELL commands to run on Linux with a simple GUI. (GJM)
  8. '
  9. ' Original code designed to run as an App in iTunes to run specifically
  10. ' on an iPhone so those who would like to know their esitmate BAC and
  11. ' how long it will take to get to a level to drive safely and legally.
  12. '
  13. ' Modified to run on the Desktop for use at home. You can judge the amount of drinks your guests
  14. ' have had and use this program to help in deciding who can drive and approximately how long
  15. ' someone needs to wait before they could possibly drive.
  16. '
  17. ' *** There is no warranty (See Disclaimer) as to the fitness or accuracy of the results.
  18. ' *** While every effort has been made to provide accurate results, other factors not considered
  19. ' *** also play a role in determining one's Blood Alcohol Content.
  20. '
  21. ' Blood alcohol content (BAC) can be estimated by a method developed by Swedish professor
  22. ' Erik Widmark in the 1920s.
  23. '
  24. ' Gives the estimated BAC (EBAC), algorhithm reduced as:
  25. '    EBAC=A/(r*Wt)*1.055-B*T (verified by Wiki source listed below)
  26. ' Where:
  27. '    EBAC: Estimated Blood Alcohol Content (%)
  28. '        A: Alcohol consumed (in ounces to grams) or FLoz
  29. '        r: Ratio of body water to total weight (men: .68, women: .55)
  30. '      Wt: Body weight (in pounds to kilograms)
  31. '        B: Rate alcohol metabolized (men: .019/hr, women: .017/hr)
  32. '        T: Time alcohol in blood or time since consumption began
  33. '    1.055: Constant value of density of blood
  34. '
  35. ' The formula can also be reduced as follows (called the 8/10 formula):
  36. '    For Men:   EBAC = 7.97*A/Wt-B*T
  37. '    For Women: EBAC = 9.86*A/Wt-B*T
  38. '
  39. ' Factors 7.97 and 9.86 are derived from "r" and 1.055 among other factors.
  40. ' Also, this formula is geared to fluid ounces and pounds, not
  41. ' grams and kilograms. While the suggested values were 8 and 10,
  42. ' testing showed the results were not accurate. So I reworked it
  43. ' and found that 7.97 and 9.86 gives better results.
  44. '
  45. ' It will be this reduced formula the program will use.
  46. '
  47. ' Each shot, wine glass and bottle/can of beer contains .6oz of
  48. ' alcohol. User records the number of drinks, which will then be
  49. ' converted to ounces (drinks * .6)
  50. '
  51. ' *** Formulas created/translated by George McGinn using the following sources:
  52. '    * Blood alcohol content can be estimated by a method developed
  53. '      by Swedish professor Erik Widmark [sv] in the 1920s.
  54. '      (https://web.archive.org/web/20031202155933/http://www.dui-law.com/810art.htm)
  55. '    * https://www.ou.edu/police/faid/blood-alcohol-calculator
  56. '    * https://www.gambonelaw.com/faqs/the-widmark-formula-and-calculating-your-bac-level/
  57. '    * https://en.wikipedia.org/wiki/Blood_alcohol_content
  58. '    * https://en.wikipedia.org/wiki/Binge_drinking
  59. '    * https://en.wikipedia.org/wiki/Alcohol_intoxication
  60. '    * https://en.wikipedia.org/wiki/Breathalyzer
  61. '    * https://ndaa.org/wp-content/uploads/toxicology_final.pdf
  62. '    * http://njlaw.rutgers.edu/collections/courts/supreme/a-96-06.doc.html
  63. '    * 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
  64. '    * https://www.cdc.gov/alcohol
  65. '------------------------------------------------------------------------------------------------
  66. '
  67. ' PROGRAM NOTES:
  68. ' --------------
  69. ' This blood alcohol content or BAC, for short, calculator can estimate
  70. ' your blood alcohol levels. Metabolism, body fat percentage and
  71. ' medication are some of the other factors that can affect the rate of absorption
  72. ' by the body, and these are not considered in this calculation.
  73. '
  74. ' Blood alcohol content (BAC) or blood alcohol level is the
  75. ' concentration of alcohol in the bloodstream. It is usually measured
  76. ' as mass per volume. For example, a Blood alcohol content BAC of
  77. ' 0.04% means 0.4% (permille) or 0.04 grams of alcohol per 100 grams
  78. ' of individuals blood. Use this BAC Calculator for informational
  79. ' purposes only, and not to drink and drive or drink and work.
  80. '
  81. ' Important Note: There is no BAC calculator that is 100% accurate.
  82. ' This is due to the number of factors that come into play regarding
  83. ' the consumption and alcohol processing rates of different people.
  84. ' Other factors not considered here include:
  85. '    * Overall health and wellness
  86. '    * Body type
  87. '    * Metabolism (Program uses an Average for Males & Females)
  88. '    * Alcohol tolerance
  89. '    * What kind of alcohol is consumed (Program uses average drink of 40% ETOH)
  90. '    * Medications
  91. '    * Amount of food eaten
  92. '    * Emotional, mental state
  93. '
  94. ' The best that can be done is a rough estimation of the
  95. ' bloodstreams alcohol content or the BAC level based on known inputs.
  96. '
  97. ' Every state in the U.S. has a legal Blood Alcohol (BAC) limit of 0.05% or 0.08%,
  98. ' (depending on the state you are driving in). Most states also have lower legal
  99. ' BAC limits for young and inexperienced drivers, professional drivers and commercial
  100. ' drivers. Sentences for drunk driving include imprisonment, large fines, lengthy drivers
  101. ' license suspension and/or revocation, house arrest, community service, DUI schools,
  102. ' alcohol treatment programs, vehicle forfeiture and ignition interlock restrictions.
  103. '
  104. '------------------------------------------------------------------------------------------------
  105. ' Program Copyright (C)2021 by George McGinn
  106. ' All Rights Reserved.
  107. '
  108. ' EBAC Calculator by George McGinn is licensed under a Creative Commons
  109. ' Attribution-NonCommercial 4.0 International License.
  110. '
  111. ' Full License Link: https://creativecommons.org/licenses/by-nc/4.0/
  112. '
  113. '
  114. ' You are free to (For non-commerical purposes only):
  115. '     Share          - copy and redistribute the material in any medium or format.
  116. '     Adapt          - remix, transform, and build upon the material.
  117. '     Attribution    - You must give appropriate credit, provide a link to
  118. '                      the license, and indicate if changes were made. You may do so in any
  119. '                      reasonable manner, but not in any way that suggests the licensor
  120. '                      endorses you or your use.
  121. '     Non Commercial - You may not use the material for commercial purposes.
  122. '
  123. ' *** None of this code is considered in the Public Domain. Rights granted under CC 4.0
  124. '     are outlined as above and the disclaimer below:
  125. '
  126. ' *** DISCLAIMER ***
  127. ' Unless otherwise separately undertaken by the Licensor, to the extent possible,
  128. ' the Licensor offers the Licensed Material as-is and as-available, and makes no
  129. ' representations or warranties of any kind concerning the Licensed Material, whether
  130. ' express, implied, statutory, or other. This includes, without limitation, warranties
  131. ' of title, merchantability, fitness for a particular purpose, non-infringement, absence
  132. ' of latent or other defects, accuracy, or the presence or absence of errors, whether or
  133. ' not known or discoverable. Where disclaimers of warranties are not allowed in full or
  134. ' in part, this disclaimer may not apply to You.
  135. '
  136. ' To the extent possible, in no event will the Licensor be liable to You on any legal theory
  137. ' (including, without limitation, negligence) or otherwise for any direct, special, indirect,
  138. ' incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages
  139. ' arising out of this Public License or use of the Licensed Material, even if the Licensor has
  140. ' been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation
  141. ' of liability is not allowed in full or in part, this limitation may not apply to You.
  142. '
  143. ' The disclaimer of warranties and limitation of liability provided above shall be interpreted
  144. ' in a manner that, to the extent possible, most closely approximates an absolute disclaimer and
  145. ' waiver of all liability.
  146. '------------------------------------------------------------------------------------------------
  147.  
  148.  
  149. '--------------------------------
  150. '*** Initialize
  151.  
  152. '*** If You comment the line below out, you will see the [DEBUG] PRINT statements in the QB64 Window. You can add your own PRINT statements if needed
  153. SCREEN _NEWIMAGE(500, 700, 32)
  154.  
  155. DIM SHARED AS SINGLE B, OZ, Wt
  156. DIM SHARED numeric(255)
  157. DIM SHARED AS INTEGER TRUE, FALSE, SOBER
  158. DIM SHARED AS STRING Weight, Drinks, TimeElapsed
  159. DIM SHARED AS STRING cmd, stdout, stderr, stdbutton
  160. DIM SHARED AS LONG result
  161. DIM SHARED AS STRING prt_text
  162.  
  163. '--------------------------------
  164. '*** Setup NUMERIC Check Table
  165. FOR I = 48 TO 57
  166.     numeric(I) = -1
  167.  
  168. EBACMain:
  169. '--------------------------------
  170. '*** Setup constant variables
  171.     A = 0
  172.     Wt = 0
  173.     B = .0
  174.     T = 0: St = 0
  175.     I = 0
  176.     Bdl = 1.055
  177.     OZ = .5
  178.     TRUE = -1: FALSE = 0
  179.     SOBER = FALSE
  180.  
  181.  
  182. EBACForm:
  183. '--------------------------------
  184. '*** Produce the Input Form
  185.     stdout = ""
  186.     cmd = "zenity --forms --title=" + CHR$(34) + "EBAC Blood Alcohol Calculator" + CHR$(34) + _
  187.           " --text=" + CHR$(34) + "Enter information about your friend." + CHR$(34) + _
  188.           " --add-entry=" + CHR$(34) + "Sex (M or F)" + CHR$(34) + _
  189.           " --add-entry=" + CHR$(34) + "Weight (lbs)" + CHR$(34) + _
  190.           " --add-entry=" + CHR$(34) + "Number of drinks" + CHR$(34) + _
  191.           " --add-entry=" + CHR$(34) + "Time (hrs) from first drink" + CHR$(34) + _
  192.           " --extra-button=HELP --extra-button=QUIT"
  193.  
  194.     result = pipecom(cmd, stdout, stderr)
  195.  
  196.     stdbutton = LEFT$(stdout, 4)
  197.  
  198.     IF result = 1 AND stdbutton = "QUIT" THEN GOTO endPROG
  199.  
  200.     IF result = 1 AND stdbutton = "HELP" THEN
  201.         cmd = "zenity --text-info " + _
  202.               " --title=" + CHR$(34) + "HELP/ABOUT: EBAC Calculator" + CHR$(34) + _
  203.               " --filename=" + "EBACHelp.txt" + _
  204.               " --width=525 --height=600"
  205.         SHELL (cmd)
  206.         GOTO EBACForm
  207.     END IF
  208.  
  209.     IF result <> 0 THEN
  210.         SHELL ("zenity --error --text=" + CHR$(34) + "Main Form did not load. Program Terminated." + CHR$(34) + " --width=175 --height=100")
  211.         GOTO endPROG
  212.     END IF
  213.  
  214. '----------------------------------------------------------
  215. '*** Populate QB64 variables from the form's stdout results
  216.  
  217. '--------------------------------------------------
  218. '*** Get and Validate Sex Input
  219.     Sex = MID$(stdout, 1, INSTR(stdout, "|") - 1)
  220.     Sex = UCASE$(Sex)
  221.     IF Sex <> "M" AND Sex <> "F" THEN
  222.         SHELL ("zenity --warning --text=" + CHR$(34) + "SEX must be either M or F." + CHR$(34) + " --width=175 --height=100")
  223.         GOTO EBACForm
  224.     END IF
  225.  
  226. '---------------------------------------------------
  227. '*** Get and Validate Weight Input
  228.     stdout = MID$(stdout, INSTR(stdout, "|") + 1)
  229.     Weight = MID$(stdout, 1, INSTR(stdout, "|") - 1)
  230.     IF ISNUMERIC(Weight) THEN
  231.         Wt = VAL(Weight)
  232.     ELSE
  233.         SHELL ("zenity --warning --text=" + CHR$(34) + "Weight must be numeric." + CHR$(34) + " --width=175 --height=100")
  234.         GOTO EBACForm
  235.     END IF
  236.  
  237.  
  238. '-----------------------------------------------------
  239. '*** Get and Validate Number of Drinks Input
  240.     stdout = MID$(stdout, INSTR(stdout, "|") + 1)
  241.     Drinks = MID$(stdout, 1, INSTR(stdout, "|") - 1)
  242.     IF ISNUMERIC(Drinks) THEN
  243.         A = VAL(Drinks)
  244.     ELSE
  245.         SHELL ("zenity --warning --text=" + CHR$(34) + "Number of drinks must be numeric." + CHR$(34) + " --width=175 --height=100")
  246.         GOTO EBACForm
  247.     END IF
  248.  
  249. '-------------------------------------------------------------------
  250. '*** Get and Validate Time Since First Drink (Time Elapsed) Input
  251.     TimeElapsed = MID$(stdout, INSTR(stdout, "|") + 1)
  252.     l = LEN(TimeElapsed)
  253.     TimeElapsed$ = LEFT$(TimeElapsed, l - 1)
  254.     IF ISNUMERIC(TimeElapsed) THEN
  255.         T = VAL(TimeElapsed)
  256.     ELSE
  257.         SHELL ("zenity --warning --text=" + CHR$(34) + "Time since first drink must be numeric." + CHR$(34) + " --width=175 --height=100")
  258.         GOTO EBACForm
  259.     END IF
  260.  
  261. '--------------------------------------------------------------------------------------------------------
  262. '*** Calculate the value of the Estimated Blood Alcohol Content (EBAC) and check for sucessful completion
  263.     result = calcEBAC
  264.     IF result <> 0 THEN
  265.         SHELL ("zenity --error --text=" + CHR$(34) + "Calulating the EBAC results failed. Program Terminated" + CHR$(34) + " --width=175 --height=100")
  266.         GOTO endPROG
  267.     END IF
  268.  
  269. '---------------------------------------------------------------------------------------------------------------------------------------------
  270. '*** Create a temp file for the Zenity Information Box and write out prt_text (This box cannot have text passed to it unless it is in a file)
  271.     OPEN "tempfile" FOR OUTPUT AS #1
  272.     PRINT #1, USING "ESTIMATED BLOOD ALCOHOL CONTENT (EBAC) in g/dL = #.###"; EBAC
  273.     PRINT #1, prt_text
  274.     CLOSE #1
  275.  
  276. displayEBAC:
  277. '------------------------------------------------------------------
  278. '*** Prepare the Zenity command and execute, check for good return
  279.  
  280.     cmd = "zenity --text-info " + _
  281.           " --title=" + CHR$(34) + "EBAC Blood Alcohol Calculator" + CHR$(34) + _
  282.           " --width=525 --height=400" + _
  283.           " --filename=tempfile" + _
  284.           " --checkbox=" + CHR$(34) + "I agree that this program and its results are not legally binding." + CHR$(34)
  285.  
  286.     result = SHELL(cmd)
  287.  
  288.     IF result = 1 THEN
  289.         result = SHELL("zenity --warning --text=" + CHR$(34) + "You must agree to the terms of use. Please check the confirmation box." + CHR$(34) + " --width=175 --height=100")
  290.         GOTO displayEBAC
  291.     END IF
  292.  
  293.     result = SHELL("zenity --question --text=" + CHR$(34) + "Do you want to run another calculation?" + CHR$(34) + " --width=175 --height=100")
  294.     IF result = 0 THEN
  295.         SHELL ("rm tempfile")
  296.         GOTO EBACForm
  297.     END IF
  298.  
  299. endPROG:
  300.     SHELL ("rm tempfile")
  301.     result = SHELL("zenity --info --text=" + CHR$(34) + "Thank You for using EBAC Calculator. Please Don't Drink and Drive." + CHR$(34) + " --width=175 --height=100")
  302.     END
  303.  
  304.  
  305. FUNCTION calcEBAC
  306. '-------------------------------------------------------------
  307. '*** Convert Drinks into Fluid Ounces of EtOH (Pure Alcohol).
  308. '*** A is number of drinks. 1 drink is about .6 FLoz of alcohol
  309.     FLoz = A * OZ
  310.  
  311. '-----------------------------------------------------
  312. '*** Set/calculate EBAC values based on Sex
  313.     SELECT CASE Sex
  314.         CASE "M"
  315.             B = .017
  316.             EBAC = 7.97 * FLoz / Wt - B * T
  317.         CASE "F"
  318.             B = .019
  319.             EBAC = 9.86 * FLoz / Wt - B * T
  320.     END SELECT
  321.  
  322.     IF EBAC < 0 THEN EBAC = 0
  323.  
  324. '----------------------------------------------------------------------------------------------
  325. '*** Populate the EBAC string with the EBAC value formatted to 3 decimal places for FORM output
  326. '    prt_text = "ESTIMATED BLOOD ALCOHOL CONTENT (EBAC) in g/dL = " + EBAC_ST$ + CHR$(10) + CHR$(10)
  327.     prt_text = "" + CHR$(10)
  328.  
  329. '-----------------------------------------------------------------------------------------
  330. '*** Based on EBAC range values, populate the FORM output string with the approriate text
  331.     SELECT CASE EBAC
  332.         CASE .500 TO 1.9999
  333.             prt_text = prt_text + "*** ALERT: CALL AN AMBULANCE, DEATH LIKELY" + CHR$(10)
  334.             prt_text = prt_text + "Unconsious/coma, unresponsive, high likelihood of death. It is illegal to operate a motor vehicle at this level of intoxication in all states."
  335.         CASE .400 TO .4999
  336.             prt_text = prt_text + "*** ALERT: CALL AN AMBULANCE, DEATH POSSIBLE" + CHR$(10)
  337.             prt_text = prt_text + "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."
  338.         CASE .350 TO .3999
  339.             prt_text = prt_text + "*** ALERT: CALL AN AMBULANCE, SEVERE ALCOHOL POISONING" + CHR$(10)
  340.             prt_text = prt_text + " 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."
  341.         CASE .300 TO .3499
  342.             prt_text = prt_text + "*** ALERT: YOU ARE IN A DRUNKEN STUP0R, AT RISK TO PASSING OUT" + CHR$(10)
  343.             prt_text = prt_text + "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."
  344.         CASE .250 TO .2999
  345.             prt_text = prt_text + "*** ALERT: SEVERLY IMPAIRED - DRUNK ENOUGH TO CAUSE SEVERE INJURY/DEATH TO SELF" + CHR$(10)
  346.             prt_text = prt_text + "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."
  347.         CASE .200 TO .2499
  348.             prt_text = prt_text + "YOU ARE EXTREMELY DRUNK" + CHR$(10)
  349.             prt_text = prt_text + "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."
  350.         CASE .160 TO .1999
  351.             prt_text = prt_text + "YOUR ARE SEVERLY DRUNK - ENOUGH TO BECOME VERY SICK" + CHR$(10)
  352.             prt_text = prt_text + "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." + CHR$(10) + CHR$(10)
  353.             prt_text = prt_text + "* Dysphoria: An emotional state of anxiety, depression, or unease."
  354.         CASE .130 TO .1599
  355.             prt_text = prt_text + "YOU ARE VERY DRUNK - ENOUGH TO LOSE PHYSICAL & MENTAL CONTROL" + CHR$(10)
  356.             prt_text = prt_text + "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." + CHR$(10) + CHR$(10)
  357.             prt_text = prt_text + "* Dysphoria: An emotional state of anxiety, depression, or unease."
  358.         CASE .100 TO .1299
  359.             prt_text = prt_text + "YOU ARE LEGALLY DRUNK" + CHR$(10)
  360.             prt_text = prt_text + "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."
  361.         CASE .070 TO .0999
  362.             prt_text = prt_text + "YOU MAY BE LEGALLY DRUNK" + CHR$(10)
  363.             prt_text = prt_text + "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." + CHR$(10) + CHR$(10)
  364.             prt_text = prt_text + "(*** As of July, 2004 ALL states had passed .08 BAC Per Se Laws. The final one took effect in August of 2005.)"
  365.         CASE .040 TO .0699
  366.             prt_text = prt_text + "YOU MAY BE LEGALLY BUZZED" + CHR$(10)
  367.             prt_text = prt_text + "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)"
  368.         CASE .020 TO .0399
  369.             prt_text = prt_text + "YOU MAY BE OK TO DRIVE, BUT IMPAIRMENT BEGINS" + CHR$(10)
  370.             prt_text = prt_text + "No loss of coordination, slight euphoria and loss of shyness. Depressant effects are not apparent. Mildly relaxed and maybe a little lightheaded."
  371.         CASE .000 TO .0199
  372.             prt_text = prt_text + "YOU ARE OK TO DRIVE" + CHR$(10)
  373.     END SELECT
  374.  
  375. '-----------------------------------------------------------
  376. '*** Determine if Drunk (>.08 EBAC) and calculate:
  377. '***    - When user will be less than .08
  378. '***    - How long it will take to become completely sober
  379.     IF EBAC > .08 THEN
  380.         SOBER = FALSE
  381.         CEBAC = EBAC
  382.         st = T
  383.         DO UNTIL SOBER = TRUE
  384.             T = T + 1
  385.             IF CEBAC > .0799 THEN I = I + 1
  386.  
  387.             SELECT CASE Sex
  388.                 CASE "M"
  389.                     B = .017
  390.                     CEBAC = 7.97 * FLoz / Wt - B * T
  391.                 CASE "F"
  392.                     B = .019
  393.                     CEBAC = 9.86 * FLoz / Wt - B * T
  394.             END SELECT
  395.  
  396.             IF legalToDrive = FALSE THEN
  397.                 IF CEBAC < .08 THEN
  398.                     prt_text = prt_text + CHR$(10) + CHR$(10) + "It will take about " + STR$(I) + " hours from your last drink to be able to drive." + CHR$(10)
  399.                     legalToDrive = TRUE
  400.                 END IF
  401.             END IF
  402.  
  403.             IF CEBAC <= 0 THEN
  404.                 prt_text = prt_text + "It will take about " + STR$(T - st) + " hours from your last drink to be completely sober."
  405.                 SOBER = TRUE
  406.             END IF
  407.         LOOP
  408.     END IF
  409.  
  410.  
  411.  
  412. FUNCTION ISNUMERIC (A$)
  413. '-----------------------------------------------------
  414. '*** Numeric Check of a STRING
  415.     l = LEN(A$)
  416.     FOR I = 1 TO l
  417.         ACODE = ASC(A$, I)
  418.         IF numeric(ACODE) THEN
  419.             ISNUMERIC = TRUE
  420.         ELSE
  421.             ISNUMERIC = FALSE
  422.             EXIT FUNCTION
  423.         END IF
  424.     NEXT I
  425.  
  426.  
  427. '$INCLUDE:'pipecomqb64.bas'
  428.  

 
____________________________________________________________________
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 Craz1000

  • Forum Regular
  • Posts: 111
  • I'm OK
    • View Profile
    • Craz1000.net
Re: Estimated Blood Alcohol Calculator (LINUX/Zenity Only)
« Reply #1 on: June 23, 2021, 10:12:22 pm »
In reading your post i have come up with this question. I have never thought about a breathalyzer actually measuring the alcohol actually leaving the body and not what is actually in the blood at the time. So then does this mean that being young vs old puts you at a disadvantage because your body works more efficiently and therefore can remove more alcohol than someone who is older. And if this is the case then i would also imagine an older smoker has a serious advantage in this test while having a much higher BAC level than a fit and healthy 21 year old who is just below the limit but blows higher because their body functions better?

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Estimated Blood Alcohol Calculator (LINUX/Zenity Only)
« Reply #2 on: June 24, 2021, 12:09:20 am »
Yes. Your metabolism rate changes with age, so in a way, age is another factor. Smoking would fall in the categories of health and even drugs, as nicotine is a drug. So smoking is another factor.

There are too many factors that go into both absorption rate and even the rate that the body removes alcohol, and both rates can be different!

The thing about alcohol level is that no matter how long it takes to metabolize it in to your system, if you drink 4 drinks, you will eventually have 4 drinks in your blood, It all depends on the amount of time it takes to get to that level, and the amount of time it takes for the body to remove it.

Theoretically, if you are in perfect health with average metabolism rates, if you have one drink an hour, you will never get drunk. But that does not happen in real life due to all the other factors involved, including alcohol tolerance.


In reading your post i have come up with this question. I have never thought about a breathalyzer actually measuring the alcohol actually leaving the body and not what is actually in the blood at the time. So then does this mean that being young vs old puts you at a disadvantage because your body works more efficiently and therefore can remove more alcohol than someone who is older. And if this is the case then i would also imagine an older smoker has a serious advantage in this test while having a much higher BAC level than a fit and healthy 21 year old who is just below the limit but blows higher because their body functions better?
« Last Edit: June 24, 2021, 12:10:45 am by George McGinn »
____________________________________________________________________
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)