Example #1
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, source
        FROM setupmatrix %s
        ORDER BY name
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        try:
          frepple.setupmatrix(name=i[0], source=i[1])
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d setup matrices in %.2f seconds' % (cnt, time() - starttime))

    with connections[database].chunked_cursor() as cursor:
      cnt = 0
      starttime = time()
      cursor.execute('''
        SELECT
          setupmatrix_id, priority, fromsetup, tosetup, duration, cost, source
        FROM setuprule %s
        ORDER BY setupmatrix_id, priority DESC
        ''' % filter_where)
      for i in cursor:
        cnt += 1
        try:
          frepple.setupmatrixrule(
            setupmatrix=frepple.setupmatrix(name=i[0]),
            priority=i[1],
            fromsetup=i[2],
            tosetup=i[3],
            duration=i[4].total_seconds(),
            cost=i[5],
            source=i[6]
            )
        except Exception as e:
          logger.error("**** %s ****" % e)
      logger.info('Loaded %d setup matrix rules in %.2f seconds' % (cnt, time() - starttime))
Example #2
0
 def loadSetupMatrices(self):
   print('Importing setup matrix rules...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT
       setupmatrix_id, priority, fromsetup, tosetup, duration, cost, source
     FROM setuprule %s
     ORDER BY setupmatrix_id, priority DESC
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       r = frepple.setupmatrix(name=i[0], source=i[6]).addRule(priority=i[1])
       if i[2]:
         r.fromsetup = i[2]
       if i[3]:
         r.tosetup = i[3]
       if i[4]:
         r.duration = i[4].total_seconds()
       if i[5]:
         r.cost = i[5]
     except Exception as e:
       print("Error:", e)
   print('Loaded %d setup matrix rules in %.2f seconds' % (cnt, time() - starttime))
Example #3
0
 def loadSetupMatrices(self):
   print('Importing setup matrix rules...')
   cnt = 0
   starttime = time()
   self.cursor.execute('''
     SELECT
       setupmatrix_id, priority, fromsetup, tosetup, duration, cost, source
     FROM setuprule %s
     ORDER BY setupmatrix_id, priority DESC
     ''' % self.filter_where)
   for i in self.cursor.fetchall():
     cnt += 1
     try:
       r = frepple.setupmatrix(name=i[0], source=i[6]).addRule(priority=i[1])
       if i[2]:
         r.fromsetup = i[2]
       if i[3]:
         r.tosetup = i[3]
       if i[4]:
         r.duration = i[4]
       if i[5]:
         r.cost = i[5]
     except Exception as e:
       print("Error:", e)
   print('Loaded %d setup matrix rules in %.2f seconds' % (cnt, time() - starttime))
Example #4
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()
      cursor.execute('''
        SELECT
          setupmatrix_id, priority, fromsetup, tosetup, duration, cost, source
        FROM setuprule %s
        ORDER BY setupmatrix_id, priority DESC
        ''' % filter_where)
      for i in cursor.fetchall():
        cnt += 1
        try:
          r = frepple.setupmatrix(name=i[0], source=i[6]).addRule(priority=i[1])
          if i[2]:
            r.fromsetup = i[2]
          if i[3]:
            r.tosetup = i[3]
          if i[4]:
            r.duration = i[4].total_seconds()
          if i[5]:
            r.cost = i[5]
        except Exception as e:
          print("Error:", e)
      print('Loaded %d setup matrix rules in %.2f seconds' % (cnt, time() - starttime))
Example #5
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 #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].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 #7
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 #8
0
def loadSetupMatrices(cursor):
  print('Importing setup matrix rules...')
  cnt = 0
  starttime = time()
  cursor.execute('''SELECT setupmatrix_id, priority, fromsetup, tosetup, duration, cost
    FROM setuprule
    order by setupmatrix_id, priority desc''')
  for i, j, k, l, m, n in cursor.fetchall():
    cnt += 1
    try:
      r = frepple.setupmatrix(name=i).addRule(priority=j)
      if k: r.fromsetup = k
      if l: r.tosetup = l
      if m: r.duration = m
      if n: r.cost = n
    except Exception as e: print("Error:", e)
  print('Loaded %d setup matrix rules in %.2f seconds' % (cnt, time() - starttime))
Example #9
0
def loadSetupMatrices(cursor):
    print('Importing setup matrix rules...')
    cnt = 0
    starttime = time()
    cursor.execute(
        '''SELECT setupmatrix_id, priority, fromsetup, tosetup, duration, cost
    FROM setuprule
    order by setupmatrix_id, priority desc''')
    for i, j, k, l, m, n in cursor.fetchall():
        cnt += 1
        try:
            r = frepple.setupmatrix(name=i).addRule(priority=j)
            if k: r.fromsetup = k
            if l: r.tosetup = l
            if m: r.duration = m
            if n: r.cost = n
        except Exception as e:
            print("Error:", e)
    print('Loaded %d setup matrix rules in %.2f seconds' %
          (cnt, time() - starttime))
Example #10
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 #11
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))