Example #1
0
 def loadCalendars(self):
     print('Importing calendars...')
     cnt = 0
     starttime = time()
     self.cursor.execute('''
   SELECT
     name, defaultvalue, source, 0 hidden
   FROM calendar %s
   union
   SELECT
     name, 0, 'common_bucket', 1 hidden
   FROM common_bucket
   order by name asc
   ''' % self.filter_where)
     for i in self.cursor.fetchall():
         cnt += 1
         try:
             frepple.calendar(name=i[0],
                              default=i[1],
                              source=i[2],
                              hidden=i[3])
         except Exception as e:
             print("Error:", e)
     print('Loaded %d calendars in %.2f seconds' %
           (cnt, time() - starttime))
Example #2
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()
      cursor.execute('''
        SELECT
          name, defaultvalue, source, 0 hidden
        FROM calendar %s
        union
        SELECT
          name, 0, 'common_bucket', 1 hidden
        FROM common_bucket
        order by name asc
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        try:
          frepple.calendar(name=i[0], default=i[1], source=i[2], hidden=i[3])
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d calendars in %.2f seconds' % (cnt, time() - starttime))
Example #3
0
def loadCalendars(cursor):
  print('Importing calendars...')
  cnt = 0
  starttime = time()
  cursor.execute("SELECT name, defaultvalue FROM calendar")
  for i, j in cursor.fetchall():
    cnt += 1
    try: frepple.calendar(name=i, default=j)
    except Exception as e: print("Error:", e)
  print('Loaded %d calendars in %.2f seconds' % (cnt, time() - starttime))
Example #4
0
def loadCalendars(cursor):
    print('Importing calendars...')
    cnt = 0
    starttime = time()
    cursor.execute("SELECT name, defaultvalue FROM calendar")
    for i, j in cursor.fetchall():
        cnt += 1
        try:
            frepple.calendar(name=i, default=j)
        except Exception as e:
            print("Error:", e)
    print('Loaded %d calendars in %.2f seconds' % (cnt, time() - starttime))
Example #5
0
 def loadResources(self):
   print('Importing resources...')
   cnt = 0
   starttime = time()
   Resource.rebuildHierarchy(database=self.database)
   self.cursor.execute('''
     SELECT
       name, description, maximum, maximum_calendar_id, location_id, type, cost,
       maxearly, setup, setupmatrix_id, category, subcategory, owner_id, source
     FROM %s %s
     ORDER BY lvl ASC, name
     ''' % (connections[self.cursor.db.alias].ops.quote_name('resource'), self.filter_where) )
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       if i[5] == "infinite":
         x = frepple.resource_infinite(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
       elif i[5] == "buckets":
         x = frepple.resource_buckets(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
         if i[3]:
           x.maximum_calendar = frepple.calendar(name=i[3])
         if i[7]:
           x.maxearly = i[7]
       elif not i[5] or i[5] == "default":
         x = frepple.resource_default(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
         if i[3]:
           x.maximum_calendar = frepple.calendar(name=i[3])
         if i[7]:
           x.maxearly = i[7].total_seconds()
         if i[2]:
           x.maximum = i[2]
       else:
         raise ValueError("Resource type '%s' not recognized" % i[5])
       if i[4]:
         x.location = frepple.location(name=i[4])
       if i[6]:
         x.cost = i[6]
       if i[8]:
         x.setup = i[8]
       if i[9]:
         x.setupmatrix = frepple.setupmatrix(name=i[9])
       if i[12]:
         x.owner = frepple.resource(name=i[12])
     except Exception as e:
       print("Error:", e)
   print('Loaded %d resources in %.2f seconds' % (cnt, time() - starttime))
Example #6
0
 def loadResources(self):
   print('Importing resources...')
   cnt = 0
   starttime = time()
   Resource.rebuildHierarchy(database=self.database)
   self.cursor.execute('''
     SELECT
       name, description, maximum, maximum_calendar_id, location_id, type, cost,
       maxearly, setup, setupmatrix_id, category, subcategory, owner_id, source
     FROM %s %s
     ORDER BY lvl ASC, name
     ''' % (connections[self.cursor.db.alias].ops.quote_name('resource'), self.filter_where) )
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       if i[5] == "infinite":
         x = frepple.resource_infinite(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
       elif i[5] == "buckets":
         x = frepple.resource_buckets(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
         if i[3]:
           x.maximum_calendar = frepple.calendar(name=i[3])
         if i[7]:
           x.maxearly = i[7]
       elif not i[5] or i[5] == "default":
         x = frepple.resource_default(
           name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
           )
         if i[3]:
           x.maximum_calendar = frepple.calendar(name=i[3])
         if i[7]:
           x.maxearly = i[7]
         if i[2]:
           x.maximum = i[2]
       else:
         raise ValueError("Resource type '%s' not recognized" % i[5])
       if i[4]:
         x.location = frepple.location(name=i[4])
       if i[6]:
         x.cost = i[6]
       if i[8]:
         x.setup = i[8]
       if i[9]:
         x.setupmatrix = frepple.setupmatrix(name=i[9])
       if i[12]:
         x.owner = frepple.resource(name=i[12])
     except Exception as e:
       print("Error:", e)
   print('Loaded %d resources in %.2f seconds' % (cnt, time() - starttime))
Example #7
0
 def loadBuffers(self):
   print('Importing buffers...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT name, description, location_id, item_id, onhand,
       minimum, minimum_calendar_id, type,
       min_interval, category, subcategory, source
     FROM buffer %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     if i[7] == "infinite":
       b = frepple.buffer_infinite(
         name=i[0], description=i[1], location=frepple.location(name=i[2]),
         item=frepple.item(name=i[3]), onhand=i[4],
         category=i[9], subcategory=i[10], source=i[11]
         )
     elif not i[7] or i[7] == "default":
       b = frepple.buffer(
         name=i[0], description=i[1], location=frepple.location(name=i[2]),
         item=frepple.item(name=i[3]), onhand=i[4],
         category=i[9], subcategory=i[10], source=i[11]
         )
       if i[8]:
         b.mininterval = i[8].total_seconds()
     else:
       raise ValueError("Buffer type '%s' not recognized" % i[7])
     if i[11] == 'tool':
       b.tool = True
     if i[5]:
       b.minimum = i[5]
     if i[6]:
       b.minimum_calendar = frepple.calendar(name=i[6])
   print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #8
0
def loadResources(cursor):
  print('Importing resources...')
  cnt = 0
  starttime = time()
  Resource.rebuildHierarchy(database=cursor.db.alias)
  cursor.execute('''SELECT
    name, description, maximum, maximum_calendar_id, location_id, type, cost,
    maxearly, setup, setupmatrix_id, category, subcategory, owner_id
    FROM %s order by lvl asc, name'''% connections[database].ops.quote_name('resource'))
  for i,j,t,k,l,m,n,o,p,q,r,s,u in cursor.fetchall():
    cnt += 1
    try:
      if m == "infinite":
        x = frepple.resource_infinite(name=i,description=j,category=r,subcategory=s)
      elif not m or m == "default":
        x = frepple.resource_default(name=i,description=j,category=r,subcategory=s)
        if k: x.maximum_calendar = frepple.calendar(name=k)
        if o: x.maxearly = o
        if t: x.maximum = t
      else:
        raise ValueError("Resource type '%s' not recognized" % m)
      if l: x.location = frepple.location(name=l)
      if n: x.cost = n
      if p: x.setup = p
      if q: x.setupmatrix = frepple.setupmatrix(name=q)
      if u: x.owner = frepple.resource(name=u)
    except Exception as e: print("Error:", e)
  print('Loaded %d resources in %.2f seconds' % (cnt, time() - starttime))
Example #9
0
def loadCalendarBuckets(cursor):
  print('Importing calendar buckets...')
  cnt = 0
  starttime = time()
  cursor.execute('''
     SELECT
       calendar_id, startdate, enddate, id, priority, value,
       sunday, monday, tuesday, wednesday, thursday, friday, saturday,
       starttime, endtime
    FROM calendarbucket
    ORDER BY calendar_id, startdate desc
    ''')
  for i, j, k, l, m, n, o1, o2, o3, o4, o5, o6, o7, t1, t2 in cursor.fetchall():
    cnt += 1
    try:
      days = 0
      if o1: days += 1
      if o2: days += 2
      if o3: days += 4
      if o4: days += 8
      if o5: days += 16
      if o6: days += 32
      if o7: days += 64
      b = frepple.calendar(name=i).addBucket(l)
      b.value = n
      b.days = days
      if t1: b.starttime = t1.hour*3600 + t1.minute*60 + t1.second
      if t2: b.endtime = t2.hour*3600 + t2.minute*60 + t2.second + 1
      if m: b.priority = m
      if j: b.start = j
      if k: b.end = k
    except Exception as e: print("Error:", e)
  print('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))
Example #10
0
 def loadBuffers(self):
   print('Importing buffers...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT name, description, location_id, item_id, onhand,
       minimum, minimum_calendar_id, type,
       min_interval, category, subcategory, source
     FROM buffer %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     if i[7] == "infinite":
       b = frepple.buffer_infinite(
         name=i[0], description=i[1], location=frepple.location(name=i[2]),
         item=frepple.item(name=i[3]), onhand=i[4],
         category=i[9], subcategory=i[10], source=i[11]
         )
     elif not i[7] or i[7] == "default":
       b = frepple.buffer(
         name=i[0], description=i[1], location=frepple.location(name=i[2]),
         item=frepple.item(name=i[3]), onhand=i[4],
         category=i[9], subcategory=i[10], source=i[11]
         )
       if i[8]:
         b.mininterval = i[8].total_seconds()
     else:
       raise ValueError("Buffer type '%s' not recognized" % i[7])
     if i[11] == 'tool':
       b.tool = True
     if i[5]:
       b.minimum = i[5]
     if i[6]:
       b.minimum_calendar = frepple.calendar(name=i[6])
   print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #11
0
 def loadLocations(self):
     print('Importing locations...')
     cnt = 0
     starttime = time()
     self.cursor.execute('''
   SELECT
     name, description, owner_id, available_id, category, subcategory, source
   FROM location %s
   ''' % self.filter_where)
     for i in self.cursor.fetchall():
         cnt += 1
         try:
             x = frepple.location(name=i[0],
                                  description=i[1],
                                  category=i[4],
                                  subcategory=i[5],
                                  source=i[6])
             if i[2]:
                 x.owner = frepple.location(name=i[2])
             if i[3]:
                 x.available = frepple.calendar(name=i[3])
         except Exception as e:
             print("Error:", e)
     print('Loaded %d locations in %.2f seconds' %
           (cnt, time() - starttime))
Example #12
0
 def loadCalendars(self):
   print('Importing calendars...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT
       name, defaultvalue, source
     FROM calendar %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       frepple.calendar(name=i[0], default=i[1], source=i[2])
     except Exception as e:
       print("Error:", e)
   print('Loaded %d calendars in %.2f seconds' % (cnt, time() - starttime))
Example #13
0
 def loadBuffers(self):
   print('Importing buffers...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT name, description, location_id, item_id, onhand,
       minimum, minimum_calendar_id, producing_id, type, leadtime, min_inventory,
       max_inventory, min_interval, max_interval, size_minimum,
       size_multiple, size_maximum, fence, carrying_cost,
       category, subcategory, source
     FROM buffer %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     if i[8] == "procure":
       b = frepple.buffer_procure(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[19], subcategory=i[20], source=i[21]
         )
       if i[9]:
         b.leadtime = i[9]
       if i[10]:
         b.mininventory = i[10]
       if i[11]:
         b.maxinventory = i[11]
       if i[14]:
         b.size_minimum = i[14]
       if i[15]:
         b.size_multiple = i[15]
       if i[16]:
         b.size_maximum = i[16]
       if i[17]:
         b.fence = i[17]
     elif i[8] == "infinite":
       b = frepple.buffer_infinite(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[19], subcategory=i[20], source=i[21]
         )
     elif not i[8] or i[8] == "default":
       b = frepple.buffer(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[19], subcategory=i[20], source=i[21]
         )
     else:
       raise ValueError("Buffer type '%s' not recognized" % i[8])
     if i[2]:
       b.location = frepple.location(name=i[2])
     if i[5]:
       b.minimum = i[5]
     if i[6]:
       b.minimum_calendar = frepple.calendar(name=i[6])
     if i[7]:
       b.producing = frepple.operation(name=i[7])
     if i[18]:
       b.carrying_cost = i[18]
     if i[12]:
       b.mininterval = i[12]
     if i[13]:
       b.maxinterval = i[13]
   print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #14
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()
      cursor.execute('''
        SELECT
          name, description, owner_id, available_id, category, subcategory, source
        FROM location %s
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        try:
          x = frepple.location(name=i[0], description=i[1], category=i[4], subcategory=i[5], source=i[6])
          if i[2]:
            x.owner = frepple.location(name=i[2])
          if i[3]:
            x.available = frepple.calendar(name=i[3])
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d locations in %.2f seconds' % (cnt, time() - starttime))
Example #15
0
 def loadBuffers(self):
   print('Importing buffers...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT name, description, location_id, item_id, onhand,
       minimum, minimum_calendar_id, producing_id, type, leadtime, min_inventory,
       max_inventory, min_interval, max_interval, size_minimum,
       size_multiple, size_maximum, fence, category, subcategory, source
     FROM buffer %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     if i[8] == "procure":
       b = frepple.buffer_procure(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[18], subcategory=i[19], source=i[20]
         )
       if i[9]:
         b.leadtime = i[9]
       if i[10]:
         b.mininventory = i[10]
       if i[11]:
         b.maxinventory = i[11]
       if i[14]:
         b.size_minimum = i[14]
       if i[15]:
         b.size_multiple = i[15]
       if i[16]:
         b.size_maximum = i[16]
       if i[17]:
         b.fence = i[17]
     elif i[8] == "infinite":
       b = frepple.buffer_infinite(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[18], subcategory=i[19], source=i[20]
         )
     elif not i[8] or i[8] == "default":
       b = frepple.buffer(
         name=i[0], description=i[1], item=frepple.item(name=i[3]), onhand=i[4],
         category=i[18], subcategory=i[19], source=i[20]
         )
     else:
       raise ValueError("Buffer type '%s' not recognized" % i[8])
     if i[20] == 'tool':
       b.tool = True
     if i[2]:
       b.location = frepple.location(name=i[2])
     if i[5]:
       b.minimum = i[5]
     if i[6]:
       b.minimum_calendar = frepple.calendar(name=i[6])
     if i[7]:
       b.producing = frepple.operation(name=i[7])
     if i[12]:
       b.mininterval = i[12]
     if i[13]:
       b.maxinterval = i[13]
   print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #16
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()
      cursor.execute('''
        SELECT
          calendar_id, startdate, enddate, priority, value,
          sunday, monday, tuesday, wednesday, thursday, friday, saturday,
          starttime, endtime, source
        FROM calendarbucket %s
        ORDER BY calendar_id, startdate desc
        ''' % filter_where)
      prevcal = None
      for i in cursor:
        cnt += 1
        try:
          days = 0
          if i[5]:
            days += 1
          if i[6]:
            days += 2
          if i[7]:
            days += 4
          if i[8]:
            days += 8
          if i[9]:
            days += 16
          if i[10]:
            days += 32
          if i[11]:
            days += 64
          if i[0] != prevcal:
            cal = frepple.calendar(name=i[0])
            prevcal = i[0]
          b = frepple.bucket(
            calendar=cal,
            start=i[1],
            end=i[2] if i[2] else datetime(2030, 12, 31),
            priority=i[3],
            source=i[14],
            value=i[4],
            days=days
            )
          if i[12]:
            b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[12].second
          if i[13]:
            b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[13].second + 1
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))
Example #17
0
def loadLocations(cursor):
  print('Importing locations...')
  cnt = 0
  starttime = time()
  cursor.execute("SELECT name, description, owner_id, available_id, category, subcategory FROM location")
  for i,j,k,l,m,n in cursor.fetchall():
    cnt += 1
    try:
      x = frepple.location(name=i, description=j, category=m, subcategory=n)
      if k: x.owner = frepple.location(name=k)
      if l: x.available = frepple.calendar(name=l)
    except Exception as e: print("Error:", e)
  print('Loaded %d locations in %.2f seconds' % (cnt, time() - starttime))
