简体   繁体   English

用于基于时间的图表和报告生成的 MySQL 数据库结构

[英]MySQL Database Structure for Time Based Chart and Report Generation

My application will allow users to like or dislike a product and leave a short feedback.我的应用程序将允许用户喜欢或不喜欢产品并留下简短的反馈。 I have to make a functionality which will show graph and produce report based on different time frame, probably it will be yearly, monthly, weekly and daily basis.我必须制作一个功能来显示图表并根据不同的时间范围生成报告,可能是每年、每月、每周和每天。

I have to show how many users liked or disliked the product on a particular time duration via a chart and generate the report.我必须通过图表显示特定时间段内有多少用户喜欢或不喜欢该产品并生成报告。 So my application should able to produce the daily graph of August 2018 or monthly graph of year 2018 of a particular product.因此,我的应用程序应该能够生成特定产品2018 年8 月日图2018 年的月图 The graph should able to reveal how many users liked or disliked the product on daily basis if it is daily graph, Similarly it may be for weekly, monthly or yearly time frame如果是日图,该图应该能够显示每天有多少用户喜欢或不喜欢该产品,同样,它可能是每周、每月或每年的时间范围

I am not sure what should be the database structure for this type of application?我不确定这种类型的应用程序的数据库结构应该是什么? Here what I have thought so far.到目前为止,我一直在想什么。

products: id, name, descp...etc // products table

users: id, name, email ...etc // users table

user_reactions: id, user_id(foreign key), product_id(foreign key), action(liked or disliked, tinyint), feedback // user_reactions table

data: id, product_id(foreign key), date(Y-m-d), total_like, total_dislike. // data table, will be used to make graph and report

What, I am thinking is that, I will run a cron job on 23:59:59 every day to count the like and dislike of each product and will add the data in last table, ie data table as mentioned above and then will use this data table to make graph and report.什么,我在想的是,我会在每天 23:59:59 运行一个 cron job 来统计每个产品的喜欢和不喜欢,并将数据添加到最后一个表中,即上面提到的data表,然后将使用此data表用于制作图表和报告。 I am not sure if this database structure is correct or it have some unseen problem (may be in future?)我不确定这个数据库结构是正确的还是有一些未知的问题(将来可能会出现?)

Note: My Application will be in PHP and MySQL注意:我的应用程序将使用PHPMySQL

Well, There is no right answer to your question.嗯,你的问题没有正确答案。 Because an answer to your question is called an opinion based answer.因为对您问题的回答称为基于意见的回答。 You and I will get enough downvotes for sure .你和我肯定会得到足够的反对票。 But still, hear me out my friend because I was in your state once.但是,请听我说我的朋友,因为我曾经处于你的状态。

There is a quote by famous professor Mr. Donald Knuth引用著名教授Donald Knuth先生的名言

Premature optimization is the root of all evil过早优化是万恶之源

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.我们应该忘记小效率,比如大约 97% 的时间:过早的优化是万恶之源。 Yet we should not pass up our opportunities in that critical 3%.然而,我们不应该错过关键的 3% 的机会。

The idea is that you have to start building.这个想法是你必须开始构建。 as your application progress, you will face troubles, you will face problems with your database, your system might not scale or it can't handle a million requests.随着您的应用程序的进展,您将面临麻烦,您将面临数据库问题,您的系统可能无法扩展或无法处理一百万个请求。 But until you hit that problem you don't have to worry about it.但是,在您遇到那个问题之前,您不必担心它。

I am not saying that you should go and build a system blindly with an infinite loop, or create a table join which can cause deadlocks.我并不是说你应该盲目地构建一个无限循环的系统,或者创建一个可能导致死锁的表连接。 I hope you get my point.我希望你明白我的意思。

Build a system with your knowledge and understanding.用你的知识和理解建立一个系统。 Because there is no one straight way to a problem.因为没有一种直接的方法可以解决问题。 build a feature -> you hit an issue -> tweak your app -> and rinse and repeat.构建功能 -> 您遇到问题 -> 调整您的应用程序 -> 冲洗并重复。 One day your own experiences will show you the right path.有一天,你自己的经历会告诉你正确的道路。

From your given description I can't figure out exactly how it will come out, but I am sure it will suffice for your initial days.从你给出的描述中,我无法确切地知道它会如何出现,但我相信它足以满足你的最初几天。 As you progress, you might find it hard to add new features or add additional constraints, But its another day.随着您的进步,您可能会发现很难添加新功能或添加其他约束,但它又是另一天。 wait for it and ask another question.等待它并提出另一个问题。

I hope I have answered your question.我希望我已经回答了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM