C#中的时间戳 [英] Time Stamps in C#

查看:75
本文介绍了C#中的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我完全不熟悉编程,而且我已经完成了一项任务。我已经看过网上了,我已经把一些代码放在一起,但我不确定我是否正朝着正确的方向前进。你介意看看它并让我知道吗?



这就是我希望程序完成后我想要的。



****将如上图所示的生命体征数据从文本文件导入到内存中。

注意:文件应由字符串路径指定;任何适当的数据结构都可以用来将数据保存在内存中。

****将灵活的时间戳与导入的每组数据相关联。 />
注意:模拟诊断会话始终从0秒开始,之后具有可配置的采样间隔(SI)

。例如,如果SI设置为5秒,则第一组数据将在0

秒收集,第二组数据收集在5秒,第三组数据收集在10秒,等等。

****在模拟诊断会话中返回给定特定时间的最新数据组。

****注意:模拟诊断会话的长度可以通过从文件导入的数据总数和采样间隔来确定。例如,如果导入了200组数据且SI = 5,则模拟会话的

长度将为(200-1)* 5 = 995秒。在这种情况下,病人模拟器应该能够在[0,995]时间窗口内的任何时间返回最新的数据组。



这是我目前拥有的代码;



Hi,

I'm completely new to programming and I've been given a task to do. I've had a look online and I've put together some code but I'm not sure if I'm going in the right direction. Do you mind having a look at it and letting me know?

This is what I want my program to do when it is complete.

****To import vital sign data as illustrated above into the memory from a text file.
Note: The location of the file should be specified by a string path; any appropriate data structures can be
used to hold the data in the memory.
****To associate flexible timestamps with each group of data that is imported.
Note: A simulated diagnostic session always starts from 0 second, with a configurable sampling interval (SI)
afterwards. For instance, if the SI was set to 5 seconds, then the first group of data would be collected at 0
second, the second group of data at 5 second, the third group of data at 10 second, and so on.
****To return the most recent group of data given a particular time within a simulated diagnostic session.
****Note: The length of a simulated diagnostic session can be determined by the total number of data imported
from the file and the sampling interval. For instance, if 200 groups of data were imported with SI = 5, the
length of the simulated session would be (200-1)*5 = 995 seconds. In this case, the Patient Simulator should be able to return the most recent group of data at any second within the [0, 995] time window.

And this is the code I currently have;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Patient_Simulator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
         string Data = string.Empty;
        private void Data_Load(object sender, 
            EventArgs e)
        {
            lblData.Hide();
        }

        private void btnData_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "Select Data File:";
            DialogResult fd = fbd.ShowDialog();
            if (fd == DialogResult.OK)
            {
                lblData.Text = Data = fbd.SelectedPath;
            }
            else
            {
                lblData.Text = Data = "";
            }

            if (!string.IsNullOrEmpty(Data))
            {
                loadData(Data);
            }
}
        private void loadData = (string Data)
        {
        string[] photo = Directory.GetFiles(Data, "*.txt");
        
        {
        
    }
}





有人能指点我吗在正确的方向?那将是非常棒的。



Could someone point me in the right direction? That would be awesome.

推荐答案

在任何技术冒险中处于开始都没有错;据我所知,每个人都从那里开始:) ...事实上,它可能比其他任何时候都更快地学习。



我建议你接近你的创建一个应用程序的任务,该应用程序使用计算机科学中经常被称为分而治之的方法来解析包含患者生命体征数据的文件:



1.制作一个大纲,其中包括:



a。你的申请目标



b。您对数据结构的记录和分析。



c。从您的应用程序(到屏幕,到打印机等)的任何输出所需的格式。



d。想法,草图,要求,用户界面



然后,针对每个目标,制定实现该目标所需的任务列表。理想情况下,任务定义应该导致设计代码的离散模块,其输入被定义,输入数据的所需转换被定义,并且其输出被定义。



某些必需模块的想法可能会跳出来:很明显,您需要为用户选择一个或多个文件。很明显,当你想要分析文件或文件列表时,你需要打开它们并解析它们。



所以:



1.模块1:选择文件



2.模块2:解析文件



显然,解析文件将受到未来数据分析要求的影响。在这种情况下,约束是您必须将数据解析为可以对其进行采样的某种形式,并根据指定的时间间隔(以秒为单位)显示数据。



因此,您希望将数据转换为内部表示(类或列表的实例或其他)一次,以便重复采样不会导致重新分析数据的高成本。



我无法从中得知:将灵活的时间戳与导入的每组数据相关联,如果您要使用的时间/日期信息基于文件的时间戳信息,或者如果你打算以某种方式自己创建它。



为了给你更具体的建议,我认为有人在帮助你这里需要了解更多关于生命体征数据的格式,以及时间戳在这种情况下的含义。
There's nothing wrong about being at the "beginning" in any technical adventure; to my knowledge everyone begins there :) ... in fact, it may be the opportunity to learn more quickly than at any other time.

I suggest you approach your task of creating an application that parses a file containing Patient vital-sign data by using what's often referred to in computer science as the "divide-and-conquer" approach:

1. make an outline that includes:

a. your goals for the application

b. your notes on, and analysis of, the structure of the data.

c. the required formats for any output from your application (to screen, to printer, etc.).

d. ideas, sketches, requirements for, the user interface

Then, for each goal, develop a list of tasks necessary to reach that goal. Ideally, a task definition should lead to the design of the discrete module of code whose inputs are defined, whose required transformation of the input data is defined, and whose output is defined.

