def _check_start(self, key, data): if data == 'now': data = now() result = convert_to_datetime(data) if not self.end: # set a default end time for project! 3 months self.end = result + datetime.timedelta(days=31 * 3) return result
def _update_end(self, key, data): if data: data = float(data) if not self.start: self.start = now() delta = datetime.timedelta(hours=data) self.effort_set = True if not hasattr(self, 'end_set'): self.end = self.start + delta return data
def _check_end(self, key, data): end = convert_to_datetime(data) start = convert_to_datetime(self.start) if start and end: data = max(start, end) # if any errors in end if data and self.project and self.project.end: try: data = min(data, self.project.end) except TypeError: pass #delta = data - start self.end_set = True # if not hasattr(self, 'effort_set'): # self.duration = delta.days * 24 + delta.seconds / 3600.0 if isinstance(data, datetime.datetime): return data else: return now()
def _check_start(self, key, data): if data == 'now': data = datetime.datetime.utcnow() else: data = convert_to_datetime(data) if data and self.project and self.project.end: try: data = min(data, self.project.end) except TypeError: pass if self.project: if data == self.project.end and self.effort: # approximate fix data = data - datetime.timedelta(hours=self.effort * 4) if isinstance(data, datetime.datetime): return data else: return now()
def plan(self, do_plan=True, do_guntt=False, do_resource=False, do_msproject=False, do_profit=False, do_trace=True, do_traceSvg=False, report_width=1000): # lets select just one task #puid = getUUID() + '_' + self.uuid schedule_path = os.path.join(public_upload_folder, 'Fearless_project_%s.tjp' % self.uuid) plan_path = os.path.join(public_upload_folder, 'plan_%s.html' % (self.uuid)) overall_plan_path = os.path.join(public_upload_folder, 'plan.html') overall_gantt_path = os.path.join(public_upload_folder, 'gantt.html') overall_resource_path = os.path.join(public_upload_folder, 'resource.html') guntt_path = os.path.join(public_upload_folder, 'guntt_%s.html' % (self.uuid)) resource_path = os.path.join(public_upload_folder, 'resource_%s.html' % (self.uuid)) msproject_path = os.path.join(public_upload_folder, 'MS-project_%s.xml' % (self.uuid)) profit_path = os.path.join(public_upload_folder, 'ProfiAndLoss_%s.html' % (self.uuid)) csv_path = os.path.join(public_upload_folder, 'csv_%s.csv' % (self.uuid)) trace_path = os.path.join(public_upload_folder, 'TraceReport_%s.csv' % (self.uuid)) traceSvg_path = os.path.join(public_upload_folder, 'TraceReport_%s.html' % (self.uuid)) if not r.get('fearless_tj3_lock'): r.set('fearless_tj3_lock', 'OK') # just for highly requested projects r.expire('fearless_tj3_lock', 5) else: return if not self.tasks: self.reports = [] return templateFile = os.path.abspath( os.path.join(os.path.dirname(__file__), '../templates/masterProject.tjp')) t = Template(filename=templateFile) session = session_factory() projects = session.query(Project).order_by(asc(Project.id)).all() resources = session.query(User).all() subProjectTasks = [] reports = [] for p in projects: if p.tasks: planData = p.tjp_subproject(do_plan=do_plan, do_guntt=do_guntt, do_resource=do_resource, do_msproject=do_msproject, do_profit=do_profit, do_trace=do_trace, do_traceSvg=do_traceSvg, report_width=report_width) subProjectTasks.append(planData.get('subProjectTasks')) reports.append(planData.get('report')) finalplan = t.render(reports=reports, subProjectTasks=subProjectTasks, now=now(), subprojects=projects, resources=resources) session.close() if self.last_plan == hashlib.md5(finalplan.encode( 'utf-8', 'ignore')).hexdigest(): print 'Using cached plan' return else: for i in [ schedule_path, plan_path, guntt_path, resource_path, msproject_path, profit_path, csv_path, traceSvg_path ]: if os.path.isfile(i): os.remove(i) #plan_path = '/tmp/Fearless_project.tjp' tj3 = sh.Command('../../bin/ruby/bin/tj3') with open(schedule_path, 'wb') as f: f.write(finalplan.encode('utf-8')) try: print 'Start Calculating project %s' % self.id import time s = time.time() tj = tj3(schedule_path, '--silent', '--no-color', '--add-trace', o=public_upload_folder, c='4') print 'Finished in %s seconds' % round(time.time() - s, 3) except Exception, e: print e # print type(repr(e)) for i in xrange(3): _d = '<br/>'.join(repr(e).split('\\n')[17:]).replace( '\\x1b[31m', '<b>').replace('\\x1b[0m', '</b>').split('\\x1b[35m') if len(_d) > 1: self.reports.append(_d[1]) self.reports = [] return