trying to import data into mrproject...

Joe deBlaquiere <[email protected]> 19 May 2003 08:35:40 -0400
Newsgroups gmane.comp.gnome.apps.mr-project.devel
Message-ID <[email protected]>
--=-SS1QhIzIXM3Pxw9v02/u
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I'm working on extracting data from our bugzilla database to build
project plans. My idea was to use calls from libmrproject to create a
project and push the tasks, estimates, and %complete into the file and
then use MrProject to fine tune the schedule. So the basic process I
followed was:

* create new project
* add all the resources
* add all the tasks
* associate resources to tasks
* save as

But the resulting file I get is the same if I omit steps 2,3,4... so I'm
inferring that I somehow didn't get these steps right... 

program attached... 

TIA for any help.  

-- 
Joe


--=-SS1QhIzIXM3Pxw9v02/u
Content-Disposition: attachment; filename=main.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c; name=main.c; charset=ISO-8859-1

/**************************************************************************=
*
                          main.c  -  description
                             -------------------
    begin                : Sat May 17 19:37:21 EDT 2003
    copyright            : (C) 2003 by Joe deBlaquiere
    email                : [email protected]
 **************************************************************************=
*/

/**************************************************************************=
*
 *                                                                         =
*
 *   This program is free software; you can redistribute it and/or modify  =
*
 *   it under the terms of the GNU General Public License as published by  =
*
 *   the Free Software Foundation; either version 2 of the License, or     =
*
 *   (at your option) any later version.                                   =
*
 *                                                                         =
*
 **************************************************************************=
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <assert.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <mrproject/mrp-application.h>
#include <mrproject/mrp-project.h>

#include "parse_csv.h"

#ifndef MAX_NAME_FIELD
#define MAX_NAME_FIELD  64
#endif

int main(int argc, char *argv[])
{
  MrpApplication *myApp;
  MrpProject *myProject;
  MrpResource *myResource;
  MrpResource **myResourceList;
  MrpTask *myTask;
  MrpTask *myRootTask;
  MrpTask *myTaskList;
  static GError *errors;
  Task_Type **tasklist;
  Resource_Type **resourcelist;
  int task_count;
  int resource_count;
  FILE *f_ptr;

  g_type_init();

  myApp =3D mrp_application_new();
  myProject =3D mrp_project_new(myApp);

  f_ptr =3D fopen(argv[1],"r");
  tasklist =3D Parse_File(f_ptr, &task_count);
  fclose(f_ptr);

  /* count the number of distinct resources */
  {
    int count;
    resource_count =3D 0;
    for ( count =3D 0 ; count < task_count ; count++ ) {
      /* resources should be monotonically increasing, we verify and count =
up */
      if ( tasklist[count]->resource->number > resource_count ) {
        if ( (tasklist[count]->resource->number-1) !=3D resource_count ) fp=
rintf(stderr,"main: resources out of order\n");
        resource_count =3D tasklist[count]->resource->number ;
      }
    }
  }

  /* generate a list or resources */
  resourcelist =3D calloc(resource_count, sizeof(*resourcelist));
  assert(resourcelist !=3D NULL);
  myResourceList =3D calloc(resource_count, sizeof(*myResourceList));
  assert(myResourceList !=3D NULL);
  {
    int count;
    int new =3D 0;
    for ( count =3D 0 ; count < task_count ; count++ ) {
      /* associate every time, wasteful but simple */
      resourcelist[tasklist[count]->resource->number] =3D tasklist[count]->=
resource ;
      if (tasklist[count]->resource->number > new) {
        new =3D tasklist[count]->resource->number;

        /* generate MrProject resources */
        myResource =3D g_object_new (MRP_TYPE_RESOURCE,"name", tasklist[cou=
nt]->resource->name,"type","1","units","0","email","",NULL);
        myResourceList[new] =3D myResource ;
        mrp_project_add_resource(myProject,myResource);
      }
    }
  }

  /* translate the tasks */
  myTaskList =3D calloc(task_count, sizeof(*myTaskList));
  assert(myTaskList !=3D NULL);
  myRootTask =3D mrp_project_get_root_task(myProject);
  assert(myRootTask !=3D NULL);
  {
    int count;
    int work;
    char namefield[MAX_NAME_FIELD];
    resource_count =3D 0;
    for ( count =3D 0 ; count < task_count ; count++ ) {
      work =3D 60*60*((int)(tasklist[count]->hours_estimated + 0.5)) ;
      strcpy(namefield,tasklist[count]->id);
      strcat(namefield," : ");
      strncat(namefield,tasklist[count]->description, MAX_NAME_FIELD - strl=
en(namefield));
      printf("adding task %s\n",namefield);
      namefield[MAX_NAME_FIELD-1] =3D 0 ;
      myTask =3D g_object_new (MRP_TYPE_TASK, "work", work, "name", namefie=
ld, NULL);
      mrp_project_insert_task(myProject,myRootTask,1,myTask);
      mrp_resource_assign(myResourceList[tasklist[count]->resource->number]=
,myTask,100);
    }
  }

  mrp_project_recalc_tasks(myProject); =20

  mrp_project_save_as(myProject,"test.mrproject",0,&errors);
 =20
  return 0;
}

--=-SS1QhIzIXM3Pxw9v02/u
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

_______________________________________________
Mrproject-devel mailing list
[email protected]
http://lists.codefactory.se/cgi-bin/mailman/listinfo/mrproject-devel

--=-SS1QhIzIXM3Pxw9v02/u--