More on the subject of Gantt charts (Using Python API to import into MS Project)

Juan Carlos Gonzalez-Najera's Avatar

Juan Carlos Gonzalez-Najera

11 Jul, 2009 07:45 PM via

I just finished entering an entire project and I have sequences, shots, tasks, etc. I was about to start adding deadlines but I got stuck, because the only way I can think of doing this is by going to each task and entering. This in itself would be tedious, but it is more complicated than that.

I know that implementation of a full Gantt may not be in the plans. However, I would love to have at least a Print function so that I could see all my tasks at the same time, in the context of their respective elements, shots., etc. If this view where more interactive where I could add dates directly there, that would be fantastic.

Juan Carlos

  1. Support Staff 2 Posted by cameron on 11 Jul, 2009 11:26 PM

    cameron's Avatar

    Juan Carlos,

    Sounds like there are multiple issues here, I'll try to separate them out:

    1) Quickly updating lots of tasks. What we probably need here is some kind of editable grid, and we've been looking into that. In the meantime, probably the best was to edit tasks is to use the Task tab and the edit link for each task. You can sort by 'Object' to get the tasks in order by sequence-shot-element.

    2) Gantt charts. I'd love to do a Gantt chart, and I think we can do one pretty soon, its just a question of figuring out where it should go and what exactly to chart. But it sounds like you are looking more for an interactive input device, right? (See attached picture.)

    3) If you go to the 'Tasks' tab, and sort by 'object', are you not able to see all of your tasks at the same time? (See picture sr_tasks.png). And, I've made a special printing CSS so if you go to print that page, it looks halfway decent (see picture sr_tasks_print.png.)

    Hope that helps. What would you say is the biggest priority right now? Changing task dates quickly?

  2. cameron closed this discussion on 11 Jul, 2009 11:26 PM.

  3. Juan Carlos Gonzalez-Najera re-opened this discussion on 14 Jul, 2009 02:45 AM

  4. 3 Posted by Juan Carlos Gonzalez-Najera on 14 Jul, 2009 02:45 AM

    Juan Carlos Gonzalez-Najera's Avatar

    Sorry for the no reply. Too much email on one day and this notifaction went to the bottom too fast.

    I really like your idea in no. 1 I was even thinking that some of the tasks would benefit from scripting if a grid-like interface is not available, but I'm a novice at Python. I did find the sort function and it helps, but I still need to do a lot of one-at-a-time page modifications.

    And yes, my main priority now is changing due dates. While waiting for a Gantt chart function, I will have to put part of our project in MS Project. Otherwise I know I will get lost.

    Juan Carlos

  5. Support Staff 4 Posted by cameron on 14 Jul, 2009 03:08 AM

    cameron's Avatar

    Juan Carlos,

    We might be able to do a Python script to export all the tasks for import into MS Project. I don't have MS Project so its hard to test, but do you know if they can import a CSV file?

    Thanks,
    Cameron

  6. cameron closed this discussion on 14 Jul, 2009 03:08 AM.

  7. Juan Carlos Gonzalez-Najera re-opened this discussion on 14 Jul, 2009 12:15 PM

  8. 5 Posted by Juan Carlos Gonzalez-Najera on 14 Jul, 2009 12:15 PM

    Juan Carlos Gonzalez-Najera's Avatar

    I have never done it before, but Project can import CSV files. Her eis what it says in its help files:

    You can import information into Microsoft Office Project 2003 into any entered field from another product's file format, such as Microsoft Office Excel 2003, Microsoft Office Access 2003, Open Database Connectivity (ODBC)-compliant database formats (Microsoft SQL Server and Oracle Server), Extensible Markup Language (XML) format, and a comma-separated values (CSV) (CSV: The comma-separated values [CSV] file format is an ASCII, record-based text format in which each field is separated by a list-separator character, usually a comma or semicolon. Each task or resource record ends with a carriage return and linefeed.) or tab-delimited text format.

    If you have a Python exporter, I'd love to test its output and see how it imports into Project. Otherwise I might have to spend a few hours re-typing a lot of the data!

    Juan Carlos

  9. Support Staff 6 Posted by cameron on 14 Jul, 2009 02:37 PM

    cameron's Avatar

    We can absolutely export CSV using Python (there is already a CSV export sample), I just have to figure out somehow what the Project 2003 import format is.

  10. 7 Posted by Juan Carlos Gonzalez-Najera on 14 Jul, 2009 04:44 PM

    Juan Carlos Gonzalez-Najera's Avatar

    If it'll help, send me the current output and I'll load it into Project to see what happens.

    Juan Carlos

  11. Support Staff 8 Posted by cameron on 16 Jul, 2009 02:21 PM

    cameron's Avatar

    Juan Carlos,

    Preparing this Python example is taking me a little longer than I expected. Hopefully will have it working today -- there is some stuff in the back-end that needs to change.

    --Cameron

  12. 9 Posted by Juan Carlos Gonzalez-Najera on 16 Jul, 2009 02:53 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Thanks Cameron. I am looking forward to how this will work.

    Juan Carlos

  13. Support Staff 10 Posted by cameron on 17 Jul, 2009 06:05 AM

    cameron's Avatar

    Juan Carlos,

    I'm attaching a copy of the Python API, which includes an example: 106_tasks.py, that queries all the tasks for a project and writes a CSV file. I've attached the CSV file that was produced also.

    I don't hold out a lot of hope that this will import into MS project as-is, but hopefully this will get us closer. I'm pretty sure we are going to need to format the dates differently.

    --Cameron

  14. 11 Posted by Juan Carlos Gonzalez-Najera on 17 Jul, 2009 02:52 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    Project uses some default field names that I mapped manually when importing the CSV:

    CSV field name MS Project
    title ------------------> Name
    Start_Date ---------> Date
    due_date -----------> Finish
    user.login -----------> Resource Names
    pct_complete --------> % Complete
    estimated_time --------> Duration
    taskable_ID --------> Text2 (there are many customizable fields; I chose this one because Project's ID field is automatically calculated and has to be unique per task)
    end_date --------> Actual Finish
    taskable_type --------> Text1
    Status ------------> Status (this is a calculated field, not importable)

    You were right about date formats. The importer failed to load in any dates. What I did is that I recreated the project inside Project and exported to CSV, attached, s that you can see the correct formatting.

    I am not an expert at Project, but doing this tests showed me the myriad fields that exist for I/O. I'm sure everything form SR could be loaded somewhere.

    Hope this helps,

    Juan Carlos

  15. Support Staff 12 Posted by cameron on 17 Jul, 2009 03:25 PM

    cameron's Avatar

    Juan Carlos,

    OK, good progress!

    We need to work on the dates first. I don't own project so this is going to require some coordination. I don't think that what you got on output is going to be a valid import format ('Thu 8/6/09') and its missing the time component. However, Python is very flexible and we can get any date-time format we want. Can you find out, by testing with a CSV file, what date time format Project expects? Then I can figure out how to format it that way (will mean my simple loop is going to get a little more complex, but that is OK -- I think this is a useful thing to do.)

    Instead of importing the task ID, I wonder if we could import a link to the original task. It would be cool if project would let you click on that link to get back to the original task. The routes look like this:

    `http://tutorial.shotrunner.com/projects/3/tasks/2`
    

    Let me know if you think this will work.

    Cheers,
    Cameron

  16. 13 Posted by Juan Carlos Gonzalez-Najera on 17 Jul, 2009 08:32 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Eureka on both fronts.

    I modified the dates slightly. Just removing the day of the week works. As for the link, Project has a field called "Hyperlink". It displays in their Gantt chart as a link. When you click on it the website opens.

    See the attached, which I imported into Project without a hitch. The first row are field headings.

    Juan Carlos

  17. Support Staff 14 Posted by cameron on 18 Jul, 2009 06:16 PM

    cameron's Avatar

    Juan Carlos,

    Try this Python script. It formats all the dates, adds a hyperlink back to the task and sets all the headers as you had in your sample. I removed the Duration field as we don't really have a way to set that.

    Let me know how this works.

    Cheers,
    Cameron

  18. cameron closed this discussion on 18 Jul, 2009 06:16 PM.

  19. Juan Carlos Gonzalez-Najera re-opened this discussion on 21 Jul, 2009 07:22 PM

  20. 15 Posted by Juan Carlos Gonzalez-Najera on 21 Jul, 2009 07:22 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Sorry I have not yet replied. Been a little occupied with work, but I will take a look as soon as I can.

    Juan Carlos

  21. 16 Posted by Juan Carlos Gonzalez-Najera on 21 Jul, 2009 07:55 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    How do I run the script from within ShotRunner?

    Juan Carlos

  22. Support Staff 17 Posted by cameron on 22 Jul, 2009 04:42 AM

    cameron's Avatar

    Juan Carlos,

    These Python scripts are run using a Python interpreter. Comes pre-installed on Mac and Linux. On Windows you might have to download Python:

    http://www.python.org/download/

  23. 18 Posted by Juan Carlos Gonzalez-Najera on 22 Jul, 2009 10:46 PM

    Juan Carlos Gonzalez-Najera's Avatar

    I understand now. I thought the script was meant to be run from within ShotRunner.

    I do have Python and the IDLE editor. I'll run it and I'll see what happens.

    Juan Carlos

  24. Support Staff 19 Posted by cameron on 23 Jul, 2009 06:25 AM

    cameron's Avatar

    Don't forget that you have to edit the top of the script to use your own domain. --Cameron

  25. Support Staff 20 Posted by cameron on 24 Jul, 2009 03:01 AM

    cameron's Avatar

    Juan Carlos, how did the Python script work out?

  26. 21 Posted by Juan Carlos Gonzalez-Najera on 24 Jul, 2009 04:39 PM

    Juan Carlos Gonzalez-Najera's Avatar

    I tried running the script but I had a syntax error, plus I have a couple questions.

    The syntax error happens on this line, with the "if" highlighted"

    task.formatted_due_date = task.due_date.strftime('%m/%d/%y %H:%M:%S') if task.due_date else None

    I am on a PC using Python 2.4.4

    My questions are:

    1. There are three credentials I need to enter in the credentials line. Other than username and password, what is the third one?

    2. Should I comment out the line that tlks about setting up the production server?

    Juan Carlos

  27. Support Staff 22 Posted by cameron on 24 Jul, 2009 08:23 PM

    cameron's Avatar

    Juan Carlos, looking at the top of the script:

    # Set user credentials and account info
    ShotRunner.set_login('sam', 'sam1', 'tutorial')
    

    The first parameter is the login name, the second is the password, and the third is your shotrunner domain. The domain in the example above is tutorial.shotrunner.com.

    # Comment this line out to use the production server instead
    ShotRunner.set_site("http://%s.shotstage.com" % ShotRunner._domain)
    

    This line is for testing only and should be removed or commented out.

    I tested the script again both the production and staging servers and it works fine. Try this out and let me know how it goes.

    --Cameron

  28. 23 Posted by Juan Carlos Gonzalez-Najera on 25 Jul, 2009 02:18 AM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    I tried again (different computer) but I keep getting the same syntax error when the interpreter finds the first "if".

    Shouldn't the "If" statement usually be the first word in a line? I don't understand how the statement works if it is in the middle after a variable is set and the if has no comparison condition after it.

    Juan Carlos

  29. Support Staff 24 Posted by cameron on 25 Jul, 2009 04:03 AM

    cameron's Avatar

    Juan Carlos,

    That 'if' syntax is actually Python's ternary operator:

    >>> print 'a' if 1==1 else 'b'
    a
    >>> print 'a' if 1==0 else 'b'
    b
    

    Why it is giving you trouble, I don't know. What version of Python are you using? If it is less than 2.5 that could be the issue. Check your Python version and send me your script and I'll debug it.

    --Cameron

  30. 25 Posted by Juan Carlos Gonzalez-Najera on 25 Jul, 2009 11:36 AM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    I upgraded to Python 2.6.2 and now, no more syntax error. However, I did get a different error as follows:

    106_tasks.py line 3, in from shotrunner.base import ShotRunner, Project, Sequence, Shot, Element, Asset, Task, Note, Attachment, User, Company, Team, Role, Code

    ImportError: No module named shotrunner.base

    Where is the "shotrunner.base" module?

    Juan Carlos

  31. Support Staff 26 Posted by cameron on 25 Jul, 2009 02:21 PM

    cameron's Avatar

    Juan Carlos,

    'shotrunner.base' is in the shotrunner/ directory from the zipfile (which I've attached again just in case.) You need to have both the pyactiveresource/ and shotrunner/ directories where you have your scripts -- or, you need to modify the python module search path to include them.

    The module search path can be changed by setting the PYTHONPATH evironment variable before you run python. Let's say I wanted to place the shotrunner/ and pyactiveresource/ directories in a folder called 'python' in my home directory:

    $ export PYTHONPATH=~/python
    

    Once in python, you can see what the current module search path is:

    >>> import sys
    >>> print sys.path
    >>> from shotrunner.base import ShotRunner
    

    The other way to do it is to append the sys.path from within python:

    >>> sys.path.append('/Users/cameron/python')
    >>> from shotrunner.base import Sequence
    

    Eventually, I'll find someone who know Python better than I to make the import simpler.

    Hope this helps.

    --Cameron

  32. 27 Posted by Juan Carlos Gonzalez-Najera on 25 Jul, 2009 06:04 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    Sorry, I had missed installing it all to the right path.

    Now that I did his, I get past the missing shotrunner module error. Now I get something else:

    DEBUG: GET http://t3x.shotrunner.com/projects.xml?conditions%5Blabel%5D=EUR
    Traceback (most recent call last):
    File "C:\Documents and Settings\gonzalc3\My Documents\Downloads\106_tasks.py", line 14, in

    p = Project.set_active_by_label("EUR")
    

    File "C:\Python26\lib\shotrunner\base.py", line 62, in set_active_by_label

    obj = cls.find_by_label(label_)
    

    File "C:\Python26\lib\shotrunner\base.py", line 23, in find_by_label

    obj = cls.find_first(**cond)
    

    File "C:\Python26\lib\pyactiveresource\activeresource.py", line 359, in find_first

    resources = cls._find_every(from_=from_, **kwargs)
    

    File "C:\Python26\lib\pyactiveresource\activeresource.py", line 478, in _find_every

    return cls._build_list(cls.connection.get(path, cls.headers),
    

    File "C:\Python26\lib\pyactiveresource\connection.py", line 275, in get

    return self.format.decode(self._open('GET', path, headers=headers).body)
    

    File "C:\Python26\lib\pyactiveresource\connection.py", line 255, in _open

    response = Response.from_httpresponse(self._handle_error(err))
    

    File "C:\Python26\lib\pyactiveresource\connection.py", line 350, in _handle_error

    raise UnauthorizedAccess(err)
    

    UnauthorizedAccess: HTTP Error 401: Unauthorized

    What is the "EUR" label? I thought that maybe I needed to change that to my own project's so I changed it to SAP. Bu I still got the same errors (same as above, except I see "SAP" instead of "EUR"

    What else am I missing?

    Juan Carlos

  33. Support Staff 28 Posted by cameron on 25 Jul, 2009 06:21 PM

    cameron's Avatar

    Juan Carlos,

    Yes, you do need to change the project code from 'EUR' to your project
    code. ;-)

    Did you plug in your correct username and password?

    Thanks,
    Cameron

    digital content producer, software architect
    t: 925-244-0973
    im: CameronOrourke

  34. 29 Posted by Juan Carlos Gonzalez-Najera on 29 Jul, 2009 06:03 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Cameron,

    I'm not sure what happened to my last reply. I am almost positive I submitted it, but I don't see it here. Here goes again.

    I changed the project to SAP in the t3x domain and modified the username, password. Now I got a little further but I still get an error, copied at the end of this note.

    What else am I missing?

    Juan Carlos

    DEBUG: GET http://t3x.shotrunner.com/projects.xml?conditions%5Blabel%5D=SAP
    
    Traceback (most recent call last):
      File "C:\Documents and Settings\gonzalc3\My Documents\Downloads\106_tasks.py", line 14, in <module>
        p = Project.set_active_by_label("SAP")
      File "C:\Python26\lib\shotrunner\base.py", line 62, in set_active_by_label
        obj = cls.find_by_label(label_)
      File "C:\Python26\lib\shotrunner\base.py", line 23, in find_by_label
        obj = cls.find_first(**cond)
      File "C:\Python26\lib\pyactiveresource\activeresource.py", line 359, in find_first
        resources = cls._find_every(from_=from_, **kwargs)
      File "C:\Python26\lib\pyactiveresource\activeresource.py", line 478, in _find_every
        return cls._build_list(cls.connection.get(path, cls.headers),
      File "C:\Python26\lib\pyactiveresource\connection.py", line 275, in get
        return self.format.decode(self._open('GET', path, headers=headers).body)
      File "C:\Python26\lib\pyactiveresource\connection.py", line 257, in _open
        raise Error(err, url)
    Error: (URLError(error(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'),), 'http://t3x.shotrunner.com/projects.xml?conditions%5Blabel%5D=SAP')
    
  35. Support Staff 30 Posted by cameron on 29 Jul, 2009 06:10 PM

    cameron's Avatar

    Juan Carlos,

    Please send me your python script (remove your password) and I will verify it here.

    Thanks,
    Cameron

  36. 31 Posted by Juan Carlos Gonzalez-Najera on 29 Jul, 2009 07:33 PM

    Juan Carlos Gonzalez-Najera's Avatar

    Here goes, sans password.

    Juan Carlos

Comments are currently closed for this discussion. You can start a new one.