def exportBuffers(self, cursor):
   with transaction.atomic(using=self.database, savepoint=False):
     print("Exporting buffers...")
     starttime = time()
     cursor.execute("SELECT name FROM buffer")
     primary_keys = set([ i[0] for i in cursor.fetchall() ])
     cursor.executemany(
       "insert into buffer \
       (name,description,location_id,item_id,onhand,minimum,minimum_calendar_id, \
       type,min_interval,category,subcategory,source,lastmodified) \
       values(%s,%s,%s,%s,%s,%s,%s,%s,%s * interval '1 second',%s,%s,%s,%s)",
       [
         (
           i.name, i.description, i.location and i.location.name or None,
           i.item and i.item.name or None,
           round(i.onhand, 6), round(i.minimum, 6),
           i.minimum_calendar and i.minimum_calendar.name or None,
           i.__class__.__name__[7:], i.mininterval,
           i.category, i.subcategory, i.source, self.timestamp
         )
         for i in frepple.buffers()
         if i.name not in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update buffer \
        set description=%s, location_id=%s, item_id=%s, onhand=%s, \
        minimum=%s, minimum_calendar_id=%s, type=%s, \
        min_interval=%s * interval '1 second', category=%s, \
        subcategory=%s, source=%s, lastmodified=%s \
        where name=%s",
       [
         (
           i.description, i.location and i.location.name or None, i.item and i.item.name or None,
           round(i.onhand, 6), round(i.minimum, 6),
           i.minimum_calendar and i.minimum_calendar.name or None,
           i.__class__.__name__[7:],
           (i.mininterval!=-1) and i.mininterval or None,
           i.category, i.subcategory, i.source, self.timestamp, i.name
         )
         for i in frepple.buffers()
         if i.name in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update buffer set owner_id=%s where name=%s",
       [
         (i.owner.name, i.name)
         for i in frepple.buffers()
         if i.owner and not i.hidden
       ])
     print('Exported buffers in %.2f seconds' % (time() - starttime))
Exemple #2
0
 def exportBuffers(self, cursor):
   with transaction.atomic(using=self.database, savepoint=False):
     print("Exporting buffers...")
     starttime = time()
     cursor.execute("SELECT name FROM buffer")
     primary_keys = set([ i[0] for i in cursor.fetchall() ])
     cursor.executemany(
       "insert into buffer \
       (name,description,location_id,item_id,onhand,minimum,minimum_calendar_id, \
       type,min_interval,category,subcategory,source,lastmodified) \
       values(%s,%s,%s,%s,%s,%s,%s,%s,%s * interval '1 second',%s,%s,%s,%s)",
       [
         (
           i.name, i.description, i.location and i.location.name or None,
           i.item and i.item.name or None,
           round(i.onhand, 6), round(i.minimum, 6),
           i.minimum_calendar and i.minimum_calendar.name or None,
           i.__class__.__name__[7:], i.mininterval,
           i.category, i.subcategory, i.source, self.timestamp
         )
         for i in frepple.buffers()
         if i.name not in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update buffer \
        set description=%s, location_id=%s, item_id=%s, onhand=%s, \
        minimum=%s, minimum_calendar_id=%s, type=%s, \
        min_interval=%s * interval '1 second', category=%s, \
        subcategory=%s, source=%s, lastmodified=%s \
        where name=%s",
       [
         (
           i.description, i.location and i.location.name or None, i.item and i.item.name or None,
           round(i.onhand, 6), round(i.minimum, 6),
           i.minimum_calendar and i.minimum_calendar.name or None,
           i.__class__.__name__[7:],
           (i.mininterval!=-1) and i.mininterval or None,
           i.category, i.subcategory, i.source, self.timestamp, i.name
         )
         for i in frepple.buffers()
         if i.name in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update buffer set owner_id=%s where name=%s",
       [
         (i.owner.name, i.name)
         for i in frepple.buffers()
         if i.owner and not i.hidden
       ])
     print('Exported buffers in %.2f seconds' % (time() - starttime))
Exemple #3
0
    def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):

        import frepple

        current_date = frepple.settings.current
        cls.fence = timedelta(cls.fence)

        for buf in frepple.buffers():
            # Get the first confirmed order, initialize at infinite past
            last_confirmed = datetime(1971, 1, 1)
            # no proposed request can be generated before current date + buffer lead time.
            # therefore we have to capture all confirmed orders
            # within current date + buffer lead time and current date + buffer lead time + plan.autoFenceOperations
            # but there might be more than one, we need to capture the furthest in time.
            lead_time = timedelta(seconds=buf.decoupledLeadTime(100))
            for j in buf.flowplans:
                if j.date > current_date + lead_time + cls.fence:
                    break
                if (j.operationplan.status == 'confirmed' or j.operationplan.status == 'approved') \
                  and j.quantity > 0 \
                  and j.date > last_confirmed:
                    last_confirmed = j.date
            if last_confirmed >= current_date:
                if isinstance(buf.producing, frepple.operation_alternate):
                    for suboper in buf.producing.suboperations:
                        myleadtime = suboper.operation.decoupledLeadTime(100)
                        new_fence = (
                            last_confirmed - current_date -
                            timedelta(seconds=myleadtime)).total_seconds()
                        if new_fence <= 0:
                            continue
                        if suboper.operation.fence is not None and suboper.operation.fence > 0:
                            suboper.operation.fence = max(
                                suboper.operation.fence, new_fence)
                        else:
                            suboper.operation.fence = new_fence
                        if cls.loglevel > 0:
                            logger.info(
                                "Setting fence to %.2f days for operation '%s' that has a lead time of %.2f days"
                                %
                                (suboper.operation.fence / 86400.0,
                                 suboper.operation.name, myleadtime / 86400.0))
                else:
                    # Found a confirmed operationplan within the defined window indeed
                    myleadtime = buf.producing.decoupledLeadTime(100)
                    new_fence = (
                        last_confirmed - current_date -
                        timedelta(seconds=myleadtime)).total_seconds()
                    if new_fence <= 0:
                        continue
                    if buf.producing.fence is not None and buf.producing.fence > 0:
                        buf.producing.fence = max(buf.producing.fence,
                                                  new_fence)
                    else:
                        buf.producing.fence = new_fence
                    if cls.loglevel > 0:
                        logger.info(
                            "Setting fence to %.2f days for operation '%s' that has a lead time of %.2f days"
                            % (buf.producing.fence / 86400.0,
                               buf.producing.name, myleadtime / 86400.0))
 def getData():
     for i in frepple.buffers():
         if self.cluster != -1 and self.cluster != i.cluster:
             continue
         for j in i.flowplans:
             # if the record is confirmed, it is already in the table.
             if not j.operationplan.reference:
                 print(
                     "Warning: skip exporting uninitialized operationplan",
                     j.operationplan.operation.name,
                     j.operationplan.quantity,
                     j.operationplan.start,
                     j.operationplan.end,
                 )
             else:
                 yield "%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\n" % (
                     clean_value(j.operationplan.id),
                     clean_value(j.buffer.item.name),
                     clean_value(j.buffer.location.name),
                     round(j.quantity, 8),
                     str(j.date),
                     round(j.onhand, 8),
                     round(j.minimum, 8),
                     round(j.period_of_cover, 8),
                     j.status,
                     self.timestamp,
                 )
 def exportOperationPlanMaterials(self, process):
     if self.verbosity:
         print("Exporting operationplan materials...")
     starttime = time()
     process.stdin.write((
         'COPY operationplanmaterial '
         '(operationplan_id, buffer, quantity, flowdate, onhand, status, lastmodified) '
         'FROM STDIN;\n').encode(self.encoding))
     currentTime = self.timestamp
     updates = []
     for i in frepple.buffers():
         if self.cluster != -1 and self.cluster != i.cluster:
             continue
         for j in i.flowplans:
             #if the record is confirmed, it is already in the table.
             if j.status == 'confirmed':
                 updates.append('''
       update operationplanmaterial
       set onhand=%s, flowdate='%s'
       where status = 'confirmed' and buffer = %s and operationplan_id = %s;
       ''' % (round(j.onhand, 6), str(j.date), adapt(
                     j.buffer.name), j.operationplan.id))
             else:
                 process.stdin.write(
                     ("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" %
                      (j.operationplan.id, j.buffer.name,
                       round(j.quantity, 6), str(j.date), round(
                           j.onhand, 6), j.status, currentTime)).encode(
                               self.encoding))
     process.stdin.write('\\.\n'.encode(self.encoding))
     process.stdin.write('\n'.join(updates).encode(self.encoding))
     if self.verbosity:
         print('Exported operationplan materials in %.2f seconds' %
               (time() - starttime))
Exemple #6
0
    def getData(timestamp, cluster=-1):
        import frepple

        for i in frepple.buffers():
            if cluster != -1 and cluster != i.cluster:
                continue
            for j in i.flowplans:
                if not j.quantity:
                    continue
                elif not j.operationplan.reference:
                    logger.error(
                        "Warning: skip exporting uninitialized operationplan %s %s %s %s"
                        % (
                            j.operationplan.operation.name,
                            j.operationplan.quantity,
                            j.operationplan.start,
                            j.operationplan.end,
                        ))
                else:
                    yield "%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\v%s\n" % (
                        clean_value(j.operationplan.reference),
                        clean_value(j.buffer.item.name),
                        clean_value(j.buffer.location.name),
                        round(j.quantity, 8),
                        str(j.date),
                        round(j.onhand, 8),
                        round(j.minimum, 8),
                        round(j.period_of_cover, 8),
                        j.status,
                        timestamp,
                    )
def exportFlowplans():
    print("Exporting flowplans...")
    starttime = time()
    writer = csv.writer(open("flowplans.csv", "wb"), quoting=csv.QUOTE_ALL)
    writer.writerow(
        ('#operationplan id', 'buffer', 'quantity', 'date', 'on hand'))
    for i in frepple.buffers():
        for j in i.flowplans:
            writer.writerow(
                (j.operationplan.id, j.buffer.name.encode(encoding, "ignore"),
                 j.quantity, j.date, j.onhand))
    print('Exported flowplans in %.2f seconds' % (time() - starttime))
Exemple #8
0
def exportFlowplans():
  print("Exporting flowplans...")
  starttime = time()
  writer = csv.writer(open("flowplans.csv", "wb"), quoting=csv.QUOTE_ALL)
  writer.writerow(('#operationplan id','buffer','quantity','date','on hand'))
  for i in frepple.buffers():
    for j in i.flowplans:
      writer.writerow((
       j.operationplan.id, j.buffer.name.encode(encoding,"ignore"),
       j.quantity, j.date, j.onhand
       ))
  print('Exported flowplans in %.2f seconds' % (time() - starttime))
def exportFlowplans(process):
  print("Exporting flowplans...")
  starttime = time()
  process.stdin.write('COPY out_flowplan (operationplan_id, thebuffer, quantity, flowdate, onhand) FROM STDIN;\n')
  for i in frepple.buffers():
    for j in i.flowplans:
      process.stdin.write("%s\t%s\t%s\t%s\t%s\n" % (
         j.operationplan.id, j.buffer.name.encode(encoding),
         round(j.quantity, settings.DECIMAL_PLACES),
         str(j.date), round(j.onhand, settings.DECIMAL_PLACES)
         ))
  process.stdin.write('\\.\n')
  print('Exported flowplans in %.2f seconds' % (time() - starttime))
    def exportOperationPlanMaterials(self):
        if self.verbosity:
            logger.info("Exporting operationplan materials...")
        starttime = time()
        cursor = connections[self.database].cursor()
        currentTime = self.timestamp
        updates = []
        with tempfile.TemporaryFile(mode="w+t", encoding='utf-8') as tmp:
            for i in frepple.buffers():
                if self.cluster != -1 and self.cluster != i.cluster:
                    continue
                for j in i.flowplans:
                    #if the record is confirmed, it is already in the table.
                    if not j.operationplan.id:
                        print(
                            "Warning: skip exporting uninitialized operationplan",
                            j.operationplan.operation.name,
                            j.operationplan.quantity, j.operationplan.start,
                            j.operationplan.end)
                    elif j.status == 'confirmed':
                        updates.append('''
            update operationplanmaterial
            set onhand=%s, flowdate='%s'
            where status = 'confirmed' and item_id = %s
              and location_id = %s and operationplan_id = %s;
            ''' % (round(j.onhand, 8), str(j.date), adapt(j.buffer.item.name),
                        adapt(j.buffer.location.name), j.operationplan.id))
                    else:
                        print(
                            ("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" %
                             (j.operationplan.id, j.buffer.item.name,
                              j.buffer.location.name, round(j.quantity, 8),
                              str(j.date), round(j.onhand, 8),
                              round(j.minimum, 8), round(j.period_of_cover, 8),
                              j.status, currentTime)),
                            file=tmp)

            tmp.seek(0)
            cursor.copy_from(tmp,
                             'operationplanmaterial',
                             columns=('operationplan_id', 'item_id',
                                      'location_id', 'quantity', 'flowdate',
                                      'onhand', 'minimum', 'periodofcover',
                                      'status', 'lastmodified'))
            tmp.close()
        if len(updates) > 0:
            cursor.execute('\n'.join(updates))
        if self.verbosity:
            logger.info('Exported operationplan materials in %.2f seconds' %
                        (time() - starttime))
Exemple #11
0
def exportFlowplans():
  print("Exporting flowplans...")
  starttime = time()
  writer = csv.writer(open("flowplans.csv", "w", newline="", encoding="utf-8"), quoting=csv.QUOTE_ALL)
  writer.writerow((
    '#operationplan id', 'item', 'location', 'quantity', 'date', 'on hand'
    ))
  for i in frepple.buffers():
    for j in i.flowplans:
      writer.writerow((
       j.operationplan.id, j.buffer.item.name, j.buffer.location.name,
       j.quantity, j.date, j.onhand
       ))
  print('Exported flowplans in %.2f seconds' % (time() - starttime))
Exemple #12
0
def exportFlowplans():
  print("Exporting flowplans...")
  starttime = time()
  writer = csv.writer(open("flowplans.csv", "w", newline="", encoding="utf-8"), quoting=csv.QUOTE_ALL)
  writer.writerow((
    '#operationplan', 'item', 'location', 'quantity', 'date', 'on hand'
    ))
  for i in frepple.buffers():
    for j in i.flowplans:
      writer.writerow((
       j.operationplan.reference, j.buffer.item.name, j.buffer.location.name,
       j.quantity, j.date, j.onhand
       ))
  print('Exported flowplans in %.2f seconds' % (time() - starttime))
def exportFlowplans(process):
    print("Exporting flowplans...")
    starttime = time()
    process.stdin.write(
        'COPY out_flowplan (operationplan_id, thebuffer, quantity, flowdate, onhand) FROM STDIN;\n'
        .encode(encoding))
    for i in frepple.buffers():
        for j in i.flowplans:
            process.stdin.write(
                ("%s\t%s\t%s\t%s\t%s\n" %
                 (j.operationplan.id, j.buffer.name, round(j.quantity, 4),
                  str(j.date), round(j.onhand, 4))).encode(encoding))
    process.stdin.write('\\.\n'.encode(encoding))
    print('Exported flowplans in %.2f seconds' % (time() - starttime))
Exemple #14
0
 def exportFlowplans(self, process):
   if self.verbosity:
     print("Exporting flowplans...")
   starttime = time()
   process.stdin.write('COPY out_flowplan (operationplan_id, thebuffer, quantity, flowdate, onhand) FROM STDIN;\n'.encode(self.encoding))
   for i in frepple.buffers():
     if self.cluster != -1 and self.cluster != i.cluster:
       continue
     for j in i.flowplans:
       process.stdin.write(("%s\t%s\t%s\t%s\t%s\n" % (
          j.operationplan.id, j.buffer.name,
          round(j.quantity, 4),
          str(j.date), round(j.onhand, 4)
          )).encode(self.encoding))
   process.stdin.write('\\.\n'.encode(self.encoding))
   if self.verbosity:
     print('Exported flowplans in %.2f seconds' % (time() - starttime))
def exportFlowplans(cursor):
  print("Exporting flowplans...")
  starttime = time()
  cnt = 0
  for i in frepple.buffers():
    cursor.executemany(
      "insert into out_flowplan \
      (operationplan_id, thebuffer, quantity, flowdate, onhand) \
      values (%s,%s,%s,%s,%s)",
      [(
         j.operationplan.id, j.buffer.name,
         round(j.quantity, settings.DECIMAL_PLACES),
         str(j.date), round(j.onhand, settings.DECIMAL_PLACES)
       ) for j in i.flowplans]
      )
    cnt += 1
  cursor.execute("select count(*) from out_flowplan")
  print('Exported %d flowplans in %.2f seconds' % (cursor.fetchone()[0], time() - starttime))
Exemple #16
0
def exportFlowplans(cursor):
  print("Exporting flowplans...")
  starttime = time()
  cnt = 0
  for i in frepple.buffers():
    cursor.executemany(
      "insert into out_flowplan \
      (operationplan_id, thebuffer, quantity, flowdate, onhand) \
      values (%s,%s,%s,%s,%s)",
      [(
         j.operationplan.id, j.buffer.name,
         round(j.quantity, settings.DECIMAL_PLACES),
         str(j.date), round(j.onhand, settings.DECIMAL_PLACES)
       ) for j in i.flowplans]
      )
    cnt += 1
  cursor.execute("select count(*) from out_flowplan")
  print('Exported %d flowplans in %.2f seconds' % (cursor.fetchone()[0], time() - starttime))
Exemple #17
0
 def exportOperationPlanMaterials(self, process):
     if self.verbosity:
         print("Exporting operationplan materials...")
     starttime = time()
     process.stdin.write(
         ('COPY operationplanmaterial '
          '(operationplan_id, buffer, quantity, flowdate, onhand) '
          'FROM STDIN;\n').encode(self.encoding))
     for i in frepple.buffers():
         if self.cluster != -1 and self.cluster != i.cluster:
             continue
         for j in i.flowplans:
             process.stdin.write(
                 ("%s\t%s\t%s\t%s\t%s\n" %
                  (j.operationplan.id, j.buffer.name, round(j.quantity, 4),
                   str(j.date), round(j.onhand, 4))).encode(self.encoding))
     process.stdin.write('\\.\n'.encode(self.encoding))
     if self.verbosity:
         print('Exported operationplan materials in %.2f seconds' %
               (time() - starttime))
Exemple #18
0
def exportFlowplans():
    print("Exporting flowplans...")
    starttime = time()
    writer = csv.writer(open("flowplans.csv",
                             "w",
                             newline="",
                             encoding="utf-8"),
                        quoting=csv.QUOTE_ALL)
    writer.writerow(
        ("#operationplan", "item", "location", "quantity", "date", "on hand"))
    for i in frepple.buffers():
        for j in i.flowplans:
            writer.writerow((
                j.operationplan.reference,
                j.buffer.item.name,
                j.buffer.location.name,
                j.quantity,
                j.date,
                j.onhand,
            ))
    print("Exported flowplans in %.2f seconds" % (time() - starttime))
  def exportOperationPlanMaterials(self):
    if self.verbosity:
      logger.info("Exporting operationplan materials...")
    starttime = time()
    cursor = connections[self.database].cursor()
    currentTime = self.timestamp
    updates = []
    with tempfile.TemporaryFile(mode="w+t", encoding='utf-8') as tmp:
      for i in frepple.buffers():
        if self.cluster != -1 and self.cluster != i.cluster:
          continue
        for j in i.flowplans:
          #if the record is confirmed, it is already in the table.
          if not j.operationplan.reference:
            print(
              "Warning: skip exporting uninitialized operationplan",
              j.operationplan.operation.name, j.operationplan.quantity, j.operationplan.start, j.operationplan.end
              )
          else:
            print(("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (
               j.operationplan.id, j.buffer.item.name, j.buffer.location.name,
               round(j.quantity, 8),
               str(j.date), round(j.onhand, 8), round(j.minimum, 8), round(j.period_of_cover, 8), j.status, currentTime
               )), file=tmp)

      tmp.seek(0)
      cursor.copy_from(
        tmp,
        'operationplanmaterial',
        columns=(
          'operationplan_id', 'item_id', 'location_id', 'quantity', 'flowdate',
          'onhand', 'minimum', 'periodofcover', 'status', 'lastmodified'
          )
        )
      tmp.close()
    if len(updates) > 0:
      cursor.execute('\n'.join(updates))
    if self.verbosity:
      logger.info('Exported operationplan materials in %.2f seconds' % (time() - starttime))
Exemple #20
0
def printModel(filename):
  '''
  A function that prints out all models to a file.
  '''

  # Open the output file
  output = open(filename,"wt")

  # Global settings
  print("Echoing global settings", file=output)
  print("Plan name:", frepple.settings.name, file=output)
  print("Plan description:", frepple.settings.description.encode('utf-8'), file=output)
  print("Plan current:", frepple.settings.current, file=output)

  # Solvers
  print("\nEchoing solvers:", file=output)
  for b in frepple.solvers():
    print("  Solver:", b.name, b.loglevel, getattr(b,'constraints',None), file=output)

  # Calendars
  print("\nEchoing calendars:", file=output)
  for b in frepple.calendars():
    print("  Calendar:", b.name, getattr(b,'default',None), file=output)
    for j in b.buckets:
      print("    Bucket:", getattr(j,'value',None), j.start, j.end, j.priority, file=output)

  # Customers
  print("\nEchoing customers:", file=output)
  for b in frepple.customers():
    print("  Customer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)

  # Locations
  print("\nEchoing locations:", file=output)
  for b in frepple.locations():
    print("  Location:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)

  # Items
  print("\nEchoing items:", file=output)
  for b in frepple.items():
    print("  Item:", b.name, b.description, b.category, b.subcategory, b.owner, b.operation, file=output)

  # Resources
  print("\nEchoing resources:", file=output)
  for b in frepple.resources():
    print("  Resource:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)
    for l in b.loads:
      print("    Load:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.loadplans:
      print("    Loadplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.startdate, l.enddate, file=output)

  # Buffers
  print("\nEchoing buffers:", file=output)
  for b in frepple.buffers():
    print("  Buffer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)
    for l in b.flows:
      print("    Flow:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.flowplans:
      print("    Flowplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.date, file=output)

  # Operations
  print("\nEchoing operations:", file=output)
  for b in frepple.operations():
    print("  Operation:", b.name, b.description, b.category, b.subcategory, file=output)
    for l in b.loads:
      print("    Load:", l.resource.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.flows:
      print("    Flow:", l.buffer.name, l.quantity, l.effective_start, l.effective_end, file=output)
    if isinstance(b, frepple.operation_alternate):
      for l in b.alternates:
        print("    Alternate:", l.name, file=output)
    if isinstance(b, frepple.operation_routing):
      for l in b.steps:
        print("    Step:", l.name, file=output)

  # Demands
  print("\nEchoing demands:", file=output)
  for b in frepple.demands():
    print("  Demand:", b.name, b.due, b.item.name, b.quantity, file=output)
    for i in b.operationplans:
      print("    Operationplan:", i.id, i.operation.name, i.quantity, i.end, file=output)

  # Operationplans
  print("\nEchoing operationplans:", file=output)
  for b in frepple.operationplans():
    print("  Operationplan:", b.operation.name, b.quantity, b.start, b.end, file=output)
    for s in b.operationplans:
      print("       ", s.operation.name, s.quantity, s.start, s.end, file=output)

  # Problems
  print("\nPrinting problems", file=output)
  for i in frepple.problems():
    print("  Problem:", i.entity, i.name, i.description, i.start, i.end, i.weight, file=output)
Exemple #21
0
 def exportBuffers(self, cursor):
   with transaction.atomic(using=self.database, savepoint=False):
     print("Exporting buffers...")
     starttime = time()
     cursor.execute("SELECT name FROM buffer")
     primary_keys = set([ i[0] for i in cursor.fetchall() ])
     cursor.executemany(
       '''insert into buffer
       (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,lastmodified)
       values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)''',
       [
         (
           i.name, i.description, i.location and i.location.name or None,
           i.item and i.item.name or None,
           round(i.onhand, settings.DECIMAL_PLACES), round(i.minimum, settings.DECIMAL_PLACES),
           i.minimum_calendar and i.minimum_calendar.name or None,
           (not isinstance(i, frepple.buffer_procure) and i.producing) and i.producing.name or None,
           i.__class__.__name__[7:],
           isinstance(i, frepple.buffer_procure) and i.leadtime or None,
           isinstance(i, frepple.buffer_procure) and round(i.mininventory, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and round(i.maxinventory, settings.DECIMAL_PLACES) or None,
           i.mininterval,
           i.maxinterval < 99999999999 and i.maxinterval or None,
           isinstance(i, frepple.buffer_procure) and round(i.size_minimum, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and round(i.size_multiple, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and i.size_maximum < 99999999999 and round(i.size_maximum, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and i.fence or None,
           round(i.carrying_cost, settings.DECIMAL_PLACES), i.category, i.subcategory,
           i.source, self.timestamp
         )
         for i in frepple.buffers()
         if i.name not in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       '''update buffer
        set description=%s, location_id=%s, item_id=%s, onhand=%s, minimum=%s, minimum_calendar_id=%s,
        producing_id=%s, type=%s, leadtime=%s, min_inventory=%s, max_inventory=%s, min_interval=%s,
        max_interval=%s, size_minimum=%s, size_multiple=%s, size_maximum=%s, fence=%s,
        carrying_cost=%s, category=%s, subcategory=%s, source=%s, lastmodified=%s
        where name=%s''',
       [
         (
           i.description, i.location and i.location.name or None, i.item and i.item.name or None,
           round(i.onhand, settings.DECIMAL_PLACES), round(i.minimum, settings.DECIMAL_PLACES),
           i.minimum_calendar and i.minimum_calendar.name or None,
           (not isinstance(i, frepple.buffer_procure) and i.producing) and i.producing.name or None,
           i.__class__.__name__[7:],
           isinstance(i, frepple.buffer_procure) and i.leadtime or None,
           isinstance(i, frepple.buffer_procure) and round(i.mininventory, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and round(i.maxinventory, settings.DECIMAL_PLACES) or None,
           (i.mininterval!=-1) and i.mininterval or None,
           i.maxinterval < 99999999999 and i.maxinterval or None,
           isinstance(i, frepple.buffer_procure) and round(i.size_minimum, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and round(i.size_multiple, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and i.size_maximum < 99999999999 and round(i.size_maximum, settings.DECIMAL_PLACES) or None,
           isinstance(i, frepple.buffer_procure) and i.fence or None,
           round(i.carrying_cost, settings.DECIMAL_PLACES), i.category, i.subcategory,
           i.source, self.timestamp, i.name
         )
         for i in frepple.buffers()
         if i.name in primary_keys and not i.hidden and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update buffer set owner_id=%s where name=%s",
       [
         (i.owner.name, i.name)
         for i in frepple.buffers()
         if i.owner and not i.hidden
       ])
     print('Exported buffers in %.2f seconds' % (time() - starttime))
Exemple #22
0
    def exportOperationPlanMaterials(self):
        if self.verbosity:
            logger.info("Exporting operationplan materials...")
        starttime = time()
        cursor = connections[self.database].cursor()
        currentTime = self.timestamp
        updates = []
        with tempfile.TemporaryFile(mode="w+t", encoding="utf-8") as tmp:
            for i in frepple.buffers():
                if self.cluster != -1 and self.cluster != i.cluster:
                    continue
                for j in i.flowplans:
                    # if the record is confirmed, it is already in the table.
                    if not j.operationplan.reference:
                        print(
                            "Warning: skip exporting uninitialized operationplan",
                            j.operationplan.operation.name,
                            j.operationplan.quantity,
                            j.operationplan.start,
                            j.operationplan.end,
                        )
                    else:
                        print(
                            (
                                "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s"
                                % (
                                    j.operationplan.id,
                                    j.buffer.item.name,
                                    j.buffer.location.name,
                                    round(j.quantity, 8),
                                    str(j.date),
                                    round(j.onhand, 8),
                                    round(j.minimum, 8),
                                    round(j.period_of_cover, 8),
                                    j.status,
                                    currentTime,
                                )
                            ),
                            file=tmp,
                        )

            tmp.seek(0)
            cursor.copy_from(
                tmp,
                "operationplanmaterial",
                columns=(
                    "operationplan_id",
                    "item_id",
                    "location_id",
                    "quantity",
                    "flowdate",
                    "onhand",
                    "minimum",
                    "periodofcover",
                    "status",
                    "lastmodified",
                ),
            )
            tmp.close()
        if len(updates) > 0:
            cursor.execute("\n".join(updates))
        if self.verbosity:
            logger.info(
                "Exported operationplan materials in %.2f seconds"
                % (time() - starttime)
            )
Exemple #23
0
def printModel(filename):
    '''
  A function that prints out all models to a file.
  '''
    # Open the output file
    with open(filename, "wt", encoding='utf-8') as output:

        # Global settings
        print("Echoing global settings", file=output)
        print("Plan name:", frepple.settings.name, file=output)
        print("Plan description:", frepple.settings.description, file=output)
        print("Plan current:", frepple.settings.current, file=output)

        # Solvers
        print("\nEchoing solvers:", file=output)
        for b in frepple.solvers():
            print("  Solver:",
                  b.name,
                  b.loglevel,
                  getattr(b, 'constraints', None),
                  file=output)

        # Calendars
        print("\nEchoing calendars:", file=output)
        for b in frepple.calendars():
            print("  Calendar:",
                  b.name,
                  getattr(b, 'default', None),
                  file=output)
            for j in b.buckets:
                print("    Bucket:",
                      getattr(j, 'value', None),
                      j.start,
                      j.end,
                      j.priority,
                      file=output)

        # Customers
        print("\nEchoing customers:", file=output)
        for b in frepple.customers():
            print("  Customer:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)

        # Locations
        print("\nEchoing locations:", file=output)
        for b in frepple.locations():
            print("  Location:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)

        # Items
        print("\nEchoing items:", file=output)
        for b in frepple.items():
            print("  Item:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  b.operation,
                  file=output)

        # Resources
        print("\nEchoing resources:", file=output)
        for b in frepple.resources():
            print("  Resource:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)
            for l in b.loads:
                print("    Load:",
                      l.operation.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.loadplans:
                print("    Loadplan:",
                      l.operationplan.id,
                      l.operationplan.operation.name,
                      l.quantity,
                      l.startdate,
                      l.enddate,
                      file=output)

        # Buffers
        print("\nEchoing buffers:", file=output)
        for b in frepple.buffers():
            print("  Buffer:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)
            for l in b.flows:
                print("    Flow:",
                      l.operation.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.flowplans:
                print("    Flowplan:",
                      l.operationplan.id,
                      l.operationplan.operation.name,
                      l.quantity,
                      l.date,
                      file=output)

        # Operations
        print("\nEchoing operations:", file=output)
        for b in frepple.operations():
            print("  Operation:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  file=output)
            for l in b.loads:
                print("    Load:",
                      l.resource.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.flows:
                print("    Flow:",
                      l.buffer.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            if isinstance(b, frepple.operation_alternate):
                for l in b.alternates:
                    print("    Alternate:",
                          l[0].name,
                          l[1],
                          l[2],
                          l[3],
                          file=output)
            if isinstance(b, frepple.operation_routing):
                for l in b.steps:
                    print("    Step:", l.name, file=output)

        # Demands
        print("\nEchoing demands:", file=output)
        for b in frepple.demands():
            print("  Demand:",
                  b.name,
                  b.due,
                  b.item.name,
                  b.quantity,
                  file=output)
            for i in b.operationplans:
                print("    Operationplan:",
                      i.id,
                      i.operation.name,
                      i.quantity,
                      i.end,
                      file=output)

        # Operationplans
        print("\nEchoing operationplans:", file=output)
        for b in frepple.operationplans():
            print("  Operationplan:",
                  b.operation.name,
                  b.quantity,
                  b.start,
                  b.end,
                  file=output)
            for s in b.operationplans:
                print("       ",
                      s.operation.name,
                      s.quantity,
                      s.start,
                      s.end,
                      file=output)

        # Problems
        print("\nPrinting problems", file=output)
        for i in frepple.problems():
            print("  Problem:",
                  i.entity,
                  i.name,
                  i.description,
                  i.start,
                  i.end,
                  i.weight,
                  file=output)