text:
require 'sensu-plugins-postgres/pgpass'
require 'sensu-plugin/metric/cli'
require 'pg'
require 'socket'

class PostgresVacuumDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
  option :pgpass,
         description: 'Pgpass file',
         short: '-f FILE',
         long: '--pgpass',
         default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"

  option :user,
         description: 'Postgres User',
         short: '-u USER',
         long: '--user USER'

  option :password,
         description: 'Postgres Password',
         short: '-p PASS',
         long: '--password PASS'

  option :hostname,
         description: 'Hostname to login to',
         short: '-h HOST',
         long: '--hostname HOST'

  option :port,
         description: 'Database port',
         short: '-P PORT',
         long: '--port PORT'

  option :database,
         description: 'Database to connect on',
         short: '-d DB',
         long: '--db DB',
         default: 'postgres'

  option :all_databases,
         description: 'Get stats for all available databases',
         short: '-a',
         long: '--all-databases',
         boolean: true,
         default: false

  option :scheme,
         description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
         long: '--scheme SCHEME',
         default: "#{Socket.gethostname}.postgresql"

  option :timeout,
         description: 'Connection timeout (seconds)',
         short: '-T TIMEOUT',
         long: '--timeout TIMEOUT',
         default: nil

  include Pgpass

  def phase_mapping(vacuum_phase)
    ['initializing',
     'scanning heap',
     'vacuuming indexes',
     'vacuuming heap',
     'cleaning up indexes',
     'truncating heap',
     'performing final cleanup'].find_index(vacuum_phase)
  end

  def run
    timestamp = Time.now.to_i
    pgpass
    con = PG.connect(host: config[:hostname],
                     dbname: config[:database],
                     user: config[:user],
                     password: config[:password],
                     port: config[:port],
                     connect_timeout: config[:timeout])

    query = 'SELECT * FROM pg_stat_progress_vacuum'
    params = []
    unless config[:all_databases]
      query += ' WHERE datname = $1'
      params.push config[:database]
    end

    con.exec_params(query, params) do |result|
      result.each do |row|
        database = row['datname']

        row.each do |key, value|
          next if %w[datid datname].include?(key)

          if key == 'phase'
            output "#{config[:scheme]}.vacuum.#{database}.phase", phase_mapping(value).to_s, timestamp
          else
            output "#{config[:scheme]}.vacuum.#{database}.#{key}", value.to_s, timestamp
          end
        end
      end
    end

    ok
  end
end

redpajama_set_name: RedPajamaGithub


text:
set(SRC_CPP_FILES
  berryAbstractSourceProvider.cpp
  berryAbstractUICTKPlugin.cpp
  berryConstants.cpp
  berryDisplay.cpp
  berryEditorPart.cpp
  berryExtensionFactory.cpp
  berryFileEditorInput.cpp
  berryGeometry.cpp

  berryIActionBars.h
  berryIContextService.cpp
  berryIContributionRoot.h
  berryIDropTargetListener.cpp
  berryIEditorDescriptor.cpp
  berryIEditorInput.cpp
  berryIEditorMatchingStrategy.cpp
  berryIEditorPart.cpp
  berryIEditorReference.cpp
  berryIEditorRegistry.cpp
  berryIEditorSite.cpp
  berryIElementFactory.cpp
  berryIFileEditorMapping.cpp
  berryIFolderLayout.cpp
  berryIMemento.cpp
  berryINullSelectionListener.cpp
  berryIPageLayout.cpp
  berryIPartListener.cpp
  berryIPageService.cpp
  berryIPartService.cpp
  berryIPathEditorInput.cpp
  berryIPersistable.cpp
  berryIPersistableElement.h
  berryIPerspectiveDescriptor.cpp
  berryIPerspectiveFactory.cpp
  berryIPerspectiveListener.cpp
  berryIPerspectiveRegistry.cpp
  berryIPlaceholderFolderLayout.cpp
  berryIPluginContribution.h
  berryIPostSelectionProvider.cpp
  berryIPreferencePage.cpp
  berryIPropertyChangeListener.cpp
  berryIQtPreferencePage.cpp
  berryIQtStyleManager.cpp
  berryIReusableEditor.cpp
  berryISaveablePart.cpp
  berryISaveablesLifecycleListener.cpp
  berryISaveablesSource.cpp
  berryISelection.cpp
  berryISelectionChangedListener.cpp
  berryISelectionListener.cpp
  berryISelectionProvider.cpp
  berryISelectionService.cpp
  berryIShellListener.cpp
  berryIShellProvider.cpp
  berryIShowInSource.h
  berryIShowInTarget.h
  berryISizeProvider.cpp
  berryISourceProvider.cpp
  berryISourceProviderListener.cpp
  berryISources.cpp
  berryIStickyViewDescriptor.cpp
  berryIStructuredSelection.cpp
  berryIViewCategory.cpp
  berryIViewDescriptor.cpp
  berryIViewLayout.cpp
  berryIViewPart.cpp
  berryIViewReference.cpp
  berryIViewRegistry.cpp
  berryIViewSite.cpp
  berryIWorkbenchCommandConstants.cpp
  berryIWindowListener.cpp
  berryIWorkbench.cpp
  berryIWorkbenchListener.cpp
  berryIWorkbenchPage.cpp
  berryIWorkbenchPart.cpp
  berryIWorkbenchPartConstants.cpp
  berryIWorkbenchPartDescriptor.cpp
  berryIWorkbenchPartReference.cpp
  berryIWorkbenchPartSite.cpp
  berryIWorkbenchSite.cpp
  berryIWorkbenchWindow.cpp
  berryMenuUtil.cpp
  berryPlatformUI.cpp
  berryPropertyChangeEvent.cpp
  berryQModelIndexObject.cpp
  berryQtEditorPart.cpp
  berryQtItemSelection.cpp
  berryQtIntroPart.cpp
  berryQtPreferences.cpp
  berryQtSelectionProvider.cpp
  berryQtViewPart.cpp
  berrySameShellProvider.cpp
  berrySaveable.cpp
  berrySaveablesLifecycleEvent.cpp
  berrySelectionChangedEvent.cpp
  berryShell.cpp
  berryShellEvent.cpp
  berryShowInContext.cpp
  berryUIException.cpp
  berryViewPart.cpp
  berryWindow.cpp
  berryWorkbenchActionConstants.cpp
  berryWorkbenchPart.cpp
  berryWorkbenchPreferenceConstants.cpp
  berryXMLMemento.cpp

  #actions
  actions/berryAbstractContributionFactory.cpp
  actions/berryCommandContributionItem.cpp
  actions/berryCommandContributionItemParameter.cpp
  actions/berryContributionItem.cpp
  actions/berryContributionItemFactory.cpp
  actions/berryContributionManager.cpp
  actions/berryGroupMarker.cpp
  actions/berryIContributionItem.h
  actions/berryIContributionManager.h
  actions/berryIContributionManagerOverrides.cpp
  actions/berryIMenuManager.h
  #actions/berryMenuBarManager.cpp
  actions/berryMenuManager.cpp
  actions/berryQActionContributionItem.cpp
  actions/berryQActionProperties.cpp
  actions/berrySeparator.cpp
  actions/berrySubContributionItem.cpp

  #application
  application/berryActionBarAdvisor.cpp
  application/berryIActionBarConfigurer.cpp
  application/berryIWorkbenchConfigurer.cpp
  application/berryIWorkbenchWindowConfigurer.cpp
  application/berryWorkbenchAdvisor.cpp
  application/berryWorkbenchWindowAdvisor.cpp

  #commands
  commands/berryICommandImageService.cpp
  commands/berryICommandService.cpp
  commands/berryIElementReference.h
  commands/berryIElementUpdater.h
  commands/berryIMenuService.h
  commands/berryUIElement.cpp

  #guitk
  guitk/berryGuiTkControlEvent.cpp
  guitk/berryGuiTkEvent.cpp
  guitk/berryGuiTkIControlListener.cpp
  guitk/berryGuiTkISelectionListener.cpp
  guitk/berryGuiTkSelectionEvent.cpp

  #handlers
  handlers/berryHandlerUtil.cpp
  handlers/berryIHandlerActivation.cpp
  handlers/berryIHandlerService.cpp
  handlers/berryRadioState.cpp
  handlers/berryRegistryToggleState.cpp
  handlers/berryToggleState.cpp

  #intro
  intro/berryIIntroManager.cpp
  intro/berryIIntroPart.cpp
  intro/berryIIntroSite.cpp
  intro/berryIntroPart.cpp

  #models
  model/berryPerspectiveListModel.cpp
  model/berryViewTreeModel.cpp

  #tweaklets
  tweaklets/berryGuiWidgetsTweaklet.cpp
  tweaklets/berryWorkbenchPageTweaklet.cpp
  tweaklets/berryWorkbenchTweaklet.cpp

  #presentations
  presentations/berryIPresentablePart.cpp
  presentations/berryIPresentationFactory.cpp
  presentations/berryIPresentationSerializer.cpp
  presentations/berryIStackPresentationSite.cpp
  presentations/berryStackDropResult.cpp
  presentations/berryStackPresentation.cpp

  #services
  services/berryIDisposable.cpp
  services/berryIEvaluationReference.h
  services/berryIEvaluationService.cpp
  services/berryINestable.cpp
  services/berryIServiceFactory.cpp
  services/berryIServiceLocator.cpp
  services/berryIServiceScopes.cpp
  services/berryIServiceWithSources.cpp
  services/berryISourceProviderService.cpp

  #testing
  testing/berryTestableObject.cpp

  #util
  util/berryISafeRunnableRunner.cpp
  util/berrySafeRunnable.cpp

  # application
  application/berryQtWorkbenchAdvisor.cpp
)

