Re: [Planner Dev] Hours per day does not have to be an integer
- From: Henning Kulander <hennikul linpro no>
- To: Richard Hult <richard imendio com>
- Cc: Planner Project Manager - Development List <planner-dev lists imendio com>
- Subject: Re: [Planner Dev] Hours per day does not have to be an integer
- Date: Thu, 18 Nov 2004 18:24:33 +0100
On Mon, 2004-11-15 at 00:59 +0100, Richard Hult wrote:
> Henning Kulander wrote:
> > I played around with the source of 0.12.1 and found that the problem is
> > a combination of hardcoding 8 hours working day and the use of integers
> > for hours_per_day. I made a patch which fixes this behaviour (attached).
>
> Nice! Although I think it would be better to use the same unit as the
> rest of the code instead of hours (i.e. seconds), rather than having a
> float here.
OK, I agree..:) The new code uses seconds in stead of floats in
planner_format_duration, but still uses floats in the spin-button. I
think it needs to be a float here still...
> We have also been loosly discussing exactly how to handle the conversion
> between the displayed value in days and the exact value. With your fix,
> it would depend on the exact calendar used by the particular resource,
> right? That's one of the solutions we've suggested, the other one was to
> have a project wide setting for how long a day should be. I'm still not
> sure which way is best. Any comments on that?
I made it this way because it was easiest, and produced the results I
wanted. To me it looks like the calendar can be chosen for the project
as a whole and for each resource. Ideally I should (as a user) be able
to select a different calendar for my english co-workers so they can
keep working 8 hour days. This does not work now. I will need some
guidance on this one from someone who knows the object-structure
better.
> > In my testing I have not encountered any new bugs. One bug related to
> > this I was not able to fix was the HTML export. I do not know anything
> > about XSLT, so I was not able to fix this. From what I gathered, a
> > variable containing the sum (in seconds) of the intervals
> > in //project//calendar//overridden-day-type//interval needs to be
> > calculated and used in the mrproj-duration template.
>
> Yeah, sounds like it's something like that.
Could anybody help to fix this?
--
Regards,
Henning Kulander
Systems consultant
Linpro
diff -u -r planner-0.12.1/src/planner-format.c planner-0.12.1-hours_per_day_fix/src/planner-format.c
--- planner-0.12.1/src/planner-format.c 2004-08-19 11:06:39.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-format.c 2004-11-18 17:41:57.000000000 +0100
@@ -128,13 +128,13 @@
gchar *
planner_format_duration (gint duration,
- gint day_length)
+ gint day_length_seconds)
{
gint days;
gint hours;
- days = duration / (60*60*day_length);
- duration -= days * 60*60*day_length;
+ days = duration / (int) (day_length_seconds);
+ duration -= days * (int) day_length_seconds;
hours = duration / (60*60);
if (days > 0 && hours > 0) {
diff -u -r planner-0.12.1/src/planner-format.h planner-0.12.1-hours_per_day_fix/src/planner-format.h
--- planner-0.12.1/src/planner-format.h 2004-08-19 11:05:09.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-format.h 2004-11-18 17:42:44.000000000 +0100
@@ -29,7 +29,7 @@
gchar *planner_format_int (gint number);
gchar *planner_format_duration (gint duration,
- gint day_length);
+ gint day_length_seconds);
gchar *planner_format_date (mrptime date);
diff -u -r planner-0.12.1/src/planner-gantt-print.c planner-0.12.1-hours_per_day_fix/src/planner-gantt-print.c
--- planner-0.12.1/src/planner-gantt-print.c 2004-08-19 11:06:39.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-gantt-print.c 2004-11-18 17:43:43.000000000 +0100
@@ -213,6 +213,8 @@
GList *l, *to;
PrintTask *ptask;
gint last, i;
+ gint seconds_per_day;
+ MrpCalendar *calendar;
if (header) {
last = first + data->tasks_per_page_with_header;
@@ -257,7 +259,12 @@
x = data->work_x1 + data->job->x_pad;
- str = planner_format_duration (work, 8);
+ calendar = mrp_project_get_calendar (data->project);
+
+ seconds_per_day = mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ());
+
+ str = planner_format_duration (work, seconds_per_day);
planner_print_job_show_clipped (data->job,
x, y,
str,
diff -u -r planner-0.12.1/src/planner-gantt-row.c planner-0.12.1-hours_per_day_fix/src/planner-gantt-row.c
--- planner-0.12.1/src/planner-gantt-row.c 2004-08-19 11:06:39.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-gantt-row.c 2004-11-18 17:45:03.000000000 +0100
@@ -1781,13 +1781,13 @@
gint work;
MrpProject *project;
MrpCalendar *calendar;
- gint hours_per_day;
+ gint seconds_per_day;
project = mrp_object_get_project (MRP_OBJECT (priv->task));
calendar = mrp_project_get_calendar (project);
- hours_per_day = mrp_calendar_day_get_total_work (
- calendar, mrp_day_get_work ()) / (60*60);
+ seconds_per_day = mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ());
wx2 = event->motion.x;
wy2 = priv->y + 0.70 * priv->height;
@@ -1818,7 +1818,7 @@
message = g_strdup_printf (
_("Change work to %s"),
- planner_format_duration (work, hours_per_day));
+ planner_format_duration (work, seconds_per_day));
planner_gantt_chart_status_updated (chart, message);
g_free (message);
}
diff -u -r planner-0.12.1/src/planner-project-properties.c planner-0.12.1-hours_per_day_fix/src/planner-project-properties.c
--- planner-0.12.1/src/planner-project-properties.c 2004-08-19 11:06:39.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-project-properties.c 2004-11-18 17:45:55.000000000 +0100
@@ -927,13 +927,11 @@
mrp_property_get_name (property), &ivalue,
NULL);
-/* work = mrp_calendar_day_get_total_work (
- mrp_project_get_calendar (tree->priv->project),
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (data->project),
mrp_day_get_work ());
-*/
- work = 8*60*60;
- svalue = planner_format_duration (ivalue, work / (60*60));
+ svalue = planner_format_duration (ivalue, work);
break;
case MRP_PROPERTY_TYPE_COST:
@@ -1596,13 +1594,11 @@
mrp_property_get_name (property), &ivalue,
NULL);
-/* work = mrp_calendar_day_get_total_work (
- mrp_project_get_calendar (tree->priv->project),
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
mrp_day_get_work ());
-*/
- work = 8*60*60;
- svalue = planner_format_duration (ivalue, work / (60*60));
+ svalue = planner_format_duration (ivalue, work);
break;
case MRP_PROPERTY_TYPE_COST:
@@ -1627,6 +1623,7 @@
{
MrpPropertyType type;
gfloat fvalue;
+ gint work;
type = mrp_property_get_property_type (property);
switch (type) {
@@ -1652,9 +1649,13 @@
case MRP_PROPERTY_TYPE_DURATION:
/* FIXME: support reading units etc... */
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
+ mrp_day_get_work ());
+
mrp_object_set (MRP_OBJECT (project),
mrp_property_get_name (property),
- atoi (text) *8*60*60,
+ atoi (text) *work,
NULL);
break;
diff -u -r planner-0.12.1/src/planner-resource-view.c planner-0.12.1-hours_per_day_fix/src/planner-resource-view.c
--- planner-0.12.1/src/planner-resource-view.c 2004-08-19 11:06:40.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-resource-view.c 2004-11-18 17:46:27.000000000 +0100
@@ -1692,6 +1692,8 @@
{
GValue value = { 0 };
MrpPropertyType type;
+ MrpProject *project;
+ gint work;
gfloat fvalue;
/* FIXME: implement mrp_object_set_property like
@@ -1718,9 +1720,12 @@
break;
case MRP_PROPERTY_TYPE_DURATION:
- /* FIXME: support reading units etc... */
+ project = mrp_object_get_project (MRP_OBJECT (property));
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
+ mrp_day_get_work ());
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, atoi (new_text) *8*60*60);
+ g_value_set_int (&value, atoi (new_text) *work);
break;
@@ -2138,6 +2143,7 @@
MrpObject *object;
MrpProperty *property = data;
MrpPropertyType type;
+ MrpProject *project;
gchar *svalue;
gint ivalue;
gfloat fvalue;
@@ -2191,13 +2197,12 @@
mrp_property_get_name (property), &ivalue,
NULL);
-/* work = mrp_calendar_day_get_total_work (
- mrp_project_get_calendar (tree->priv->project),
+ project = mrp_object_get_project ( object );
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
mrp_day_get_work ());
-*/
- work = 8*60*60;
- svalue = planner_format_duration (ivalue, work / (60*60));
+ svalue = planner_format_duration (ivalue, work);
break;
case MRP_PROPERTY_TYPE_COST:
diff -u -r planner-0.12.1/src/planner-task-dialog.c planner-0.12.1-hours_per_day_fix/src/planner-task-dialog.c
--- planner-0.12.1/src/planner-task-dialog.c 2004-08-19 11:06:40.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-task-dialog.c 2004-11-13 20:38:49.000000000 +0100
@@ -38,7 +38,7 @@
#include "planner-task-dialog.h"
/* FIXME: This should be read from the option menu when that works */
-#define WORK_MULTIPLIER (60*60*8.0)
+#define WORK_MULTIPLIER (60*60*work_per_day)
typedef struct {
PlannerWindow *main_window;
@@ -2297,6 +2297,9 @@
gchar *name;
MrpTaskType type;
MrpTaskSched sched;
+ MrpProject *project;
+ MrpCalendar *calendar;
+ gint work_per_day;
gchar *note;
gint int_value;
@@ -2349,10 +2352,15 @@
G_CALLBACK (task_dialog_fixed_toggled_cb),
data);
+ g_object_get (data->task, "project", &project, NULL);
+ calendar = mrp_project_get_calendar (project);
+ work_per_day = mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ());
+
data->work_spinbutton = glade_xml_get_widget (glade, "work_spinbutton");
g_object_get (data->task, "work", &int_value, NULL);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->work_spinbutton),
- int_value / WORK_MULTIPLIER);
+ (gfloat) int_value / work_per_day);
g_signal_connect (data->work_spinbutton,
"value_changed",
G_CALLBACK (task_dialog_work_changed_cb),
@@ -2370,7 +2378,7 @@
data->duration_spinbutton = glade_xml_get_widget (glade, "duration_spinbutton");
g_object_get (data->task, "duration", &int_value, NULL);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->duration_spinbutton),
- int_value / WORK_MULTIPLIER);
+ (gfloat) int_value / work_per_day);
g_signal_connect (data->duration_spinbutton,
"value_changed",
G_CALLBACK (task_dialog_duration_changed_cb),
diff -u -r planner-0.12.1/src/planner-task-input-dialog.c planner-0.12.1-hours_per_day_fix/src/planner-task-input-dialog.c
--- planner-0.12.1/src/planner-task-input-dialog.c 2004-08-19 11:05:09.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-task-input-dialog.c 2004-11-18 17:48:56.000000000 +0100
@@ -56,7 +56,14 @@
const gchar *name;
const gchar *workstr;
gint work;
-
+ MrpCalendar *calendar;
+ gint seconds_per_day;
+
+ calendar = mrp_project_get_calendar (data->project);
+
+ seconds_per_day = (float) mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ());
+
switch (response) {
case GTK_RESPONSE_OK:
data = g_object_get_data (G_OBJECT (dialog), "data");
@@ -64,7 +71,7 @@
name = gtk_entry_get_text (GTK_ENTRY (data->name_entry));
workstr = gtk_entry_get_text (GTK_ENTRY (data->work_entry));
- work = 60*60*8 * g_strtod (workstr, NULL);
+ work = seconds_per_day * g_strtod (workstr, NULL);
task = g_object_new (MRP_TYPE_TASK,
"work", work,
diff -u -r planner-0.12.1/src/planner-task-tree.c planner-0.12.1-hours_per_day_fix/src/planner-task-tree.c
--- planner-0.12.1/src/planner-task-tree.c 2004-08-19 11:06:40.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-task-tree.c 2004-11-18 17:51:06.000000000 +0100
@@ -1463,7 +1463,7 @@
PlannerTaskTree *task_tree;
PlannerTaskTreePriv *priv;
MrpCalendar *calendar;
- gint hours_per_day;
+ gint seconds_per_day;
gint duration;
gchar *str;
gint weight;
@@ -1481,10 +1481,10 @@
calendar = mrp_project_get_calendar (priv->project);
- hours_per_day = mrp_calendar_day_get_total_work (
- calendar, mrp_day_get_work ()) / (60*60);
+ seconds_per_day = (gfloat) mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ());
- str = planner_format_duration (duration, hours_per_day);
+ str = planner_format_duration (duration, seconds_per_day);
g_object_set (cell,
"text", str,
@@ -1531,7 +1531,7 @@
{
PlannerTaskTree *tree;
gint work;
- gint hours_per_day;
+ gint seconds_per_day;
MrpTask *task;
MrpTaskType type;
gint weight;
@@ -1540,13 +1540,13 @@
g_return_if_fail (PLANNER_IS_TASK_TREE (data));
tree = PLANNER_TASK_TREE (data);
- hours_per_day = mrp_calendar_day_get_total_work (
+ seconds_per_day = mrp_calendar_day_get_total_work (
mrp_project_get_calendar (tree->priv->project),
- mrp_day_get_work ()) / (60*60);
+ mrp_day_get_work ());
/* FIXME */
- if (hours_per_day == 0) {
- hours_per_day = 8;
+ if (seconds_per_day == 0) {
+ seconds_per_day = 8*60*60;
}
gtk_tree_model_get (tree_model,
@@ -1567,7 +1567,7 @@
if (type == MRP_TASK_TYPE_MILESTONE) {
g_object_set (cell, "text", "", NULL);
} else {
- gchar *str = planner_format_duration (work, hours_per_day);
+ gchar *str = planner_format_duration (work, seconds_per_day);
g_object_set (cell, "text", str, NULL);
g_free (str);
}
@@ -1582,17 +1582,17 @@
{
PlannerTaskTree *tree = data;
gint slack;
- gint hours_per_day;
+ gfloat seconds_per_day;
gchar *str;
gint weight;
- hours_per_day = mrp_calendar_day_get_total_work (
+ seconds_per_day = mrp_calendar_day_get_total_work (
mrp_project_get_calendar (tree->priv->project),
- mrp_day_get_work ()) / (60*60);
+ mrp_day_get_work ());
/* FIXME */
- if (hours_per_day == 0) {
- hours_per_day = 8;
+ if (seconds_per_day == 0) {
+ seconds_per_day = 8*60*60;
}
gtk_tree_model_get (tree_model, iter,
@@ -1600,7 +1600,7 @@
COL_WEIGHT, &weight,
-1);
- str = planner_format_duration (slack, hours_per_day);
+ str = planner_format_duration (slack, seconds_per_day);
g_object_set (cell,
"text", str,
@@ -1771,7 +1771,7 @@
seconds_per_day = mrp_calendar_day_get_total_work (
mrp_project_get_calendar (tree->priv->project),
mrp_day_get_work ());
-
+
flt = g_ascii_strtod (new_text, &ptr);
if (ptr != NULL) {
duration = flt * seconds_per_day;
@@ -1838,12 +1838,14 @@
MrpObject *object;
MrpProperty *property = data;
MrpPropertyType type;
+ MrpProject *project;
gchar *svalue;
gint ivalue;
gfloat fvalue;
mrptime tvalue;
gint work;
+
gtk_tree_model_get (tree_model,
iter,
COL_TASK,
@@ -1893,13 +1895,14 @@
mrp_property_get_name (property), &ivalue,
NULL);
-/* work = mrp_calendar_day_get_total_work (
- mrp_project_get_calendar (tree->priv->project),
+ project = mrp_object_get_project (object);
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
mrp_day_get_work ());
-*/
- work = 8*60*60;
- svalue = planner_format_duration (ivalue, work / (60*60));
+ /* work = 8*60*60;*/
+
+ svalue = planner_format_duration (ivalue, (gfloat) work / (60*60));
break;
case MRP_PROPERTY_TYPE_COST:
@@ -1928,6 +1931,10 @@
GValue value = { 0 };
MrpPropertyType type;
gfloat fvalue;
+ gint work;
+ MrpObject *object;
+ MrpProject *project;
+
/* FIXME: implement mrp_object_set_property like
* g_object_set_property that takes a GValue.
@@ -1954,8 +1961,17 @@
case MRP_PROPERTY_TYPE_DURATION:
/* FIXME: support reading units etc... */
+ mrp_object_get (object,
+ mrp_property_get_name (property), &fvalue,
+ NULL);
+
+ project = mrp_object_get_project (object);
+ work = mrp_calendar_day_get_total_work (
+ mrp_project_get_calendar (project),
+ mrp_day_get_work ());
+
g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, atoi (new_text) *8*60*60);
+ g_value_set_int (&value, atoi (new_text) *work);
break;
diff -u -r planner-0.12.1/src/planner-ttable-row.c planner-0.12.1-hours_per_day_fix/src/planner-ttable-row.c
--- planner-0.12.1/src/planner-ttable-row.c 2004-08-19 11:06:40.000000000 +0200
+++ planner-0.12.1-hours_per_day_fix/src/planner-ttable-row.c 2004-11-18 17:52:56.000000000 +0100
@@ -2041,16 +2041,14 @@
gint start;
MrpProject *project;
MrpCalendar *calendar;
- gint hours_per_day;
+ gint seconds_per_day;
g_object_get (task, "project", &project, NULL);
calendar = mrp_project_get_calendar (project);
- hours_per_day =
- mrp_calendar_day_get_total_work (calendar,
- mrp_day_get_work
- ()) / (60 *
- 60);
+ seconds_per_day =
+ (gfloat) mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work());
wx2 = event->motion.x;
wy2 = priv->y + 0.70 * priv->height;
@@ -2085,7 +2083,7 @@
("Change task '%s' work to %s, duration to %s (%d)"),
task_name,
planner_format_duration
- (work, hours_per_day),
+ (work, seconds_per_day),
planner_format_duration
(duration, 24), duration);
planner_ttable_chart_status_updated (chart, message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]