我正在编写软件来为许多类别的人们提供反馈。例如,我可能有 30 名员工和 40 个评估标准(例如“准时到达”、“有礼貌”、“似乎在刷牙”等)。在任意时间,主管可以提交一条反馈,例如“员工 3 获得标准 8 的 5/5(他闻起来很棒)”或“员工 10 获得标准 12 的 1/5(他刚刚称客户为白痴) )”。
我的想法是单独存储这些小反馈,通过保留 userId 和 standardId 字段将其链接到员工和标准。
当我想查看所有 30 名员工和 40 项标准的反馈时,问题就来了。我当前的方法需要 1200 个查询才能检索所有数据。我正在寻找更好的方法。我正在使用 google appengine 数据存储,它是一个非关系数据库。
我一直在考虑的事情,以及我欢迎反馈的事情:
-
我可以将反馈存储在网格中,每个用户一行,每个标准列。然后,单个查询获取所有数据(优于 1200),但输入新数据变得更加困难(获取网格、更新正确位、存储网格)并且用户集或标准集的更改变得更加复杂(如果我在中间添加一个标准,这个网格就需要更新)。此外,某些查询变得更加困难 - 我无法再轻松搜索在特定日期或特定主管输入的评估。
-
我可以将特定(一组用户 x 一组标准)的所有反馈存储在一个无组织的列表中,通过单个查询获取它,然后在我自己的代码中对其进行排序。这需要我循环遍历 1200 个条目,但这比对整个系统中的所有数据进行 1200 个查询要快(可能有很多很多与其他用户组和不相关标准不相关的数据)。
因此,我的问题的简短版本是:我应该如何存储这些数据,以便在快速检索大型子集和快速插入个别反馈之间取得最佳平衡?
I'm writing software to provide feedback to people across many categories. For example, I might have 30 employees and 40 standards of evaluation (e.g. "arrives on time," "is polite," "appears to brush his teeth," etc). At arbitrary times, the supervisor can submit a piece of feedback like "employee 3 gets a 5/5 for standard 8 (he smells great)" or "employee 10 gets a 1/5 for standard 12 (he just called a customer an idiot)."
My idea is to store these small pieces of feedback individually, linked to the employee and standard by keeping userId and standardId fields.
The problem comes when I want to look at the feedback for all 30 employees and 40 standards. My current approach requires 1200 queries to retrieve all of that data. I'm looking for a better way. I'm using the google appengine datastore, which is a non-relational db.
Things I've been thinking about, and on which I welcome feedback:
-
I could store the feedback in a grid, with a row per user and column per standard. Then, a single query gets all of the data (better than 1200), but entering new data becomes more difficult (fetch the grid, update the correct bit, store the grid) and changes in the user set or standard set become much more complex (if I add a standard in the middle, this grid needs to be updated). Also, some queries become much harder - I can no longer easily search for the assessments entered on a certain date or by a certain supervisor.
-
I could store all of the feedback for a certain (set of users x set of standards) in an unorganized list, fetch it with a single query, and then sort it out in my own code. This requires me to loop through 1200 entries, but that would be faster than 1200 queries over all of the data in the whole system (there may be many, many irrelevant data for other sets of users and unrelated standards).
So, the short version of my question is: how should I store this data for the best balance of quick retrieval of a large subset and quick insertion of individual pieces of feedback?
发布评论
评论(1)
您也许可以使用RelationIndex 来完成此操作。根据您希望允许用户查看和查询数据的具体程度,它应该可以工作。
这个想法非常简单,基本上您将为每个员工存储一个“标准”列表。可能还有每个标准的员工名单。然后你就可以提出诸如所有“闻起来很香”的员工之类的问题。
因为您有每个标准的分数,所以您可能需要执行一些操作,例如将“分数”和“标准数字”作为一对存储在列表中 (“3:12”),以便您可以找到分数为 3 的每个人基于标准 12。
编辑:根据评论进行更新。
听起来您需要处理几个不同的问题。首先,您需要处理数据的编辑和维护。其次,您需要处理数据查询。第三,您将需要处理数据的显示。
为了有效地查询数据,您可能需要一些类似于我最初建议的方法。编辑或查看数据哪个更常见?这将影响您设置模型的方式。
如果您只处理 30 或 40 名员工和 30 或 40 个标准,也许您可以使用如下内容:
使用评估的标准属性来存储评估的标准列表。然后将您的员工标准分数网格存储在分数属性中。显然,您需要序列化标准列表和评估网格,也许使用 JSON 之类的东西。使用我上面提到的评估指数模型。
有了这个(或真正类似的东西),您将可以非常轻松地进行编辑,非常容易地显示,并且支持查询。
您可以添加一个额外的模型来跟踪哪个主管输入了评估及其注释。
You might be able to do this using a RelationIndex. Depending on how exactly you will want to allow user to view and query the data, it should work.
The idea is pretty straight forward, basically you will store a list of "standards" for each employee. And possibly a list of employee's for each standard. Then you'll be able to ask questions such as all employee's who 'smell good'.
Because you have scores for each standard, you might want to do something like store the "score" and "standard number" as a pair in the list ("3:12") so that you can find everyone who has a score of 3 on standard 12.
edit: Updated based on comment.
It sounds like you need to deal with a few different issues. First, you need to deal with editing and maintaining the data. Second, you need to deal with querying the data. Third, you are going to need to handle displaying the data.
For querying the data efficiently you will probably need some approach similar to what I initially suggested. What is more common, editing or viewing the data? That will impact how you setup your models.
If you are only dealing with 30 or 40 employees and 30 or 40 standards, maybe you could use something like the following:
Use the standards property on Evaluations to store a list of standards evaluated. Then store your employee-standard-score grid in the scores property. Obviously you'll need to serialize both the standards list and the evaluation grid, perhaps using something like JSON. Use the EvaluationsIndex model as I mentioned above.
With this (or something really similar) you will have pretty easy edits, very easy display, and support for queries.
You could add an additional model to track which supervisor entered the evaluation and her notes.