set(INTERNAL_CPP_FILES

  defaultpresentation/berryEmptyTabFolder.cpp
  defaultpresentation/berryEmptyTabItem.cpp
  defaultpresentation/berryNativeTabFolder.cpp
  defaultpresentation/berryNativeTabItem.cpp
  defaultpresentation/berryQCTabBar.cpp
  defaultpresentation/berryQtWorkbenchPresentationFactory.cpp

  dialogs/berryPerspectivesPreferencePage.cpp
  dialogs/berrySavePerspectiveDialog.cpp

  handlers/berryCloseAllPerspectivesHandler.cpp
  handlers/berryClosePerspectiveHandler.cpp
  handlers/berryDynamicHelpHandler.cpp
  handlers/berryHelpContentsHandler.cpp
  handlers/berryIntroHandler.cpp
  handlers/berryNewEditorHandler.cpp
  handlers/berryOpenInNewWindowHandler.cpp
  handlers/berryQuitHandler.cpp
  handlers/berryResetPerspectiveHandler.cpp
  handlers/berrySavePerspectiveHandler.cpp
  handlers/berryShowPerspectiveHandler.cpp
  handlers/berryShowViewHandler.cpp

  util/berryAbstractTabFolder.cpp
  util/berryAbstractTabItem.cpp
  util/berryIPresentablePartList.cpp
  util/berryLeftToRightTabOrder.cpp
  util/berryPartInfo.cpp
  util/berryPresentablePartFolder.cpp
  util/berryReplaceDragHandler.cpp
  util/berryTabbedStackPresentation.cpp
  util/berryTabDragHandler.cpp
  util/berryTabFolderEvent.cpp
  util/berryTabOrder.cpp

  #intro
  intro/berryEditorIntroAdapterPart.cpp
  intro/berryIIntroDescriptor.cpp
  intro/berryIIntroRegistry.cpp
  intro/berryIntroConstants.cpp
  intro/berryIntroDescriptor.cpp
  intro/berryIntroPartAdapterSite.cpp
  intro/berryIntroRegistry.cpp
  intro/berryViewIntroAdapterPart.cpp
  intro/berryWorkbenchIntroManager.cpp

  berryAbstractGroupMarker.cpp
  berryAbstractMenuAdditionCacheEntry.cpp
  berryAbstractPartSelectionTracker.cpp
  berryAbstractSelectionService.cpp
  berryActivePartExpression.cpp
  berryAlwaysEnabledExpression.cpp
  berryAndExpression.cpp
  berryBundleUtility.cpp
  berryChangeToPerspectiveMenu.cpp
  berryCommandParameter.cpp
  berryCommandPersistence.cpp
  berryCommandService.cpp
  berryCommandServiceFactory.cpp
  berryCommandStateProxy.cpp
  berryCompositeExpression.cpp
  berryContainerPlaceholder.cpp
  berryContributionRoot.cpp
  berryDetachedPlaceHolder.cpp
  berryDefaultSaveable.cpp
  berryDefaultStackPresentationSite.cpp
  berryDetachedWindow.cpp
  berryDirtyPerspectiveMarker.cpp
  berryDragUtil.cpp
  berryEditorAreaHelper.cpp
  berryEditorDescriptor.cpp
  berryEditorHistory.cpp
  berryEditorHistoryItem.cpp
  berryEditorManager.cpp
  berryEditorReference.cpp
  berryEditorRegistry.cpp
  berryEditorRegistryReader.cpp
  berryEditorSashContainer.cpp
  berryEditorSite.cpp
  berryElementReference.cpp
  berryErrorViewPart.cpp
  berryEvaluationAuthority.cpp
  berryEvaluationReference.cpp
  berryEvaluationResultCache.cpp
  berryEvaluationService.cpp
  berryExpressionAuthority.cpp
  berryFileEditorMapping.cpp
  berryFolderLayout.cpp
  berryHandlerActivation.cpp
  berryHandlerAuthority.cpp
  berryHandlerPersistence.cpp
  berryHandlerProxy.cpp
  berryHandlerService.cpp
  berryHandlerServiceFactory.cpp
  berryIDragOverListener.cpp
  berryIDropTarget.cpp
  berryIEvaluationResultCache.cpp
  berryILayoutContainer.cpp
  berryInternalMenuService.h
  berryIServiceLocatorCreator.cpp
  berryIStickyViewManager.cpp
  berryIWorkbenchLocationService.cpp
  berryKeywordRegistry.cpp
  berryLayoutHelper.cpp
  berryLayoutPart.cpp
  berryLayoutPartSash.cpp
  berryLayoutTree.cpp
  berryLayoutTreeNode.cpp
  berryMenuServiceFactory.cpp
  berryNestableHandlerService.cpp
  berryNullEditorInput.cpp
  berryOpenPerspectivePropertyTester.cpp
  berryPageLayout.cpp
  berryPagePartSelectionTracker.cpp
  berryPageSelectionService.cpp
  berryParameterValueConverterProxy.cpp
  berryPartList.cpp
  berryPartPane.cpp
  berryPartPlaceholder.cpp
  berryPartSashContainer.cpp
  berryPartService.cpp
  berryPartSite.cpp
  berryPartStack.cpp
  berryPartTester.cpp
  berryPersistentState.cpp
  berryPerspective.cpp
  berryPerspectiveDescriptor.cpp
  berryPerspectiveExtensionReader.cpp
  berryPerspectiveHelper.cpp
  berryPerspectiveParameterValues.cpp
  berryPerspectiveRegistry.cpp
  berryPerspectiveRegistryReader.cpp
  berryPlaceholderFolderLayout.cpp
  berryPolicy.cpp
  berryPreferenceConstants.cpp
  berryPreferencePageParameterValues.cpp
  berryPresentablePart.cpp
  berryPresentationFactoryUtil.cpp
  berryPresentationSerializer.cpp
  berryQtControlWidget.cpp
  berryQtDnDControlWidget.cpp
  berryQtDisplay.cpp
  berryQtGlobalEventFilter.cpp
  berryQtMainWindowControl.cpp
  berryQtOpenPerspectiveAction.cpp
  berryQtPerspectiveSwitcher.cpp
  berryQtSash.cpp
  berryQtShell.cpp
  berryQtShowPerspectiveDialog.cpp
  berryQtShowViewAction.cpp
  berryQtShowViewDialog.cpp
  berryQtStyleManager.cpp
  berryQtStylePreferencePage.cpp
  berryQtTracker.cpp
  berryQtWidgetController.cpp
  berryQtWidgetsTweaklet.cpp
  berryQtWidgetsTweakletImpl.cpp
  berryQtWorkbenchPageTweaklet.cpp
  berryQtWorkbenchTweaklet.cpp
  berryRegistryPersistence.cpp
  berryRegistryReader.cpp
  berryReopenEditorMenu.cpp
  berrySaveablesList.cpp
  berryShowViewMenu.cpp
  berryServiceLocator.cpp
  berryServiceLocatorCreator.cpp
  berryShellPool.cpp
  berrySlaveCommandService.cpp
  berrySlaveHandlerService.cpp
  berrySlaveMenuService.cpp
  berrySourceProviderService.cpp
  berrySourcePriorityNameMapping.cpp
  berryStatusUtil.cpp
  berryStickyViewDescriptor.cpp
  berryStickyViewManager.cpp
  berrySwitchToWindowMenu.cpp
  berryTweaklets.cpp
  berryUIExtensionTracker.cpp
  berryUtil.cpp
  berryViewDescriptor.cpp
  berryViewFactory.cpp
  berryViewLayout.cpp
  berryViewReference.cpp
  berryViewRegistry.cpp
  berryViewRegistryReader.cpp
  berryViewSashContainer.cpp
  berryViewSite.cpp
  berryWorkbenchPage.cpp
  berryWindowManager.cpp
  berryWindowPartSelectionTracker.cpp
  berryWindowSelectionService.cpp
  berryWorkbench.cpp
  berryWorkbenchConfigurer.cpp
  berryWorkbenchConstants.cpp
  berryWorkbenchLocationService.cpp
  berryWorkbenchMenuService.cpp
  berryWorkbenchPagePartList.cpp
  berryWorkbenchPartReference.cpp
  berryWorkbenchPlugin.cpp
  berryWorkbenchRegistryConstants.cpp
  berryWorkbenchServiceRegistry.cpp
  berryWorkbenchSourceProvider.cpp
  berryWorkbenchTestable.cpp
  berryWorkbenchWindow.cpp
  berryWorkbenchWindowConfigurer.cpp
  berryWorkbenchWindowExpression.cpp
  berryWWinActionBars.cpp
  berryWWinPartService.cpp

)

set(MOC_H_FILES

  src/berryAbstractUICTKPlugin.h
  src/berryEditorPart.h
  src/berryExtensionFactory.h
  src/berryQtSelectionProvider.h
  src/berryViewPart.h
  src/berryWorkbenchPart.h

  src/actions/berryCommandContributionItem.h
  src/actions/berryMenuManager.h

  src/intro/berryIntroPart.h

  src/model/berryPerspectiveListModel.h
  src/model/berryViewTreeModel.h

  src/internal/berryChangeToPerspectiveMenu.h
  src/internal/berryCommandServiceFactory.h
  src/internal/berryHandlerServiceFactory.h
  src/internal/berryMenuServiceFactory.h
  src/internal/berryOpenPerspectivePropertyTester.h
  src/internal/berryPerspectiveParameterValues.h
  src/internal/berryPreferencePageParameterValues.h
  src/internal/berryQtDisplay.h
  src/internal/berryQtGlobalEventFilter.h
  src/internal/berryQtMainWindowControl.h
  src/internal/berryQtOpenPerspectiveAction.h
  src/internal/berryQtPerspectiveSwitcher.h
  src/internal/berryQtSash.h
  src/internal/berryQtShowPerspectiveDialog.h
  src/internal/berryQtShowViewAction.h
  src/internal/berryQtShowViewDialog.h
  src/internal/berryQtStyleManager.h
  src/internal/berryQtStylePreferencePage.h
  src/internal/berryQtTracker.h
  src/internal/berryQtWidgetsTweaklet.h
  src/internal/berryQtWidgetsTweakletImpl.h
  src/internal/berryQtWorkbenchTweaklet.h
  src/internal/berryQtWorkbenchPageTweaklet.h
  src/internal/berryReopenEditorMenu.h
  src/internal/berryShowViewMenu.h
  src/internal/berrySwitchToWindowMenu.h
  src/internal/berryWorkbenchPlugin.h
  src/internal/berryWorkbenchSourceProvider.h

  src/internal/defaultpresentation/berryNativeTabFolder.h
  src/internal/defaultpresentation/berryNativeTabItem.h
  src/internal/defaultpresentation/berryQCTabBar.h
  src/internal/defaultpresentation/berryQtWorkbenchPresentationFactory.h

  src/internal/dialogs/berryPerspectivesPreferencePage.h
  src/internal/dialogs/berrySavePerspectiveDialog.h

  src/internal/handlers/berryCloseAllPerspectivesHandler.h
  src/internal/handlers/berryClosePerspectiveHandler.h
  src/internal/handlers/berryDynamicHelpHandler.h
  src/internal/handlers/berryHelpContentsHandler.h
  src/internal/handlers/berryIntroHandler.h
  src/internal/handlers/berryNewEditorHandler.h
  src/internal/handlers/berryOpenInNewWindowHandler.h
  src/internal/handlers/berryQuitHandler.h
  src/internal/handlers/berryResetPerspectiveHandler.h
  src/internal/handlers/berrySavePerspectiveHandler.h
  src/internal/handlers/berryShowPerspectiveHandler.h
  src/internal/handlers/berryShowViewHandler.h

  src/internal/intro/berryEditorIntroAdapterPart.h
)

set(UI_FILES
  src/internal/berryQtShowPerspectiveDialog.ui
  src/internal/berryQtShowViewDialog.ui
  src/internal/berryQtStylePreferencePage.ui
  src/internal/berryQtStatusPart.ui

  src/internal/dialogs/berryPerspectivesPreferencePage.ui
  src/internal/dialogs/berrySavePerspectiveDialog.ui
)

set(QRC_FILES
  resources/org_blueberry_ui_qt.qrc
)

set(CACHED_RESOURCE_FILES
  plugin.xml
)

set(CPP_FILES )

foreach(file ${SRC_CPP_FILES})
  set(CPP_FILES ${CPP_FILES} src/${file})
endforeach(file ${SRC_CPP_FILES})

foreach(file ${INTERNAL_CPP_FILES})
  set(CPP_FILES ${CPP_FILES} src/internal/${file})
endforeach(file ${INTERNAL_CPP_FILES})


text:
nogen: true

====

# Observable

### riot.observable(el)

