def loadSuboperations(cursor): print('Importing suboperations...') cnt = 0 starttime = time() cursor.execute(''' SELECT operation_id, suboperation_id, priority, effective_start, effective_end, operation.type FROM suboperation, operation WHERE suboperation.operation_id = operation.name AND priority >= 0 ORDER BY operation_id, priority ''') curopername = None for i, j, k, l, m, n in cursor.fetchall(): cnt += 1 try: if i != curopername: curopername = i if n == 'alternate': curoper = frepple.operation_alternate(name=curopername) else: curoper = frepple.operation_routing(name=curopername) if isinstance(curoper,frepple.operation_routing): curoper.addStep(frepple.operation(name=j)) else: if l: if m: curoper.addAlternate(operation=frepple.operation(name=j),priority=k,effective_start=l,effective_end=m) else: curoper.addAlternate(operation=frepple.operation(name=j),priority=k,effective_start=l) elif m: curoper.addAlternate(operation=frepple.operation(name=j),priority=k,effective_end=m) else: curoper.addAlternate(operation=frepple.operation(name=j),priority=k) except Exception as e: print("Error:", e) print('Loaded %d suboperations in %.2f seconds' % (cnt, time() - starttime))
def loadOperations(self): print('Importing operations...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, fence, pretime, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source FROM operation %s ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: if not i[7] or i[7] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) if i[8]: x.duration = i[8] elif i[7] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) if i[8]: x.duration = i[8] if i[9]: x.duration_per = i[9] elif i[7] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) elif i[7] == "routing": x = frepple.operation_routing( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) else: raise ValueError("Operation type '%s' not recognized" % i[7]) if i[1]: x.fence = i[1] if i[2]: x.pretime = i[2] if i[3]: x.posttime = i[3] if i[4]: x.size_minimum = i[4] if i[5]: x.size_multiple = i[5] if i[6]: x.size_maximum = i[6] if i[10]: x.location = frepple.location(name=i[10]) if i[11]: x.cost = i[11] if i[12]: x.search = i[12] except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
def loadOperations(cursor): print('Importing operations...') cnt = 0 starttime = time() cursor.execute(''' SELECT name, fence, pretime, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory FROM operation ''') for i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x in cursor.fetchall(): cnt += 1 try: if not p or p == "fixed_time": x = frepple.operation_fixed_time(name=i, description=v, category=w, subcategory=x) if q: x.duration = q elif p == "time_per": x = frepple.operation_time_per(name=i, description=v, category=w, subcategory=x) if q: x.duration = q if r: x.duration_per = r elif p == "alternate": x = frepple.operation_alternate(name=i, description=v, category=w, subcategory=x) elif p == "routing": x = frepple.operation_routing(name=i, description=v, category=w, subcategory=x) else: raise ValueError("Operation type '%s' not recognized" % p) if j: x.fence = j if k: x.pretime = k if l: x.posttime = l if m: x.size_minimum = m if n: x.size_multiple = n if o: x.size_maximum = o if s: x.location = frepple.location(name=s) if t: x.cost = t if u: x.search = u except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
def loadSuboperations(cursor): print('Importing suboperations...') cnt = 0 starttime = time() cursor.execute(''' SELECT operation_id, suboperation_id, priority, effective_start, effective_end, operation.type FROM suboperation, operation WHERE suboperation.operation_id = operation.name AND priority >= 0 ORDER BY operation_id, priority ''') curopername = None for i, j, k, l, m, n in cursor.fetchall(): cnt += 1 try: if i != curopername: curopername = i if n == 'alternate': curoper = frepple.operation_alternate(name=curopername) else: curoper = frepple.operation_routing(name=curopername) if isinstance(curoper, frepple.operation_routing): curoper.addStep(frepple.operation(name=j)) else: if l: if m: curoper.addAlternate( operation=frepple.operation(name=j), priority=k, effective_start=l, effective_end=m) else: curoper.addAlternate( operation=frepple.operation(name=j), priority=k, effective_start=l) elif m: curoper.addAlternate(operation=frepple.operation(name=j), priority=k, effective_end=m) else: curoper.addAlternate(operation=frepple.operation(name=j), priority=k) except Exception as e: print("Error:", e) print('Loaded %d suboperations in %.2f seconds' % (cnt, time() - starttime))
def loadSuboperations(self): print('Importing suboperations...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT operation_id, suboperation_id, priority, effective_start, effective_end, (select type from operation where suboperation.operation_id = operation.name) as type FROM suboperation WHERE priority >= 0 %s ORDER BY operation_id, priority ''' % self.filter_and) curopername = None for i in self.cursor.fetchall(): cnt += 1 try: if i[0] != curopername: curopername = i[0] if i[5] == 'alternate': curoper = frepple.operation_alternate(name=curopername) else: curoper = frepple.operation_routing(name=curopername) if isinstance(curoper, frepple.operation_routing): curoper.addStep(frepple.operation(name=i[1])) else: if i[3]: if i[4]: curoper.addAlternate(operation=frepple.operation(name=i[1]), priority=i[2], effective_start=i[3], effective_end=i[4]) else: curoper.addAlternate(operation=frepple.operation(name=i[1]), priority=i[2], effective_start=i[3]) elif i[4]: curoper.addAlternate(operation=frepple.operation(name=i[1]), priority=i[2], effective_end=i[4]) else: curoper.addAlternate(operation=frepple.operation(name=i[1]), priority=i[2]) except Exception as e: print("Error:", e) print('Loaded %d suboperations in %.2f seconds' % (cnt, time() - starttime))
def loadOperations(self): print('Importing operations...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, fence, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source, item_id, priority, effective_start, effective_end FROM operation %s ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: if not i[6] or i[6] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() elif i[6] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() if i[8]: x.duration_per = i[8].total_seconds() elif i[6] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "split": x = frepple.operation_split( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "routing": x = frepple.operation_routing( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) else: raise ValueError("Operation type '%s' not recognized" % i[6]) if i[1]: x.fence = i[1].total_seconds() if i[2]: x.posttime = i[2].total_seconds() if i[3] is not None: x.size_minimum = i[3] if i[4]: x.size_multiple = i[4] if i[5]: x.size_maximum = i[5] if i[9]: x.location = frepple.location(name=i[9]) if i[10]: x.cost = i[10] if i[11]: x.search = i[11] if i[16]: x.item = frepple.item(name=i[16]) if i[17] is not None: x.priority = i[17] if i[18]: x.effective_start = i[18] if i[19]: x.effective_end = i[19] except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
if inspect.isroutine(o): continue if not(not inspect.isclass(o) or not issubclass(o,Exception)): continue if not(not inspect.isclass(o) or not hasattr(o,"__iter__")): continue print(" %s: %s" % (name, o)) ### print("\nUpdating global settings") frepple.settings.name = "demo model" frepple.settings.description = "unicode А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь" frepple.settings.current = datetime.datetime(2009,1,1) ### print("\nCreating operations") shipoper = frepple.operation_fixed_time(name="delivery end item", duration=86400) choice = frepple.operation_alternate(name="make or buy item") makeoper = frepple.operation_routing(name="make item") makeoper.addStep(frepple.operation_fixed_time(name="make item - step 1", duration=4*86400)) makeoper.addStep(frepple.operation_fixed_time(name="make item - step 2", duration=3*86400)) buyoper = frepple.operation_fixed_time(name="buy item", duration=86400) choice.addAlternate(operation=makeoper, priority=1) choice.addAlternate(operation=buyoper, priority=2) ### print("\nCreating calendars") c = frepple.calendar(name="Cal1", default=4.56) c.setValue(datetime.datetime(2009,1,1), datetime.datetime(2009,3,1), 1) c.setValue(datetime.datetime(2009,2,1), datetime.datetime(2009,5,1), 2) c.setValue(datetime.datetime(2009,2,1), datetime.datetime(2009,3,1), 3) frepple.calendar(name="Cal2", default=1.23) frepple.calendar(name="Cal3", default=1.23)
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].cursor() as cursor: cnt = 0 starttime = time() # Preprocessing step # Make sure any routing has the produced item of its last step populated in the operation table cursor.execute(''' update operation set item_id = t.item_id from ( select operation.name operation_id, min(operationmaterial.item_id) item_id from operation inner join suboperation s1 on s1.operation_id = operation.name inner join operationmaterial on operationmaterial.operation_id = s1.suboperation_id and quantity > 0 where operation.type = 'routing' and not exists (select 1 from suboperation s2 where s1.operation_id = s2.operation_id and s1.priority < s2.priority) group by operation.name having count(operationmaterial.item_id) = 1 ) t where operation.type = 'routing' and operation.name = t.operation_id ''') # Preprocessing step # Make sure any regular operation (i.e. that has no suboperation and is not a suboperation) # has its item_id field populated # That should cover 90% of the cases cursor.execute(''' update operation set item_id = t.item_id from ( select operation.name operation_id, min(operationmaterial.item_id) item_id from operation inner join operationmaterial on operationmaterial.operation_id = operation.name and quantity > 0 where not exists (select 1 from suboperation where suboperation.operation_id = operation.name or suboperation.suboperation_id = operation.name) and operation.type not in ('routing', 'alternate', 'split') group by operation.name having count(operationmaterial.item_id) = 1 ) t where operation.type not in ('routing', 'alternate', 'split') and t.operation_id = operation.name ''') # Preprocessing step # Operations that are suboperation of a parent operation shouldn't have # the item field set. It is the parent operation that should have it set. cursor.execute(''' update operation set item_id = null from suboperation where operation.name = suboperation.suboperation_id and operation.item_id is not null ''') with connections[database].chunked_cursor() as cursor: cursor.execute(''' SELECT name, fence, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source, item_id, priority, effective_start, effective_end, available_id FROM operation %s ''' % filter_where) for i in cursor: cnt += 1 try: if not i[6] or i[6] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() elif i[6] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() if i[8]: x.duration_per = i[8].total_seconds() elif i[6] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "split": x = frepple.operation_split( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "routing": x = frepple.operation_routing( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) else: raise ValueError("Operation type '%s' not recognized" % i[6]) if i[1]: x.fence = i[1].total_seconds() if i[2]: x.posttime = i[2].total_seconds() if i[3] is not None: x.size_minimum = i[3] if i[4]: x.size_multiple = i[4] if i[5]: x.size_maximum = i[5] if i[9]: x.location = frepple.location(name=i[9]) if i[10]: x.cost = i[10] if i[11]: x.search = i[11] if i[16]: x.item = frepple.item(name=i[16]) if i[17] is not None: x.priority = i[17] if i[18]: x.effective_start = i[18] if i[19]: x.effective_end = i[19] if i[20]: x.available = frepple.calendar(name=i[20]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
continue if not (not inspect.isclass(o) or not hasattr(o, "__iter__")): continue print(" %s: %s" % (name, o)) ### print("\nUpdating global settings") frepple.settings.name = "demo model" frepple.settings.description = "unicode А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь" frepple.settings.current = datetime.datetime(2009, 1, 1) ### print("\nCreating operations") shipoper = frepple.operation_fixed_time(name="delivery end item", duration=86400) choice = frepple.operation_alternate(name="make or buy item") makeoper = frepple.operation_routing(name="make item") makeoper.addStep( frepple.operation_fixed_time(name="make item - step 1", duration=4 * 86400)) makeoper.addStep( frepple.operation_fixed_time(name="make item - step 2", duration=3 * 86400)) buyoper = frepple.operation_fixed_time(name="buy item", duration=86400) choice.addAlternate(operation=makeoper, priority=1) choice.addAlternate(operation=buyoper, priority=2) ### print("\nCreating calendars") c = frepple.calendar(name="Cal1", default=4.56) c.setValue(datetime.datetime(2009, 1, 1), datetime.datetime(2009, 3, 1), 1)