[Planner Dev] Hours per day does not have to be an integer
- From: Henning Kulander <hennikul linpro no>
- To: planner-dev lists imendio com
- Subject: [Planner Dev] Hours per day does not have to be an integer
- Date: Sun, 14 Nov 2004 15:22:56 +0100
Hi!
I've been playing around with Planner here, trying to use it for a
project. When I adjusted the working-day to a standard Norwegian 7.5
hours day, things started too look wrong.
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).
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.
--
Regards,
Henning Kulander
Systems consultant
Linpro
diff -u -r planner-0.12.1/src/planner-format.c planner-0.12.1-float_hours_per_day/src/planner-format.c
--- planner-0.12.1/src/planner-format.c 2004-08-19 11:06:39.000000000 +0200
+++ planner-0.12.1-float_hours_per_day/src/planner-format.c 2004-11-13 19:23:04.000000000 +0100
@@ -128,13 +128,13 @@
gchar *
planner_format_duration (gint duration,
- gint day_length)
+ gfloat day_length)
{
gint days;
gint hours;
- days = duration / (60*60*day_length);
- duration -= days * 60*60*day_length;
+ days = duration / (int) (60*60*day_length);
+ duration -= days * (int) 60*60*day_length;
hours = duration / (60*60);
if (days > 0 && hours > 0) {
diff -u -r planner-0.12.1/src/planner-format.h planner-0.12.1-float_hours_per_day/src/planner-format.h
--- planner-0.12.1/src/planner-format.h 2004-08-19 11:05:09.000000000 +0200
+++ planner-0.12.1-float_hours_per_day/src/planner-format.h 2004-11-13 18:52:15.000000000 +0100
@@ -29,7 +29,7 @@
gchar *planner_format_int (gint number);
gchar *planner_format_duration (gint duration,
- gint day_length);
+ gfloat day_length);
gchar *planner_format_date (mrptime date);
diff -u -r planner-0.12.1/src/planner-gantt-print.c planner-0.12.1-float_hours_per_day/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-float_hours_per_day/src/planner-gantt-print.c 2004-11-13 20:45:35.000000000 +0100
@@ -213,6 +213,8 @@
GList *l, *to;
PrintTask *ptask;
gint last, i;
+ gfloat hours_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);
+
+ hours_per_day = (gfloat) mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ()) / (60*60);
+
+ str = planner_format_duration (work, hours_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-float_hours_per_day/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-float_hours_per_day/src/planner-gantt-row.c 2004-11-13 20:58:26.000000000 +0100
@@ -1781,13 +1781,13 @@
gint work;
MrpProject *project;
MrpCalendar *calendar;
- gint hours_per_day;
+ gfloat hours_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);
+ hours_per_day = (gfloat)mrp_calendar_day_get_total_work (
+ calendar, mrp_day_get_work ()) / (60*60);
wx2 = event->motion.x;
wy2 = priv->y + 0.70 * priv->height;
diff -u -r planner-0.12.1/src/planner-project-properties.c planner-0.12.1-float_hours_per_day/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-float_hours_per_day/src/planner-project-properties.c 2004-11-13 21:11:53.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, (gfloat) work / (60*60));
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, (gfloat) work / (60*60));
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-float_hours_per_day/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-float_hours_per_day/src/planner-resource-view.c 2004-11-13 21:31:17.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, (gfloat) work / (60*60));
break;
case MRP_PROPERTY_TYPE_COST:
diff -u -r planner-0.12.1/src/planner-task-dialog.c planner-0.12.1-float_hours_per_day/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-float_hours_per_day/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-float_hours_per_day/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-float_hours_per_day/src/planner-task-input-dialog.c 2004-11-14 15:05:52.594533858 +0100
@@ -56,7 +56,14 @@
const gchar *name;
const gchar *workstr;
gint work;
-
+ MrpCalendar *calendar;
+ gfloat hours_per_day;
+
+ calendar = mrp_project_get_calendar (data->project);
+
+ hours_per_day = (float) mrp_calendar_day_get_total_work ( calendar, mrp_day_get_work ())
+ / (60*60);
+ printf("Using %f hours pr. day\n", hours_per_day);
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 = (int) 60*60*hours_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-float_hours_per_day/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-float_hours_per_day/src/planner-task-tree.c 2004-11-13 19:08:46.000000000 +0100
@@ -1463,7 +1463,7 @@
PlannerTaskTree *task_tree;
PlannerTaskTreePriv *priv;
MrpCalendar *calendar;
- gint hours_per_day;
+ gfloat hours_per_day;
gint duration;
gchar *str;
gint weight;
@@ -1481,7 +1481,7 @@
calendar = mrp_project_get_calendar (priv->project);
- hours_per_day = mrp_calendar_day_get_total_work (
+ hours_per_day = (gfloat) mrp_calendar_day_get_total_work (
calendar, mrp_day_get_work ()) / (60*60);
str = planner_format_duration (duration, hours_per_day);
@@ -1531,7 +1531,7 @@
{
PlannerTaskTree *tree;
gint work;
- gint hours_per_day;
+ gfloat hours_per_day;
MrpTask *task;
MrpTaskType type;
gint weight;
@@ -1540,7 +1540,7 @@
g_return_if_fail (PLANNER_IS_TASK_TREE (data));
tree = PLANNER_TASK_TREE (data);
- hours_per_day = mrp_calendar_day_get_total_work (
+ hours_per_day = (gfloat) mrp_calendar_day_get_total_work (
mrp_project_get_calendar (tree->priv->project),
mrp_day_get_work ()) / (60*60);
@@ -1582,11 +1582,11 @@
{
PlannerTaskTree *tree = data;
gint slack;
- gint hours_per_day;
+ gfloat hours_per_day;
gchar *str;
gint weight;
- hours_per_day = mrp_calendar_day_get_total_work (
+ hours_per_day = (gfloat) mrp_calendar_day_get_total_work (
mrp_project_get_calendar (tree->priv->project),
mrp_day_get_work ()) / (60*60);
@@ -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-float_hours_per_day/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-float_hours_per_day/src/planner-ttable-row.c 2004-11-13 19:08:55.000000000 +0100
@@ -2041,13 +2041,13 @@
gint start;
MrpProject *project;
MrpCalendar *calendar;
- gint hours_per_day;
+ gfloat hours_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,
+ (gfloat) mrp_calendar_day_get_total_work (calendar,
mrp_day_get_work
()) / (60 *
60);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]