Adds an [Observer](http://en.wikipedia.org/wiki/Observer_pattern) support for the given object `el` or if the argument is empty a new observable instance is created and returned. After this the object is able to trigger and listen to events. For example:

``` js
function Car() {

  // Make Car instances observable
  riot.observable(this)

  // listen to 'start' event
  this.on('start', function() {
    // engine started
  })

}

// make a new Car instance
var car = new Car()

// trigger 'start' event
car.trigger('start')
```

@returns the given object `el` or a new observable instance

### el.on(events, callback) | #observable-on

Listen to the given space separated list of `events` and execute the `callback` each time an event is triggered.

``` js
// listen to single event
el.on('start', function() {

})

// listen to multiple events, the event type is given as the argument
el.on('start stop', function(type) {

  // type is either 'start' or 'stop'

})
```

@returns `el`

### el.one(event, callback) | #observable-one

Listen to the given `event` and execute the `callback` at most once.

``` js
// run the function once, even if 'start' is triggered multiple times
el.one('start', function() {

})
```

@returns `el`

### el.off(events) | #observable-off

Removes the given space separated list of event listeners

``` js
el.off('start stop')
```

@returns `el`

### el.off(event, fn)

Removes the given callback from the list of events

``` js
function doStart() {
  console.log('starting')
}

el.on('start', doStart)

// remove a specific listener
el.off('start', doStart)
```

@returns `el`

### el.off('*')

Removes all listeners from all event types.

@returns `el`

### el.trigger(event) | #observable-trigger

Execute all callback functions that listen to the given `event`

``` js
el.trigger('start')
```

@returns `el`

### el.trigger(event, arg1 ... argN)

Execute all callback functions that listen to the given `event`. Any number of extra parameters can be provided for the listeners.

``` js
// listen to 'start' event and expect extra arguments
el.on('start', function(engine_details, is_rainy_day) {

})

// trigger start event with extra parameters
el.trigger('start', { fuel: 89 }, true)

```

@returns `el`


text:
<!DOCTYPE html>

  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Make sample data — makeSampleData • basejump</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous" />

<link rel="stylesheet" href="../bootstrap-toc.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous" />

<link href="../pkgdown.css" rel="stylesheet">

  <link href="../extra.css" rel="stylesheet">

<meta property="og:title" content="Make sample data — makeSampleData" />
<meta property="og:description" content="Utility function that prepares metadata to be slotted into
colData()." />

      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        Toggle navigation

      </button>

        basejump
        0.12.6

  Get started

  Reference

  Changelog

Make sample data

    Source: R/AllGenerics.R, R/makeSampleData-methods.R

makeSampleData.Rd

Utility function that prepares metadata to be slotted into
colData().

makeSampleData(object, ...)

# S4 method for data.frame
makeSampleData(object)

# S4 method for DataFrame
makeSampleData(object)

Arguments

    <colgroup><col class="name" /><col class="desc" /></colgroup>

      object

Object.

      ...

Additional arguments.

Value

DataFrame.

Details

This function adheres to the following conventions:

Row names are required. Either define manually (recommended) or pass in as
a rownames column (data.table / tibble style).
Supported colnames: "sampleID", "rowname", "rn".

All column names will be converted to lower camel case
(see camelCase() for details).

sampleName column is always placed first.

Required columns:

sampleName: Human readable sample names. Note that this column is
useful for plots and doesn't have to match the column names of a
SummarizedExperiment object, which should use valid names.

Blacklisted columns:

filename (use fileName).

id.

interestingGroups. Defined automatically downstream.

sample. Too vague. Does this represent an ID or human readable name?

samplename (use sampleName).

Note

Updated 2019-10-10.

See also

makeNames.

Examples

object <- DataFrame(
    genotype = rep(c("control", "wildtype"), times = 2L),
    treatment = rep(c("vector", "RNAi"), each = 2L),
    sampleName = paste("sample", seq_len(4L)),
    row.names = paste0("GSM000000", seq_len(4L))
)
makeSampleData(object)

#> DataFrame with 4 rows and 3 columns
#>            sampleName genotype treatment
#>              <factor> <factor>  <factor>
#> GSM0000001   sample 1 control     vector
#> GSM0000002   sample 2 wildtype    vector
#> GSM0000003   sample 3 control     RNAi
#> GSM0000004   sample 4 wildtype    RNAi

Contents

Developed by Michael Steinbaugh, Acid Genomics.

Site built with pkgdown 1.5.1.


text:
"""
Digital Elevation Model Data I/O
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Provide surface/terrain elevation information from SRTM data

.. autosummary::
   :nosignatures:
   :toctree: generated/

   {}
"""
__all__ = ["download_srtm", "get_srtm", "get_srtm_tile_names"]
__doc__ = __doc__.format("\n   ".join(__all__))

import os

import numpy as np

from wradlib import util

gdal = util.import_optional("osgeo.gdal")
requests = util.import_optional("requests")

def init_header_redirect_session(token):
    class HeaderRedirection(requests.Session):
        AUTH_HOST = "urs.earthdata.nasa.gov"

        def __init__(self, token):
            super().__init__()
            self.headers.update({"Authorization": f"Bearer {token}"})

        def rebuild_auth(self, request, response):
            headers = request.headers
            url = request.url
            if "Authorization" in headers:
                original = requests.utils.urlparse(response.request.url).hostname
                redirect = requests.utils.urlparse(url).hostname
                if (
                    original != redirect
                    and redirect != self.AUTH_HOST
                    and original != self.AUTH_HOST
                ):
                    del headers["Authorization"]
            return

    return HeaderRedirection(token)

def download_srtm(filename, destination, resolution=3):
    """
    Download NASA SRTM elevation data
    Only available with login/password

    Parameters
    ----------
    filename : str
        srtm file to download
    destination : str
        output filename
    resolution : int
        resolution of SRTM data (1, 3 or 30)
    """

    website = "https://e4ftl01.cr.usgs.gov/MEASURES"
    subres = 3
    if resolution == 30:
        subres = 2
    resolution = f"SRTMGL{resolution}.00{subres}"
    source = "/".join([website, resolution, "2000.02.11"])
    url = "/".join([source, filename])
    token = os.environ.get("WRADLIB_EARTHDATA_BEARER_TOKEN", None)

    if token is None:
        raise ValueError(
            "WRADLIB_EARTHDATA_BEARER_TOKEN environment variable missing. "
            "Downloading SRTM data requires a NASA Earthdata Account and Bearer Token. "
            "To obtain a NASA Earthdata Login account, "
            "please visit https://urs.earthdata.nasa.gov/users/new/."
        )
    session = init_header_redirect_session(token)
    status_code = 0
    try:
        r = session.get(url, stream=True, timeout=5)
        r.raise_for_status()
        if destination is None:
            destination = filename
        with open(destination, "wb") as fd:
            for chunk in r.iter_content(chunk_size=1024 * 1014):
                fd.write(chunk)
    except requests.exceptions.HTTPError as err:
        status_code = err.response.status_code
        if status_code != 404:
            raise err
    except requests.exceptions.Timeout as err:
        raise err
    return status_code

def get_srtm_tile_names(extent):
    """
    Get NASA SRTM elevation data tile names

    Parameters
    ----------
    extent : list
        list containing lonmin, lonmax, latmin, latmax

    Returns
    -------
    out : list
        list of tile names
    """
    extent = [int(np.floor(x)) for x in extent]
    lonmin, lonmax, latmin, latmax = extent

    filelist = []
    for latitude in range(latmin, min(latmax, 0)):
        for longitude in range(lonmin, min(lonmax, 0)):
            tilename = f"S{-latitude:02g}W{-longitude:03g}"
            filelist.append(tilename)
        for longitude in range(max(lonmin, 0), lonmax + 1):
            tilename = f"S{-latitude:02g}E{longitude:03g}"
            filelist.append(tilename)
    for latitude in range(max(0, latmin), latmax + 1):
        for longitude in range(lonmin, min(lonmax + 1, 0)):
            tilename = f"N{latitude:02g}W{-longitude:03g}"
            filelist.append(tilename)
        for longitude in range(max(lonmin, 0), lonmax + 1):
            tilename = f"N{latitude:02g}E{longitude:03g}"
            filelist.append(tilename)
    return filelist

def get_srtm(extent, resolution=3, merge=True):
    """
    Get NASA SRTM elevation data

    Parameters
    ----------
    extent : list
        list containing lonmin, lonmax, latmin, latmax
    resolution : int
        resolution of SRTM data (1, 3 or 30)
    merge : bool
        True to merge the tiles in one dataset

    Returns
    -------
    dataset : :py:class:`gdal:osgeo.gdal.Dataset`
        gdal.Dataset Raster dataset containing elevation information
    """
    filelist = get_srtm_tile_names(extent)
    filelist = [f"{f}.SRTMGL{resolution}.hgt.zip" for f in filelist]
    wrl_data_path = util.get_wradlib_data_path()
    srtm_path = os.path.join(wrl_data_path, "geo")
    if not os.path.exists(srtm_path):
        os.makedirs(srtm_path)
    demlist = []
    for filename in filelist:
        path = os.path.join(srtm_path, filename)
        status_code = 0
        if not os.path.exists(path):
            status_code = download_srtm(filename, path, resolution)
        if status_code == 0:
            demlist.append(path)

    demlist = [gdal.Open(d) for d in demlist]
    if not merge:
        return demlist
    dem = gdal.Warp("", demlist, format="MEM")

    return dem


text:
[![Join the chat at https://gitter.im/thepropterhoc/TreeHacks_2016](https://badges.gitter.im/thepropterhoc/TreeHacks_2016.svg)](https://gitter.im/thepropterhoc/TreeHacks_2016?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Diagnosing walking disorders with accelerometers and machine learning

**Based on the original work of Dr. Matt Smuck**

![Walking correctly](https://d30y9cdsu7xlg0.cloudfront.net/png/79275-200.png)

Author : _Shelby Vanhooser_
Mentor : _Dr. Matt Smuck_

___
### Goals

***Can we diagnose patient walking disorders?***

  - Log data of walking behavior for a known distance through a smartphone
  - Using nothing but an accelerometer on the smartphone, characterize walking behaviors as _good_ or _bad_ (classification)
  - Collect enough meaningful data to distinguish between these two classes, and draw inferences about them

___
### Technologies

  - Wireless headphone triggering of sampling
  - Signal processing of collected data
  - Internal database for storing collection
  - Support Vector Machine (machine learning classification)

  -> Over the course of the weekend, I was able to test the logging abilities of the app by taking my own phone outside, placing it in my pocket after selecting the desired sampling frequency and distance I would be walking (verified by Google Maps), and triggering its logging using my wireless headphones.  This way, I made sure I was not influencing any data collected by having abnormal movements be recorded as I placed it in my pocket.

  ***_Main screen of app I designed_***
  ![Landing screen](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Screenshots/Screenshot_2.png)

  ***_The logging in action_***
  ![The logging app in action](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Screenshots/Screenshot_1.png)

  -> This way, we can go into the field, collect data from walking, and log if this behavior is 'good' or 'bad' so we can tell the difference on new data!

___
### Data

First, let us observe the time-domain samples recorded from the accelerometer:

![Raw signal recorded](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/Time_Domain.png)

It is immediately possible to see where my steps were! Very nice. Let's look at what the spectrums are like after we take the FFT...

_Frequency Spectrums of good walking behavior_
![Good walking behavior frequency spectrum](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/images/good_animated.gif)

_Frequency spectrums of bad walking behavior_
![Bad walking behavior frequency spectrum](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/images/bad_animated.gif)

19 'correct' walking samples and 5 'incorrect' samples were collected around the grounds of Stanford across reasonably flat ground with no obstacle interference.

***Let's now take these spectrums and use them as features for a machine learning classification problem***

-> Additionally, I ran numerous simulations to see what kernel in SVM would give the best output prediction accuracy:

**How many features do we need to get good prediction ability?**

_Linear kernel_
![ROC-like characterization](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/Linear_SVM_2000_Sample_FFT.png)

**Look at that characterization for so few features!**

Moving right along...

_Quadratic kernel_
![ROC-like characterization](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/Quadratic_SVM_2000_Sample_FFT.png)

Not as good as linear.  What about cubic?

_Cubic kernel_
![ROC-like characterization](https://raw.githubusercontent.com/thepropterhoc/TreeHacks_2016/master/Collected_Data/Cubic_SVM_2000_Sample_FFT.png)

Conclusion: We can get 100% cross-validated accuracy with...
***A linear kernel***

Good to know.  We can therefore predict on incoming patient data if their gait is problematic!

___
### Results

  - From analysis of the data, its structure seems to be well-defined at several key points in the spectrum.  That is, after feature selection was run on the collected samples, 11 frequencies were identified as dominating its behavior:

  **[0, 18, 53, 67, 1000, 1018, 1053, 2037, 2051, 2052, 2069]**

**_Note_** : it is curious that index 0 has been selected here, implying that the overall angle of an accelerometer on the body while walking has influence over the observed 'correctness' of gait

  - From these initial results it is clear we _can_ characterize 'correctness' of walking behavior using a smartphone application!
  - In the future, it would seem very reasonable to have a patient download an application such as this, and, using a set of known walking types from measurements taken in the field, be able to diagnose and report to an unknown patient if they have a disorder in gait.

___
### Acknowledgments

  - __Special thanks to Dr. Matt Smuck for his original work and aid in pushing this project in the correct direction__

  - __Special thanks to [Realm](https://realm.io) for their amazing database software__

  - __Special thanks to [JP Simard](https://cocoapods.org/?q=volume%20button) for his amazing code to detect volume changes for triggering this application__

  - __Special thanks to everyone who developed [Libsvm](https://www.csie.ntu.edu.tw/~cjlin/libsvm/) and for writing it in C so I could compile it in iOS__


text:
package com.dexdrip.stephenblack.nightwatch;

import retrofit.Callback;
import retrofit.http.Body;
import retrofit.http.GET;
import retrofit.http.Path;

/**
 * Created by stephenblack on 12/26/14.
 */
public interface PebbleEndpointInterface {
    @GET("/pebble")
    PebbleEndpoint getPebbleInfo();
}


text:
import { Iterable } from 'ix';
import * as React from 'react';
import { MouseEvent, MouseEventHandler } from 'react';
import { Button } from 'react-bootstrap';
import { Icon } from 'react-fa';

import { IterableLike } from '../../../WebRx';
import {
  PanelFragment,
  PanelItemContext,
  PanelItemProps,
  PanelRenderProps,
} from '../Panel/Panel';
import { ItemsPresenter, ItemsPresenterTemplateProps } from './ItemsPresenter';

export type RecursiveItemsSource<T> = (item: T) => IterableLike<T> | undefined;

export interface TreeItemSourceProps<T = {}> {
  /**
   * function to produce the recursive items source for the provided item
   */
  itemsSource: RecursiveItemsSource<T>;
}

export interface TreeItemTemplateProps<T = {}> {
  /**
   * Override the expander icon template
   * default behaviour is to render an icon using the expandedIconName and collapsedIconName
   */
  expanderIconTemplate?: (
    isExpanded: boolean,
    expandedIconName?: string,
    collapsedIconName?: string,
  ) => PanelFragment;

  /**
   * Override the header template
   * compose a custom header out of the subcomponents
   */
  headerTemplate?: (
    item: T,
    index: number,
    indent: PanelFragment[],
    expander: PanelFragment,
    headerContent: PanelFragment,
    view: TreeItem,
  ) => PanelFragment;

  /**
   * template to render each item belonging to the bound item
   * use this template to define your own items presenter template
   */
  itemsTemplate?: (
    items: IterableLike<T> | undefined,
    view: TreeItem,
  ) => PanelFragment;
}

export interface TreeItemRenderProps {
  /**
   * tree node depth (defaults to 0)
   * this should not be assigned unless defining your own itemsTemplate
   */
  depth?: number;

  /**
   * set the isExpanded intial state (modified existing state)
   */
  startExpanded?: boolean;

  /**
   * override the current expansion state (does not modify state)
   * true will override isExpanded to true, false will not override the current state
   * use a function to handle async changes in state overrides where override logic is computerd
   * outside the treeitem container component (i.e., outside the treeview).
   */
  overrideExpanded?: boolean | (() => boolean);

  /**
   * override the default expanded icon name
   * default is a '-' in a rounded square
   */
  expandedIconName?: string;

  /**
   * override the default collapsed icon name
   * default is a '+' in a rounded square
   */
  collapsedIconName?: string;

  /**
   * flag to enable clicking anywhere on the node to toggle expansion state
   */
  clickToExpand?: boolean;
}

export interface TreeItemFacadeProps<
  T = {},
  TContext extends PanelItemContext = PanelItemContext
>
  extends TreeItemSourceProps<T>,
    TreeItemTemplateProps<T>,
    TreeItemRenderProps,
    ItemsPresenterTemplateProps<T>,
    PanelItemProps<T, TContext>,
    PanelRenderProps {}

export interface TreeItemProps<
  T = {},
  TContext extends PanelItemContext = PanelItemContext
> extends TreeItemFacadeProps<T, TContext> {
  /**
   * the item that this tree node represents
   */
  item: {};

  /**
   * the index this item is found within its parent container.
   * this is necessary for key construction if no key is specified
   */
  index: number;
}

export interface TreeItemComponentProps
  extends React.HTMLProps<any>,
    TreeItemProps {}

export interface TreeItemState {
  /**
   * true if the tree item is expanded
   */
  isExpanded: boolean;
}

export class TreeItem extends React.Component<
  TreeItemComponentProps,
  TreeItemState
> {
  static defaultProps: Partial<TreeItemProps> = {
    depth: 0,
  };

  public static defaultExpandedIconName = 'minus-square-o';
  public static defaultCollapsedIconName = 'plus-square-o';

  public static generateKey(fragment: PanelFragment, index: number) {
    if (React.isValidElement(fragment) && fragment.key != null) {
      return fragment.key;
    }

    return index;
  }

  public static renderTreeItem(
    item: {},
    index: number,
    props: TreeItemFacadeProps,
  ) {
    return (
      <TreeItem
        key={index}
        item={item}
        index={index}
        itemsSource={props.itemsSource}
        expanderIconTemplate={props.expanderIconTemplate}
        headerTemplate={props.headerTemplate}
        itemsTemplate={props.itemsTemplate}
        depth={props.depth == null ? 0 : props.depth + 1}
        startExpanded={props.startExpanded}
        overrideExpanded={props.overrideExpanded}
        expandedIconName={props.expandedIconName}
        collapsedIconName={props.collapsedIconName}
        clickToExpand={props.clickToExpand}
        viewTemplate={props.viewTemplate}
        itemsPanelTemplate={props.itemsPanelTemplate}
        itemTemplate={props.itemTemplate}
        itemClassName={props.itemClassName}
        itemStyle={props.itemStyle}
        itemProps={props.itemProps}
        compact={props.compact}
        emptyContent={props.emptyContent}
      />
    );
  }

  public static defaultHeaderTemplate(
    item: {},
    index: number,
    indent: PanelFragment[],
    expander: PanelFragment,
    headerContent: PanelFragment,
    view: TreeItem,
  ) {
    return (
      <div
        className="TreeItem-Header"
        onClick={
          view.props.clickToExpand
            ? view.toggleExpansion.bind<MouseEventHandler<any>>(view)
            : undefined
        }
      >
        {indent}

{expander}

{headerContent}

    );
  }

  public static defaultItemsTemplate(
    items: IterableLike<{}> | undefined,
    view: TreeItem,
  ) {
    const isExpanded = view.getIsExpanded();

    const template = (item: {}, index: number) => {
      return TreeItem.renderTreeItem(item, index, view.props);
    };

    return isExpanded === false || items == null ? (
      false
    ) : (
      <ItemsPresenter
        itemsSource={items}
        viewTemplate={view.props.viewTemplate}
        itemsPanelTemplate={view.props.itemsPanelTemplate}
        itemTemplate={template}
        itemClassName={view.props.itemClassName}
        itemStyle={view.props.itemStyle}
        itemProps={view.props.itemProps}
        compact={view.props.compact}
        emptyContent={view.props.emptyContent}
      />
    );
  }

  public static defaultExpanderIconTemplate(
    isExpanded: boolean,
    expandedIconName = TreeItem.defaultExpandedIconName,
    collapsedIconName = TreeItem.defaultCollapsedIconName,
  ) {
    const iconName = isExpanded === true ? expandedIconName : collapsedIconName;

    return <Icon name={iconName} size="lg" fixedWidth />;
  }

  constructor(props: any) {
    super(props);

    this.toggleExpansion = this.toggleExpansion.bind(this);

    this.state = {
      isExpanded: this.props.startExpanded || false,
    };
  }

  componentWillReceiveProps(
    nextProps: Readonly<TreeItemComponentProps>,
    nextContext: any,
  ) {
    if (
      nextProps.startExpanded != null &&
      nextProps.startExpanded !== this.state.isExpanded
    ) {
      this.setState((prevState, props) => {
        // props.startExpanded should not be null (as per above) but we do a check just in case
        if (props.startExpanded == null) {
          return prevState;
        }

        return {
          isExpanded: props.startExpanded,
        };
      });
    }
  }

  render() {
    const { className, props, rest, children } = this.restProps(x => {
      const {
        item,
        index,
        itemsSource,
        expanderIconTemplate,
        headerTemplate,
        itemsTemplate,
        depth,
        startExpanded,
        overrideExpanded,
        expandedIconName,
        collapsedIconName,
        clickToExpand,
        viewTemplate,
        itemsPanelTemplate,
        itemTemplate,
        itemClassName,
        itemStyle,
        itemProps,
        compact,
        emptyContent,
      } = x;
      return {
        item,
        index,
        itemsSource,
        expanderIconTemplate,
        headerTemplate,
        itemsTemplate,
        depth,
        startExpanded,
        overrideExpanded,
        expandedIconName,
        collapsedIconName,
        clickToExpand,
        viewTemplate,
        itemsPanelTemplate,
        itemTemplate,
        itemClassName,
        itemStyle,
        itemProps,
        compact,
        emptyContent,
      };
    });

    const headerContent = this.renderHeaderContent();
    const key = TreeItem.generateKey(headerContent, this.props.index);
    const items = this.props.itemsSource(this.props.item);
    const indent = this.renderIndent();
    const expander = this.renderExpander(items);
    const header = this.renderHeader(indent, expander, headerContent);
    const treeItems = this.renderItems(items);

    return (

        {header}
        {treeItems && (

{treeItems}

        )}

    );
  }

  protected getIsExpanded() {
    if (this.props.overrideExpanded != null) {
      // if an override prop is provided, then check to see if it is set to true
      const override =
        this.props.overrideExpanded instanceof Function
          ? this.props.overrideExpanded()
          : this.props.overrideExpanded;

      if (override) {
        // override is set to true so return true for isExpanded state (overridden)
        return true;
      }
    }

    // either no override prop is provided or the override result was false
    // so fallback onto standard component state
    return this.state.isExpanded || false;
  }

  protected toggleExpansion(e: MouseEvent<any>) {
    e.stopPropagation();

    this.setState((prevState, props) => {
      return {
        isExpanded: !this.state.isExpanded,
      };
    });
  }

  protected renderIndent() {
    return Iterable.range(0, this.props.depth || 0)
      .map((x, i) => {
        return
 as
          | PanelFragment
          | false;
      })
      .defaultIfEmpty(false)
      .toArray();
  }

  protected renderExpanderIcon() {
    const template =
      this.props.expanderIconTemplate || TreeItem.defaultExpanderIconTemplate;
    const isExpanded = this.getIsExpanded();

    return template(
      isExpanded,
      this.props.expandedIconName,
      this.props.collapsedIconName,
    );
  }

  protected renderExpander(items: IterableLike<{}> | undefined) {
    const isEmpty = items == null || Iterable.from(items).isEmpty();

    return isEmpty ? (
      false
    ) : (
      <Button bsStyle="link" onClick={this.toggleExpansion}>
        {this.renderExpanderIcon()}
      </Button>
    );
  }

  protected renderHeaderContent() {
    const itemTemplate =
      this.props.itemTemplate || ItemsPresenter.defaultItemTemplate;

    return itemTemplate(this.props.item, this.props.index, this.state);
  }

  protected renderHeader(
    indent: PanelFragment[],
    expander: PanelFragment,
    headerContent: PanelFragment,
  ) {
    const template =
      this.props.headerTemplate || TreeItem.defaultHeaderTemplate;

    return template(
      this.props.item,
      this.props.index,
      indent,
      expander,
      headerContent,
      this,
    );
  }

  protected renderItems(items: IterableLike<{}> | undefined): PanelFragment {
    const template = this.props.itemsTemplate || TreeItem.defaultItemsTemplate;

    return template(items, this);
  }
}


text:
package org.kaaproject.kaa.server.common.zk;

import org.kaaproject.kaa.server.common.zk.gen.ControlNodeInfo;

/**
 * The Interface ControlNodeAware.
 */
public interface ControlNodeAware {

    /**
     * Gets the control server info.
     *
     * @return the control server info
     */
    ControlNodeInfo getControlServerInfo();

}


text:
- WeChat Account (English): wewaterloo
- 微信账号 (中文): wewaterloo_cn

WeLoo is an open WeChat plaform for University of Waterloo students, the server side is built by Team WeluuBA at 2014 Water Hackathon. The platform is providing specific searching service for university student.

微卢是一个面向滑铁卢大学学生的微信公众账号,由WeLuuBa团队成猿在2014 Water Hackathon中开发完成后台。主要提供面向大学生的信息查询服务。

## Functions 功能
- Exam Schedule Lookup 考试信息查询
- Food Services Open Hours, Menu, and Location Lookup 学校餐饮服务信息查询
- Waterloo Weather Information 滑铁卢天气信息查询
- More Functions are Developing... 更多功能开发中...

## Run on Local Machine 本地运行

```bash
git clone https://github.com/slovey528/WeLoo.git
cd WeLoo/
npm install
make start UW_API_TOKEN=TOKEN MONGO_TEST_URI=mongodb://username:password@oceanic.mongohq.com:10087/app_sample
```
Use `make start` to run `node app.js`. 使用`make start` 命令会调用 `node app.js` 。

## Message Test 消息调试

Use [`webot-cli`](https://github.com/node-webot/webot-cli) command line tool to test the message.
使用 [`webot-cli`](https://github.com/node-webot/webot-cli) 命令行工具来发送测试消息。

For more information about [wechat-robot](https://github.com/node-webot/weixin-robot) and how to [test](https://github.com/node-webot/webot-cli), please go to the github page.

## Team WeluuBA 开发者
- [Jerry Mao](http://slovey528.github.io)
- [Ken Huang](https://github.com/y88huang)
- [Elton Gao](http://gyfelton.github.io)
- [Frank Li](http://xuefei-frank.com)
- [Chao Chen](https://github.com/mellwa)
- [Irene Jiang](https://github.com/iJuliet)

## Credit
- University of Waterloo Open Data

- [weixin-robot](https://github.com/node-webot/weixin-robot),
[Original Version](https://github.com/node-webot/weixin-robot/tree/0.0.x) developed by [@ktmud](https://github.com/ktmud),
[@atian](https://github.com/atian25) refactored and finished version 0.2.

- [weixin-robot](https://github.com/node-webot/weixin-robot) used [wechat](https://github.com/node-webot/wechat) developed by [@JacksonTian](https://github.com/JacksonTian).


text:
"""
tests for quantecon.discrete_rv

@author : Spencer Lyon
@date : 2014-07-31

"""
from __future__ import division
from collections import Counter
import unittest
import numpy as np
from numpy.testing import assert_allclose
from nose.plugins.attrib import attr
import pandas as pd
from quantecon import DiscreteRV

class TestDiscreteRV(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        x = np.random.rand(10)
        x /= x.sum()
        # make sure it sums to 1
        cls.x = x
        cls.drv = DiscreteRV(cls.x)

    def test_Q_updates(self):
        "discrete_rv: Q attributes updates on q change?"
        Q_init = np.copy(self.drv.Q)

        # change q, see if Q updates
        x = np.random.rand(10)
        x /= x.sum()
        self.drv.q = x
        Q_after = self.drv.Q

        # should be different
        self.assertFalse(np.allclose(Q_init, Q_after))

        # clean up: reset values
        self.drv.q = self.x

        # now we should have our original Q back
        assert_allclose(Q_init, self.drv.Q)

    def test_Q_end_1(self):
        "discrete_rv: Q sums to 1"
        assert (self.drv.Q[-1] - 1.0 < 1e-10)

    @attr("slow")
    def test_draw_lln(self):
        "discrete_rv: lln satisfied?"
        draws = self.drv.draw(1000000)
        counts = pd.Series(Counter(draws))
        counts = (counts / counts.sum()).values
        assert max(np.abs(counts - self.drv.q)) < 1e-2


text:
package com.intellij.sh.highlighting;

import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

public class ShOccurrencesHighlightUsagesHandler extends HighlightUsagesHandlerBase<PsiElement> {
  ShOccurrencesHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file) {
    super(editor, file);
  }

  @Override
  public @NotNull List<PsiElement> getTargets() {
    return Collections.singletonList(myFile);
  }

  @Override
  protected void selectTargets(@NotNull List<? extends PsiElement> targets, @NotNull Consumer<? super List<? extends PsiElement>> selectionConsumer) {
    selectionConsumer.consume(targets);
  }

  @Override
  public void computeUsages(@NotNull List<? extends PsiElement> targets) {
    TextRange textRange = ShTextOccurrencesUtil.findTextRangeOfIdentifierAtCaret(myEditor);
    if (textRange != null) {
      CharSequence documentText = StringUtil.newBombedCharSequence(myEditor.getDocument().getImmutableCharSequence(), 3000);
      boolean hasSelection = myEditor.getCaretModel().getPrimaryCaret().hasSelection();
      ShTextOccurrencesUtil.consumeAllOccurrences(
        documentText,
        textRange.subSequence(documentText),
        !hasSelection, range -> myReadUsages.add(range));
    }
  }
}


text:
"""

=============================================================
Online Latent Dirichlet Allocation with variational inference
=============================================================

This implementation is modified from Matthew D. Hoffman's onlineldavb code
Link: http://matthewdhoffman.com/code/onlineldavb.tar
"""

# Author: Chyi-Kwei Yau
# Author: Matthew D. Hoffman (original onlineldavb implementation)

import numpy as np
import scipy.sparse as sp
from scipy.special import gammaln
import warnings

from ..base import BaseEstimator, TransformerMixin
from ..utils import (check_random_state, check_array,
                     gen_batches, gen_even_slices, _get_n_jobs)
from ..utils.validation import check_non_negative
from ..utils.extmath import logsumexp
from ..externals.joblib import Parallel, delayed
from ..externals.six.moves import xrange
from ..exceptions import NotFittedError

from ._online_lda import (mean_change, _dirichlet_expectation_1d,
                          _dirichlet_expectation_2d)

EPS = np.finfo(np.float).eps

def _update_doc_distribution(X, exp_topic_word_distr, doc_topic_prior,
                             max_iters,
                             mean_change_tol, cal_sstats, random_state):
    """E-step: update document-topic distribution.

    Parameters
    ----------
    X : array-like or sparse matrix, shape=(n_samples, n_features)
        Document word matrix.

    exp_topic_word_distr : dense matrix, shape=(n_topics, n_features)
        Exponential value of expection of log topic word distribution.
        In the literature, this is `exp(E[log(beta)])`.

    doc_topic_prior : float
        Prior of document topic distribution `theta`.

    max_iters : int
        Max number of iterations for updating document topic distribution in
        the E-step.

    mean_change_tol : float
        Stopping tolerance for updating document topic distribution in E-setp.

    cal_sstats : boolean
        Parameter that indicate to calculate sufficient statistics or not.
        Set `cal_sstats` to `True` when we need to run M-step.

    random_state : RandomState instance or None
        Parameter that indicate how to initialize document topic distribution.
        Set `random_state` to None will initialize document topic distribution
        to a constant number.

    Returns
    -------
    (doc_topic_distr, suff_stats) :
        `doc_topic_distr` is unnormalized topic distribution for each document.
        In the literature, this is `gamma`. we can calculate `E[log(theta)]`
        from it.
        `suff_stats` is expected sufficient statistics for the M-step.
            When `cal_sstats == False`, this will be None.

    """
    is_sparse_x = sp.issparse(X)
    n_samples, n_features = X.shape
    n_topics = exp_topic_word_distr.shape[0]

    if random_state:
        doc_topic_distr = random_state.gamma(100., 0.01, (n_samples, n_topics))
    else:
        doc_topic_distr = np.ones((n_samples, n_topics))

    # In the literature, this is `exp(E[log(theta)])`
    exp_doc_topic = np.exp(_dirichlet_expectation_2d(doc_topic_distr))

    # diff on `component_` (only calculate it when `cal_diff` is True)
    suff_stats = np.zeros(exp_topic_word_distr.shape) if cal_sstats else None

    if is_sparse_x:
        X_data = X.data
        X_indices = X.indices
        X_indptr = X.indptr

    for idx_d in xrange(n_samples):
        if is_sparse_x:
            ids = X_indices[X_indptr[idx_d]:X_indptr[idx_d + 1]]
            cnts = X_data[X_indptr[idx_d]:X_indptr[idx_d + 1]]
        else:
            ids = np.nonzero(X[idx_d, :])[0]
            cnts = X[idx_d, ids]

        doc_topic_d = doc_topic_distr[idx_d, :]
        # The next one is a copy, since the inner loop overwrites it.
        exp_doc_topic_d = exp_doc_topic[idx_d, :].copy()
        exp_topic_word_d = exp_topic_word_distr[:, ids]

        # Iterate between `doc_topic_d` and `norm_phi` until convergence
        for _ in xrange(0, max_iters):
            last_d = doc_topic_d

            # The optimal phi_{dwk} is proportional to
            # exp(E[log(theta_{dk})]) * exp(E[log(beta_{dw})]).
            norm_phi = np.dot(exp_doc_topic_d, exp_topic_word_d) + EPS

            doc_topic_d = (exp_doc_topic_d *
                           np.dot(cnts / norm_phi, exp_topic_word_d.T))
            # Note: adds doc_topic_prior to doc_topic_d, in-place.
            _dirichlet_expectation_1d(doc_topic_d, doc_topic_prior,
                                      exp_doc_topic_d)

            if mean_change(last_d, doc_topic_d) < mean_change_tol:
                break
        doc_topic_distr[idx_d, :] = doc_topic_d

        # Contribution of document d to the expected sufficient
        # statistics for the M step.
        if cal_sstats:
            norm_phi = np.dot(exp_doc_topic_d, exp_topic_word_d) + EPS
            suff_stats[:, ids] += np.outer(exp_doc_topic_d, cnts / norm_phi)

    return (doc_topic_distr, suff_stats)

class LatentDirichletAllocation(BaseEstimator, TransformerMixin):
    """Latent Dirichlet Allocation with online variational Bayes algorithm

    .. versionadded:: 0.17

    Read more in the :ref:`User Guide <LatentDirichletAllocation>`.

    Parameters
    ----------
    n_topics : int, optional (default=10)
        Number of topics.

    doc_topic_prior : float, optional (default=None)
        Prior of document topic distribution `theta`. If the value is None,
        defaults to `1 / n_topics`.
        In the literature, this is called `alpha`.

    topic_word_prior : float, optional (default=None)
        Prior of topic word distribution `beta`. If the value is None, defaults
        to `1 / n_topics`.
        In the literature, this is called `eta`.

    learning_method : 'batch' | 'online', default='online'
        Method used to update `_component`. Only used in `fit` method.
        In general, if the data size is large, the online update will be much
        faster than the batch update.
        The default learning method is going to be changed to 'batch' in the 0.20 release.
        Valid options::

            'batch': Batch variational Bayes method. Use all training data in
                each EM update.
                Old `components_` will be overwritten in each iteration.
            'online': Online variational Bayes method. In each EM update, use
                mini-batch of training data to update the ``components_``
                variable incrementally. The learning rate is controlled by the
                ``learning_decay`` and the ``learning_offset`` parameters.

    learning_decay : float, optional (default=0.7)
        It is a parameter that control learning rate in the online learning
        method. The value should be set between (0.5, 1.0] to guarantee
        asymptotic convergence. When the value is 0.0 and batch_size is
        ``n_samples``, the update method is same as batch learning. In the
        literature, this is called kappa.

    learning_offset : float, optional (default=10.)
        A (positive) parameter that downweights early iterations in online
        learning.  It should be greater than 1.0. In the literature, this is
        called tau_0.

    max_iter : integer, optional (default=10)
        The maximum number of iterations.

    total_samples : int, optional (default=1e6)
        Total number of documents. Only used in the `partial_fit` method.

    batch_size : int, optional (default=128)
        Number of documents to use in each EM iteration. Only used in online
        learning.

    evaluate_every : int optional (default=0)
        How often to evaluate perplexity. Only used in `fit` method.
        set it to 0 or negative number to not evalute perplexity in
        training at all. Evaluating perplexity can help you check convergence
        in training process, but it will also increase total training time.
        Evaluating perplexity in every iteration might increase training time
        up to two-fold.

    perp_tol : float, optional (default=1e-1)
        Perplexity tolerance in batch learning. Only used when
        ``evaluate_every`` is greater than 0.

    mean_change_tol : float, optional (default=1e-3)
        Stopping tolerance for updating document topic distribution in E-step.

    max_doc_update_iter : int (default=100)
        Max number of iterations for updating document topic distribution in
        the E-step.

    n_jobs : int, optional (default=1)
        The number of jobs to use in the E-step. If -1, all CPUs are used. For
        ``n_jobs`` below -1, (n_cpus + 1 + n_jobs) are used.

    verbose : int, optional (default=0)
        Verbosity level.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    Attributes
    ----------
    components_ : array, [n_topics, n_features]
        Variational parameters for topic word distribution. Since the complete
        conditional for topic word distribution is a Dirichlet,
        ``components_[i, j]`` can be viewed as pseudocount that represents the
        number of times word `j` was assigned to topic `i`.
        It can also be viewed as distribution over the words for each topic
        after normalization:
        ``model.components_ / model.components_.sum(axis=1)[:, np.newaxis]``.

    n_batch_iter_ : int
        Number of iterations of the EM step.

    n_iter_ : int
        Number of passes over the dataset.

    References
    ----------
    [1] "Online Learning for Latent Dirichlet Allocation", Matthew D. Hoffman,
        David M. Blei, Francis Bach, 2010

    [2] "Stochastic Variational Inference", Matthew D. Hoffman, David M. Blei,
        Chong Wang, John Paisley, 2013

    [3] Matthew D. Hoffman's onlineldavb code. Link:
        http://matthewdhoffman.com//code/onlineldavb.tar

    """

    def __init__(self, n_topics=10, doc_topic_prior=None,
                 topic_word_prior=None, learning_method=None,
                 learning_decay=.7, learning_offset=10., max_iter=10,
                 batch_size=128, evaluate_every=-1, total_samples=1e6,
                 perp_tol=1e-1, mean_change_tol=1e-3, max_doc_update_iter=100,
                 n_jobs=1, verbose=0, random_state=None):
        self.n_topics = n_topics
        self.doc_topic_prior = doc_topic_prior
        self.topic_word_prior = topic_word_prior
        self.learning_method = learning_method
        self.learning_decay = learning_decay
        self.learning_offset = learning_offset
        self.max_iter = max_iter
        self.batch_size = batch_size
        self.evaluate_every = evaluate_every
        self.total_samples = total_samples
        self.perp_tol = perp_tol
        self.mean_change_tol = mean_change_tol
        self.max_doc_update_iter = max_doc_update_iter
        self.n_jobs = n_jobs
        self.verbose = verbose
        self.random_state = random_state

    def _check_params(self):
        """Check model parameters."""

        if self.n_topics <= 0:
            raise ValueError("Invalid 'n_topics' parameter: %r"
                             % self.n_topics)

        if self.total_samples <= 0:
            raise ValueError("Invalid 'total_samples' parameter: %r"
                             % self.total_samples)

        if self.learning_offset < 0:
            raise ValueError("Invalid 'learning_offset' parameter: %r"
                             % self.learning_offset)

        if self.learning_method not in ("batch", "online", None):
            raise ValueError("Invalid 'learning_method' parameter: %r"
                             % self.learning_method)

    def _init_latent_vars(self, n_features):
        """Initialize latent variables."""

        self.random_state_ = check_random_state(self.random_state)
        self.n_batch_iter_ = 1
        self.n_iter_ = 0

        if self.doc_topic_prior is None:
            self.doc_topic_prior_ = 1. / self.n_topics
        else:
            self.doc_topic_prior_ = self.doc_topic_prior

        if self.topic_word_prior is None:
            self.topic_word_prior_ = 1. / self.n_topics
        else:
            self.topic_word_prior_ = self.topic_word_prior

        init_gamma = 100.
        init_var = 1. / init_gamma
        # In the literature, this is called `lambda`
        self.components_ = self.random_state_.gamma(
            init_gamma, init_var, (self.n_topics, n_features))

        # In the literature, this is `exp(E[log(beta)])`
        self.exp_dirichlet_component_ = np.exp(
            _dirichlet_expectation_2d(self.components_))

    def _e_step(self, X, cal_sstats, random_init, parallel=None):
        """E-step in EM update.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        cal_sstats : boolean
            Parameter that indicate whether to calculate sufficient statistics
            or not. Set ``cal_sstats`` to True when we need to run M-step.

        random_init : boolean
            Parameter that indicate whether to initialize document topic
            distribution randomly in the E-step. Set it to True in training
            steps.

        parallel : joblib.Parallel (optional)
            Pre-initialized instance of joblib.Parallel.

        Returns
        -------
        (doc_topic_distr, suff_stats) :
            `doc_topic_distr` is unnormalized topic distribution for each
            document. In the literature, this is called `gamma`.
            `suff_stats` is expected sufficient statistics for the M-step.
            When `cal_sstats == False`, it will be None.

        """

        # Run e-step in parallel
        random_state = self.random_state_ if random_init else None

        # TODO: make Parallel._effective_n_jobs public instead?
        n_jobs = _get_n_jobs(self.n_jobs)
        if parallel is None:
            parallel = Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1))
        results = parallel(
            delayed(_update_doc_distribution)(X[idx_slice, :],
                                              self.exp_dirichlet_component_,
                                              self.doc_topic_prior_,
                                              self.max_doc_update_iter,
                                              self.mean_change_tol, cal_sstats,
                                              random_state)
            for idx_slice in gen_even_slices(X.shape[0], n_jobs))

        # merge result
        doc_topics, sstats_list = zip(*results)
        doc_topic_distr = np.vstack(doc_topics)

        if cal_sstats:
            # This step finishes computing the sufficient statistics for the
            # M-step.
            suff_stats = np.zeros(self.components_.shape)
            for sstats in sstats_list:
                suff_stats += sstats
            suff_stats *= self.exp_dirichlet_component_
        else:
            suff_stats = None

        return (doc_topic_distr, suff_stats)

    def _em_step(self, X, total_samples, batch_update, parallel=None):
        """EM update for 1 iteration.

        update `_component` by batch VB or online VB.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        total_samples : integer
            Total umber of documents. It is only used when
            batch_update is `False`.

        batch_update : boolean
            Parameter that controls updating method.
            `True` for batch learning, `False` for online learning.

        parallel : joblib.Parallel
            Pre-initialized instance of joblib.Parallel

        Returns
        -------
        doc_topic_distr : array, shape=(n_samples, n_topics)
            Unnormalized document topic distribution.
        """

        # E-step
        _, suff_stats = self._e_step(X, cal_sstats=True, random_init=True,
                                     parallel=parallel)

        # M-step
        if batch_update:
            self.components_ = self.topic_word_prior_ + suff_stats
        else:
            # online update
            # In the literature, the weight is `rho`
            weight = np.power(self.learning_offset + self.n_batch_iter_,
                              -self.learning_decay)
            doc_ratio = float(total_samples) / X.shape[0]
            self.components_ *= (1 - weight)
            self.components_ += (weight * (self.topic_word_prior_
                                           + doc_ratio * suff_stats))

        # update `component_` related variables
        self.exp_dirichlet_component_ = np.exp(
            _dirichlet_expectation_2d(self.components_))
        self.n_batch_iter_ += 1
        return

    def _check_non_neg_array(self, X, whom):
        """check X format

        check X format and make sure no negative value in X.

        Parameters
        ----------
        X :  array-like or sparse matrix

        """
        X = check_array(X, accept_sparse='csr')
        check_non_negative(X, whom)
        return X

    def partial_fit(self, X, y=None):
        """Online VB with Mini-Batch update.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        Returns
        -------
        self
        """
        self._check_params()
        X = self._check_non_neg_array(X,
                                      "LatentDirichletAllocation.partial_fit")
        n_samples, n_features = X.shape
        batch_size = self.batch_size

        # initialize parameters or check
        if not hasattr(self, 'components_'):
            self._init_latent_vars(n_features)

        if n_features != self.components_.shape[1]:
            raise ValueError(
                "The provided data has %d dimensions while "
                "the model was trained with feature size %d." %
                (n_features, self.components_.shape[1]))

        n_jobs = _get_n_jobs(self.n_jobs)
        with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:
            for idx_slice in gen_batches(n_samples, batch_size):
                self._em_step(X[idx_slice, :],
                              total_samples=self.total_samples,
                              batch_update=False,
                              parallel=parallel)

        return self

    def fit(self, X, y=None):
        """Learn model for the data X with variational Bayes method.

        When `learning_method` is 'online', use mini-batch update.
        Otherwise, use batch update.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        Returns
        -------
        self
        """
        self._check_params()
        X = self._check_non_neg_array(X, "LatentDirichletAllocation.fit")
        n_samples, n_features = X.shape
        max_iter = self.max_iter
        evaluate_every = self.evaluate_every
        learning_method = self.learning_method
        if learning_method == None:
            warnings.warn("The default value for 'learning_method' will be "
                          "changed from 'online' to 'batch' in the release 0.20. "
                          "This warning was introduced in 0.18.",
                          DeprecationWarning)
            learning_method = 'online'

        batch_size = self.batch_size

        # initialize parameters
        self._init_latent_vars(n_features)
        # change to perplexity later
        last_bound = None
        n_jobs = _get_n_jobs(self.n_jobs)
        with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:
            for i in xrange(max_iter):
                if learning_method == 'online':
                    for idx_slice in gen_batches(n_samples, batch_size):
                        self._em_step(X[idx_slice, :], total_samples=n_samples,
                                      batch_update=False, parallel=parallel)
                else:
                    # batch update
                    self._em_step(X, total_samples=n_samples,
                                  batch_update=True, parallel=parallel)

                # check perplexity
                if evaluate_every > 0 and (i + 1) % evaluate_every == 0:
                    doc_topics_distr, _ = self._e_step(X, cal_sstats=False,
                                                       random_init=False,
                                                       parallel=parallel)
                    bound = self._perplexity_precomp_distr(X, doc_topics_distr,
                                                           sub_sampling=False)
                    if self.verbose:
                        print('iteration: %d, perplexity: %.4f'
                              % (i + 1, bound))

                    if last_bound and abs(last_bound - bound) < self.perp_tol:
                        break
                    last_bound = bound
                self.n_iter_ += 1

        # calculate final perplexity value on train set
        doc_topics_distr, _ = self._e_step(X, cal_sstats=False,
                                           random_init=False,
                                           parallel=parallel)
        self.bound_ = self._perplexity_precomp_distr(X, doc_topics_distr,
                                                     sub_sampling=False)

        return self

    def _unnormalized_transform(self, X):
        """Transform data X according to fitted model.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        Returns
        -------
        doc_topic_distr : shape=(n_samples, n_topics)
            Document topic distribution for X.
        """
        if not hasattr(self, 'components_'):
            raise NotFittedError("no 'components_' attribute in model."
                                 " Please fit model first.")

        # make sure feature size is the same in fitted model and in X
        X = self._check_non_neg_array(X, "LatentDirichletAllocation.transform")
        n_samples, n_features = X.shape
        if n_features != self.components_.shape[1]:
            raise ValueError(
                "The provided data has %d dimensions while "
                "the model was trained with feature size %d." %
                (n_features, self.components_.shape[1]))

        doc_topic_distr, _ = self._e_step(X, cal_sstats=False,
                                          random_init=False)

        return doc_topic_distr

    def transform(self, X):
        """Transform data X according to the fitted model.

           .. versionchanged:: 0.18
              *doc_topic_distr* is now normalized

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        Returns
        -------
        doc_topic_distr : shape=(n_samples, n_topics)
            Document topic distribution for X.
        """
        doc_topic_distr = self._unnormalized_transform(X)
        doc_topic_distr /= doc_topic_distr.sum(axis=1)[:, np.newaxis]
        return doc_topic_distr

    def _approx_bound(self, X, doc_topic_distr, sub_sampling):
        """Estimate the variational bound.

        Estimate the variational bound over "all documents" using only the
        documents passed in as X. Since log-likelihood of each word cannot
        be computed directly, we use this bound to estimate it.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        doc_topic_distr : array, shape=(n_samples, n_topics)
            Document topic distribution. In the literature, this is called
            gamma.

        sub_sampling : boolean, optional, (default=False)
            Compensate for subsampling of documents.
            It is used in calculate bound in online learning.

        Returns
        -------
        score : float

        """

        def _loglikelihood(prior, distr, dirichlet_distr, size):
            # calculate log-likelihood
            score = np.sum((prior - distr) * dirichlet_distr)
            score += np.sum(gammaln(distr) - gammaln(prior))
            score += np.sum(gammaln(prior * size) - gammaln(np.sum(distr, 1)))
            return score

        is_sparse_x = sp.issparse(X)
        n_samples, n_topics = doc_topic_distr.shape
        n_features = self.components_.shape[1]
        score = 0

        dirichlet_doc_topic = _dirichlet_expectation_2d(doc_topic_distr)
        dirichlet_component_ = _dirichlet_expectation_2d(self.components_)
        doc_topic_prior = self.doc_topic_prior_
        topic_word_prior = self.topic_word_prior_

        if is_sparse_x:
            X_data = X.data
            X_indices = X.indices
            X_indptr = X.indptr

        # E[log p(docs | theta, beta)]
        for idx_d in xrange(0, n_samples):
            if is_sparse_x:
                ids = X_indices[X_indptr[idx_d]:X_indptr[idx_d + 1]]
                cnts = X_data[X_indptr[idx_d]:X_indptr[idx_d + 1]]
            else:
                ids = np.nonzero(X[idx_d, :])[0]
                cnts = X[idx_d, ids]
            temp = (dirichlet_doc_topic[idx_d, :, np.newaxis]
                    + dirichlet_component_[:, ids])
            norm_phi = logsumexp(temp)
            score += np.dot(cnts, norm_phi)

        # compute E[log p(theta | alpha) - log q(theta | gamma)]
        score += _loglikelihood(doc_topic_prior, doc_topic_distr,
                                dirichlet_doc_topic, self.n_topics)

        # Compensate for the subsampling of the population of documents
        if sub_sampling:
            doc_ratio = float(self.total_samples) / n_samples
            score *= doc_ratio

        # E[log p(beta | eta) - log q (beta | lambda)]
        score += _loglikelihood(topic_word_prior, self.components_,
                                dirichlet_component_, n_features)

        return score

    def score(self, X, y=None):
        """Calculate approximate log-likelihood as score.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Document word matrix.

        Returns
        -------
        score : float
            Use approximate bound as score.
        """
        X = self._check_non_neg_array(X, "LatentDirichletAllocation.score")

        doc_topic_distr = self._unnormalized_transform(X)
        score = self._approx_bound(X, doc_topic_distr, sub_sampling=False)
        return score

    def _perplexity_precomp_distr(self, X, doc_topic_distr=None,
                                  sub_sampling=False):
        """Calculate approximate perplexity for data X with ability to accept
        precomputed doc_topic_distr

        Perplexity is defined as exp(-1. * log-likelihood per word)

        Parameters
        ----------
        X : array-like or sparse matrix, [n_samples, n_features]
            Document word matrix.

        doc_topic_distr : None or array, shape=(n_samples, n_topics)
            Document topic distribution.
            If it is None, it will be generated by applying transform on X.

        Returns
        -------
        score : float
            Perplexity score.
        """
        if not hasattr(self, 'components_'):
            raise NotFittedError("no 'components_' attribute in model."
                                 " Please fit model first.")

        X = self._check_non_neg_array(X,
                                      "LatentDirichletAllocation.perplexity")

        if doc_topic_distr is None:
            doc_topic_distr = self._unnormalized_transform(X)
        else:
            n_samples, n_topics = doc_topic_distr.shape
            if n_samples != X.shape[0]:
                raise ValueError("Number of samples in X and doc_topic_distr"
                                 " do not match.")

            if n_topics != self.n_topics:
                raise ValueError("Number of topics does not match.")

        current_samples = X.shape[0]
        bound = self._approx_bound(X, doc_topic_distr, sub_sampling)

        if sub_sampling:
            word_cnt = X.sum() * (float(self.total_samples) / current_samples)
        else:
            word_cnt = X.sum()
        perword_bound = bound / word_cnt

        return np.exp(-1.0 * perword_bound)

    def perplexity(self, X, doc_topic_distr='deprecated', sub_sampling=False):
        """Calculate approximate perplexity for data X.

        Perplexity is defined as exp(-1. * log-likelihood per word)

        .. versionchanged:: 0.19
           *doc_topic_distr* argument has been deprecated and is ignored
           because user no longer has access to unnormalized distribution

        Parameters
        ----------
        X : array-like or sparse matrix, [n_samples, n_features]
            Document word matrix.

        doc_topic_distr : None or array, shape=(n_samples, n_topics)
            Document topic distribution.
            This argument is deprecated and is currently being ignored.

            .. deprecated:: 0.19

        Returns
        -------
        score : float
            Perplexity score.
        """
        if doc_topic_distr != 'deprecated':
            warnings.warn("Argument 'doc_topic_distr' is deprecated and is "
                          "being ignored as of 0.19. Support for this "
                          "argument will be removed in 0.21.",
                          DeprecationWarning)

        return self._perplexity_precomp_distr(X, sub_sampling=sub_sampling)


text:
package org.apache.ignite.ml.math.primitives.vector;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/** */
public class VectorAttributesTest {
    /** */
    private final List<AttrCfg> attrCfgs = Arrays.asList(
        new AttrCfg("isDense", Vector::isDense,
            DenseVector.class),
        new AttrCfg("isArrayBased", Vector::isArrayBased,
            DenseVector.class),
        new AttrCfg("isSequentialAccess", Vector::isSequentialAccess,
            DenseVector.class, SparseLocalVectorSequentialAccess.class),
        new AttrCfg("guidNotNull", v -> v.guid() == null), // IMPL NOTE this is somewhat artificial
        new AttrCfg("isRandomAccess", Vector::isRandomAccess,
            DenseVector.class, SparseLocalVectorSequentialAccess.class, SparseLocalVectorRandomAccess.class),
        new AttrCfg("isDistributed", Vector::isDistributed));

    /** */
    private final List<Specification> specFixture = Arrays.asList(
        new Specification(new DenseVector(1)),
        new Specification(new DelegatingVector(new DenseVector(1)),
            DenseVector.class, "isDense", "isArrayBased", "isSequentialAccess",
            "isRandomAccess", "isDistributed"),
        new Specification(new SparseLocalVectorSequentialAccess(1)),
        new Specification(new SparseLocalVectorRandomAccess(1)),
        new Specification(new VectorizedViewMatrix(new DenseMatrix(1, 1), 0, 0, 1, 1),
            DenseVector.class, "isDense",
            "isRandomAccess", "isDistributed")); // TODO: IGNITE-5723, find out why "isSequentialAccess" fails here

    /** */
    @Test
    public void isDenseTest() {
        assertAttribute("isDense");
    }

    /** */
    @Test
    public void isArrayBasedTest() {
        assertAttribute("isArrayBased");
    }

    /** */
    @Test
    public void isSequentialAccessTest() {
        assertAttribute("isSequentialAccess");
    }

    /** */
    @Test
    public void guidTest() {
        assertAttribute("guidNotNull");
    }

    /** */
    @Test
    public void isRandomAccessTest() {
        assertAttribute("isRandomAccess");
    }

    /** */
    @Test
    public void isDistributedTest() {
        assertAttribute("isDistributed");
    }

    /** */
    private void assertAttribute(String name) {
        final AttrCfg attr = attrCfg(name);

        for (Specification spec : specFixture)
            spec.verify(attr);
    }

    /** */
    private AttrCfg attrCfg(String name) {
        for (AttrCfg attr : attrCfgs)
            if (attr.name.equals(name))
                return attr;

        throw new IllegalArgumentException("Undefined attribute " + name);
    }

    /** See http://en.wikipedia.org/wiki/Specification_pattern */
    private static class Specification {
        /** */
        private final Vector v;
        /** */
        private final Class<? extends Vector> underlyingType;
        /** */
        private final List<String> attrsFromUnderlying;
        /** */
        final String desc;

        /** */
        Specification(Vector v, Class<? extends Vector> underlyingType, String... attrsFromUnderlying) {
            this.v = v;
            this.underlyingType = underlyingType;
            this.attrsFromUnderlying = Arrays.asList(attrsFromUnderlying);
            final Class<? extends Vector> clazz = v.getClass();
            desc = clazz.getSimpleName() + (clazz.equals(underlyingType)
                ? "" : " (underlying type " + underlyingType.getSimpleName() + ")");
        }

        /** */
        Specification(Vector v) {
            this(v, v.getClass());
        }

        /** */
        void verify(AttrCfg attr) {
            final boolean obtained = attr.obtain.apply(v);

            final Class<? extends Vector> typeToCheck
                = attrsFromUnderlying.contains(attr.name) ? underlyingType : v.getClass();

            final boolean exp = attr.trueInTypes.contains(typeToCheck);

            assertEquals("Unexpected " + attr.name + " value for " + desc, exp, obtained);
        }
    }

    /** */
    private static class AttrCfg {
        /** */
        final String name;
        /** */
        final Function<Vector, Boolean> obtain;
        /** */
        final List<Class> trueInTypes;

        /** */
        AttrCfg(String name, Function<Vector, Boolean> obtain, Class... trueInTypes) {
            this.name = name;
            this.obtain = obtain;
            this.trueInTypes = Arrays.asList(trueInTypes);
        }
    }

    /** */
    private static class SparseLocalVectorSequentialAccess extends SparseVector {
        /** */
        public SparseLocalVectorSequentialAccess() {
            // No-op.
        }

        /** */
        SparseLocalVectorSequentialAccess(int size) {
            super(size, SEQUENTIAL_ACCESS_MODE);
        }
    }

    /** */
    private static class SparseLocalVectorRandomAccess extends SparseVector {
        /** */
        public SparseLocalVectorRandomAccess() {
            // No-op.
        }

        /** */
        SparseLocalVectorRandomAccess(int size) {
            super(size, RANDOM_ACCESS_MODE);
        }
    }
}


text:
package com.documents4j.conversion.msoffice;

import com.documents4j.api.DocumentType;

import java.io.File;

import org.junit.BeforeClass;

public class MicrosoftWordInaccessibilityTest extends AbstractMicrosoftOfficeInaccessibilityTest {

    public MicrosoftWordInaccessibilityTest() {
        super(new DocumentTypeProvider(MicrosoftWordDocument.DOCX_VALID,
                MicrosoftWordDocument.DOCX_CORRUPT,
                MicrosoftWordDocument.DOCX_INEXISTENT,
                DocumentType.DOCX,
                DocumentType.PDF,
                "pdf",
                true));
    }

    @BeforeClass
    public static void setUpConverter() throws Exception {
        AbstractMicrosoftOfficeConversionTest.setUp(MicrosoftWordBridge.class,
                MicrosoftWordScript.ASSERTION,
                MicrosoftWordScript.SHUTDOWN);
    }

	@Override
	public File getUserScript() {
		// TODO Auto-generated method stub
		return null;
	}
}


text:
package com.intellij.compiler.impl;

import com.intellij.codeInsight.daemon.impl.actions.AddSuppressInspectionFix;
import com.intellij.codeInsight.daemon.impl.actions.AddSuppressInspectionForClassFix;
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.HelpID;
import com.intellij.compiler.options.CompilerConfigurable;
import com.intellij.ide.errorTreeView.*;
import com.intellij.ide.util.treeView.NodeDescriptor;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.compiler.CompilerBundle;
import com.intellij.openapi.compiler.options.ExcludeEntryDescription;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vcs.FileStatusManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class CompilerErrorTreeView extends NewErrorTreeViewPanel {
  public CompilerErrorTreeView(Project project, Runnable rerunAction) {
    super(project, HelpID.COMPILER, true, true, rerunAction);
  }

  protected void fillRightToolbarGroup(DefaultActionGroup group) {
    super.fillRightToolbarGroup(group);
    group.add(new CompilerPropertiesAction());
  }

  protected void addExtraPopupMenuActions(DefaultActionGroup group) {
    group.add(new ExcludeFromCompileAction());
    group.addSeparator();
    group.add(new SuppressJavacWarningsAction());
    group.add(new SuppressJavacWarningForClassAction());
    group.addSeparator();
    ActionGroup popupGroup = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_COMPILER_ERROR_VIEW_POPUP);
    if (popupGroup != null) {
      for (AnAction action : popupGroup.getChildren(null)) {
        group.add(action);
      }
    }
  }

  protected boolean shouldShowFirstErrorInEditor() {
    return CompilerWorkspaceConfiguration.getInstance(myProject).AUTO_SHOW_ERRORS_IN_EDITOR;
  }

  private static class CompilerPropertiesAction extends AnAction {
    private static final Icon ICON_OPTIONS = IconLoader.getIcon("/general/ideOptions.png");

    public CompilerPropertiesAction() {
      super(CompilerBundle.message("action.compiler.properties.text"), null, ICON_OPTIONS);
    }

    public void actionPerformed(AnActionEvent e) {
      Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
      ShowSettingsUtil.getInstance().editConfigurable(project, CompilerConfigurable.getInstance(project));
    }
  }

  private class ExcludeFromCompileAction extends AnAction {
    public ExcludeFromCompileAction() {
      super(CompilerBundle.message("actions.exclude.from.compile.text"));
    }

    public void actionPerformed(AnActionEvent e) {
      VirtualFile file = getSelectedFile();

      if (file != null && file.isValid()) {
        ExcludeEntryDescription description = new ExcludeEntryDescription(file, false, true, myProject);
        ((CompilerConfigurationImpl) CompilerConfiguration.getInstance(myProject)).getExcludedEntriesConfiguration().addExcludeEntryDescription(description);
        FileStatusManager.getInstance(myProject).fileStatusesChanged();
      }
    }

    private VirtualFile getSelectedFile() {
      final ErrorTreeElement selectedElement = getSelectedErrorTreeElement();
      if (selectedElement == null) return null;

      String filePresentableText = getSelectedFilePresentableText(selectedElement);

      if (filePresentableText == null) return null;

      return LocalFileSystem.getInstance().findFileByPath(filePresentableText.replace('\\', '/'));
    }

    private String getSelectedFilePresentableText(final ErrorTreeElement selectedElement) {
      String filePresentableText = null;

      if (selectedElement instanceof GroupingElement) {
        GroupingElement groupingElement = (GroupingElement)selectedElement;
        filePresentableText = groupingElement.getName();
      }
      else {
        NodeDescriptor parentDescriptor = getSelectedNodeDescriptor().getParentDescriptor();
        if (parentDescriptor instanceof ErrorTreeNodeDescriptor) {
          ErrorTreeNodeDescriptor treeNodeDescriptor = (ErrorTreeNodeDescriptor)parentDescriptor;
          ErrorTreeElement element = treeNodeDescriptor.getElement();
          if (element instanceof GroupingElement) {
            GroupingElement groupingElement = (GroupingElement)element;
            filePresentableText = groupingElement.getName();
          }
        }

      }
      return filePresentableText;
    }

    public void update(AnActionEvent e) {
      final Presentation presentation = e.getPresentation();
      final boolean isApplicable = getSelectedFile() != null;
      presentation.setEnabled(isApplicable);
      presentation.setVisible(isApplicable);
    }
  }

  private class SuppressJavacWarningsAction extends AnAction {
    public void actionPerformed(final AnActionEvent e) {
      final NavigatableMessageElement messageElement = (NavigatableMessageElement)getSelectedErrorTreeElement();
      final String[] text = messageElement.getText();
      final String id = text[0].substring(1, text[0].indexOf("]"));
      final AddSuppressInspectionFix suppressInspectionFix = getSuppressAction(id);
      final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
      assert project != null;
      final OpenFileDescriptor navigatable = (OpenFileDescriptor)messageElement.getNavigatable();
      final PsiFile file = PsiManager.getInstance(project).findFile(navigatable.getFile());
      assert file != null;
      CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            public void run() {
              try {
                suppressInspectionFix.invoke(project, null, file.findElementAt(navigatable.getOffset()));
              }
              catch (IncorrectOperationException e1) {
                LOG.error(e1);
              }
            }
          });
        }
      }, suppressInspectionFix.getText(), null);
    }

    @Override
    public void update(final AnActionEvent e) {
      final Presentation presentation = e.getPresentation();
      presentation.setVisible(false);
      presentation.setEnabled(false);
      final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
      if (project == null) return;
      final ErrorTreeElement errorTreeElement = getSelectedErrorTreeElement();
      if (errorTreeElement instanceof NavigatableMessageElement) {
        final NavigatableMessageElement messageElement = (NavigatableMessageElement)errorTreeElement;
        final String[] text = messageElement.getText();
        if (text.length > 0) {
          if (text[0].startsWith("[") && text[0].indexOf("]") != -1) {
            presentation.setVisible(true);
            final Navigatable navigatable = messageElement.getNavigatable();
            if (navigatable instanceof OpenFileDescriptor) {
              final OpenFileDescriptor fileDescriptor = (OpenFileDescriptor)navigatable;
              final VirtualFile virtualFile = fileDescriptor.getFile();
              final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
              if (module == null) return;
              final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
              if (jdk == null) return;
              final boolean is_1_5 = JavaSdk.getInstance().compareTo(jdk.getVersionString(), "1.5") >= 0;
              if (!is_1_5) return;
              final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
              if (psiFile == null) return;
              if (LanguageLevelUtil.getEffectiveLanguageLevel(module).compareTo(LanguageLevel.JDK_1_5) < 0) return;
              final PsiElement context = psiFile.findElementAt(fileDescriptor.getOffset());
              if (context == null) return;
              final String id = text[0].substring(1, text[0].indexOf("]"));
              final AddSuppressInspectionFix suppressInspectionFix = getSuppressAction(id);
              final boolean available = suppressInspectionFix.isAvailable(project, null, context);
              presentation.setEnabled(available);
              if (available) {
                presentation.setText(suppressInspectionFix.getText());
              }
            }
          }
        }
      }
    }

    protected AddSuppressInspectionFix getSuppressAction(final String id) {
      return new AddSuppressInspectionFix(id) {
        @Override
        @SuppressWarnings({"SimplifiableIfStatement"})
        public boolean isAvailable(@NotNull final Project project, final Editor editor, @Nullable final PsiElement context) {
          if (getContainer(context) instanceof PsiClass) return false;
          return super.isAvailable(project, editor, context);
        }

        @Override
        protected boolean use15Suppressions(final PsiDocCommentOwner container) {
          return true;
        }
      };
    }
  }

  private class SuppressJavacWarningForClassAction extends SuppressJavacWarningsAction {
    @Override
    protected AddSuppressInspectionFix getSuppressAction(final String id) {
      return new AddSuppressInspectionForClassFix(id){
        @Override
        protected boolean use15Suppressions(final PsiDocCommentOwner container) {
          return true;
        }
      };
    }
  }
}