def loadLoads(cursor): print('Importing loads...') cnt = 0 starttime = time() # Note: The sorting of the loads is not really necessary, but helps to make # the planning progress consistent across runs and database engines. cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, priority, setup, search, skill_id FROM resourceload WHERE alternate IS NULL OR alternate = '' ORDER BY operation_id, resource_id ''') curresname = None for i, j, k, l, m, n, o, p, q, r in cursor.fetchall(): cnt += 1 try: if j != curresname: curresname = j curres = frepple.resource(name=curresname) curload = frepple.load(operation=frepple.operation(name=i), resource=curres, quantity=k) if l: curload.effective_start = l if m: curload.effective_end = m if n: curload.name = n if o: curload.priority = o if p: curload.setup = p if q: curload.search = q if r: curload.skill = frepple.skill(name=r) except Exception as e: print("Error:", e) cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, alternate, priority, setup, search, skill_id FROM resourceload WHERE alternate IS NOT NULL AND alternate <> '' ORDER BY operation_id, resource_id ''') curresname = None for i, j, k, l, m, n, o, p, q, r, s in cursor.fetchall(): cnt += 1 try: if j != curresname: curresname = j curres = frepple.resource(name=curresname) curload = frepple.load(operation=frepple.operation(name=i), resource=curres, quantity=k) if l: curload.effective_start = l if m: curload.effective_end = m if n: curload.name = n if o: curload.alternate = o if p: curload.priority = p if q: curload.setup = q if r: curload.search = r if s: curload.skill = frepple.skill(name=s) except Exception as e: print("Error:", e) print('Loaded %d loads in %.2f seconds' % (cnt, time() - starttime))
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple if cls.filter: filter_and = "and %s " % cls.filter filter_where = "where %s " % cls.filter else: filter_and = "" filter_where = "" with connections[database].chunked_cursor() as cursor: cnt = 0 starttime = time() cursor.execute(''' SELECT resource_id, skill_id, effective_start, effective_end, priority, source FROM resourceskill %s ORDER BY skill_id, priority, resource_id ''' % filter_where) for i in cursor: cnt += 1 try: cur = frepple.resourceskill( resource=frepple.resource(name=i[0]), skill=frepple.skill(name=i[1]), priority=i[4] or 1, source=i[5] ) if i[2]: cur.effective_start = i[2] if i[3]: cur.effective_end = i[3] except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d resource skills in %.2f seconds' % (cnt, time() - starttime))
def loadResourceSkills(self): print('Importing resource skills...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT resource_id, skill_id, effective_start, effective_end, priority, source FROM resourceskill %s ORDER BY skill_id, priority, resource_id ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: cur = frepple.resourceskill( resource=frepple.resource(name=i[0]), skill=frepple.skill(name=i[1]), priority=i[4] or 1, source=i[5]) if i[2]: cur.effective_start = i[2] if i[3]: cur.effective_end = i[3] except Exception as e: print("Error:", e) print('Loaded %d resource skills in %.2f seconds' % (cnt, time() - starttime))
def loadLoads(self): print('Importing loads...') cnt = 0 starttime = time() # Note: The sorting of the loads is not really necessary, but helps to make # the planning progress consistent across runs and database engines. self.cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, priority, setup, search, skill_id, source FROM resourceload %s ORDER BY operation_id, resource_id ''' % self.filter_where) curresname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[1] != curresname: curresname = i[1] curres = frepple.resource(name=curresname) curload = frepple.load(operation=frepple.operation(name=i[0]), resource=curres, quantity=i[2], source=i[10]) if i[3]: curload.effective_start = i[3] if i[4]: curload.effective_end = i[4] if i[5]: curload.name = i[5] if i[6]: curload.priority = i[6] if i[7]: curload.setup = i[7] if i[8]: curload.search = i[8] if i[9]: curload.skill = frepple.skill(name=i[9]) except Exception as e: print("Error:", e) self.cursor.execute(''' SELECT count(*) FROM resourceload WHERE alternate IS NOT NULL AND alternate <> '' ''') if self.cursor.fetchone()[0]: raise ValueError( "Load.alternate field is not used any longer. Use only load.name" ) print('Loaded %d loads in %.2f seconds' % (cnt, time() - starttime))
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple if cls.filter: filter_and = "and %s " % cls.filter filter_where = "where %s " % cls.filter else: filter_and = "" filter_where = "" with connections[database].chunked_cursor() as cursor: cnt = 0 starttime = time() # Note: The sorting of the loads is not really necessary, but helps to make # the planning progress consistent across runs and database engines. cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, priority, setup, search, skill_id, source FROM operationresource %s ORDER BY operation_id, resource_id ''' % filter_where) for i in cursor: cnt += 1 try: curload = frepple.load( operation=frepple.operation(name=i[0]), resource=frepple.resource(name=i[1]), quantity=i[2], source=i[10] ) if i[3]: curload.effective_start = i[3] if i[4]: curload.effective_end = i[4] if i[5]: curload.name = i[5] if i[6]: curload.priority = i[6] if i[7]: curload.setup = i[7] if i[8]: curload.search = i[8] if i[9]: curload.skill = frepple.skill(name=i[9]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d resource loads in %.2f seconds' % (cnt, time() - starttime))
def loadResourceSkills(cursor): print('Importing resource skills...') cnt = 0 starttime = time() cursor.execute('''SELECT resource_id, skill_id, effective_start, effective_end, priority FROM resourceskill ORDER BY skill_id, priority, resource_id''') for i,j,k,l,m in cursor.fetchall(): cnt += 1 try: cur = frepple.resourceskill(resource=frepple.resource(name=i), skill=frepple.skill(name=j), priority=m or 1) if k: cur.effective_start = k if l: cur.effective_end = l except Exception as e: print("Error:", e) print('Loaded %d resource skills in %.2f seconds' % (cnt, time() - starttime))
def loadLoads(self): print('Importing loads...') cnt = 0 starttime = time() # Note: The sorting of the loads is not really necessary, but helps to make # the planning progress consistent across runs and database engines. self.cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, priority, setup, search, skill_id, source FROM resourceload %s ORDER BY operation_id, resource_id ''' % self.filter_where) curresname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[1] != curresname: curresname = i[1] curres = frepple.resource(name=curresname) curload = frepple.load(operation=frepple.operation(name=i[0]), resource=curres, quantity=i[2], source=i[10]) if i[3]: curload.effective_start = i[3] if i[4]: curload.effective_end = i[4] if i[5]: curload.name = i[5] if i[6]: curload.priority = i[6] if i[7]: curload.setup = i[7] if i[8]: curload.search = i[8] if i[9]: curload.skill = frepple.skill(name=i[9]) except Exception as e: print("Error:", e) self.cursor.execute(''' SELECT count(*) FROM resourceload WHERE alternate IS NOT NULL AND alternate <> '' ''') if self.cursor.fetchone()[0]: raise ValueError("Load.alternate field is not used any longer. Use only load.name") print('Loaded %d loads in %.2f seconds' % (cnt, time() - starttime))
def loadResourceSkills(cursor): print('Importing resource skills...') cnt = 0 starttime = time() cursor.execute('''SELECT resource_id, skill_id, effective_start, effective_end, priority FROM resourceskill ORDER BY skill_id, priority, resource_id''') for i, j, k, l, m in cursor.fetchall(): cnt += 1 try: cur = frepple.resourceskill(resource=frepple.resource(name=i), skill=frepple.skill(name=j), priority=m or 1) if k: cur.effective_start = k if l: cur.effective_end = l except Exception as e: print("Error:", e) print('Loaded %d resource skills in %.2f seconds' % (cnt, time() - starttime))
def loadOperationResources(self): print('Importing operation resources...') cnt = 0 starttime = time() # Note: The sorting of the loads is not really necessary, but helps to make # the planning progress consistent across runs and database engines. self.cursor.execute(''' SELECT operation_id, resource_id, quantity, effective_start, effective_end, name, priority, setup, search, skill_id, source FROM operationresource %s ORDER BY operation_id, resource_id ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: curload = frepple.load( operation=frepple.operation(name=i[0]), resource=frepple.resource(name=i[1]), quantity=i[2], source=i[10] ) if i[3]: curload.effective_start = i[3] if i[4]: curload.effective_end = i[4] if i[5]: curload.name = i[5] if i[6]: curload.priority = i[6] if i[7]: curload.setup = i[7] if i[8]: curload.search = i[8] if i[9]: curload.skill = frepple.skill(name=i[9]) except Exception as e: print("Error:", e) print('Loaded %d resource loads in %.2f seconds' % (cnt, time() - starttime))
def loadResourceSkills(self): print('Importing resource skills...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT resource_id, skill_id, effective_start, effective_end, priority, source FROM resourceskill %s ORDER BY skill_id, priority, resource_id ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: cur = frepple.resourceskill( resource=frepple.resource(name=i[0]), skill=frepple.skill(name=i[1]), priority=i[4] or 1, source=i[5] ) if i[2]: cur.effective_start = i[2] if i[3]: cur.effective_end = i[3] except Exception as e: print("Error:", e) print('Loaded %d resource skills in %.2f seconds' % (cnt, time() - starttime))