将加速度计传感器读数记录到 SQLite 或平面文件?
我正在编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,两者都可以工作,但我个人(不提倡或有任何东西支持)的经验法则是,如果您可以使用文件完成任务,那就去做吧。它比数据库代码更容易编写和管理,并且您可以即时将其格式化为 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 toflush()
andclose()
when you're done, a rule as appropriate in Java as it is in life).如果是我,我会使用 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.
通过收集大量此类数据,然后将其作为大块写入平面文件,您应该会看到更好的性能。正如您提到的,之后提取会更容易。
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.