# Copyright (c) 2015 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License").  This software is distributed "AS IS"
# as set forth in the License.

import steelscript.appfwk.apps.datasource.modules.analysis as analysis
from steelscript.appfwk.apps.report.models import Report
from steelscript.appfwk.apps.datasource.models import Column
import steelscript.appfwk.apps.report.modules.tables as tables
import steelscript.appfwk.apps.report.modules.c3 as c3

import steelscript.wave.appfwk.datasources.wave_source as wave

#
# Sample WaveGenerator report
#

report = Report.create("Wave Report", position=12)

report.add_section()

#
# Define a waves table with 3 separate waves.
#
table = wave.WaveTable.create(
    name='wave-table', duration='15min', resolution='1s', beta=4)

# Add columns for time and the related waves
table.add_column('time', 'Time', datatype=Column.DATATYPE_TIME, iskey=True)
table.add_column('sin1', 'Sine Wave 1', func='sin', period='5min', alpha=3)
table.add_column('sin2', 'Sine Wave 2', func='sin', period='8min', alpha=10)
table.add_column('cos',  'Cosine Wave', func='cos', period='3min', alpha=2.5)

# Bind the table to a widget for display
report.add_widget(c3.TimeSeriesWidget, table, "Waves", width=12)

#
# Define a clipped version of the above table.  The function
# func_wave_table_limits processes the rows and clips to
# the criteria parameters 'min' and 'max'
#
clipped_table = wave.ClippedWaveTable.create(
    name='clipped-wave-table', tables={'waves': table})

# Bind to a timeseries widget
report.add_widget(c3.TimeSeriesWidget, clipped_table,
                  "Clipped Waves", width=12)

#
# Define a criteria table that just displays all criteria for a
# given report run
#
table = analysis.CriteriaTable.create('wave-criteria')
report.add_widget(tables.TableWidget, table, "Report Criteria",
                  width=12, height=200)