Example #18
0
 def loadCalendarBuckets(self):
     print('Importing calendar buckets...')
     cnt = 0
     starttime = time()
     self.cursor.execute('''
    SELECT
      calendar_id, startdate, enddate, priority, value,
      sunday, monday, tuesday, wednesday, thursday, friday, saturday,
      starttime, endtime, source
   FROM calendarbucket %s
   ORDER BY calendar_id, startdate desc
   ''' % self.filter_where)
     prevcal = None
     for i in self.cursor.fetchall():
         cnt += 1
         try:
             days = 0
             if i[5]:
                 days += 1
             if i[6]:
                 days += 2
             if i[7]:
                 days += 4
             if i[8]:
                 days += 8
             if i[9]:
                 days += 16
             if i[10]:
                 days += 32
             if i[11]:
                 days += 64
             if i[0] != prevcal:
                 cal = frepple.calendar(name=i[0])
                 prevcal = i[0]
             b = frepple.bucket(calendar=cal,
                                start=i[1],
                                end=i[2],
                                priority=i[3],
                                source=i[14],
                                value=i[4],
                                days=days)
             if i[12]:
                 b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[
                     12].second
             if i[13]:
                 b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[
                     13].second + 1
         except Exception as e:
             print("Error:", e)
     print('Loaded %d calendar buckets in %.2f seconds' %
           (cnt, time() - starttime))
