Exemplo n.º 1
0
def loadFlows(cursor):
    print('Importing flows...')
    cnt = 0
    starttime = time()
    # Note: The sorting of the flows is not really necessary, but helps to make
    # the planning progress consistent across runs and database engines.
    cursor.execute('''SELECT
      operation_id, thebuffer_id, quantity, type, effective_start,
      effective_end, name, priority, search
    FROM flow
    WHERE alternate IS NULL OR alternate = ''
    ORDER BY operation_id, thebuffer_id
    ''')
    curbufname = None
    for i, j, k, l, m, n, o, p, q in cursor.fetchall():
        cnt += 1
        try:
            if j != curbufname:
                curbufname = j
                curbuf = frepple.buffer(name=curbufname)
            curflow = frepple.flow(operation=frepple.operation(name=i),
                                   type="flow_%s" % l,
                                   buffer=curbuf,
                                   quantity=k)
            if m: curflow.effective_start = m
            if n: curflow.effective_end = n
            if o: curflow.name = o
            if p: curflow.priority = p
            if q: curflow.search = q
        except Exception as e:
            print("Error:", e)
    cursor.execute('''
    SELECT
      operation_id, thebuffer_id, quantity, type, effective_start,
      effective_end, name, alternate, priority, search
    FROM flow
    WHERE alternate IS NOT NULL AND alternate <> ''
    ORDER BY operation_id, thebuffer_id
    ''')
    curbufname = None
    for i, j, k, l, m, n, o, p, q, r in cursor.fetchall():
        cnt += 1
        try:
            if j != curbufname:
                curbufname = j
                curbuf = frepple.buffer(name=curbufname)
            curflow = frepple.flow(operation=frepple.operation(name=i),
                                   type=l,
                                   buffer=curbuf,
                                   quantity=k)
            if m: curflow.effective_start = m
            if n: curflow.effective_end = n
            if o: curflow.name = o
            if p: curflow.alternate = p
            if q: curflow.priority = q
            if r: curflow.search = r
        except Exception as e:
            print("Error:", e)
    print('Loaded %d flows in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 2
0
def loadFlows(cursor):
  print('Importing flows...')
  cnt = 0
  starttime = time()
  # Note: The sorting of the flows is not really necessary, but helps to make
  # the planning progress consistent across runs and database engines.
  cursor.execute('''SELECT
      operation_id, thebuffer_id, quantity, type, effective_start,
      effective_end, name, priority, search
    FROM flow
    WHERE alternate IS NULL OR alternate = ''
    ORDER BY operation_id, thebuffer_id
    ''')
  curbufname = None
  for i, j, k, l, m, n, o, p, q in cursor.fetchall():
    cnt += 1
    try:
      if j != curbufname:
        curbufname = j
        curbuf = frepple.buffer(name=curbufname)
      curflow = frepple.flow(operation=frepple.operation(name=i), type="flow_%s" % l, buffer=curbuf, quantity=k)
      if m: curflow.effective_start = m
      if n: curflow.effective_end = n
      if o: curflow.name = o
      if p: curflow.priority = p
      if q: curflow.search = q
    except Exception as e: print("Error:", e)
  cursor.execute('''
    SELECT
      operation_id, thebuffer_id, quantity, type, effective_start,
      effective_end, name, alternate, priority, search
    FROM flow
    WHERE alternate IS NOT NULL AND alternate <> ''
    ORDER BY operation_id, thebuffer_id
    ''')
  curbufname = None
  for i, j, k, l, m, n, o, p, q, r in cursor.fetchall():
    cnt += 1
    try:
      if j != curbufname:
        curbufname = j
        curbuf = frepple.buffer(name=curbufname)
      curflow = frepple.flow(operation=frepple.operation(name=i), type=l, buffer=curbuf, quantity=k)
      if m: curflow.effective_start = m
      if n: curflow.effective_end = n
      if o: curflow.name = o
      if p: curflow.alternate = p
      if q: curflow.priority = q
      if r: curflow.search = r
    except Exception as e: print("Error:", e)
  print('Loaded %d flows in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 3
0
  def loadOperationMaterials(self):
    print('Importing operation materials...')
    cnt = 0
    starttime = time()
    # Note: The sorting of the flows is not really necessary, but helps to make
    # the planning progress consistent across runs and database engines.
    self.cursor.execute('''
      SELECT
        operation_id, item_id, quantity, type, effective_start,
        effective_end, name, priority, search, source
      FROM operationmaterial %s
      ORDER BY operation_id, item_id
      ''' % self.filter_where)
    for i in self.cursor.fetchall():
      cnt += 1
      try:
        curflow = frepple.flow(
          operation=frepple.operation(name=i[0]),
          item=frepple.item(name=i[1]),
          quantity=i[2],
          type="flow_%s" % i[3],
          source=i[9]
          )
        if i[4]:
          curflow.effective_start = i[4]
        if i[5]:
          curflow.effective_end = i[5]
        if i[6]:
          curflow.name = i[6]
        if i[7]:
          curflow.priority = i[7]
        if i[8]:
          curflow.search = i[8]
      except Exception as e:
        print("Error:", e)
    print('Loaded %d operation materials in %.2f seconds' % (cnt, time() - starttime))

    # Check for operations where:
    #  - operation.item is still blank
    #  - they have a single operationmaterial item with quantity > 0
    # If found we update
    starttime = time()
    cnt = 0
    print('Auto-update operation items...')
    for oper in frepple.operations():
      if oper.hidden or oper.item:
        continue
      item = None
      for fl in oper.flows:
        if fl.quantity < 0 or fl.hidden:
          continue
        if item and item != fl.item:
          item = None
          break
        else:
          item = fl.item
      if item:
        cnt += 1
        oper.item = item
    print('Auto-update of %s operation items in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 4
0
  def loadOperationMaterials(self):
    print('Importing operation materials...')
    cnt = 0
    starttime = time()
    # Note: The sorting of the flows is not really necessary, but helps to make
    # the planning progress consistent across runs and database engines.
    self.cursor.execute('''
      SELECT
        operation_id, item_id, quantity, type, effective_start,
        effective_end, name, priority, search, source
      FROM operationmaterial %s
      ORDER BY operation_id, item_id
      ''' % self.filter_where)
    for i in self.cursor.fetchall():
      cnt += 1
      try:
        curflow = frepple.flow(
          operation=frepple.operation(name=i[0]),
          item=frepple.item(name=i[1]),
          quantity=i[2],
          type="flow_%s" % i[3],
          source=i[9]
          )
        if i[4]:
          curflow.effective_start = i[4]
        if i[5]:
          curflow.effective_end = i[5]
        if i[6]:
          curflow.name = i[6]
        if i[7]:
          curflow.priority = i[7]
        if i[8]:
          curflow.search = i[8]
      except Exception as e:
        print("Error:", e)
    print('Loaded %d operation materials in %.2f seconds' % (cnt, time() - starttime))

    # Check for operations where:
    #  - operation.item is still blank
    #  - they have a single operationmaterial item with quantity > 0
    # If found we update
    starttime = time()
    cnt = 0
    print('Auto-update operation items...')
    for oper in frepple.operations():
      if oper.hidden or oper.item:
        continue
      item = None
      for fl in oper.flows:
        if fl.quantity < 0 or fl.hidden:
          continue
        if item and item != fl.item:
          item = None
          break
        else:
          item = fl.item
      if item:
        cnt += 1
        oper.item = item
    print('Auto-update of %s operation items in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 5
0
 def loadFlows(self):
     print('Importing flows...')
     cnt = 0
     starttime = time()
     # Note: The sorting of the flows is not really necessary, but helps to make
     # the planning progress consistent across runs and database engines.
     self.cursor.execute('''
   SELECT
     operation_id, thebuffer_id, quantity, type, effective_start,
     effective_end, name, priority, search, source
   FROM flow %s
   ORDER BY operation_id, thebuffer_id
   ''' % self.filter_where)
     curbufname = None
     for i in self.cursor.fetchall():
         cnt += 1
         try:
             if i[1] != curbufname:
                 curbufname = i[1]
                 curbuf = frepple.buffer(name=curbufname)
             curflow = frepple.flow(operation=frepple.operation(name=i[0]),
                                    type="flow_%s" % i[3],
                                    buffer=curbuf,
                                    quantity=i[2],
                                    source=i[9])
             if i[4]:
                 curflow.effective_start = i[4]
             if i[5]:
                 curflow.effective_end = i[5]
             if i[6]:
                 curflow.name = i[6]
             if i[7]:
                 curflow.priority = i[7]
             if i[8]:
                 curflow.search = i[8]
         except Exception as e:
             print("Error:", e)
     self.cursor.execute('''
   SELECT count(*)
   FROM flow
   WHERE alternate IS NOT NULL AND alternate <> ''
   ''')
     if self.cursor.fetchone()[0]:
         raise ValueError(
             "Flow.alternate field is not used any longer. Use only flow.name"
         )
     print('Loaded %d flows in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 6
0
 def loadFlows(self):
   print('Importing flows...')
   cnt = 0
   starttime = time()
   # Note: The sorting of the flows is not really necessary, but helps to make
   # the planning progress consistent across runs and database engines.
   self.cursor.execute('''
     SELECT
       operation_id, thebuffer_id, quantity, type, effective_start,
       effective_end, name, priority, search, source
     FROM flow %s
     ORDER BY operation_id, thebuffer_id
     ''' % self.filter_where)
   curbufname = None
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       if i[1] != curbufname:
         curbufname = i[1]
         curbuf = frepple.buffer(name=curbufname)
       curflow = frepple.flow(operation=frepple.operation(name=i[0]), type="flow_%s" % i[3], buffer=curbuf, quantity=i[2], source=i[9])
       if i[4]:
         curflow.effective_start = i[4]
       if i[5]:
         curflow.effective_end = i[5]
       if i[6]:
         curflow.name = i[6]
       if i[7]:
         curflow.priority = i[7]
       if i[8]:
         curflow.search = i[8]
     except Exception as e:
       print("Error:", e)
   self.cursor.execute('''
     SELECT count(*)
     FROM flow
     WHERE alternate IS NOT NULL AND alternate <> ''
     ''')
   if self.cursor.fetchone()[0]:
     raise ValueError("Flow.alternate field is not used any longer. Use only flow.name")
   print('Loaded %d flows in %.2f seconds' % (cnt, time() - starttime))
Exemplo n.º 7
0
  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 flows is not really necessary, but helps to make
      # the planning progress consistent across runs and database engines.
      cursor.execute('''
        SELECT
          operation_id, item_id, quantity, type, effective_start,
          effective_end, name, priority, search, source
        FROM operationmaterial %s
        ORDER BY operation_id, item_id
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        try:
          curflow = frepple.flow(
            operation=frepple.operation(name=i[0]),
            item=frepple.item(name=i[1]),
            quantity=i[2],
            type="flow_%s" % i[3],
            source=i[9]
            )
          if i[4]:
            curflow.effective_start = i[4]
          if i[5]:
            curflow.effective_end = i[5]
          if i[6]:
            curflow.name = i[6]
          if i[7]:
            curflow.priority = i[7]
          if i[8]:
            curflow.search = i[8]
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d operation materials in %.2f seconds' % (cnt, time() - starttime))

      # Check for operations where:
      #  - operation.item is still blank
      #  - they have a single operationmaterial item with quantity > 0
      # If found we update
      starttime = time()
      cnt = 0
      logger.info('Auto-update operation items...')
      for oper in frepple.operations():
        if oper.hidden or oper.item or oper.hasSuperOperations:
          continue
        item = None
        for fl in oper.flows:
          if fl.quantity < 0 or fl.hidden:
            continue
          if item and item != fl.item:
            item = None
            break
          else:
            item = fl.item
        if item:
          cnt += 1
          oper.item = item
      logger.info('Auto-update of %s operation items in %.2f seconds' % (cnt, time() - starttime))