Ideas for some of the required modules may "jump out at you:" it's obvious you are going to need to have a way for the user to select a file, or files. It's obvious that when you have the file, or list of files, you want to analyze, you are going to need to open them and parse them.

So:

1. module 1: select files

2. module 2: parse files

Clearly, parsing the file(s) is going to be shaped/constrained by the requirements for future analysis of the data. In this case, a constraint is that you must parse the data into some form where you can sample it, and present the data, based on a specified interval in seconds.

So, you want to transform the data into internal representations (instances of Classes, or Lists, or whatever) once so that repeated sampling does not incur a high cost of re-analyzing the data.

I can't quite tell from this: "To associate flexible timestamps with each group of data that is imported," if the time/date information you are going to use is based on the file's time-stamp information, or if you are going to create this yourself, on-the-fly, in some way.

To give you more specific advice, I think anyone assisting you here would need to know more about the format of the vital-sign data, and what "timestamp" means in this context.


不,我不认为你是在右边方向,或者至少,你还没有还有。

您展示的代码只关注任务的重要部分:查找包含模拟数据的文件。这很简单,您可以暂时忽略它并硬编码文件路径,并将硬编码路径传递给LoadFile方法:

No, I don't think you are going in the right direction, or at least, you haven't got there yet.
The code you show is concerned only with the trivial part of the task: finding the file containing your simulation data. That's the easy bit, and you can ignore that for the moment and hard-code the file path, and hand the hardcoded path through to a LoadFile method:
myData = LoadFile(@"D:\Temp\MySimulationData.txt");



加载文件时会出现复杂的部分:我们无法在此处给出具体的答案,因为我们无权访问该文件,也无法访问其中包含的内容。



因此,您需要先查看文件(以及您的导师给您描述文件内容的任何支持信息)并首先确定每个文件中的信息。 记录。我们知道它会包含一个时间戳,但我不知道它包含的其他数据,或者时间戳占用的格式 - 所以你需要隔离这些信息。



然后,创建一个包含单行信息的类,并开始读取行并创建该类的实例。我们可以帮助你做到这一点,因为我们不知道它是什么数据,或者它是如何存储的 - 所以你需要坐下来思考它一段时间并完成其中的一些工作! />


然后,您可以查看一次读取一行文件,并创建必要的实例,然后再将它们从LoadFile方法返回到某个集合中。


The complicated part starts when you load the file: and we can't give you specific answers here because we don't have access to the file, or to a description of what it contains.

So, you need to start by looking at the file (and at any supporting info your tutor gave you describing the file content) and begin by identifying the information in each "record". We know it will contain a timestamp, but I don't know what other data it contains, or what format the timestamp takes - so you need to isolate that info.

Then, create a class which contains the information for a single row, and start reading the rows and creating instances of the class. We can;t help you do that yet, because we don't know what data it is, or how it is stored - so you need to sit down and think about it for a while and work some of this stuff out!

You can then look at reading the file a row at a time, and creating the necessary instances, before returning them from your LoadFile method in a collection for some sort.


在开始考虑具体程序之前,您必须首先了解问题域。



您给出的描述只是一个片段看来你的整个作业。

例如有几个术语不清楚:

a)什么是生命体征数据?

b)什么意思是如上所示?

c)什么是数据组?

d)什么是诊断会话?

e)什么是病人模拟器?

。 ..

z)这些条款是如何相互关联的?



在一张纸上画整个系统:



  • 涉及哪些组件(模拟器,PC,数据交换,在每个设备上运行的程序等)。
  • 写一些用例如何操作
  • 触发用例触发器发生的操作序列
  • ...
Before starting to think about the concrete program, you must understand the problem domain first.

The description you give is only a snippet of your whole assignment, it seems.
E.g. several terms are unclear:
a) what are "vital sign" data?
b) whati meant by "as shown above"?
c) what are "group of data"?
d) what is a "diagnostic session"?
e) what is a "patient simulator"?
...
z) how are these terms interrelated?

Draw on a sheet of paper the whole system:

  • what components are involved (simulator, PC, Data exchange, programs that run on each device, etc.)
  • write some use cases how actions are triggered and what the output is from such triggers
  • draw the sequence of actions that happened with such a trigger of a use case
  • ...


  • 写一个程序启动一个Dialog窗口,要求用户输入一些文件路径进行处理



    • 该文件包含一个或多个诊断会话数据( ?)
    • 一个诊断数据由数据组组成(?)
    • 一组数据由一系列数据样本组成(?)
    • 一个数据sample表示诊断会话的时间片(?)


      • 触发器阅读文件



        • 阅读意味着将文件的(文本?)内容转换为有意义的信息块(这称为解析)
        • 取决于实际的文件格式,这种解析可能从非常简单到相当精细
        • 设计一个适合您需求的数据结构,例如类似于上面列出的项目:


        • trigger reading the file

          • reading means convert the (text?) content of the file into meaningful information chuncks (this is called parsing)
          • depending on the actual file format, this parsing may be from very simple to rather elaborate
          • design a data structure that suits your needs, e.g. analogous to the items identified above:
          - a list of diagnostics sessions instances
            - a dignostics session class consists of a list of data groups
              - a data group class consists of a sequence of data samples
                - a data sample class consists of ...

        • 解析器现在必须将文件中的文本转换为此类数据结构


          • 到数据库?
          • 到用户界面?
          • 到某个文件?
          • 已过滤?
          • 已排序?
          • ...?


          这篇关于C#中的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