Example #19
0
def loadBuffers(cursor):
    print('Importing buffers...')
    cnt = 0
    starttime = time()
    cursor.execute('''SELECT name, description, location_id, item_id, onhand,
     minimum, minimum_calendar_id, producing_id, type, leadtime, min_inventory,
     max_inventory, min_interval, max_interval, size_minimum,
     size_multiple, size_maximum, fence, carrying_cost,
     category, subcategory FROM buffer''')
    for i, j, k, l, m, t, n, o, q, f1, f2, f3, f4, f5, f6, f7, f8, f9, p, r, s in cursor.fetchall(
    ):
        cnt += 1
        if q == "procure":
            b = frepple.buffer_procure(name=i,
                                       description=j,
                                       item=frepple.item(name=l),
                                       onhand=m,
                                       category=r,
                                       subcategory=s)
            if f1: b.leadtime = f1
            if f2: b.mininventory = f2
            if f3: b.maxinventory = f3
            if f4: b.mininterval = f4
            if f5: b.maxinterval = f5
            if f6: b.size_minimum = f6
            if f7: b.size_multiple = f7
            if f8: b.size_maximum = f8
            if f9: b.fence = f9
        elif q == "infinite":
            b = frepple.buffer_infinite(name=i,
                                        description=j,
                                        item=frepple.item(name=l),
                                        onhand=m,
                                        category=r,
                                        subcategory=s)
        elif not q or q == "default":
            b = frepple.buffer(name=i,
                               description=j,
                               item=frepple.item(name=l),
                               onhand=m,
                               category=r,
                               subcategory=s)
        else:
            raise ValueError("Buffer type '%s' not recognized" % q)
        if k: b.location = frepple.location(name=k)
        if t: b.minimum = t
        if n: b.minimum_calendar = frepple.calendar(name=n)
        if o: b.producing = frepple.operation(name=o)
        if p: b.carrying_cost = p
    print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #20
