SemlerPDX

AVCS SENS Diagnostics MAIN-v8 Inline Function in VB.net for VoiceAttack & AIDA64

Jun 14th, 2022 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 12.43 KB | None | 0 0
  1. 'AVCS SENS Parse Data Last Average or Differential Diagnostic* Report per Sensor Label
  2. ' *(When paired with AVCS-DHT1) - Based on current & historic PC operational state level bracket data (low/medium/high/extreme)
  3. ' by SemlerPDX Mar2022
  4. ' VETERANS-GAMING.COM
  5.  
  6. 'Format of incoming data from global variable:
  7. 'VA.SetText("AVCS_SENS_DIAGNOSTICS_" + currentLabel, differentialDiagnosis)
  8. 'differentialDiagnosis =
  9. '  currentAverage.ToString() + "," +
  10. '  historicAverage.ToString() + "," +
  11. '  averageDistance.ToString() + "," +
  12. '  percentDifference.ToString() + "," +
  13. '  differentialDiagnosis  ("stable","higher","lower")
  14.  
  15. ' output to ~~avcs_sens_tts_final
  16.  
  17. Imports Microsoft.VisualBasic
  18. Imports System
  19. Imports System.IO
  20. Imports System.IO.Ports
  21. Imports System.Math
  22. Imports System.Text.RegularExpressions
  23. Imports System.Collections
  24. Imports System.Collections.Generic
  25. Imports System.Data
  26. Imports System.Drawing
  27. Imports System.Diagnostics
  28. Imports System.Text
  29. Imports System.Windows.Forms
  30. Imports System.Linq
  31. Imports System.Xml
  32. Imports System.Xml.Linq
  33. Imports System.Threading
  34. Imports System.Threading.Tasks
  35.  
  36.  
  37. Public Class VAInline
  38.     dim contents() as string
  39.     dim sensorName as string = ""
  40.     dim sensorUnit as string = ""
  41.     dim differentialDiagnosis as string = ""
  42.     dim lastAverage as decimal = 0
  43.     dim percentDifference as decimal = 0
  44.     dim decimalPlacesMax as integer = 1
  45.     dim roundedFanValue as string = "0"
  46.    
  47.     dim debugReports as boolean = false
  48.    
  49.    
  50.     Public Function GetRoundedDecimal(ByVal thisDecimal as decimal, ByVal decimalPlaces as integer)
  51.         try
  52.             'Try to compare decimal with integer version of itself to discover decimal places, then round
  53.             dim checkInteger as Int32 = Convert.ToInt32(thisDecimal)
  54.             if (thisDecimal = checkInteger)
  55.                 'For TTS brevity use the one that couldn't end with .000
  56.                 thisDecimal = checkInteger
  57.             elseif (checkInteger <> thisDecimal)
  58.                 dim roundDecimal as Double = thisDecimal
  59.                 thisDecimal = Round(roundDecimal, decimalPlaces)
  60.             end if
  61.         catch
  62.             'Result is a whole number already, does not need rounding for TTS brevity
  63.         end try
  64.        
  65.         return thisDecimal
  66.     end function
  67.    
  68.     Public Function GetRoundedFanRPM(ByVal thisFanRPM as decimal)
  69.         dim thisRoundedRPM as string = GetRoundedDecimal(thisFanRPM, 0).ToString()
  70.         thisFanRPM = GetRoundedDecimal(thisFanRPM, 0)
  71.         if (thisFanRPM > 1000)
  72.             thisFanRPM /= 100
  73.             thisFanRPM = GetRoundedDecimal(thisFanRPM, 0)
  74.             if (thisFanRPM.ToString().EndsWith("0"))
  75.                 thisRoundedRPM = "around " + (thisFanRPM * 100).ToString()
  76.             else
  77.                 thisRoundedRPM = "around " + thisFanRPM.ToString() + " hundred"
  78.             end if
  79.         elseif (thisFanRPM <= 999) and (thisFanRPM > 100)
  80.             thisFanRPM /= 10
  81.             thisRoundedRPM = "around " + ((GetRoundedDecimal(thisFanRPM, 0)) * 10).ToString()
  82.         end if
  83.        
  84.         return thisRoundedRPM
  85.     end function
  86.    
  87.     Public Sub Main()
  88.         if (debugReports)
  89.             'AVCS_SENS_DIAGNOSTICS_dTa_TempCPU
  90.             'VA.SetText("~~avcs_sens_tts_label", "CPU")
  91.             'VA.SetText("~~avcs_sens_sensor_label", "dTa_TempCPU")
  92.             'VA.SetText("~~avcs_sens_tts_unit", "degrees over ambient")
  93.             'VA.SetText("AVCS_SENS_Current_LevelBracket", "HIGH") (phased out in v4)
  94.         end if
  95.        
  96.         if ((VA.GetBoolean("AVCS_SENS_DebugReports") isNot nothing) andAlso (VA.GetBoolean("AVCS_SENS_DebugReports")))
  97.             debugReports = true
  98.         end if
  99.        
  100.         if ((VA.GetText("~~avcs_sens_tts_label") isNot nothing) andAlso (VA.GetText("~~avcs_sens_tts_unit") isNot nothing) andAlso (VA.GetText("~~avcs_sens_sensor_label") isNot nothing) andAlso (VA.GetText("~~avcs_sens_sensor_type") isNot nothing))
  101.             sensorName = VA.GetText("~~avcs_sens_tts_label")
  102.             sensorUnit = VA.GetText("~~avcs_sens_tts_unit")
  103.             if (VA.GetText("~~avcs_sens_sensor_label") isNot nothing)
  104.             VA.GetText("~~avcs_sens_sensor_label")
  105.                 if (VA.GetText("AVCS_SENS_DIAGNOSTICS_" + VA.GetText("~~avcs_sens_sensor_label")) isNot nothing)
  106.                     'VA.WriteToLog("HAS DIAGNOSTIC DATA!!","green")
  107.                     try
  108.                         contents = VA.GetText("AVCS_SENS_DIAGNOSTICS_" + VA.GetText("~~avcs_sens_sensor_label")).Replace(" ","").Split(",")
  109.                         if (debugReports)
  110.                             for i as integer = 0 to contents.GetUpperBound(0)
  111.                                 VA.WriteToLog("contents("+ i.ToString() +") = " + contents(i).ToString(), "yellow")
  112.                             next
  113.                         end if
  114.                        
  115.                         VA.SetText("AVCS_SENS_TTS_LastQuery_CurrentAverage", contents(1).ToString())
  116.                         VA.SetText("AVCS_SENS_TTS_LastQuery_HistoricAverage", contents(2).ToString())
  117.                         VA.SetText("AVCS_SENS_TTS_LastQuery_AverageDistance", contents(3).ToString())
  118.                         VA.SetText("AVCS_SENS_TTS_LastQuery_PercentDifference", contents(4).ToString())
  119.                         VA.SetText("AVCS_SENS_TTS_LastQuery_DifferentialDiagnosis", contents(5).ToString())
  120.                        
  121.                         'Set this value to be available immediately as "that" in AVCS Voice Calculator & Conversions Profile
  122.                         VA.SetDecimal("AVCS_CALC_LastResult", contents(1).ToString())
  123.                         if (contents(5) <> "")
  124.                             if (contents(5) = "stable")
  125.                                 if ((VA.GetText("~~avcs_sens_sensor_label").EndsWith("fan")) or (VA.GetText("~~avcs_sens_sensor_label").EndsWith("Fan")))' or (sensorName.StartsWith("fan")) or (sensorName.Contains("Fan")) or (sensorName.Contains("fan")) or (sensorName.Contains("Fan")))
  126.                                     sensorName = sensorName + " fan"
  127.                                     roundedFanValue = GetRoundedFanRPM(Convert.ToDecimal(contents(1)))
  128.                                     differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;reporting;;;reading;] [;;;;;stable;;;standard;;;typical;;;nominal;;;] at " + roundedFanValue + " " + sensorUnit
  129.                                     VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + roundedFanValue.Replace("around ", "").Replace(" hundred", "00") + " " + sensorUnit, "blank")
  130.                                 else
  131.                                     if ((sensorName.ToLower() = "cpu") andAlso (VA.GetText("~~avcs_sens_sensor_type") = "temp"))
  132.                                         sensorName = sensorName + " core"
  133.                                     end if
  134.                                     differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;reporting;;;reading;;;] [;;;;stable;;;standard;;;typical;;;nominal;;;] at " + GetRoundedDecimal(Convert.ToDecimal(contents(1)), 1).ToString() + " " + sensorUnit
  135.                                     VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + GetRoundedDecimal(Convert.ToDecimal(contents(1)), 1).ToString() + " " + sensorUnit.Replace("percent", "%"), "blank")
  136.                                 end if
  137.                             else
  138.                                 if ((VA.GetText("~~avcs_sens_sensor_label").EndsWith("fan")) or (VA.GetText("~~avcs_sens_sensor_label").EndsWith("Fan")))' or (sensorName.StartsWith("fan")) or (sensorName.Contains("Fan")) or (sensorName.Contains("fan")) or (sensorName.Contains("Fan")))
  139.                                     sensorName = sensorName + " fan"
  140.                                     roundedFanValue = GetRoundedFanRPM(Convert.ToDecimal(contents(1)))
  141.                                     differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;averaging;reporting;reading;] " + contents(5) + " than [standard;typical;baseline] at " + roundedFanValue + " " + sensorUnit
  142.                                     VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + roundedFanValue.Replace("around ", "").Replace(" hundred", "00") + " " + sensorUnit + " (" + contents(5) + " than typical)", "blank")
  143.                                 else
  144.                                     if ((sensorName.ToLower() = "cpu") andAlso (VA.GetText("~~avcs_sens_sensor_type") = "temp"))
  145.                                         sensorName = sensorName + " core"
  146.                                     end if
  147.                                     differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;averaging;reporting;reading;] " + GetRoundedDecimal(Convert.ToDecimal(contents(4)), 0).ToString() + " percent " + contents(5) + " than [standard;typical;baseline] at " + GetRoundedDecimal(Convert.ToDecimal(contents(1)), 1).ToString() + " " + sensorUnit
  148.                                     VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + GetRoundedDecimal(Convert.ToDecimal(contents(1)), 1).ToString() + " " + sensorUnit.Replace("percent", "%") + " (" + contents(5) + " than typical)", "blank")
  149.                                 end if
  150.                             end if
  151.                         else
  152.                             differentialDiagnosis = "[The;My;] " + sensorName + " is currently [unavailable;not reporting;silent] for some reason."
  153.                             differentialDiagnosis = "[I do not have;There is no;I cannot locate] " + sensorName + " sensor data."
  154.                             differentialDiagnosis = "[I do not have;There is no;I cannot locate] " + sensorName + " " + VA.GetText("~~avcs_sens_sensor_type").Replace("temp","temperature").Replace("fan_use","fan use").Replace("use","utilization") + " sensor data. Please check configuration."
  155.                             VA.WriteToLog("Current Average " + VA.GetText("~~avcs_sens_sensor_label").Replace("_"," ").Replace("dTa","ΔT/a") + " is unavailable. Please check configuration.", "red")
  156.                         end if
  157.                     catch
  158.                         differentialDiagnosis = "[The;My;] " + sensorName + " is currently [unavailable;not reporting;silent] for some reason."
  159.                         differentialDiagnosis = "[I do not have;There is no;I cannot locate] " + sensorName + " sensor data."
  160.                         differentialDiagnosis = "[I do not have;There is no;I cannot locate] " + sensorName + " " + VA.GetText("~~avcs_sens_sensor_type").Replace("temp","temperature").Replace("fan_use","fan use").Replace("use","utilization") + " sensor data. Please check configuration."
  161.                         VA.WriteToLog("Current Average " + VA.GetText("~~avcs_sens_sensor_label").Replace("_"," ").Replace("dTa","ΔT/a") + " is unavailable. Please check configuration.", "red")
  162.                     finally
  163.                         VA.SetText("~~avcs_sens_tts_final", differentialDiagnosis.Replace("_"," "))
  164.                         if (debugReports)
  165.                             VA.WriteToLog("~~avcs_sens_tts_final = " + VA.ParseTokens("{TXT:~~avcs_sens_tts_final}"), "yellow")
  166.                         end if
  167.                     end try
  168.                 else
  169.                     'VA.WriteToLog("HAS NO DIAGNOSTIC DATA!!","red")
  170.                     if ((VA.GetDecimal("AVCS_SENS_LastAverage_" + VA.GetText("~~avcs_sens_sensor_label")) isNot nothing) andAlso (Decimal.TryParse(VA.GetDecimal("AVCS_SENS_LastAverage_" + VA.GetText("~~avcs_sens_sensor_label")), lastAverage)))
  171.                        
  172.                         'Set this value to be available immediately as "that" in AVCS Voice Calculator & Conversions Profile
  173.                         VA.SetDecimal("AVCS_CALC_LastResult", lastAverage.ToString())
  174.                         if ((VA.GetText("~~avcs_sens_sensor_label").EndsWith("fan")) or (VA.GetText("~~avcs_sens_sensor_label").EndsWith("Fan"))) ' or (sensorName.StartsWith("fan")) or (sensorName.Contains("Fan")) or (sensorName.Contains("fan")) or (sensorName.Contains("Fan")))
  175.                             sensorName = sensorName + " fan"
  176.                             roundedFanValue = GetRoundedFanRPM(lastAverage)
  177.                             differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;reporting;;;reading;] [at;;;] " + roundedFanValue + " " + sensorUnit
  178.                             VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + roundedFanValue.Replace("around ", "").Replace(" hundred", "00") + " " + sensorUnit, "blank")
  179.                         else
  180.                             if ((sensorName.ToLower() = "cpu") andAlso (VA.GetText("~~avcs_sens_sensor_type") = "temp"))
  181.                                 sensorName = sensorName + " core"
  182.                             end if
  183.                             if ((VA.GetText("~~avcs_sens_sensor_type") = "voltage") or (VA.GetText("~~avcs_sens_sensor_type") = "amperage") or (VA.GetText("~~avcs_sens_sensor_type") = "wattage"))
  184.                                 decimalPlacesMax = 2
  185.                             else
  186.                                 decimalPlacesMax = 1
  187.                             end if
  188.                             differentialDiagnosis = "[The;My;] " + sensorName + " is [;;;;;reporting;;;reading;;;] [;;;;stable;;;standard;;;typical;;;nominal;;;] at " + GetRoundedDecimal(lastAverage, decimalPlacesMax).ToString() + " " + sensorUnit
  189.                             VA.WriteToLog("Current Average " + sensorName.Replace("_"," ").Replace("dTa","ΔT/a") + " value:  " + GetRoundedDecimal(lastAverage, decimalPlacesMax).ToString() + " " + sensorUnit.Replace("percent", "%"), "blank")
  190.                         end if
  191.                     else
  192.                         differentialDiagnosis = "[The;My;] " + sensorName + " is currently unavailable. Please check configuration."
  193.                         differentialDiagnosis = "[I do not have;There is no;I cannot locate] " + sensorName + " " + VA.GetText("~~avcs_sens_sensor_type").Replace("temp","temperature").Replace("fan_use","fan use").Replace("use","utilization") + " sensor data. Please check configuration."
  194.                         VA.WriteToLog("Current Average " + VA.GetText("~~avcs_sens_sensor_label").Replace("_"," ").Replace("dTa","ΔT/a") + " is unavailable. Please check configuration.", "red")
  195.                     end if
  196.                    
  197.                     VA.SetText("~~avcs_sens_tts_final", differentialDiagnosis.Replace("_"," "))
  198.                     if (debugReports)
  199.                         VA.WriteToLog("~~avcs_sens_tts_final = " + VA.ParseTokens("{TXT:~~avcs_sens_tts_final}"), "yellow")
  200.                     end if
  201.                    
  202.                 end if
  203.             end if
  204.         end if
  205.     End Sub
  206.    
  207. End Class
Add Comment
Please, Sign In to add comment