Provides table of scheduling block instance metadata for use with AJAX
    tables
438381
def get_table():
    """"""
    response = dict(blocks=[])
    block_ids = DB.get_sched_block_instance_ids()
    for index, block_id in enumerate(block_ids):
        block = DB.get_block_details([block_id]).__next__()
        info = [
            index,
            block['id'],
            block['sub_array_id'],
            len(block['processing_blocks'])
        ]
        response['blocks'].append(info)
    return response, HTTPStatus.OK
282947
def json_for_query(calendar_ids, start_time, end_time)
      {}.tap{ |obj|
        obj[:items] = calendar_ids.map {|id| Hash[:id, id] }
        obj[:timeMin] = start_time.utc.iso8601
        obj[:timeMax] = end_time.utc.iso8601
      }.to_json
    end
853242
def get_scheduler_info():
    """"""

    scheduler = current_app.apscheduler

    d = OrderedDict([
        ('current_host', scheduler.host_name),
        ('allowed_hosts', scheduler.allowed_hosts),
        ('running', scheduler.running)
    ])

    return jsonify(d)
489685
def prepare_schedule(schedule):
    
    ret = {}
    for room in schedule:
        ret[room] = []
        for event in schedule[room]:
            ret[room].append(((event[0].hour,
                                event[0].minute),
                             (event[1].hour,
                              event[1].minute),
                             event[2]))
    return ret
888811
def processing_blocks(self):
        
        sbi_ids = Subarray(self.get_name()).sbi_ids
        pbs = []
        for sbi_id in sbi_ids:
            sbi = SchedulingBlockInstance(sbi_id)
            pbs.append(sbi.processing_block_ids)
        return 'PB', pbs
734911
def table_metadata(self, database, table):
        ""
        return (self.metadata("databases") or {}).get(database, {}).get(
            "tables", {}
        ).get(
            table, {}
        )
550894
def tabulate(collection, headers, datetime_fmt='%Y-%m-%d %H:%M:%S', **kwargs):
    """"""
    if isinstance(headers, dict):
        attrs = headers.keys()
        # if mapping is not specified keep original
        names = [
            key if value is None else value for key, value in headers.items()
        ]
    else:
        attrs = names = headers
    table = [(
        format_cell(cell, datetime_fmt=datetime_fmt)
        for cell in attrgetter(*attrs)(c)
    ) for c in collection]
    return tblte(table, headers=[h.upper() for h in names], **kwargs)
82543
def get():
    """"""

    LOG.debug('GET Processing Block list')
    _url = get_root_url()

    # Get list of Processing block Ids
    block_ids = sorted(DB.get_processing_block_ids())
    LOG.debug('Processing Block IDs: %s', block_ids)

    # Construct response object
    response = dict(num_processing_blocks=len(block_ids),
                    processing_blocks=list())

    # Loop over blocks and add block summary to response.
    for block in DB.get_block_details(block_ids):
        block_id = block['id']
        LOG.debug('Creating PB summary for %s', block_id)
        block['links'] = dict(
            detail='{}/processing-block/{}'.format(_url, block_id),
            scheduling_block='{}/scheduling-block/{}'
            .format(_url, block_id.split(':')[0])
        )
        response['processing_blocks'].append(block)
    response['links'] = {
        'self': '{}'.format(request.url),
        'home': '{}'.format(_url)
    }
    return response, HTTPStatus.OK
522799
function updateSchedule (scheduleId, name, enabled, callback) {
  if (typeof scheduleId !== 'string') {
    throw new JError.InvalidArgumentError('Schedule ID must be set to string.')
  }
  var body = {}
  if (name != null) {
    if (typeof name !== 'string') {
      throw new JError.InvalidArgumentError('name must be set to string.')
    }
    body = JUtil.extend(body, {
      'name': name
    })
  }
  if (enabled != null) {
    if (typeof enabled !== 'boolean') {
      throw new JError.InvalidArgumentError('enabled must be set to boolean.')
    }
    body = JUtil.extend(body, {
      'enabled': enabled
    })
  }
  if (!JUtil.isEmptyObject(this.trigger)) {
    body = JUtil.extend(body, {
      'trigger': this.trigger
    })
  }
  if (!JUtil.isEmptyObject(this.payload)) {
    validate(this.payload)
    this.payload.options = JUtil.extend({
      'sendno': generateSendno(),
      'apns_production': false
    },
      this.payload.options)
    body = JUtil.extend(body, {
      'push': this.payload
    })
  }
  return this.client.updateSchedule(scheduleId, JSON.stringify(body), callback)
}
501584
def table(table_name, options={}, &block)
      table = Mongify::Database::Table.new(table_name, options, &block)
      add_table(table)
    end
