5

我有一个看似简单的问题,但我无法找到解决方案。我正在创建一个数据库设计来存储目标。目标是手动更新的,每次更新目标时我都需要一个条目。例如:

减掉 10 磅:

第 1 天:减掉 1 磅。第 3 天:减掉 2 磅。第 7 天:减了 7 磅。

然后,一旦总磅数达到目标数量,该目标就完成了。到目前为止,这是我的设计,但我发现它存在一些问题:

目标表:

GoalId - int - PK

UserId = int - FK

GoalTypeId = int - FK

标题 - 字符串

进度表:

ProgressId - int - PK

GoalId - int - FK

IntervalX - 字符串?

间隔 - 字符串?

目标金额 - 字符串?

这是跟踪此问题的最佳方法吗?有没有人看到我可以建立的基本模式来完成这个?

我的另一个想法是可能对我所有的原始数据使用这种设计,并依靠存储过程和视图以我想要的方式呈现数据?

编辑:

对不起,我会详细说明一下。区间 X 和 Y 将是图表上的区间值。因此,如果 X = 1 且 Y = 10,则 x 轴将变为 1,2,3,... 而 Y 将变为 10,20,30,...(这完全是另外一回事,我需要找出最好的方式来实现,但现在是次要的)

目标的类型很棘手,因为我想做很多事情。它们需要是一堆不同的数据类型:

目标示例:

每日阅读 - 布尔值

减 10 磅 - int 或 float

节省 5000 美元 - 钱或浮动

达到销售配额 - 浮动

学习一门新语言——字符串?(不确定跟踪这个的最佳方法)

等等..希望这有助于澄清一点

4

4 回答 4

8

You're certianly on the right track. The only other thing I can recommend is looking into key value indicators, and using this principle in your design. KVIs (or KPIs, as they're referred to in management) are values of disparate sources, which are converted into a common set of values that can be processed using common logic. This will help with evaulating progress on goals that have milestones of different types, and for compound goals, this is a crucial step. I'll elaborate a bit on this:

A goal is defined as reaching a certain milestone or combination of milestones within a certain period. The milestone is the value the needs to have a common processing value, or key value indiator. For example, losing 10 pounds, you could have a key value type of "Weight Loss", converting 1 pound to 1 KVI. Where you wish to compare milestones with one another, you may wish to adjust the weights. For example, I wish to become fitter and feel more energetic (goal). In order to do this, I must lose 10 pounds, cut sugar from my diet and cycle at least 15 miles per day (milestones). When comparing these values, 1 mile does not equate to 1 pound. More like 30 miles. Cutting sugar from my diet is not easy, but let's call the KVI "Days without sugar", and give each day without sugar a value equivalent to half a pound. The KVIs are then:

1 pound = 2 KVI
1 day without sugar = 1 KVI
1 mile = 1/30 KVI

If I ride an extra 15 miles per day, I can probably forgive myself a little bit of sugar, so this should be built into the milestones. In other words, I can achieve 200% of my cycling milestone and only 75% of my sugar milestone, and still achieve my overall goal. However, I can't go over that and still expect to feel healthy. My milestone for this goal would therefore look something like:

Lose 10 pounds: KVIType="Weight Loss", Target=20KVI, cap=100%
No sugar for period (let's say 2 weeks):KVIType="Days without sugar", target=14KVI, cap=100%
Cycle 15 miles per day: KVIType="Cycling", target=7KVI, cap=200%

Learning a new language is a good example. This requires learning the grammatical nuances of the language, sometimes a different alphabet, a whole new vocabulary and then tying these all together into daily use. So here's an example:

Learn language grammar = 100 KVI, which you can work as a percentage of a grammar course completed, for example
1000 words vocabulary = 100 KVI
Conversation = 20 KVI

In this example, you would cap each milestone at 100%. You may know the grammar off by heart and have 10,000 words under your belt, but until you've spent some time speaking the language, you haven't learned it.

By adjusting the weights in your conversion table, you can start comparing goals with one another in a way that makes sense to you. I can afford to lose 10 pounds but don't need to, so I wouldn't put too high a price tag on that one. My friend Luka, however, is 100 pounds overweight and has to for health reasons, so he'd have a higher KVI value for that one. You can also expand on how the milestones are combined to provide a progress indication of the goal (i.e. using the sum of all KVIs, average or minimum percentage completed for any component milestone).

This is sort of what I had in mind:

CREATE TABLE KVIType (
    KVITypeId INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
    KVIName VARCHAR(50),
    Description VARCHAR(200),
    Multiplier DOUBLE PRECISION
)

CREATE TABLE Goal (
    GoalId INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
    UserId INT FOREIGN KEY REFERENCES User(UserId),
    GoalName VARCHAR(50),
    GoalStart DATETIME,
    GoalComplete DATETIME,
    TargetKVI DOUBLE PRECISION,
    CurrentKVI DOUBLE PRECISION
)

CREATE TABLE Milestone (
    MilestoneId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
    GoalId INT FOREIGN KEY REFERENCES Goal(GoalId),
    KVITypeId INT FOREIGN KEY REFERENCES KVIType(KVITypeId),
    MilestoneName VARCHAR(50),
    Description VARCHAR(200),
    TargetKVI DOUBLE PRECISION,
    CurrentKVI DOUBLE PRECISION,
    TargetDate DATETIME,
    CompletedDate DATETIME,
    Cap INT)

CREATE TABLE Progress (
    ProgressId INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
    MilestoneID INT FOREIGN KEY REFERENCES Milestone(MilestoneId),
    InputValue DOUBLE PRECISIoN,
    KVIValue DOUBLE PRECISION,
    OccuranceDate DATETIME
)

CREATE TABLE User (
    UserId INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
    UserName VARCHAR(100)
)
于 2012-04-07T07:29:07.023 回答
1

有这样的东西是不是不行:

Goals(Goal_ID, User_ID, Goal_Type_ID, Title, Goal_Amount)
Progress(Goal_ID, Date_Time, Progress)

PK_Goals(Goal_ID)
PK_Progress(Goal_ID, Date_Time)

FK_Progress_Goals(Goal_ID)

进度可以是“自上次以来”或总金额 - 没关系。我不太确定区间 X 和区间 Y 在您的设计中提供哪些功能 - 您能否进一步详细说明?

于 2012-04-06T02:25:35.277 回答
1

如果所有目标都与数字有关..即减少体重,跑步里程等..那么当然,你可以做到..

就像是

UserTable Userid(PK) 用户名

GoalTable GoalId(PK) GoalExpectedProgress(Int) UserId(FK)

ProgressTable GoadId(FK) Progress_Int

可以为相同的 GoalId 添加此 Progress_Int,然后确保它符合 GoalExpectedProgress..

但是对于完成一本书、购买杂货等目标,你必须想出一个更好的计划。

于 2012-04-06T02:29:38.720 回答
1

感谢您的回答!我接受了你所说的一些内容,然后重新设计了我想要做的事情。这是我想出的解决方案:

目标表

目标 ID - PK

目标类型 ID - FK

用户 ID - FK

目标名称

目标开始

目标完成

完成目标

目标类型表

目标类型 ID - PK

类型名称

类型描述

进度数据类型

增量数据类型

进度表

ProgressId - PK

进度增量

时间增量

发生日期

用户表

用户 ID - PK

用户名

我如何实现逻辑

我试图完成的大部分工作是我离实现目标的距离,或完成的百分比。通过此设置,我在存储过程中使用了 If ElseIf 语句,该语句将操纵 Progress 表中的原始数据以提供所需的结果。If 语句将基于 GoalType 表来确定需要执行哪种逻辑。

感谢大家的投入!

于 2012-04-06T18:54:00.570 回答