0
 def loadCalendarBuckets(self):
   print('Importing calendar buckets...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
      SELECT
        calendar_id, startdate, enddate, priority, value,
        sunday, monday, tuesday, wednesday, thursday, friday, saturday,
        starttime, endtime, source
     FROM calendarbucket %s
     ORDER BY calendar_id, startdate desc
     ''' % self.filter_where)
   prevcal = None
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       days = 0
       if i[5]:
         days += 1
       if i[6]:
         days += 2
       if i[7]:
         days += 4
       if i[8]:
         days += 8
       if i[9]:
         days += 16
       if i[10]:
         days += 32
       if i[11]:
         days += 64
       if i[0] != prevcal:
         cal = frepple.calendar(name=i[0])
         prevcal = i[0]
       b = frepple.bucket(
         calendar=cal,
         start=i[1],
         end=i[2],
         priority=i[3],
         source=i[14],
         value=i[4],
         days=days
         )
       if i[12]:
         b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[12].second
       if i[13]:
         b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[13].second + 1
     except Exception as e:
       print("Error:", e)
   print('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))
Example #21
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()
      cursor.execute('''
        SELECT name, description, location_id, item_id, onhand,
          minimum, minimum_calendar_id, type,
          min_interval, category, subcategory, source
        FROM buffer %s
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        if i[7] == "infinite":
          b = frepple.buffer_infinite(
            name=i[0], description=i[1], location=frepple.location(name=i[2]),
            item=frepple.item(name=i[3]), onhand=max(i[4] or 0, 0),
            category=i[9], subcategory=i[10], source=i[11]
            )
        elif not i[7] or i[7] == "default":
          b = frepple.buffer(
            name=i[0], description=i[1], location=frepple.location(name=i[2]),
            item=frepple.item(name=i[3]), onhand=max(i[4] or 0, 0),
            category=i[9], subcategory=i[10], source=i[11]
            )
          if i[8]:
            b.mininterval = i[8].total_seconds()
        else:
          raise ValueError("Buffer type '%s' not recognized" % i[7])
        if i[10] == 'tool':
          b.tool = True
        if i[5]:
          b.minimum = i[5]
        if i[6]:
          b.minimum_calendar = frepple.calendar(name=i[6])
      logger.info('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #22
0
def loadLocations(cursor):
    print('Importing locations...')
    cnt = 0
    starttime = time()
    cursor.execute(
        "SELECT name, description, owner_id, available_id, category, subcategory FROM location"
    )
    for i, j, k, l, m, n in cursor.fetchall():
        cnt += 1
        try:
            x = frepple.location(name=i,
                                 description=j,
                                 category=m,
                                 subcategory=n)
            if k: x.owner = frepple.location(name=k)
            if l: x.available = frepple.calendar(name=l)
        except Exception as e:
            print("Error:", e)
    print('Loaded %d locations in %.2f seconds' % (cnt, time() - starttime))
Example #23
0
def loadBuffers(cursor):
  print('Importing buffers...')
  cnt = 0
  starttime = time()
  cursor.execute('''SELECT name, description, location_id, item_id, onhand,
     minimum, minimum_calendar_id, producing_id, type, leadtime, min_inventory,
     max_inventory, min_interval, max_interval, size_minimum,
     size_multiple, size_maximum, fence, carrying_cost,
     category, subcategory FROM buffer''')
  for i,j,k,l,m,t,n,o,q,f1,f2,f3,f4,f5,f6,f7,f8,f9,p,r,s in cursor.fetchall():
    cnt += 1
    if q == "procure":
      b = frepple.buffer_procure(
        name=i, description=j, item=frepple.item(name=l), onhand=m,
        category=r, subcategory=s
        )
      if f1: b.leadtime = f1
      if f2: b.mininventory = f2
      if f3: b.maxinventory = f3
      if f4: b.mininterval = f4
      if f5: b.maxinterval = f5
      if f6: b.size_minimum = f6
      if f7: b.size_multiple = f7
      if f8: b.size_maximum = f8
      if f9: b.fence = f9
    elif q == "infinite":
      b = frepple.buffer_infinite(
        name=i, description=j, item=frepple.item(name=l), onhand=m,
        category=r, subcategory=s
        )
    elif not q or q == "default":
      b = frepple.buffer(
        name=i, description=j, item=frepple.item(name=l), onhand=m,
        category=r, subcategory=s
        )
    else:
      raise ValueError("Buffer type '%s' not recognized" % q)
    if k: b.location = frepple.location(name=k)
    if t: b.minimum = t
    if n: b.minimum_calendar = frepple.calendar(name=n)
    if o: b.producing = frepple.operation(name=o)
    if p: b.carrying_cost = p
  print('Loaded %d buffers in %.2f seconds' % (cnt, time() - starttime))
Example #24
0
 def loadLocations(self):
   print('Importing locations...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT
       name, description, owner_id, available_id, category, subcategory, source
     FROM location %s
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       x = frepple.location(name=i[0], description=i[1], category=i[4], subcategory=i[5], source=i[6])
       if i[2]:
         x.owner = frepple.location(name=i[2])
       if i[3]:
         x.available = frepple.calendar(name=i[3])
     except Exception as e:
       print("Error:", e)
   print('Loaded %d locations in %.2f seconds' % (cnt, time() - starttime))
Example #25
0
 def loadParameter(self):
   print('Importing parameters...')
   self.cursor.execute('''
     SELECT name, value
     FROM common_parameter
     where name in ('currentdate', 'plan.calendar')
     ''')
   default_current_date = True
   for rec in self.cursor.fetchall():
     if rec[0] == 'currentdate':
       try:
         frepple.settings.current = datetime.strptime(rec[1], "%Y-%m-%d %H:%M:%S")
         default_current_date = False
       except:
         pass
     elif rec[0] == 'plan.calendar' and rec[1]:
       frepple.settings.calendar = frepple.calendar(name=rec[1])
       print('Bucketized planning using calendar %s' % rec[1])
   if default_current_date:
     frepple.settings.current = datetime.now().replace(microsecond=0)
   print('Current date: %s' % frepple.settings.current)
Example #26
0
 def loadParameter(self):
   print('Importing parameters...')
   self.cursor.execute('''
     SELECT name, value
     FROM common_parameter
     where name in ('currentdate', 'plan.calendar')
     ''')
   default_current_date = True
   for rec in self.cursor.fetchall():
     if rec[0] == 'currentdate':
       try:
         frepple.settings.current = datetime.strptime(rec[1], "%Y-%m-%d %H:%M:%S")
         default_current_date = False
       except:
         pass
     elif rec[0] == 'plan.calendar' and rec[1]:
       frepple.settings.calendar = frepple.calendar(name=rec[1])
       print('Bucketized planning using calendar %s' % rec[1])
   if default_current_date:
     frepple.settings.current = datetime.now().replace(microsecond=0)
   print('Current date: %s' % frepple.settings.current)
Example #27
0
  def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
    import frepple

    with connections[database].chunked_cursor() as cursor:
      cursor.execute('''
        SELECT name, value
        FROM common_parameter
        where name in ('currentdate', 'plan.calendar')
        ''')
      default_current_date = True
      for rec in cursor:
        if rec[0] == 'currentdate':
          try:
            frepple.settings.current = datetime.strptime(rec[1], "%Y-%m-%d %H:%M:%S")
            default_current_date = False
          except:
            pass
        elif rec[0] == 'plan.calendar' and rec[1]:
          frepple.settings.calendar = frepple.calendar(name=rec[1])
          logger.info('Bucketized planning using calendar %s' % rec[1])
      if default_current_date:
        frepple.settings.current = datetime.now().replace(microsecond=0)
      logger.info('Current date: %s' % frepple.settings.current)
Example #28
0
def loadResources(cursor):
    print('Importing resources...')
    cnt = 0
    starttime = time()
    Resource.rebuildHierarchy(database=cursor.db.alias)
    cursor.execute('''SELECT
    name, description, maximum, maximum_calendar_id, location_id, type, cost,
    maxearly, setup, setupmatrix_id, category, subcategory, owner_id
    FROM %s order by lvl asc, name''' %
                   connections[cursor.db.alias].ops.quote_name('resource'))
    for i, j, t, k, l, m, n, o, p, q, r, s, u in cursor.fetchall():
        cnt += 1
        try:
            if m == "infinite":
                x = frepple.resource_infinite(name=i,
                                              description=j,
                                              category=r,
                                              subcategory=s)
            elif not m or m == "default":
                x = frepple.resource_default(name=i,
                                             description=j,
                                             category=r,
                                             subcategory=s)
                if k: x.maximum_calendar = frepple.calendar(name=k)
                if o: x.maxearly = o
                if t: x.maximum = t
            else:
                raise ValueError("Resource type '%s' not recognized" % m)
            if l: x.location = frepple.location(name=l)
            if n: x.cost = n
            if p: x.setup = p
            if q: x.setupmatrix = frepple.setupmatrix(name=q)
            if u: x.owner = frepple.resource(name=u)
        except Exception as e:
            print("Error:", e)
    print('Loaded %d resources in %.2f seconds' % (cnt, time() - starttime))
Example #29
0
def loadCalendarBuckets(cursor):
    print('Importing calendar buckets...')
    cnt = 0
    starttime = time()
    cursor.execute('''
     SELECT
       calendar_id, startdate, enddate, id, priority, value,
       sunday, monday, tuesday, wednesday, thursday, friday, saturday,
       starttime, endtime
    FROM calendarbucket
    ORDER BY calendar_id, startdate desc
    ''')
    for i, j, k, l, m, n, o1, o2, o3, o4, o5, o6, o7, t1, t2 in cursor.fetchall(
    ):
        cnt += 1
        try:
            days = 0
            if o1: days += 1
            if o2: days += 2
            if o3: days += 4
            if o4: days += 8
            if o5: days += 16
            if o6: days += 32
            if o7: days += 64
            b = frepple.calendar(name=i).addBucket(l)
            b.value = n
            b.days = days
            if t1: b.starttime = t1.hour * 3600 + t1.minute * 60 + t1.second
            if t2: b.endtime = t2.hour * 3600 + t2.minute * 60 + t2.second + 1
            if m: b.priority = m
            if j: b.start = j
            if k: b.end = k
        except Exception as e:
            print("Error:", e)
    print('Loaded %d calendar buckets in %.2f seconds' %
          (cnt, time() - starttime))
Example #30
0
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)

###
print("\nTesting the calendar iterator")
print("calendar events:")
for date, value in c.events():
  print("  ", date, value)

###
print("\nDeleting a calendar")
frepple.calendar(name="Cal3", action="R")
Example #31
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()
      Resource.rebuildHierarchy(database=database)
      cursor.execute('''
        SELECT
          name, description, maximum, maximum_calendar_id, location_id, type,
          cost, maxearly, setup, setupmatrix_id, category, subcategory,
          owner_id, source, available_id
        FROM %s %s
        ORDER BY lvl ASC, name
        ''' % (connections[cursor.db.alias].ops.quote_name('resource'), filter_where) )
      for i in cursor:
        cnt += 1
        try:
          if i[5] == "infinite":
            x = frepple.resource_infinite(
              name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
              )
          elif i[5] == "buckets":
            x = frepple.resource_buckets(
              name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
              )
            if i[3]:
              x.maximum_calendar = frepple.calendar(name=i[3])
            if i[7] is not None:
              x.maxearly = i[7]
          elif not i[5] or i[5] == "default":
            x = frepple.resource_default(
              name=i[0], description=i[1], category=i[10], subcategory=i[11], source=i[13]
              )
            if i[3]:
              x.maximum_calendar = frepple.calendar(name=i[3])
            if i[7] is not None:
              x.maxearly = i[7].total_seconds()
            if i[2] is not None:
              x.maximum = i[2]
          else:
            raise ValueError("Resource type '%s' not recognized" % i[5])
          if i[4]:
            x.location = frepple.location(name=i[4])
          if i[6]:
            x.cost = i[6]
          if i[8]:
            x.setup = i[8]
          if i[9]:
            x.setupmatrix = frepple.setupmatrix(name=i[9])
          if i[12]:
            x.owner = frepple.resource(name=i[12])
          if i[14]:
            x.available = frepple.calendar(name=i[14])
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d resources in %.2f seconds' % (cnt, time() - starttime))
Example #32
0
                                        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)

###
print("\nTesting the calendar iterator")
print("calendar events:")
for date, value in c.events():
    print("  ", date, value)

###
print("\nDeleting a calendar")
frepple.calendar(name="Cal3", action="R")
Example #33
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].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))