将加速度计传感器读数记录到 SQLite 或平面文件?

发布于 2024-11-04 07:40:00 字数 397 浏览 1 评论 0原文

我正在编写一个 Android 应用程序来记录和保存高速加速度计数据(以及后来的陀螺仪数据)。我的数据的架构将如下所示:

timestamp, x_accel, y_accel, z_accel

我应该将数据保存到 SQLite 中还是保存到平面文件中(使用 FileWriter 和 BufferedWriter,如所解释的 这里)?哪一种延迟最低或更合适?

最终我需要将数据作为 csv 文件导入 Excel 中以创建图表。因此,如果我写入 SQLite,我需要稍后将其写入 csv。

I'm writing an Android app to record and save high-rate accelerometer data (and later gyroscope data). The schema of my data will look like:

timestamp, x_accel, y_accel, z_accel

Should I save the data into SQLite or into a flat file (using FileWriter and BufferedWriter, as explained here)? Which one has the lowest latency or is more appropriate?

Eventually I need to import the data as a csv file into Excel to create graphs. So if I write to SQLite, I need to later write it out to csv.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光下慵懒的猫 2024-11-11 07:40:00

显然,两者都可以工作,但我个人(不提倡或有任何东西支持)的经验法则是,如果您可以使用文件完成任务,那就去做吧。它比数据库代码更容易编写和管理,并且您可以即时将其格式化为 CSV,而无需稍后进行转换。我说别想太多。 BufferedWriter 将为您处理大块的写入,因此只需保持输出流打开,直到完成数据记录,就不会有任何延迟问题。 (完成后不要忘记 flush()close(),这条规则在 Java 中和在生活中一样适用)。

Either will work obviously, but my personal (non-advocating or backed up by anything) rule of thumb is that if you can accomplish your task with a File, go for it. It's way easier to write and manage than database code, and you'll be able to format it for CSV on-the-fly with no conversion needed later. I say don't over-think it. BufferedWriter will take care of writing out in large chunks for you, so just keep the output stream open until you're done recording your data and you shouldn't have any latency problems. (don't forget to flush() and close() when you're done, a rule as appropriate in Java as it is in life).

鹿童谣 2024-11-11 07:40:00

如果是我,我会使用 SQLite 数据库。 SQLite 非常快,但更重要的是,它为您提供了比平面文件更大的灵活性。与平面文件格式相比,您可以更轻松地更新数据库结构,并且能够更好地对数据进行排序和搜索,这对于必须将数据导出为 CSV 时可能很有价值。

If it were me, I would use a SQLite database. SQLite is very fast, but more importantly, it gives you far more flexibility than a flat file. You can update the database structure far more easily than a flat file format and you'll be able to sort and search data better, which may be valuable for when yo do have to export it to CSV.

So尛奶瓶 2024-11-11 07:40:00

通过收集大量此类数据,然后将其作为大块写入平面文件,您应该会看到更好的性能。正如您提到的,之后提取会更容易。

You should see better performance by collecting a large chunk of this data and then writing it to a flat file as a large chunk. As you mentioned, it will be easier to extract afterwards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文