16873
def _scheduling_block_config(num_blocks=5, start_sbi_id=0, start_pb_id=0,
                             project='sip'):
    """"""
    pb_id = start_pb_id
    for sb_id, sbi_id in _scheduling_block_ids(num_blocks, start_sbi_id,
                                               project):
        sub_array_id = 'subarray-{:02d}'.format(random.choice(range(5)))
        config = dict(id=sbi_id,
                      sched_block_id=sb_id,
                      sub_array_id=sub_array_id,
                      processing_blocks=_generate_processing_blocks(pb_id))
        pb_id += len(config['processing_blocks'])
        yield config
1252258
function ResultSet(metadata, rows) {
  this.rows = [];
  this.metadata = metadata;
  for (var i = 0; i < rows.length; i++) {
    this.rows.push(new Row(metadata.columnSpecs, rows[i]));
  }
}
321741
def delete_scheduling_block(block_id):
    """"""
    DB.delete('scheduling_block/{}'.format(block_id))

    # Add a event to the scheduling block event list to notify
    # of a deleting a scheduling block from the db
    DB.rpush('scheduling_block_events',
             json.dumps(dict(type="deleted", id=block_id)))
248065
def add_sched_block_instance(self, config_dict):
        
        # Get schema for validation
        schema = self._get_schema()
        LOG.debug('Adding SBI with config: %s', config_dict)

        # Validates the schema
        validate(config_dict, schema)

        # Add status field and value to the data
        updated_block = self._add_status(config_dict)

        # Splitting into different names and fields before
        # adding to the database
        scheduling_block_data, processing_block_data = \
            self._split_sched_block_instance(updated_block)

        # Adding Scheduling block instance with id
        name = "scheduling_block:" + updated_block["id"]
        self._db.set_specified_values(name, scheduling_block_data)

        # Add a event to the scheduling block event list to notify
        # of a new scheduling block being added to the db.
        self._db.push_event(self.scheduling_event_name,
                            updated_block["status"],
                            updated_block["id"])

        # Adding Processing block with id
        for value in processing_block_data:
            name = ("scheduling_block:" + updated_block["id"] +
                    ":processing_block:" + value['id'])
            self._db.set_specified_values(name, value)

            # Add a event to the processing block event list to notify
            # of a new processing block being added to the db.
            self._db.push_event(self.processing_event_name,
                                value["status"],
                                value["id"])
1176902
def resource_row_set(package, resource):
    
    # This is a work-around because messytables hangs on boto file
    # handles, so we're doing it via plain old HTTP.
    table_set = any_tableset(resource.fh(),
                             extension=resource.meta.get('extension'),
                             mimetype=resource.meta.get('mime_type'))
    tables = list(table_set.tables)
    if not len(tables):
        log.error("No tables were found in the source file.")
        return

    row_set = tables[0]
    offset, headers = headers_guess(row_set.sample)
    row_set.register_processor(headers_processor(headers))
    row_set.register_processor(offset_processor(offset + 1))
    types = type_guess(row_set.sample, strict=True)
    row_set.register_processor(types_processor(types))
    return row_set
519794
def get(self, request):
        """"""
        # Heavily inspired by https://djangosnippets.org/snippets/2223/ and
        # the icalendar documentation
        calendar = Calendar()
        site = get_current_site(request)
        calendar.add('prodid', '-//%s Schedule//%s//' % (site.name, site.domain))
        calendar.add('version', '2.0')

        # Since we don't need to format anything here, we can just use a list
        # of schedule items
        for item in ScheduleItem.objects.all():
            sched_event = Event()
            sched_event.add('dtstamp', item.last_updated)
            sched_event.add('summary', item.get_title())
            sched_event.add('location', item.venue.name)
            sched_event.add('dtstart', item.get_start_datetime())
            sched_event.add('duration', datetime.timedelta(minutes=item.get_duration_minutes()))
            sched_event.add('class', 'PUBLIC')
            sched_event.add('uid', '%s@%s' % (item.pk, site.domain))
            calendar.add_component(sched_event)
        response = HttpResponse(calendar.to_ical(), content_type="text/calendar")
        response['Content-Disposition'] = 'attachment; filename=schedule.ics'
        return response
34279
def get_tables_for_bind(self, bind=None):
        """"""
        result = []
        tables = Model.metadata.tables
        for key in tables:
            if tables[key].info.get("bind_key") == bind:
                result.append(tables[key])
        return result