def create(cls, name, groupby, realm, duration, resolution='auto', filterexpr=None, interface=False, **kwargs): logger.debug('Creating ProfilerTable table %s (%s) - %s/%s' % (name, duration, groupby, realm)) options = TableOptions(groupby=groupby, realm=realm, centricity='int' if interface else 'hos') t = Table(name=name, module=__name__, filterexpr=filterexpr, options=options, **kwargs) t.save() if resolution != 'auto': if isinstance(resolution, int): res = resolution else: res = int(timedelta_total_seconds(parse_timedelta(resolution))) resolution = rvbd.profiler.report.Report.RESOLUTION_MAP[res] if isinstance(duration, int): duration = "%d min" % duration fields_add_device_selection(t, keyword='profiler_device', label='Profiler', module='profiler', enabled=True) fields_add_time_selection(t, initial_duration=duration) fields_add_filterexpr(t) fields_add_resolution(t, initial=resolution, resolutions=[('auto', 'Automatic'), '1min', '15min', 'hour', '6hour'], special_values=['auto']) return t
def create(cls, name, duration='1m', durations=None, resolution='1m', resolutions=None, aggregated=False, filterexpr=None, sortcol=None): """ Create a Shark table. `duration` is in minutes """ logger.debug('Creating Shark table %s (%s)' % (name, duration)) options = TableOptions(aggregated=aggregated) t = Table(name=name, module=__name__, filterexpr=filterexpr, options=options, sortcol=sortcol) t.save() if durations is None: durations = ['1m', '15m'] if isinstance(duration, int): duration = "%dm" % duration if resolutions is None: resolutions = ['1s', '1m'] fields_add_device_selection(t, keyword='shark_device', label='Shark', module='shark', enabled=True) TableField.create(keyword='shark_source_name', label='Source', obj=t, field_cls=forms.ChoiceField, parent_keywords=['shark_device'], dynamic=True, pre_process_func=Function(shark_source_name_choices)) fields_add_time_selection(t, initial_duration=duration, durations=durations) fields_add_resolution(t, initial=resolution, resolutions=resolutions) fields_add_filterexpr(t) return t
def fields_add_business_hour_fields(report, default_start='8:00am', default_end='5:00pm', default_timezone='US/Eastern', default_weekends=False): fields_add_time_selection(report, initial_duration="1 week") TIMES = ['%d:00am' % h for h in range(1, 13)] TIMES.extend(['%d:00pm' % h for h in range(1, 13)]) business_hours_start = TableField( keyword='business_hours_start', label='Start Business', initial=default_start, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(TIMES, TIMES)}, required=True) business_hours_start.save() report.fields.add(business_hours_start) business_hours_end = TableField( keyword='business_hours_end', label='End Business', initial=default_end, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(TIMES, TIMES)}, required=True) business_hours_end.save() report.fields.add(business_hours_end) business_hours_tzname = TableField(keyword='business_hours_tzname', label='Business Timezone', initial=default_timezone, field_cls=forms.ChoiceField, field_kwargs={ 'choices': zip(pytz.common_timezones, pytz.common_timezones) }, required=True) business_hours_tzname.save() report.fields.add(business_hours_tzname) business_hours_weekends = TableField(keyword='business_hours_weekends', field_cls=forms.BooleanField, label='Business includes weekends', initial=default_weekends, required=False) business_hours_weekends.save() report.fields.add(business_hours_weekends)
def create(cls, name, options, duration='1h', resolution='1min', **kwargs): # Create the table object and save it t = BaseTable(name=name, module=__name__, options=options, **kwargs) t.save() # # Add criteria fields that are required by this table # # Add a device selection criteria to the table, # listing only devices from sample_device module that are # enabled fields_add_device_selection(t, keyword='sample_device', label='Sample', module='sample_device', enabled=True) # Add a time selection field fields_add_time_selection(t, initial_duration=duration) # Add a time resolution field fields_add_resolution(t, initial=resolution, resolutions=[('auto', 'Automatic'), '1sec', '1min', '15min', 'hour', '6hour'], special_values=['auto']) # Add a custom field TableField.create( obj=t, keyword='min', initial=-100, label='Min value', help_text=('Clip all wave forms at this minimum value'), required=False) # Add a custom field TableField.create( obj=t, keyword='max', initial=100, label='Max value', help_text=('Clip all wave forms at this maximum value'), required=False) return t
def create(cls, name, options, duration="1h", resolution="1min", **kwargs): # Create the table object and save it t = BaseTable(name=name, module=__name__, options=options, **kwargs) t.save() # # Add criteria fields that are required by this table # # Add a device selection criteria to the table, # listing only devices from sample_device module that are # enabled fields_add_device_selection(t, keyword="sample_device", label="Sample", module="sample_device", enabled=True) # Add a time selection field fields_add_time_selection(t, initial_duration=duration) # Add a time resolution field fields_add_resolution( t, initial=resolution, resolutions=[("auto", "Automatic"), "1sec", "1min", "15min", "hour", "6hour"], special_values=["auto"], ) # Add a custom field TableField.create( obj=t, keyword="min", initial=-100, label="Min value", help_text=("Clip all wave forms at this minimum value"), required=False, ) # Add a custom field TableField.create( obj=t, keyword="max", initial=100, label="Max value", help_text=("Clip all wave forms at this maximum value"), required=False, ) return t
def fields_add_business_hour_fields(obj, initial_business_hours_start='8:00am', initial_business_hours_end='5:00pm', initial_business_hours_tzname='US/Eastern', initial_business_hours_weekends=False, **kwargs): kwargs['initial_duration'] = kwargs.get('initial_duration', '1w') fields_add_time_selection(obj, **kwargs) TIMES = ['%d:00am' % h for h in range(1, 13)] TIMES.extend(['%d:00pm' % h for h in range(1, 13)]) business_hours_start = TableField(keyword='business_hours_start', label='Start Business', initial=initial_business_hours_start, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(TIMES, TIMES)}, required=True) business_hours_start.save() obj.fields.add(business_hours_start) business_hours_end = TableField(keyword='business_hours_end', label='End Business', initial=initial_business_hours_end, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(TIMES, TIMES)}, required=True) business_hours_end.save() obj.fields.add(business_hours_end) business_hours_tzname = TableField(keyword='business_hours_tzname', label='Business Timezone', initial=initial_business_hours_tzname, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(pytz.common_timezones, pytz.common_timezones)}, required=True) business_hours_tzname.save() obj.fields.add(business_hours_tzname) business_hours_weekends = TableField(keyword='business_hours_weekends', field_cls=forms.BooleanField, label='Business includes weekends', initial=initial_business_hours_weekends, required=False) business_hours_weekends.save() obj.fields.add(business_hours_weekends)
def create(cls, name, template_id, duration, resolution='auto', filterexpr=None, **kwargs): """ Create a ProfilerTemplateTable. This queries a Profiler saved report template rather than creating a new report from scratch. `template_id` is a saved-report template ID `duration` is in minutes or a string like '15min' """ logger.debug('Creating ProfilerTemplateTable table %s (%s) - %s/%s' % (name, template_id, duration, resolution)) options = TableOptions(template_id=template_id) t = Table(name=name, module=__name__, filterexpr=filterexpr, options=options, **kwargs) t.save() if resolution != 'auto': if isinstance(resolution, int): res = resolution else: res = int(timedelta_total_seconds(parse_timedelta(resolution))) resolution = rvbd.profiler.report.Report.RESOLUTION_MAP[res] if isinstance(duration, int): duration = "%d min" % duration fields_add_device_selection(t, keyword='profiler_device', label='Profiler', module='profiler', enabled=True) fields_add_time_selection(t, initial_duration=duration) fields_add_filterexpr(t) fields_add_resolution(t, initial=resolution, resolutions=[('auto', 'Automatic'), '1min', '15min', 'hour', '6hour'], special_values=['auto']) return t
from rvbd_portal.apps.report.models import Report, Section import rvbd_portal.apps.report.modules.raw as raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.tests.reports import criteria_functions as funcs report = Report(title='Criteria Time Selection' ) report.save() section = Section(report=report, title='Section 0') section.save() table = AnalysisTable.create('test-criteria-timeselection', tables={}, func = funcs.analysis_echo_criteria) fields_add_time_selection(table, initial_duration='1 day') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection, fields_add_resolution from . import synthentic_functions as funcs # Report report = Report(title='Synthetic No Resampling' ) report.save() # Section section = Section(report=report, title='Section 0') section.save() # Table table = AnalysisTable.create('test-synthetic-noresampling', tables={}, func = funcs.analysis_echo_criteria) fields_add_time_selection(table) fields_add_resolution(table) Column.create(table, 'time', 'Time', iskey=True, isnumeric=True, datatype='time') Column.create(table, 'value', 'Value', isnumeric=True) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection, fields_add_resolution # Report from rvbd_portal.apps.report.tests.reports import synthetic_functions as funcs report = Report(title='Synthetic No Resampling' ) report.save() # Section section = Section(report=report, title='Section 0') section.save() # Table table = AnalysisTable.create('test-synthetic-resampling', tables={}, func = funcs.analysis_generate_data, resample = True, params = {'source_resolution': 60 }) fields_add_time_selection(table) fields_add_resolution(table) Column.create(table, 'time', 'Time', iskey=True, isnumeric=True, datatype='time') Column.create(table, 'value', 'Value', isnumeric=True) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.report.models import Report, Section import rvbd_portal.apps.report.modules.raw as raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.tests.reports import criteria_functions as funcs report = Report(title='Criteria Time Selection') report.save() section = Section(report=report, title='Section 0') section.save() table = AnalysisTable.create('test-criteria-timeselection', tables={}, func=funcs.analysis_echo_criteria) fields_add_time_selection(table, initial_duration='1 day') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table')