尝试创建一个程序来接收用户输入的包含病历的文本文件位置时遇到问题。正在将疾病和患者人数添加到列表中。我遇到一个问题,我的控制台为XX种独特疾病和YYY患者遇到的所有疾病都打印了0。我没有收到任何错误,只是没有正确的输出。
我相信我的问题出在我的processData()子目录中,但是我不确定为什么它回打印0。此外,当我尝试添加时,如何跟踪添加到列表中的重复疾病每次看到这种疾病时,都会有一个计数器。
来自Disease.txt的样本
3710079 JUDITH CLOUTIER 2012-08-04痉挛性结肠炎
3680080弗吉尼亚杏仁2012-07-25慢性痰
3660068 ELLEN ENGLEHARDT 2012-04-06百日咳
3810076莉莲·凯默(LILLIAN KEMMER)2014-07-04坏血病
3630055 TERESA BANASZAK 2012-06-15坏血病
输出:
总共观察到0种独特疾病。
总共进行了0次患者诊
Main():
' Global variables
Dim inputFile As String
Dim patientCounter = 0
Dim diseaseList As New List(Of String)
Dim dateList As New List(Of Date)
Sub Main()
Dim reportFile As String
Dim yn As String
Console.ForegroundColor = ConsoleColor.Yellow
Console.BackgroundColor = ConsoleColor.Blue
Console.Title = "Medical Practice Data Analysis Application"
Console.Clear()
Console.WriteLine("Please enter the path and name of the file to process:")
inputFile = Console.ReadLine
If (File.Exists(inputFile)) Then
' Call to processData sub if input file exists
processData()
Console.WriteLine(vbCrLf & "Processing Completed...")
Console.WriteLine(vbCrLf & "Please enter the path and name of the report file to generate")
reportFile = Console.ReadLine
File.Create(reportFile).Dispose()
If (File.Exists(reportFile)) Then
Console.WriteLine(vbCrLf & "Report File Generation Completed...")
Else
' Call to sub to end program if directory does not exist
closeProgram()
End If
' Get user input to see report
Console.WriteLine(vbCrLf & "Would you like to see the report file [Y/n]")
yn = Console.ReadLine
' If user inputs "y" or "Y" then print report
' Otherwise close the program
If (yn = "y" OrElse "Y") Then
printFile()
Else
closeProgram()
End If
Else
' Call to sub to end program if file does not exist
closeProgram()
End If
Console.ReadLine()
End Sub
processData Sub():
Public Sub processData()
Dim lines As String() = File.ReadAllLines(inputFile)
Dim tab
Dim dates
Dim diseaseCounter = 0
For Each line As String In lines
tab = line.Split(vbTab)
patientCounter += 1
dates = Date.Parse(line(3))
dateList.Add(dates)
'diseaseList.Add(line(4))
Dim disease As New disease(line(4))
diseaseList.Add(disease.ToString)
'diseaseList(line(4)).
For Each value In diseaseList
'If value.Equals(line(4)) Then disease.counter += 1
Next
Next
Dim uniqueDiseases As String() = diseaseList.Distinct().ToArray
End Sub
Disease.class
Class disease
Dim counter As Integer = 0
Dim name As String = ""
Sub New(newDisease As String)
name = newDisease
counter = 0
End Sub
End Class
printFile()
Sub printFile()
Dim muchoMedical As String = "MuchoMedical Health Center"
Dim diseaseReport As String = "Disease Report For the Period " & "earliest_date" & " through " & "latest_date"
Console.WriteLine(vbCrLf & muchoMedical.PadLeft(Console.WindowWidth / 2))
Console.WriteLine(diseaseReport.PadLeft(Console.WindowWidth / 2))
Console.WriteLine(vbCrLf & "There were a total of " & diseaseList.Count & " unique diseases observed")
Console.WriteLine("A total of " & patientCounter & " patient encounters were held")
Console.WriteLine(vbCrLf & "Relative Histogram of each disease")
For Each disease As String In diseaseList
Console.WriteLine(vbCrLf & disease & vbTab & " ")
Next
End Sub
closeProgram()
Sub closeProgram()
Console.WriteLine(vbCrLf & "File does not exist")
Console.WriteLine("Press Enter to exit the program...")
Console.ReadLine()
End Sub
答案 0 :(得分:0)
实际上,您不需要疾病分类,如果您正在做的最复杂的事情是计算疾病发生率(您的疾病分类没有公共成员,那么我无论如何都不知道您在做什么)。您只需使用LINQ就可以完成所有操作。
from tkinter import *
root=Tk()
B1=Button(text="Click here")
B1.pack()
root.mainloop()
我认为您的疾病名称在索引3中。您最初查看的是4。也许您在名字和姓氏之间有一个标签?如果我错了,请更改它。这可能适用于任何或所有索引。
输出:
蒲种医疗保健中心
2012年4月6日至2014年7月4日的疾病报告
总共观察到4种独特的疾病。
总共进行了5次患者patient诊
痉挛性结肠炎1
慢性痰1
呼呼咳嗽1
坏血病2
答案 1 :(得分:0)
我认为上面列出的代码的主要问题是在processData子目录中:
let quantity = 6;
let ingredients = [0.02, 0.05, 0.5, 1.2];
// Define a correction factor for arithmetic operations with the
// set of float numbers available on ingredients.
let cf = Math.pow(10, 2);
let map = ingredients.map(x =>
{
let res = (x * cf) * (quantity * cf) / (cf * cf);
return res.toString().replace(".", ",");
});
let mapRounded = ingredients.map(x =>
{
let res = (x * cf) * (quantity * cf) / (cf * cf);
return Math.ceil(res);
});
console.log("Original: ", map, "Rounded-Up: ", mapRounded);
我认为您更可能打算使用tab(3)和tab(4)代替line(3)和line(4)等。您将行拆分为“ tab”变量,但不要使用它。尽管您可以重写所有内容并以不同的方式处理它,但是如果您想使用已有的功能,我认为这是您的核心错误。
答案 2 :(得分:0)
我喜欢你上课的想法。您可以将所有数据包装在一个列表中。我增强了您的课程,使其可以包含文件中的所有数据。公共属性是具有Get,Set和Private字段的自动属性,这些属性保存由编译器写入的数据。我添加了.ToString的Overrides,因为您没有获得预期的结果。我们拥有与您一样的参数化构造函数,只是扩展了它以包括所有属性。
Linq查询中包含魔术。 d代表diseaseList中的一个项目,该项目是Disease类的一个实例。然后,我添加了一个order by子句,该子句将按疾病名称(按字符串)的字母顺序生成结果。按唯一的DiseaseName分组为带有Count的组。
在第二个For Each循环中注意,我们具有该类的所有属性。
我碰巧在Windows Forms应用程序中,所以我使用了Debug.Print。只需替换为Console.WriteLine。如果您愿意,我会留给您精美的格式。
Public Class Disease
Public Property Name As String
Public Property DiagnosisDate As Date
Public Property DiseaseName As String
Public Property ID As Integer
Public Sub New(PatientID As Integer, PatientName As String, dDate As Date, sDisease As String)
ID = PatientID
Name = PatientName
DiagnosisDate = dDate
DiseaseName = sDisease
End Sub
'If you don't override ToString you will get the fully qualified name of the class
'You can return any combination of the Properties as long as the end
'result is a string
Public Overrides Function ToString() As String
Return Name
End Function
End Class
Public Sub processData()
Dim lines As String() = File.ReadAllLines(inputFile)
Dim diseaseList As New List(Of Disease)
For Each line As String In lines
'I was having trouble with the tabs so I changed it to a comma in the file
'3710079,JUDITH CLOUTIER,2012-08-04,Spastic Colonitis
'the small c following the "," tells the compiler that this is a Char
Dim tab = line.Split(","c)
Dim inputDate = Date.ParseExact(tab(2), "yyyy-MM-dd", CultureInfo.InvariantCulture)
Dim Studentdisease As New Disease(CInt(tab(0)), tab(1), inputDate, tab(3))
diseaseList.Add(Studentdisease)
Next
Dim diseaseGrouping = From d In diseaseList
Order By d.DiseaseName
Group By d.DiseaseName
Into Group, Count
For Each diseaseAndCount In diseaseGrouping
Debug.Print($"{diseaseAndCount.DiseaseName} {diseaseAndCount.Count()} ")
For Each d In diseaseAndCount.Group
Debug.Print($" {d.Name}, {d.DiagnosisDate.ToShortDateString}")
Next
Next
End Sub