예제 #1
0
파일: load.py 프로젝트: dhl/frePPLe
 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))
예제 #2
0
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))
예제 #3
0
파일: load.py 프로젝트: ConePerez/frePPLe
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))
예제 #4
0
 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))
예제 #5
0
파일: commands.py 프로젝트: mgear/frepple
  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))